[Bioperl-l] seqIO and file handle

Damien Mattei Damien.Mattei@unice.fr
Thu, 25 Jul 2002 15:34:03 +0200


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/
--------------------------------------