#!/usr/bin/perl use strict; use CGI qw(:standard); use GD; print "Content-type: text/html\n\n"; my $cgi = new CGI; my $orf = $cgi->param('ORF_name'); my $new_inter = $cgi->param('inter_new'); my $new_categ = $cgi->param('categ_new'); my %nei; my $group; my $line; my @data; my @datasets; my $data_trans; 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; my $element_file = '../dataset/nav_elements/'.$time_id.'.txt'; ### checking the input ### my $factor1 = 1; my $factor2 = 1; if (!$orf) { $factor1 = 0; print " Did you forget to input the starting node?
"; } if ((!$cgi->param('bdm')) && (!$cgi->param('twohybrid')) && (!$cgi->param('coip')) && (!$cgi->param('inter_new_db'))) { $factor2 = 0; print " Did you forget to select any interaction datasets?
"; } if ((!$factor1) || (!$factor2)) { print "
Input error!
"; print '   Return to the main menu '; exit; } $orf =~ s/\-//g; $orf =~ tr/[a-z]/[A-Z]/; (open (OUTPUT, ">$element_file")) || die " cannot open the out file"; #deal with the data sets $datasets #======================= if ($cgi->param('bdm')) { $dataset_description[$k++]='BIND/DIP'; $dataset_description[$k++]='MIPS'; $datasets[$gnum++]='../dataset/BIND_DIP_New.txt'; $datasets[$gnum++]='../dataset/MC.txt'; $data_trans='&&bdm=1'; } if ($cgi->param('twohybrid')) { $dataset_description[$k++]='Two Hybrid'; $datasets[$gnum++]='../dataset/U_I.txt'; $data_trans.='&&twohybrid=1'; } if ($cgi->param('coip')) { $dataset_description[$k++]='CoIP'; $datasets[$gnum++]='../dataset/M_C.txt'; $data_trans.='&&coip=1'; } if ($cgi->param('inter_new_db')) { $dataset_description[$k++]='New_dataset'; $datasets[$gnum++]=$new_inter; $data_trans.='&&inter_new_db=1'; } for($i=0; $i<$gnum; $i++) { $infile=$datasets[$i]; (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 $orf) { $nei{$data[1]}[$i]=1; } elsif($data[1] eq $orf) { $nei{$data[0]}[$i]=1; } } } for $group(keys %nei) { $length++; for ($i=0; $i<$gnum; $i++) { if (!defined($nei{$group}[$i])) { $nei{$group}[$i]=0; } } } print "\n"; print "Network properties calcula1tion\n"; print <
Yale Gerstein Lab
END_OF_BANNER print "

Network Navigation Output for $orf


\n"; print "

Description

\n"; print "
\n"; if (($cgi->param('new_dataset'))&&($cgi->param('new_data'))) { $description = $cgi->param('new_dataset'); print ""; print ""; print "\n"; } print "\n"; $description=$cgi->param('ORF_name'); print ""; print "\n"; print ""; print "\n"; print "
New Dataset:$description
Dataset:$dataset_description[0]"; for($i=1;$i<$k;$i++) { print " && $dataset_description[$i]"; } print "
Search for:$description
Number of Interactions$length


\n"; print '
Click here to get SGD annotation for '."$orf"."
"; print '
Return to the main menu
'; print OUTPUT "ORF"; for ($i=0; $i<$k; $i++) { print OUTPUT "\t$dataset_description[$i]"; } print OUTPUT "\n"; for $group(keys %nei) { print OUTPUT "$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 $orf

