[Bioperl-l] avoiding temporary files

Paul Gordon gordonp@cbr.nrc.ca
Wed, 17 Apr 2002 12:41:54 -0300 (ADT)


> Hi,
>   I think this is a basic perl question but I can't figure it out and
> since it is with my bioperl calls I'm sure one of you will know the
> answer.  I would like to take a sequence file that is in a single variable
> like from a textarea of a webpage and make it into a sequence object
> without writing it to a temporary file.  It would be nice for me to do
> this with any program that I call through perl....like blastall where the
> query sequence does not have to be written as temporary file.

Sure, blastall (and many other programs) take standard input, but you want
to read the output as well right?  IPC::Open2 is the trick, since it'll
open a process for both reading and writing.

use IPC::Open2;
...
open2(\*BLASTOUT, \*BLASTIN, "/path/to/blastall -p blastn -d mydb")
    or die "Couldn't run blast: $!\n";  
print BLASTIN ">$name\n$seq";
close(BLASTIN);
...

Then BLASTOUT is your regular blast output file handle.  Of course, a
nicer way to do it is to use filehandle objects instead of globs, but
that's more for me to write.  But then of course, I wouldn't have had to
explain this, oh well. :-)

----------------------------------------------------
Purgamentum init, exit purgamentum

Paul Gordon
Research Associate
University of Calgary