[Bioperl-l] combining a CGI filehandle with SeqIO

nkuipers nkuipers at uvic.ca
Fri Feb 7 10:34:48 EST 2003


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__



More information about the Bioperl-l mailing list