"; exit; } $total_level=int(log($length/5)/log(2))+2; my $total_x = 180 * $total_level; my $total_y = 200 * $total_level+100; $total_x=(($total_x < 400)?400:$total_x); $total_y=(($total_y < 400)?400:$total_y); my $center_x= $total_x/2; my $center_y= $total_y/2+80; $orf=$cgi->param('ORF_name'); print '
'."\n"; my $im = new GD::Image ($total_x, $total_y+20); my $i=0; my ($ALL, $FILE); my ($x1, $y1, $x2, $y2); my $label; my $radius; my $angle; my $ele_angle; my $start_angle; my $level=0; my @level_num; my $line; my @data; my $left=$length; my $pi=atan2(1,1)*4; my $piover180=$pi/180; my $ele_num; my $html; my @colors; my $label; my $time='../png/nav/'."$time_id".'.png'; (open (FILE, "<$element_file")) || die "cannot open the infile"; ; (open (ALL, ">$time")) || print "cannot open the time file"; binmode ALL; $colors[0] = $im->colorAllocate(255,255,255); #white $colors[1] = $im->colorAllocate(0,0,0); #black $colors[2] = $im->colorAllocate(0,255,0); #green $colors[3] = $im->colorAllocate(255,0,0); #red $colors[4] = $im->colorAllocate(0,0,255); #blue $colors[5] = $im->colorAllocate(255,180,0); #Orange $colors[6] = $im->colorAllocate(230,230,0); #Yellow $colors[7] = $im->colorAllocate(160,160,0); #Purple $colors[8] = $im->colorAllocate(170,170,170); #gray $im->transparent($colors[0]); $im->interlaced('true'); #intiate the process $im->arc($center_x, $center_y, 20, 20, 0, 360, $colors[1]); # the center of the picture $level_num[0]=5; for ($i=1; $i<15; $i++) { $level_num[$i]=0; } while($left>0) { $ele_num=&find_level_num($level); # radius and angles of this level $radius=80*($level+1); $ele_angle=360/$ele_num; $start_angle=72*(2**(-$level)); $ele_num=&min($left, $ele_num); for ($i=0; $i<$ele_num; $i++) { chomp($line=); ($orf,@data) = split("\t", $line); $angle = $start_angle + $i*$ele_angle; $x1 =$center_x + ($radius-10) * sin($angle * $piover180); $y1 =$center_y - ($radius-10) * cos($angle * $piover180); $x2 =$center_x; $y2 =$center_y; $im->line($x1, $y1, $x2, $y2, $colors[1]); $x1 =$center_x + $radius * sin($angle * $piover180); $y1 =$center_y - $radius * cos($angle * $piover180); &draw_pie($x1, $y1); $x1=$x1-10; $y1=$y1-10; $x2=$x1+20; $y2=$y1+20; $html=''."\n"; print "$html"; if($angle<180) { $x1-=6; } else { $x1-=30; } if(($angle<270)&&($angle>90)) { $y1+=15; } else { $y1-=25; } $im->string(gdSmallFont, $x1, $y1, $orf, $colors[1]); } $left-=$ele_num; $level++; } $im->fill(1, 1, $colors[0]); #legends: for ($i=0; $i<$gnum; $i++) { $x1=$center_x-20; $y1=10+$i*15; $x2=$center_x-10; $y2=20+$i*15; $im->filledRectangle($x1, $y1, $x2, $y2, $colors[$i+2]); $x1=$center_x+20; $y1=10+$i*15; $label=$dataset_description[$i]; $im->string(gdSmallFont, $x1, $y1, $label, $colors[$i+2]); } binmode STDOUT; print ALL $im->png; close(ALL); print '

'."\n"; print 'You can also choose to display the result in a table (recomended when too many interactions)
'; print '
'."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''; print '
'; print '
'; sub min { my $a=shift; my $b=shift; return (($a>$b)?$b:$a); } sub find_level_num { my $level=shift; if ($level>0) { for ($i=0; $i<$level; $i++) { $level_num[$level]+=$level_num[$i]; } } else { $level_num[$level]=5; } return($level_num[$level]); } sub draw_pie { my $x=shift; my $y=shift; my $sector_num=0; my $angle_start; my $angle_end; my $angle_elem; my $i=0; my $j=0; my $cut_x; my $cut_y; my $cut_angle=0; my $fill_x; my $fill_y; my $fill_angle; my $radius=5; my $pi=atan2(1,1)*4; my $piover180=$pi/180; $im->arc($x, $y, 20, 20, 0, 360, $colors[1]); for ($i=0; $i<$gnum; $i++) { $sector_num+=$data[$i]; } $angle_elem=360/$sector_num; for ($i=0; $i<$gnum; $i++) { if ($data[$i]) { $angle_start = $j * $angle_elem; $angle_end = ($j+1) * $angle_elem; $cut_angle = $angle_end; if ($sector_num>1) { $cut_x = $x; $cut_y = $y-10; $im->line($x, $y, $cut_x, $cut_y, $colors[1]); $cut_x = $x + 10 * sin($cut_angle * $piover180); $cut_y = $y - 10 * cos($cut_angle * $piover180); $im->line($x, $y, $cut_x, $cut_y, $colors[1]); } $fill_angle = ($angle_start + $angle_end)/2; $fill_x = $radius * sin($fill_angle * $piover180); $fill_y = $radius * cos($fill_angle * $piover180); $fill_x = $x + $fill_x; $fill_y = $y - $fill_y; $im->fill($fill_x, $fill_y, $colors[$i+2]); $j++; } } } close(FILE); exit;