[Bioperl-l] Bemusement with get_seq_by_gi in a CGI script
simon andrews (BI)
simon.andrews at bbsrc.ac.uk
Wed Aug 20 12:07:49 EDT 2003
> -----Original Message-----
> From: Mark Wilkinson [mailto:markw at illuminae.com]
> Sent: 20 August 2003 15:49
> To: Bioperl-l at portal.open-bio.org
> Subject: [Bioperl-l] Bemusement with get_seq_by_gi in a CGI script
>
> use lib '/usr/local/apache/cgi-bin/bioperl/core';
> print "Content-type: text/plain\n\n";
> use Bio::DB::GenBank;
> $d = Bio::DB::GenBank->new();
> $seq = $d->get_Seq_by_gi('163483');
> print "I didn't print the sequence!\n";
> ===============================================
>
> If you look at the output you see that the genbank record is
> printed to the screen, but the last print statement is not!
> If I run the same code from the command line I don't see the
> record, and the last print statement prints.
Actually that's not quite what's happening. If you view the raw http
traffic then what you actually get is the sequence, then the http
headers, then the "I didn't print the sequence" line.
lynx --dump http://mobycentral.cbr.nrc.ca/cgi-bin/testseq.cgi
Gives:
##########################################
LOCUS BOVPANPRO 947 bp mRNA linear MAM 29-APR-1996
DEFINITION B.taurus prepreproelastase I mRNA, complete cds.
ACCESSION M80838
[snip some stuff]
781 tcttggataa ataatgccat tgccagcaac tgaacatctt cctgagtcca gtggtattcc
841 caagatggtt ctgggattga cagcagaact tgaggccatc aaggaaaaaa ccagtctaag
901 agactattga gccagatgtg gaaaagcaaa taaaatcgaa tatatgt
//
HTTP/1.1 200 OK
Date: Wed, 20 Aug 2003 15:40:02 GMT
Server: Apache/2.0.47 (Unix) mod_perl/1.99_09 Perl/v5.8.0 DAV/2
Connection: close
Content-Type: text/plain; charset=ISO-8859-1
I didn't print the sequence!
############################################
So your script is doing what it's supposed to, it's just that some other stuff is getting out on STDOUT before your webserver is able to get in on the act.
Having played a bit, this proves to be interesting:
#!/usr/bin/perl -w
use strict;
use Bio::DB::GenBank;
close STDOUT;
my $d = Bio::DB::GenBank->new();
my $seq = $d -> get_Seq_by_gi('163483');
This gives me:
print() on closed filehandle STDOUT at /usr/lib/perl5/site_perl/5.8.0/Bio/DB/WebDBSeqI.pm line 701
So WebDBSeqI.pm is usurping STDOUT as part of its query. This probably explains what you're getting. Apache will redirect STDOUT straight to the return stream for the connection. This means it gets the output intended for WbDBSeq and it appears in your programs output. You then get the output you printed.
If this is right, you should have some interesting error messages in your logs if you run your script with warnings enabled.
I can't see an immediate fix for this, short of running your fetch as a completely detached process with a separate STDOUT, but that kind of defeats the point of using mod-perl. The use of a pipe from STDOUT to read the results of a webquery seem pretty engrained into WebQueryI.pm and it may not be trivial to change it.
Maybe others will be able to think of a simpler work-round?
Simon.
More information about the Bioperl-l
mailing list