#!/usr/bin/perl

# use strict for better code writing
use strict;

# use CGI.pm for web interaction
use CGI;

# avoid buffering problems
$|=1;

my $catdir = "/share/ftp/pub/go/gene-associations";
my $query = $ENV{REQUEST_URI};

#print STDERR "QUERY: $query\n";

$query =~ s#/cgi-bin/GO/downloadGOGA.pl/##;
$query =~ s#/cgi-bin/downloadGOGA.pl/##;

# Now Redirect to Browser
print "Content-type: application/octet-stream\n\n";

my $catfile = $catdir . "/" . $query;

if ($catfile =~ /\.gz$/) {
    open (CAT, "$catfile") || warn "Cannot open gene-association file $catfile\n";
} else {
    # all gene_association files end with gz, old links will not have the extension
    $catfile .= ".gz";
    open (CAT, "/usr/bin/gzcat $catfile |") || warn "Cannot open gene-association file $catfile\n";
}

while (<CAT>) {
    print "$_";
}

close (CAT);

exit;
