[Bioperl-l] combining a CGI filehandle with SeqIO
Jamie Hatfield (AGCoL)
jamie at genome.arizona.edu
Fri Feb 7 11:54:58 EST 2003
Not a bioperl problem exactly. Just a output buffering issue.
Just out of curiosity, why do you use FileHandle instead of just an
open? Is that more correct or just OO?
:
:
> # 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: $!";
autoflush $fh 1;
> # initialize HTML doc
> print $fh $q->start_html(-title => 'test page',
> -author => 'nkuipers at uvic.ca',);
:
:
----------------------------------------------------------------------
Jamie Hatfield Room 541H, Marley Building
Systems Programmer University of Arizona
Arizona Genomics Computational Tucson, AZ 85721
Laboratory (AGCoL) (520) 626-9598
> -----Original Message-----
> From: bioperl-l-bounces at bioperl.org
> [mailto:bioperl-l-bounces at bioperl.org] On Behalf Of nkuipers
> Sent: Friday, February 07, 2003 11:35 AM
> To: bioperl-l at bioperl.org
> Subject: [Bioperl-l] combining a CGI filehandle with SeqIO
>
>
> 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
>
More information about the Bioperl-l
mailing list