#!/usr/bin/perl
use strict;
use CGI qw(:standard);
use GD;
print "Content-type: text/html\n\n";
print "
\n";
print "Network Navigation\n";
print <
END_OF_BANNER
my $cgi = new CGI;
my $bait = $cgi->param('ORF_name'); ### node to start the navigation ###
my $cutoff = $cgi->param('cutoff'); ### The likelihood ratio cutoff
my $PI = $cgi->param('dataset'); ### The interaction dataset
my $Lfile = "../pull_down/L/L_PIT/" . $bait . ".txt"; # the file to read in the likelihood ratio information;
my %L; # the likelihood ratio for each pair of interaction;
my $N;
my $ratio;
my $orf;
my %nei;
my $group;
my $line;
my @data;
my @datasets;
my $i=0;
my $infile;
my ($NEW, $OUTPUT, $DATASET);
my @dataset_description;
my $k=0;
my $gnum=0;
my $description;
my $length=0;
my $total_level=0;
my $time_id=time; ### different IDs for different tasks ###
my $element_file = './results/'.$time_id.'.txt'; ### output file ###
### checking the input ###
my $factor = 0;
if ($bait eq "")
{
$factor = 1;
print " Did you forget to input the starting node?
";
}
if ($PI eq "")
{
$factor = 1;
print " Did you forget to select any interaction datasets?
";
}
if ($cutoff eq "") {
$factor = 1;
print " Did you forget to input the likelihood ratio cutoff?
";
}
if (!($cutoff =~ /^(\d+\.?\d*|\.\d+)$/) || ($cutoff < 0)) {
$factor = 1;
print " The cutoff has to be a number larger than or equal to 0!
";
}
if ($factor)
{
print "
Input error!
";
print "   Return to the main menu \n";
exit;
}
$bait =~ s/\-//g;
$bait =~ tr/[a-z]/[A-Z]/;
(open (OUTPUT, ">$element_file")) || die " cannot open the out file";
# Read in the Likelihood ratio information from the dataset that the user chooses;
if ($PI eq "PIP") {
$N = 2;
}
if ($PI eq "PIE") {
$N = 1;
}
if ($PI eq "PIT") {
$N = 3;
}
open (DATA, $Lfile) || die "Unable to open $Lfile";
while () {
chomp;
my @temp = split (/\t/);
$temp[0] =~ tr/[a-z]/[A-Z]/;
$temp[0] =~ s/\-//g;
$temp[$N] = -1 if ($temp[$N] eq "NA");
$L{$temp[0]} = $temp[$N] if ($temp[$N] >= $cutoff);
$nei{$temp[0]}[0] = 0 if ($temp[$N] >= $cutoff); # The neighbours of the orf that the user is interested in, the neighbors must have a ratio larger than the cutoff;
}
close (DATA);
#deal with the data sets $datasets
#=======================
### Selection of databases ###
$dataset_description[$k++]='Gold standard positives'; ### description for this interaction dataset ###
$datasets[$gnum++]='MIPS.txt'; ### path for this interaction dataset ###
$dataset_description[$k++]='Interacting pairs from BIND and DIP';
$datasets[$gnum++]='BD.txt';
$dataset_description[$k++]='in vivo pull down dataset by Gavin et al';
$datasets[$gnum++]='Gavin.txt';
$dataset_description[$k++]='in vivo pull down dataset by Ho et al';
$datasets[$gnum++]='Ho.txt';
$dataset_description[$k++]='Yeast two hybrid dataset by Uetz et al';
$datasets[$gnum++]='Uetz.txt';
$dataset_description[$k++]='Yeast two hybrid dataset by Ito et al';
$datasets[$gnum++]='Ito.txt';
$dataset_description[$k++]='Gold standard negatives';
$datasets[$gnum++]='Neg.txt';
####################################################
# read in the negative data in virtual-bait format #
####################################################
my $k = $gnum - 1;
my $negfile = $bait . ".txt";
open (DATA, "./Neg/$negfile");
while () {
chomp;
$nei{$_}[$k] = 1 if (exists $nei{$_});
}
close (DATA);
#########################
# End of read negatives #
#########################
for($i=0; $i<$k; $i++)
{
$infile=$datasets[$i];
### combine all the interaction datasets ###
(open(DATASET, "<$infile")) || die "cannot open the data file";
while($line=)
{
chomp($line);
@data=split("\t", $line);
$data[0] =~ s/\-//g;
$data[0] =~ tr/[a-z]/[A-Z]/;
$data[1] =~ s/\-//g;
$data[1] =~ tr/[a-z]/[A-Z]/;
if (($data[0] eq $bait) && (exists $nei{$data[1]}))
{
$nei{$data[1]}[$i]=1;
}
elsif(($data[1] eq $bait) && (exists $nei{$data[0]}))
{
$nei{$data[0]}[$i]=1;
}
}
close (DATASET);
}
for $group(keys %nei)
{
$length++;
for ($i=0; $i<$gnum; $i++)
{
if (!defined($nei{$group}[$i]))
{
$nei{$group}[$i]=0;
}
}
}
print "Network Navigation Output for $bait
\n";
print <
Probabilistic interactome |
END_DES
print "$PI |
\n";
print "Virtual bait | \n";
print "$bait | \n";
print "Likelihood ratio cutoff | ";
print "$cutoff |
\n";
print "Number of Interactions | ";
print "$length |
\n";
print "
\n";
print 'You can also choose to display the result in a table (recomended when too many interactions)
';
print '
';
print '
Click here to get SGD annotation for '."$bait"."
";
print '
Return to the main menu';
print OUTPUT "ORF\tLikelihood ratio";
for ($i=0; $i<$k; $i++)
{
print OUTPUT "\t$dataset_description[$i]";
}
print OUTPUT "\n";
for $group(keys %nei)
{
print OUTPUT "$group\t$L{$group}";
for ($i=0; $i<$gnum; $i++)
{
print OUTPUT "\t$nei{$group}[$i]";
}
print OUTPUT "\n";
}
close(OUTPUT);
close (DATASET);
# draw the graph
#==============================
if ($length==0)
{
print "
No interactions found for $bait with likelihood ratios larger than or equal to $cutoff
";
print "