분석 은행일:을 얻을 로커 태그 vs 상품
문제
기본적으로,은행 파일로 구성되어 있에 유전자 항목(이 발표한'진'다음에 해당하는'CD'항목이(단당 하나의 유전자)다음과 같은 두 가지가 여기에 표시오.내 locus_tag 대에서 제품의 탭으로 구분된 두 개의 열은 파일입니다.'유전자'와'CD'는 항상 앞이나 뒤에 공간이 있습니다.
문제는 것 같기 때문에'제품'은 때로는'/'캐릭터 내부에 그 이름은,그것 가지고는 충돌과 함께 이 스크립트는 것으로,지금까지 이해할 수 있고,사용하고'/'으로 구분한 정보를 저장에서 배열?
나는 이것을 해결할을 수정하거나 이 스크립트나 건물 다른 하나입니다.
perl -nE'
BEGIN{ ($/, $") = ("CDS", "\t") }
say "@r[0,1]" if @r= m!/(?:locus_tag|product)="(.+?)"!g and @r>1
' file
gene complement(8972..9094)
/locus_tag="HAPS_0004"
/db_xref="GeneID:7278619"
CDS complement(8972..9094)
/locus_tag="HAPS_0004"
/codon_start=1
/transl_table=11
/product="hypothetical protein"
/protein_id="YP_002474657.1"
/db_xref="GI:219870282"
/db_xref="GeneID:7278619"
/translation="MYYKALAHFLPTLSTMQNILSKSPLSLDFRLLFLAFIDKR"
gene 68..637
/locus_tag="HPNK_00040"
CDS 68..637
/locus_tag="HPNK_00040"
/codon_start=1
/transl_table=11
/product="NinG recombination protein/bacteriophage lambda
NinG family protein"
/protein_id="CRESA:HPNK_00040"
/translation="MIKPKVKKRKCKCCGGEFKSADSFRKWCSAECGVKLAKIAQEKA
RQKAIEKRNREERAKIKATRERLKSRSEWLKDAQAIFNEYIRLRDKDEPCISCRRFHQ
GQYHAGHYRTVKAMPELRFNEDNVHKQCSACNNHLSGNITEYRINLVRKIGAERVEAL
ESYHPPVKWSVEDCKEIIKTYRAKIKELK"
해결책
당신의 견본으로 은행 파일이 불완전하고,제가 갔을 찾기 위해 온라인 샘플 파일에서 사용할 수 있는 예를 들어,그리고 내가 발견 이 파일.
이 코드를 사용하여과 Bio::GenBankParser
모듈,그것은 분석 시작 부분의 구조가 당신이 있었습니다.이 경우에는"기능"을 포함한 모두 locus_tag
분야 product
다.
use strict;
use warnings;
use feature 'say';
use Bio::GenBankParser;
my $file = shift;
my $parser = Bio::GenBankParser->new( file => $file );
while ( my $seq = $parser->next_seq ) {
my $feat = $seq->{'FEATURES'};
for my $f (@$feat) {
my $tag = $f->{'feature'}{'locus_tag'};
my $prod = $f->{'feature'}{'product'};
if (defined $tag and defined $prod) {
say join "\t", $tag, $prod;
}
}
}
사용법:
perl script.pl input.txt > output.txt
출력:
MG_001 DNA polymerase III, beta subunit
MG_470 CobQ/CobB/MinD/ParA nucleotide binding domain-containing protein
출력에서 당신의 하나-라이너에 대한 동일한 입력 것:
MG_001 DNA polymerase III, beta subunit
MG_470 CobQ/CobB/MinD/ParA nucleotide binding
domain-containing protein
가정의 코스는 추가 /s
수정하는 정규 표현식을 계정에 대한 여러 항목(는 leeduhem 에서 지적 댓글):
m!/(?:locus_tag|product)="(.+?)"!sg
# ^---- this
다른 팁
Having read your duplicated question http://www.biostars.org/p/94164/ (please don't double post like this), here's a minimal Biopython answer:
import sys
from Bio import SeqIO
filename = sys.argv[1] # Takes first command line argument input filename
for record in SeqIO.parse(filename, "genbank"):
for feature in record.features:
if feature.type == "CDS":
locus_tag = feature.qualifiers.get("locus_tag", ["???"])[0]
product = feature.qualifiers.get("product", ["???"])[0]
print("%s\t%s" % (locus_tag, product))
With minor changes you can write this out to a file instead.