Parsing GenBank file

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-15 10:58:05

问题


Basically, a GenBank file consists on gene entries (announced by 'gene' followed by its corresponding 'CDS' entry (only one per gene) like the two I show here below. I would like to get locus_tag vs product in a tab-delimited two column file. 'gene' and 'CDS' are always preceded and followed by spaces. If this task can be easily performed using an already available tool, please let me know.

Input 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            9632..11416
                 /gene="frdA"
                 /locus_tag="HAPS_0005"
                 /db_xref="GeneID:7278620"
 CDS             9632..11416
                 /gene="frdA"
                 /locus_tag="HAPS_0005"
                 /note="part of four member fumarate reductase enzyme
                 complex FrdABCD which catalyzes the reduction of fumarate
                 to succinate during anaerobic respiration; FrdAB are the
                 catalytic subcomplex consisting of a flavoprotein subunit
                 and an iron-sulfur subunit, respectively; FrdCD are the
                 membrane components which interact with quinone and are
                 involved in electron transfer; the catalytic subunits are
                 similar to succinate dehydrogenase SdhAB"
                 /codon_start=1
                 /transl_table=11
                 /product="fumarate reductase flavoprotein subunit"
                 /protein_id="YP_002474658.1"
                 /db_xref="GI:219870283"
                 /db_xref="GeneID:7278620"
                 /translation="MQTVNVDVAIVGAGGGGLRAAIAAAEANPNLKIALISKVYPMRS
                 HTVAAEGGAAAVAKEEDSYDKHFHDTVAGGDWLCEQDVVEYFVEHSPVEMTQLERWGC
                 PWSRKADGDVNVRRFGGMKIERTWFAADKTGFHLLHTLFQTSIKYPQIIRFDEHFVVD
                 ILVDDGQVRGCVAMNMMEGTFVQINANAVVIATGGGCRAYRFNTNGGIVTGDGLSMAY
                 RHGVPLRDMEFVQYHPTGLPNTGILMTEGCRGEGGILVNKDGYRYLQDYGLGPETPVG
                 KPENKYMELGPRDKVSQAFWQEWRKGNTLKTAKGVDVVHLDLRHLGEKYLHERLPFIC
                 ELAQAYEGVDPAKAPIPVRPVVHYTMGGIEVDQHAETCIKGLFAVGECASSGLHGANR
                 LGSNSLAELVVFGKVAGEMAAKRAVEATARNQAVIDAQAKDVLERVYALARQEGEESW
                 SQIRNEMGDSMEEGCGIYRTQESMEKTVAKIAELKERYKRIKVKDSSSVFNTDLLYKI
                 ELGYILDVAQSISSSAVERKESRGAHQRLDYVERDDVNYLKHTLAFYNADGTPTIKYS
                 DVKITKSQPAKRVYGAEAEAQEAAAKKE"

Desired output (locus_tag vs product in a tab-delimited two columnfile):

HAPS_0004 hypothetical protein
HAPS_0005 fumarate reductase flavoprotein subunit

In fact, having this output would be ideal, one line for each gene (shown for only one gene):

 locus_tag="HAPS_0004" db_xref="GeneID:7278619" complement(8972..9094) codon_start=1 transl_table=11 product="hypothetical protein" protein_id="YP_002474657.1" db_xref="GI:219870282" db_xref="GeneID:7278619" translation="MYYKALAHFLPTLSTMQNILSKSPLSLDFRLLFLAFIDKR"

回答1:


perl -nE'
  BEGIN{ ($/, $") = ("CDS", "\t") }
  say "@r[0,1]" if @r= m!/(?:locus_tag|product)="(.+?)"!g and @r>1
' file

output

HAPS_0004       hypothetical protein
HAPS_0005       fumarate reductase flavoprotein subunit


来源:https://stackoverflow.com/questions/21888945/parsing-genbank-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!