[Bioperl-l] How to write a Bio::DB:Fasta sequence into a file?

Mark A. Jensen maj at fortinbras.us
Sat Nov 29 00:57:56 EST 2008

What you are doing is a little unclear. If you have obtained a
sequence object, from Bio::DB::Fasta or anywhere, you can write
it to a FASTA file by using the write_sequence call. Maybe you
have done

$seq = read_sequence("theirseqs.fas", 'fasta');


($seq, @more_seqs) = read_all_sequences("theirseqs.fas", 'fasta');

or even

$db = new Bio::DB::Fasta("theirseqs.fas");
$seq = $db->get_Seq_by_id('THX1138');

then write it with

write_sequence(">myseqs.fas", 'fasta', $seq);

or append it to your file with

write_sequence(">>myseqs.fas", 'fasta', $seq);

If your problem is, you have a sequence string, and you want to
write it to a file in FASTA format, then you create a sequence
object directly:

$seq = new_sequence( 'atcgtgcaat', 'THX1138' )

and write it using write_sequence() as above. 

Hope this helps-

More information about the Bioperl-l mailing list