Have you looked into
Bioperl? It will simplify parsing for you (especially for the sequence itself). Here's a program that gets the sequence and some other basic information:
#!/usr/local/bin/perl -w
use strict;
use Bio::SeqIO;
my $seqobj;
print "please type in the name of a file\n";
my $file = <STDIN>;
my $seqio = Bio::SeqIO->new (-format => 'GenBank',
-file => $file);
while ($seqobj = $seqio->next_seq())
{
printf "Sequence: %s\n",$seqobj->seq;
# I'm not sure what you need other than the
# sequence - here's some examples:
printf "Display ID: %s\n",$seqobj->display_id;
printf "Description: %s\n",$seqobj->desc;
printf "Division: %s\n",$seqobj->division;
printf "Accession: %s\n",$seqobj->accession;
}
In your program, you're putting all of the non-sequence lines into @annotation. I'm not sure specifically which information you need (i.e. descriprtion, accession number, etc.), but those are all accessible through the "$seqobj" object. There's some examples in the code above; you'll find many more in the documentation.
This method also has the advantage of being able to handle multiple GenBank records per file.
This is just a tiny portion of the functions available with BioPerl - it will also parse BLAST files, perform alignments, etc. If you're interested, you can grab the latest release from CPAN or from BioPerl
here. Hope this helps!
-
robsv
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.