[Bioperl-l] SeqIO fixing: detecting if a filehandle is open for writing

Jason Stajich jason at cgt.duhs.duke.edu
Thu Aug 5 11:58:40 EDT 2004


On Thu, 5 Aug 2004, Peter van Heusden wrote:

> I'm busy preparing patches to catch the different failure modes of
> SeqIO's constructor, but I'm stuck with one particular case. What if I
> open a filehandle for reading, and then pass that filehandle to SeqIO's
> constructor, and then call write_seq() on the SeqIO object. I.e. like this:
>
> use IO::File;
> use Bio::SeqIO;
> use Bio::PrimarySeq;
>
> my $fh = IO::File->new("myfile.fasta") || die "open failed: $!\n";
>
> my $seqio = Bio::SeqIO->new(-fh => $fh, -format => 'fasta');
>
> my $seq = new Bio::PrimarySeq(id => 'MYID', seq => 'GATTACCA');
>
> $seqio->write_seq($seq);
>
> The current result is that write_seq() silently fails. I'm trying to
> deal with all misleading error messages & late failures at the moment,
> but I feel we're going to be left with some cases that can't be avoided
> in the end.

My feeling is that any logic here should be pushed up to Bio::Root::IO
anyays.

If we had a way to test if a filehandle was read/write we would use this
in a number of places in Bioperl.  The removal of automagic use of \*ARGV
from Bio::Root::IO was due to a problem with this as well in
Bio::Tools::GFF.  AFAIK there is no way to test if a handle is for reading
or writing or both...

-jason

 >
> Peter
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l
>

--
Jason Stajich
Duke University
jason at cgt.mc.duke.edu


More information about the Bioperl-l mailing list