[Bioperl-l] capture of STDOUT from write_seq?

Heikki Lehvaslaiho heikki at ebi.ac.uk
Wed Feb 9 06:23:28 EST 2005


Neil,

In this case the best place to look inot is the Bio::SeqIO module 
documentation. From the SYNOPSIS:

    # The SeqIO system does have a filehandle binding. Most people find this
    # a little confusing, but it does mean you write the world's smallest
    # reformatter

    use Bio::SeqIO;
    $in  = Bio::SeqIO->newFh(-file => "inputfilename" ,
                             -format => 'Fasta');
    $out = Bio::SeqIO->newFh(-format => 'EMBL');
    # World's shortest Fasta<->EMBL format converter:
    print $out $_ while <$in>;

In other words, if you do not specify a filename the newFh method defaults to 
STDOUT for output.

Yours,
       -Heikki


On Wednesday 09 February 2005 01:47, Neil Saunders wrote:
> dear all,
>
> I'm using Bio::SeqIO to pipe fasta sequences to an external program
> (hmmtop), as follows:
>
> while(my $seqin = $seqio->next_seq) {
> my $seqout = Bio::SeqIO->new('-file' => "| hmmtop -if=-- -sf=FAS -pi=spred
> -is=pseudo", '-format' => 'Fasta'); $seqout->write_seq($seqin);
>
>
> This works nicely and spits out the 1 line STDOUT from hmmtop for each
> sequence.  What I would really like to do is capture the STDOUT as a
> variable in my Perl script.  I've read numerous Perl docs (e.g. the FAQ
> on capturing STDERR/STDOUT, perlipc, use of backticks versus open versus
> system and so on), but I'm unclear on how these relate to the example
> above.  Is there some cunning bioperl-specific way of directing STDOUT
> from an external call to a perl variable, perhaps via a filehandle?
>
> your help much appreciated,
> Neil

-- 
______ _/      _/_____________________________________________________
      _/      _/                      http://www.ebi.ac.uk/mutations/
     _/  _/  _/  Heikki Lehvaslaiho    heikki at_ebi _ac _uk
    _/_/_/_/_/  EMBL Outstation, European Bioinformatics Institute
   _/  _/  _/  Wellcome Trust Genome Campus, Hinxton
  _/  _/  _/  Cambridge, CB10 1SD, United Kingdom
     _/      Phone: +44 (0)1223 494 644   FAX: +44 (0)1223 494 468
___ _/_/_/_/_/________________________________________________________


More information about the Bioperl-l mailing list