[Bio] / Clearinghouse / precomputed_pin.pl Repository:
ViewVC logotype

View of /Clearinghouse/precomputed_pin.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Thu Jun 22 16:38:58 2006 UTC (13 years, 3 months ago) by olson
Branch: MAIN
CVS Tags: myrast_33, HEAD
new file

use CGI;
use strict;
use URI::Escape;
use Clearinghouse::utils;

my $dbh = db_init();

#
# Retrieve the cached pins page for the peg given in the peg parameter.
#

#
# Text form of pins is here.
#
my $pin_base_dir = "/disks/space0/olson/Pins/text";

my $cgi = new CGI;

my $peg = $cgi->param('peg');
my $cutoff = $cgi->param('cutoff');

$cutoff = 1.0e-20 unless defined($cutoff);

if (!$peg)
{
    &error("PEG parameter missing");
}

my($genome, $pnum) = $peg =~ /^fig\|(\d+\.\d+)\.peg\.(\d+)/;

#
# Look up the pin.
#
# Darn floating point. need to compare on relative error.
#

my $res = $dbh->SQL(qq(SELECT t.file, t.fileno, p.seek, p.len
		       FROM  file_table t, pin_seeks p
		       WHERE abs(p.cutoff - ?) / ? < 1e-5 AND fid = ? AND t.fileno = p.fileno
		       ), undef, $cutoff, $cutoff, $peg);
if (!defined($res))
{
    error("database lookup failed", $dbh->errstr);
}
elsif (@$res == 0)
{
    print $cgi->header();
    print "NOT FOUND\n";
    exit;
}     

my ($file, $fileno, $seek, $len) = @{$res->[0]};

if (!open(F, "<$file"))
{
    error("cannot open file", "cannot open file $file: $!\n");
}

seek(F, $seek, 0);
my $buf;
read(F, $buf, $len);
print $cgi->header();
print $buf;
exit 0;

sub error
{
    my($why, $body) = @_;

    print $cgi->header(-type => 'text/plain',
		       -status => "500 $why");
    print "$body\n";
    exit(0);
    
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3