From what you describe, it doesn't appear that a general solution is necessary in terms of parsing this - you only are asking for 2 parameters. I would keep it simple and add more complex stuff when needed. You don't say whether there are multiple records like this in the file or whether this is some kind of "header per file". If there are multiple records like this in the file, then some modifications are needed.
But basically look for the keywords and if found, use split to extract either the 2nd thing on the line or the last thing on the line. All sorts of complex things are possible, but if you don't need them, then don't do it!
#!/usr/bin/perl -w
use strict;
my $protname;
my $rna;
while (<DATA>) #while (<PROTEIN>) in your case
{
if (/^VERSION/)
{
$protname = (split)[1];
}
elsif (/^DBSOURCE/)
{
$rna = (split)[-1];
}
}
print "protname = $protname\n";
print "rna = $rna\n";
__END__
PRINTS:
protname = YP_001648463.1
rna = NC_010202.1
__DATA__
LOCUS YP_001648463 258 aa linear INV 17
+-JUN-2009
DEFINITION cytochrome c oxidase subunit II [Ephydatia muelleri].
ACCESSION YP_001648463
VERSION YP_001648463.1 GI:164420795
DBLINK Project: 28177
DBSOURCE REFSEQ: accession NC_010202.1
KEYWORDS .
....
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.