[Bioperl-l] seqIO and file handle

Jason Stajich jason@cgt.mc.duke.edu
Thu, 25 Jul 2002 09:46:35 -0400 (EDT)


This is an autoflush problem, it is fixed in the live code but probably
not in the code you are dealing with.  You just need to close the
Bio::SeqIO object .. $seqio->close() or better $seqio = undef.

BTW, a better way to do what you want below would be to use IO::String to
create a filehandle and just write it rather than the
tempfile and read it back in route. You get your sequence string back out
from the IO::String object.

-jason
On Thu, 25 Jul 2002, Damien Mattei wrote:

>
> i have a problem writing sequence in a temp file with seqIO
> and reading it immediately the end of file is truncated even if it is
> not on disk.
>
> here is my code:
>
> # create temporary sequence file in specific format
> # (genbank, fasta or embl) and write it in text widget
> # param 1 : format (Fasta,GenBank,EMBL)
> # param 2 : sequence
> sub  seqtmptxt {
>
>      my ($format,$seq) = @_;
>      my ($fh, $name_file) = tempfile( SUFFIX => '.' . $format);
>      print $name_file . "\n" ;
>      my $seqio = Bio::SeqIO->new('-format' => $format,-file =>
> ">$name_file");
>      $seqio->write_seq($seq);
>      close($fh);
>      print "Sequence written in tmp file\n";
>      #$scrolled_texte->configure(-state => 'normal');
>      #$scrolled_texte->delete("1.0","end");
>
>      #`tail $name_file`;
>
>      open(TMPFILE,"< $name_file") or goto NOOPEN;
>      my $buffer;
>      while (my $byteread = read(TMPFILE, $buffer, 16384)) {
>      #while (my $record = <TMPFILE> ) {
> 	#print "byte read = $byteread\n";
> 	#$scrolled_texte->insert('end', $buffer);
> 	print $buffer;
>
>      }
>      print $buffer;
>      close TMPFILE or print "impossible to close $name_file : $!";
>      #$scrolled_texte->configure(-state => 'disabled');
>      unlink $name_file;
>      return;
>    NOOPEN:
>      print "impossible to open $name_file : $!";
> }
>
> i comment out all the Tk relative code to don't annoy readers and assume
> the problem is that the problem is with file handler.
> If i add `tail $name_file`; (see in code where it is commented) the file
> display well, so there should be a way to flush this file but i don't
> know how.
>
> Damien
>
> --------------------------------------
> Damien Mattei
> C.N.R.S / U.N.S.A - UMR 6549
> mailto:mattei@unice.fr
> http://www-iag.unice.fr/
> --------------------------------------
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l@bioperl.org
> http://bioperl.org/mailman/listinfo/bioperl-l
>

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