[Bioperl-l] seqIO and file handle
Damien Mattei
Damien.Mattei@unice.fr
Thu, 25 Jul 2002 17:01:41 +0200
thanks you Jason,
i rewrite the code with your idea and it works well and faster with
IO:string and the undef solved the problem of truncated data sequence.
here is what it looks like now:
# create string sequence 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 $str;
my $io = IO::String->new( $str );
my $seqio = Bio::SeqIO->new('-format' => $format,
-fh => $io
);
$seqio->write_seq($seq);
undef $seqio;
$io->setpos(0);
$scrolled_texte->configure(-state => 'normal');
$scrolled_texte->delete("1.0","end");
$scrolled_texte->insert('end', $str);
$scrolled_texte->configure(-state => 'disabled');
undef $io;
}
Damien
Jason Stajich wrote:
> 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
>>
>>
>
--
--------------------------------------
Damien Mattei
C.N.R.S / U.N.S.A - UMR 6549
Instabilite & Alterations des Genomes
Universite de Nice - Sophia Antipolis
Faculte de Medecine, Av. de Valombrose
06107 NICE Cedex 2 FRANCE
Phone: +33 (0)4 93 37 76 66
Fax: +33 (0)4 93 53 30 71
mailto:mattei@unice.fr
http://www-iag.unice.fr/
--------------------------------------