[Bioperl-l] capture of STDOUT from write_seq?

Jason Stajich jason.stajich at duke.edu
Wed Feb 9 11:03:00 EST 2005


I think you want a pipe at the end of that open - however, this might 
not work on long sequences though...
open $fh, "echo '$seq' | hmmtop -if=-- -sf=FAS -pi=spred -is=pseudo |";

Because what you want is reading and writing to the same filehandle you 
have to play some tricks.  I think IO::Pipe or IPC::Run3 might help, 
but I couldn't get it to work right in my little bit of playing around.

-jason
--
Jason Stajich
jason.stajich at duke.edu
http://www.duke.edu/~jes12/

On Feb 9, 2005, at 8:43 AM, Marc Logghe wrote:

> 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
>>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://portal.open-bio.org/pipermail/bioperl-l/attachments/20050209/e2afc184/PGP-0001.bin


More information about the Bioperl-l mailing list