There must be some sub contained with all the bio Perl modules that does this, but the format is simple and here is a parser for you. I didn't parse the older format that starts with ;. But you can add that if needed. See Wiki FASTA format. Blank lines between sequences are optional as well as ending a sequence with a '*';
#!/usr/bin/perl -w use strict; use Data::Dump qw(pp); my %sequences; my $line; my $skip_read=0; while ($skip_read or defined ($line = <DATA>) ) { chomp $line; my ($id) = $line =~ /^\>(\w+)/; ($skip_read, $line) = finish_record($id,\%sequences) if ( defined +$id); } sub finish_record { my ($id, $seqHashRef) = @_; my $line; while (defined ($line = <DATA>) and $line !~ m/^\s*$/ and $line !~ m/^\>/) { chomp $line; if ($line =~ /\*$/) { $line =~ s/\*$//; $seqHashRef->{$id}.= $line; return 0; } $seqHashRef->{$id}.= $line; } print "$line\n" if defined $line; return (1, $line) if (defined ($line) and $line =~ m/^\>/); return 0; } print pp(\%sequences); =prints { MCHU => "ADQLTEEQIAEFKEAFSLFDKDGDGT....", gi => "LCLYTHIGRNIYYGSYLYSETWNTGI....", } =cut __DATA__ >MCHU - Calmodulin - Human, rabbit, bovine, rat, and chicken ADQLTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMINEVDADGNGTID DIDGDGQVNYEEFVQMMTAK* >gi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus] LCLYTHIGRNIYYGSYLYSETWNTGIMLLLITMATAFMGYVLPWGQMSFWGATVITNLFSAIPYIGTNLV GLMPFLHTSKHRSMMLRPLSQALFWTLTMDLLTLTWIGSQPVEYPYTIIGQMASILYFSIILAFLPIAGX IENY

In reply to Re: New to Perl by Marshall
in thread New to Perl by rolandomantilla

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.