genbank parsing using perl
1
0
Entering edit mode
3.7 years ago

I have genbank file. and want to retrieve relevant information. the problem is when the code fetches data related to product, it considers only one line information. since the while loop read data line by line.

#! /usr/local/bin/perl -w

open (GB,"$ARGV[0]"); open (AC, ">$ARGV[1]");

print AC "Locus_Tag\tProtein_ID\tProduct\tDB_Xref\n";

#print "Locus\tLength\tSequence name\tGI\tOrganism\tGene\tCDS\tTranslation\n";
while (<GB>)
{
if (/(\/locus_tag=")(.*)(")/)
{
print AC "\n$2\t"; } elsif (/(\/protein_id=")(.*)(")/) { print AC "$2\t";
}
#elsif (/(\/strain=")(.*)(")/)
#{
#  print AC "$2\t"; # } elsif (/(\/product=")(.*?)(")/) { print AC "$2\t";
}
elsif (/(\/db_xref=")(.*)(")/)
{
print AC "$2"; } # elsif (/(\/translation=")(.*)(")/) # { # print AC "$2\t";
#}

# elsif (/(\/db_xref="UniProtKB)(.*)(")/)
# {
#print "\$3\t";
#}
else
{
# Skip this data
}
}
close AC;

close GB;


and if the product is mention in multiple line like this.

gene            171455..172330
/locus_tag="A1S_0148"
CDS             171455..172330
/locus_tag="A1S_0148"
/codon_start=1
/transl_table=11
/product="membrane-bound ATP synthase F0 sector, subunit
a"


how to retrieve multiline data.

genome parse genbank file • 1.5k views
0
Entering edit mode
3.7 years ago

Don't use a handwritten parser, use Bio::DB::Genbank instead.

0
Entering edit mode

i want to use this program. Just wanted to get complete product name but could not fetch with this regex.

0
Entering edit mode

Genbank is a notoriously difficult format to handle computationally. BioPerl has all of the tools you need to retrieve the product/feature fully. I don't know perl well, but it will probably take about 10 lines of code.

0
Entering edit mode

But my code works well with the single line data of genbank file. Anyways, thanks for reply.

0
Entering edit mode

Your code does not work correctly and causes problems or the format does, as you have experienced, therefore there is no good reason of using it. 'I want' is not a good argument in this case. If you want to look how to parse it correctly the only thing I could recommend is to look into the code of the perl package.