[Bioperl-l] writing sequences to a file

Jason Eric Stajich jason@cgt.mc.duke.edu
Mon, 22 Oct 2001 21:11:29 -0400 (EDT)

[Disclaimer: I'm confused as to what you are trying to so this may be a
 bad answer]

# open a handle for creating a local FASTA db file
my $stream = Bio::SeqIO->newFH(-file => ">$output", -format => 'fasta');

while( # get seqs from somewhere ) {
 print $stream $seq;

I actually prefer
my $seqio = Bio::SeqIO->new(-file => ">$output", -format => 'fasta');
while( # get seqs ) {

because it is a little more explicit what is doing the writing.

If you are talking about mixing streams of data by printing a Bio::Seq and
then some of your own strings - the following should give you the access
you want.  You won't be providing FASTA format datafiles anymore though
cause that is what bioperl seqio system already does...

open(OUT, ">$output);

my $seqio = new Bio::SeqIO(-format => 'fasta', -fh => \*OUT);
while( # get seqs ) {
  print OUT "some data"; # look ma, data stream access

(more below)

On Mon, 22 Oct 2001, Jason Raymond wrote:

> Spinoff from an earlier post... Per Seq::IO,

>  I'm using $stream =
> Bio::SeqIO->newFh(-file => ">$output"; ...
>  print $stream $seq; to
> write to my $output file once retrieved from a local db.

> How do I also write the (FASTA formatted) names of these sequences?
> Previously (as in BLAST parsing) I had used:
> open(OUT, ">$output); ...
> print OUT ">",$hit->name;

If you wanted these names printed out with the seqio system you should
make sure and set the display id:

display id should really not have spaces in it since it is the
intended unique id for the sequence in a db.

Additionally the fasta format allows a description line to be printed,
you can set data here:
$seq->desc("Set description data here");

and have it show up in the fasta db produced by seqio.

> But combining the parsing and retrieval scripts (i.e. mixing print OUT with the print $stream $seq above
> doesn't give the desired output of a nicely formatted file).

Jason Stajich
Duke University