[Bioperl-l] combining a CGI filehandle with SeqIO
Hilmar Lapp
hlapp at gnf.org
Fri Feb 7 11:52:57 EST 2003
I don't think that your code can possibly work, regardless of language.
Essentially the two filehandles would need to 'talk' to each other in
the kernel, otherwise how could one filehandle know that you just
advanced the other?
Try using the physically same file handle, by, e.g., either
- creating a file handle yourself beforehand (see perldoc Symbol) and
passing that on to SeqIO (-fh => $handle) as well as using it for
print, or
- obtaining the file handle from SeqIO that it created ($seqio->_fh())
and using it for printing interspersed content
-hilmar
On Friday, February 7, 2003, at 10:34 AM, nkuipers wrote:
> Hello,
>
> I have written a script to convert a fasta flat file to an html
> version of the
> same. The CGI object writes to the same filehandle as the SeqIO
> object, with
> a shared lock. For some reason (maybe a Perl thing?) every CGI event
> is
> ignored until the SeqIO iteration is finished. So I end up getting a
> bunch of
> fasta sequences followed by all the html that should precede, be
> dispersed
> through, and end the document. Does anyone know what's up? The
> script is
> small, and as follows:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> =pod
> author: nkuipers at uvic.ca
> written: 02/05/03
> updated: 02/07/03
> usage: perl FastatoHTML fastafile
>
> OS: Red Hat Linux 8.0
> Perl: 5.8.0
> bioperl: 1.2
> =cut
>
> use lib "/home/nkuipers/lib";
> use Bio::SeqIO;
> use CGI::Pretty ":html13";
> use FileHandle;
> use Fcntl ":flock";
>
> # input file
> my $fastafile = shift;
>
> # input reader
> my $i = Bio::SeqIO->new(-file => $fastafile);
>
> # output writers
> my $q = CGI::Pretty->new;
> my $o = Bio::SeqIO->new(-file => ">>${fastafile}.html",
> -format => 'Fasta');
>
> # output filehandle, same as $o destination
> my $fh = FileHandle->new(">>${fastafile}.html") or die "No append: $!";
> flock($fh, LOCK_SH) or die "No LOCK_SH: $!";
>
> # initialize HTML doc
> print $fh $q->start_html(-title => 'test page',
> -author => 'nkuipers at uvic.ca',);
>
> # iterate through the input sequences
> while (my $seqobj = $i->next_seq)
> {
> $o->write_seq($seqobj);
> print $fh $q->br,$q->hr,$q->br;
> }
>
> # end HTML doc and clean up
> print $fh $q->end_html;
> $fh->close;
>
> __END__
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at bioperl.org
> http://bioperl.org/mailman/listinfo/bioperl-l
>
--
-------------------------------------------------------------
Hilmar Lapp email: lapp at gnf.org
GNF, San Diego, Ca. 92121 phone: +1-858-812-1757
-------------------------------------------------------------
More information about the Bioperl-l
mailing list