Biotech > FAQ > BioPerl FAQ (Frequently Asked Questions)

How can I use Bio::SeqIO to parse sequence data ...

To see other biotech frequently asked questions, please visit http://biotech.fyicenter.com/faq/

(Continued from previous question...)

How can I use Bio::SeqIO to parse sequence data to or from a string?

Use this code to parse sequence records from a string:

use IO::String;
use Bio::SeqIO;
my $stringfh = new IO::String($string);
my $seqio = new Bio::SeqIO(-fh => $stringfh,
                           -format => 'fasta');
while( my $seq = $seqio->next_seq ) {
 # process each seq
}

And here is how to write to a string:

use IO::String;
use Bio::SeqIO;
my $s;
my $io = IO::String->new(\$s);
my $seqOut = new Bio::SeqIO(-format =>'swiss', -fh =>$io);
$seqOut->write_seq($seq1);
print $s; # $s contains the record in swissprot format and is stored in the string

(Continued on next question...)

Other Frequently Asked Questions