Entering edit mode
7.2 years ago
sharmatina189059
▴
110
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.
i want to use this program. Just wanted to get complete product name but could not fetch with this regex.
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.But my code works well with the single line data of genbank file. Anyways, thanks for reply.
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.
This was an unhelpful comment if there ever was one. Github indicates that the bioperl converter has had many bugs patched since the time this comment was posted and still fails to properly handle chromosomes with repeated genes nearly six years later (which is how I came across this thread). Even the tools NCBI uses to convert their genbanks to GFF work better than the bioperl script, a shame we cannot access them.
I agree that this answer wasn't really helpful and I apologize for not meeting the user's expectations and for any confusion caused. I should have at least provided a working code example and also should have asked for a reproducible input example. For the sake of completeness, I will add a code example to the original answer.
Also, it should have been mentioned that the reason for the OP's program not working as intended is that it parses the input statelessly in a line-by-line mode. That way, it is difficult to parse multi-line blocks, because a line will not contain a complete block. An option would be to read complete records into memory and then use regex modifier /m or /s to parse multi-line regex, e.g.:
/(\/product=")(.*?)"/m
. Another option would be to implement a simple state automaton and read ahead upon entering a multi-line block.