[Bioperl-l] SeqIO unwilling to work

Gert Thijs gert.thijs@esat.kuleuven.ac.be
Mon, 11 Feb 2002 17:52:26 +0100


Michal,

Here is some code that I have been using lately and that does the job for me.

---
my $query = new CGI;
my $file = $query->param('file');

my $stream;
if ( defined($file) ){
     $stream = new Bio::SeqIO( -fh => $file,
                          -format => 'fasta' );
}else{
     print "Error: No sequences found.\n";
     exit -1;
}

while ( my $ss = $stream->next_seq ){
   # do some stuff
}
---

There was no need to first read the stream from $file into a string and then 
tie this string to a IO::Scalar. You can pass filehandle $file immediatly to 
Bio::SeqIO.


Gert


Michal Kurowski wrote:

> Hi,
> After spending some time with SeqIO interface I've got to say there
> are a few things a bit mysterious to me.
> 
> Let's say I've got something like this:
> 
> 
> 
> $file1 = param("file1");
> $file2 = param("file2");
> $area1 = param("text1");
> $area2 = param("text2");
> 
> $stream1 = "";
> $stream2 = "";
> 
> if ($file1) {
>     while (<$file1>) {
>         $stream1 .= $_;
>     }
> } else {
>     $stream1 = $area1;
> }
> 
> if ($file2) {
>     while (<$file2>) {
>         $stream2 .= $_;
>     }
> } else {
>     $stream2 = $area2;
> }
> 
> $stream1 =~ s/\r//g;
> $stream2 =~ s/\r//g;
> 
> 
> tie *IN1, 'IO::Scalar', \$stream1;
> tie *IN2, 'IO::Scalar', \$stream2;
> 
> my $first = Bio::SeqIO->new(-fh => \*IN1);
> my $second = Bio::SeqIO->new(-fh => \*IN2);
> 
> ...dealing with $first and $second ...
> 
> 
> It doesn't work.
> The point is "-fh" method (with a tied Symbol::gensym) does not work
> for me giving lots of mysterious errors (see below). It does not
> matter if I use object interface or "tied" objects.
> 
> Operation `ne': no method found,
> left argument in overloaded package IO::Scalar,
> right argument has no overloaded magic at
> /usr/lib/perl5/site_perl/5.6.0/Bio/Root/IO.pm line 242.
> 
> And when I try to investigate thing using "Data::Dumper":
> 
> Use of uninitialized value in -d at /usr/lib/perl5/5.6.0/CGI.pm line
> 3355.
> fasta.pl: Use of uninitialized value in
> join at (eval 13) line 44.
> fasta.pl: Use of uninitialized value in
> join at (eval 13) line 44.
> fasta.pl: Can't locate object method
> "FETCH" via package "IO::Scalar" at
> /usr/lib/perl5/5.6.0/i386-linux/Data/Dumper.pm line 150,
> <fh00001duzy.fa> line 12.
> 
> I thought "FETCH" is not necessary when using tied handles...
> 
> (Bio)Perl wizards needed,
> 
> 



-- 
+ Gert Thijs
+
+ email: gert.thijs@esat.kuleuven.ac.be
+ homepage: http://www.esat.kuleuven.ac.be/~thijs
+
+ K.U.Leuven
+ ESAT-SISTA
+ Kasteelpark Arenberg 10
+ B-3001 Leuven-Heverlee
+ Belgium
+ Tel : +32 16 32 85 88 (new number)
+ Fax : +32 16 32 19 70