[Bioperl-l] Parsing a Fasta file

Chris Dwan (CCGB) cdwan at mail.ahc.umn.edu
Thu Apr 1 12:55:36 EST 2004


> I have a file that contains protein sequences in fasta format.

The module you seek is Sio::SeqIO.  Here's an example:

#!/usr/local/bin/perl

use strict;
use Bio::SeqIO;

my $filename = shift;
my $count    = 0;
my $in = Bio::SeqIO->new('-file'   => "<$filename",
                         '-format' => 'fasta');
while (my $seq = $in->next_seq()) {
  print "For sequence $count\n";
  print "The defline was:  " . $seq->id() . " "    . $seq->desc() . "\n";
  print "The sequence was: " . length($seq->seq()) . "bp in length\n";
  $count++;
}



More information about the Bioperl-l mailing list