[Bioperl-l] capture of STDOUT from write_seq?

Marc Logghe Marc.Logghe at devgen.com
Wed Feb 9 08:43:29 EST 2005


It is probably not really optimal, but this should work:

use IO::String;

while(my $seqin = $seqio->next_seq) {
  my $seq = '';
  my $io = IO::String->new($seq);
  my $fh;

  # print fasta to scalar $seq
  my $seqout = Bio::SeqIO->new(-fh => $io, '-format' => 'Fasta');
  $seqout->write_seq($seqin);

  # pipe fasta to hmmtop and catch output
  open $fh, "echo '$seq' | hmmtop -if=-- -sf=FAS -pi=spred -is=pseudo";
  my ($s) = <$fh>;
  print $s;
}

HTH,
Marc

> -----Original Message-----
> From: bioperl-l-bounces at portal.open-bio.org
> [mailto:bioperl-l-bounces at portal.open-bio.org]On Behalf Of Heikki
> Lehvaslaiho
> Sent: Wednesday, February 09, 2005 12:23 PM
> To: bioperl-l at portal.open-bio.org
> Cc: Neil Saunders; bioperl-l at bioperl.org
> Subject: Re: [Bioperl-l] capture of STDOUT from write_seq?
> 
> 
> 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
> ___ _/_/_/_/_/________________________________________________________
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l
> 



More information about the Bioperl-l mailing list