-
Notifications
You must be signed in to change notification settings - Fork 0
/
protint_query.cgi
executable file
·1867 lines (1360 loc) · 50.8 KB
/
protint_query.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/local/bin/perl
#
# Author: vp
# Maintainer:
# Created: 6 december 2010
# Last Modified:
#many things might be unneccessary, copy pasted code from GLA and YOGI
#Basically there are 2 options:
#1) find all interactions of one or more proteins with all other proteins
#2) Find interactions only involving a specific list of proteins
# The table highlights whether the predictions match existing known interactions (pombe physical/genetic or cerevisiae physical/genetic)
#Required functionality:
#Ideally represent network of interactions above specified cutoff (there are two SVM and RF), with possibility to expand
#Ideally no need to open the network on another window
#Colour links according to colour of table field for different type of interactions
#Name nodes with common names where they exist
use strict;
use lib qw(/var/www/lib/core);
use SangerWeb;
use CGI qw/:cgi :standard/;
use CGI::Carp qw(fatalsToBrowser);
use File::Basename;
#use Data::Dumper;
use DBI;
use GD;
use GD::Graph::bars;
use GD::Graph::colour qw(:colours);
use Website::Utilities::IdGenerator;
#$ENV{PATH} = '';
# TODO: many of these hashes should really be put into a database!
local $| = 1;
main();
1;
###############################################################################
sub main {
my $title = qq(PP: Pombe Protein Interaction Prediction);
my $cgi = CGI->new();
my $sw = SangerWeb->new({title => $title});
# print $sw->header();
#<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
print qq(Content-type: text/html\n\n);
print qq (<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Bahler Lab</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="/css/other.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
<div style="text-align:left; margin-left:70px; margin-bottom:0px; margin-top:0px;"><span style="text-shadow:#FFF; font-family:'Arial Black', Gadget, sans-serif; font-size:32pt; color:#EBF1DE; ">bähler</span><span style="text-shadow:auto; font-family:'Arial Black', Gadget, sans-serif; font-size:32pt; color:#77933C; ">lab </span></div>
<div style="text-align:left; margin-left:30px; margin-top:0px;"><span style="font-family:'Arial Black', Gadget, sans-serif; font-size:20pt; color:#4F6228; "> Genome Regulation</span></div>
<div class="O">
<div style="text-align:center; margin-bottom:0px;margin-top:-67px; margin-left:120px;"><span style="font-family:Arial, Helvetica, sans-serif; font-size:80pt; color:#D7E4BD; "><strong><em>PInt </em></strong></span></div>
<div style="text-align:right; margin-bottom:0px; margin-top:-129px; margin-left:150px;"><span style="font-family:'Arial Black', Helvetica, sans-serif; font-size:36pt; color:white; ">
<img src="/images/uclogo.gif";/></span></div>
<div></div>
</div>
</div>
<div id="sidebar">
<div id="menu">
<ul>
<li ><a href="/index.html" title="">Home</a></li>
<li><a href="/group" title="">People</a></li>
<li><a href="/research.htm" title="">Research</a></li>
<li><a href="/publications" title="">Publications</a></li>
<li class="active first"><a href="/resources" title="">Resources</a></li>
<li ><a href="/cont.htm" title="">Contact</a></li>
</ul>
</div>
</div><div id="content">
<div class="feature bg7">
</div>
<div class="content" >
);
print qq(<p><img src="/PInt/logoPint.jpg" alt="Logo" width="20%" height="20%" align="right"></p></br></p>);
print start_html("protint");
#eval{
#scriptpart(
if ($cgi->param() ) {
my $defaultval="OFF";
my $type=$cgi->param('interactions_type'); ##can be 'amongst' or 'all'
my $method=$cgi->param('method'); ##can be 'RF and SVM' 'RF' 'SVM'
my $mscore=$cgi->param('minscore'); ##number from 0 to 1
my $intnum=$cgi->param('intnumber'); ## number of top hits to be returned
#if ((!defined $mscore or $mscore eq '' )){ $mscore=0.5; $intnum=100;}
#print "mscore not defined hence $mscore";
#if($intnum>100){$intnum=100;}
# print "$intnum intnum\n";
if ($intnum eq '' ){
$intnum=100;
# print "intnum not defined hence $intnum";
}
if ($mscore eq '' ){
$mscore=0.5;
# print "intnum not defined hence $intnum";
}
$defaultval=~/OFF/;
if($intnum eq '' and $mscore eq ''){
$mscore=0.5;
$intnum=200;
$defaultval="ON";
#print "intnum not defined hence $intnum, $mscore, $defaultval";
}
my @gene_info;
my $dbh=connect_to_DB('mysql', 'interactions', 'localhost', '3306', '', 'pintweb', 'pintpass' );
#my Connecting to interactions database with user pintweb and password pintpass using table pred
#test_query($dbh);
my $pre_genelist=undef;
my $gene=undef;
my $filename=undef;
$pre_genelist = $cgi->param('gene_names');
$gene=$cgi->param('gene');
#print "url param $gene";
$filename=$cgi->param('filename');
#print "$pre_genelist pre genelist or $gene or $filename at line 146";
#check inputs:
my $list=0;
my $g=0;
my $file=0;
if($pre_genelist ne ''){$list=1; }
if($gene ne ''){$g=1; }
if($filename ne ''){$file=1; }
my $sum=$list+$g+$file;
#print " $list, $g, $filename, sum $sum</p>\n";
if($sum>1){
print qq(You have chosen more than one source for your list please go back<p>);
print qq(<FORM><INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;" </FORM>);
exit;
}
if($pre_genelist eq ''){
#print "pregenelist = $pre_genelist hence need gene $gene";
$pre_genelist = $gene;
}
if($pre_genelist eq '' and $filename ne '' ){
$pre_genelist=upload($cgi);
}
#print "pre genelist at 173 $pre_genelist<p>\n ";
my @genelist = split(/\s+|\t|\n|\|,|,\s+/,($pre_genelist));
#print "@genelist genelist at 173<p>\n ";
##################################
##Retrieve all entries from variours hashes
my (%common)=ID2name();
my (%ids)=name2ID();
my (%product)=getdesc();
my (%protcer)=getcerprotint();
my (%protpb)=getpbprotint();
my (%genpb)=getpbgen();
my (%gencer)=getcergen();
my %nodes;
my %edges;
#####################################
my (@proc_genelist)=check_genenames(\@genelist, \%common,\%ids);
@genelist=@proc_genelist;
#print "genelist here at line 184@genelist<p>\n";
#print "cbf11: $product{$genelist[0]}\n";
#my @keys=keys%product;
#print "keys at prod @keys<p>\n";
#print"hash test: $common{$genelist[0]} random test $keys[2]\t $common{$keys[2]}<p>\n";
#my @keys2=keys%ids;
#print"hash test: $keys2[1]\t$ids{$keys2[1]}<p>\n";
#my @keys2=keys%product;
#print"hash test: $product{$genelist[0]}random test $keys2[2]\t $product{$keys2[2]}<p>\n";
#print "\n<p> NOTE: THE WEBSITE IS UNDERGOING MAINTENANCE, some functions might be not working correctly<p>\n";
if(! defined @genelist or $genelist[0]=~/^$/){
print qq(<p> You haven't chosen any proteins, please go back<p>);
# <a href="/PInt/protint_index.htm">go back</a> <p>);
}
else{
$pre_genelist='';
for my $i(0..$#genelist-1){
$pre_genelist.="$genelist[$i] ";
}
$pre_genelist.=$genelist[$#genelist];
#print "Pre_genelist in main program: $pre_genelist";
my $singleprot='notsingle';###flag for single protein
my $countlist=$#genelist+1;
if($#genelist==0){
$singleprot=$genelist[0];
print "<p>You are looking for interactions of protein:<p>\n @genelist=$common{$genelist[0]}\n";
}
if($#genelist>0){
if($type=~/amongst/){
print "<p>You are looking for interactions amongst $countlist proteins:<p>\n <b>@genelist<p> </b>(common names:<b>";
}
if($type=~/all/){
print "<p>You are looking for all interactions of $countlist proteins:<p>\n <b> @genelist<p><p> </b>(common names:<b>";
}
for my $i(0..$#genelist-1){
print " $common{$genelist[$i]},";
}
print " $common{$genelist[$#genelist]}</b>)<p>";
}
#print "later default val $defaultval";
if($defaultval=~/ON/){
print "<p>You didn't specify a threshold or maximum number of hits. Shown are the first <b>100</b> hits predicted with <b>$method </b> with score above <b>0.5</b>.<p>\n";
}
if($intnum<5000 and $defaultval!~/ON/){
print "<p>Predicted with <b> $method </b>above score <b> $mscore </b>and showing a maximum of <b>$intnum</b> hits.<p>\n";
}
# if($intnum==5000 and $defaultval=="OFF"){
# print "<p>All interactions predicted with $method with score above $mscore.<p>\n";
# }
print qq(<p><a href="#table">View results in a table</a> <a href="#download">Download predictions</a>);
# <a href="http://www.bahlerlab.info/PInt">Reset search</a>);
print qq(<p><FORM METHOD="LINK" ACTION="a href="http://www.bahlerlab.info/PInt"> <INPUT TYPE="submit" VALUE="Reset search"></FORM>);
#####makes table appear after the network
print qq(
<div id="table_div" style="position: relative; padding-top: 1000 ">);
###########################print colour legend:
print qq(<p><a name="table">Known interactions are highlighted as follows:<p>\n);
print qq(<table border='1' ><tr>
<th bgcolor="#99FF99">Protein interaction in fission yeast</th>
<th bgcolor="#CCFFFF">Genetic interaction in fission yeast</th>
<th bgcolor="#FFF99">Protein interaction in budding yeast</th>
<th bgcolor="#FFCCCC">Genetic interaction in budding yeast</th>
</tr></table><br>);
my $sth_query=get_interactions($dbh, $pre_genelist, $type, $method, $mscore, $intnum, $singleprot);
if($singleprot=~/notsingle/){
my $count =print_results_table($sth_query, $method, $mscore, $intnum, $pre_genelist, \%common, \%product, \%protcer, \%protpb, \%genpb, \%gencer);
#print "\n\n<p>using multiple protein results format<p>\n";
}
else{
my $count=print_results_single_table($sth_query, $method, $mscore, $intnum, $pre_genelist, \%common, \%product, \%protcer, \%protpb, \%genpb, \%gencer);
#print "\n\n<p>using single protein results protcer=<p>\n";
}
print qq(</div>);
disconnect_from_DB($dbh);
#print "disconnected<p>\n";
}
}##end cgi param
#);###end scriptpart
#1;
#}
#or do{ print "There was an error with the processing, contact the website administrator";
#};
print end_html;
print qq(<FORM><INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;" </FORM>);
}
#############
sub upload{
my ($cgi)=@_;
my $filename = $cgi->param('filename');
#print "Inside upload file subroutine<p>\n$filename<p>\n";
if ( !$filename )
{
#print $cgi->header ( );
print "There was a problem uploading your file $filename (try a smaller file).";
exit;
}
my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' );
$filename = $name . $extension;
$filename =~ tr/ /_/;
my $safe_filename_characters = "a-zA-Z0-9_.-";
$filename =~ s/[^$safe_filename_characters]//g;
if ( $filename =~ /^([$safe_filename_characters]+)$/ )
{
$filename = $1;
}
else
{
die "Filename contains invalid characters";
}
my $filename = $cgi->upload('filename');
my @time=localtime;
my $output_file= "/var/www/htdocs/PInt/tmp/uploaded".$time[0].$time[1].$time[2].".txt";
open ( OUTPUTFILE, ">","$output_file" ) or die "Couldn't open $output_file for writing: $!";
#print "File opened!!!!<p>\n";
my ($bytesread, $buffer);
my $numbytes = 1024;
my $text='';
while($bytesread=read($filename, $buffer, $numbytes)){
print OUTPUTFILE $buffer;
$text=$text.$buffer;
}
close OUTPUTFILE;
##check that text only contains correc characters and separators:
if($text!~/^[a-zA-Z0-9.\s]/){
$text='';
print"<p>There is a problem with your file $filename, it contains illegal characters<p>";
}
if($text!~/^$/){
print"<p>Thanks for uploading your file $filename</p> ";
}
#print "<p>$text<p>\n" ;
return($text);
}
###############################################################################
sub get_interactions{ ###choose different queries depending on parameter choices
my($dbh, $pre_genelist, $type, $method, $mscore, $intnum, $singleprot)=@_;
#print "Inside get_interactions singleprot:$singleprot, pregenelist: $pre_genelist\n";
my %gene_interactions=undef;
my $sth_query=undef;
if($type eq 'all' or $singleprot!~/notsingle/){
$sth_query=get_all_interactions($dbh, $pre_genelist, $method, $mscore, $intnum);
#print " inside get all ints<p>\n";
}
if($type eq 'amongst' and $singleprot=~/notsingle/){
$sth_query=get_amongst_interactions($dbh, $pre_genelist, $method, $mscore, $intnum);
#print "inside amongst<p>\n"
}
return($sth_query);
}
##############################################################################
sub get_all_interactions {
my ($dbh, $pre_genelist, $method, $mscore, $intnum) = @_;
my $sth_query=undef;
my @genelist= split(/\s+/,$pre_genelist);
#print "@genelist\n <p>Method $method inside all interactions<p>\n score=$mscore<p>\n";
my $whichscore;
my $RFminscore;
# print "Method $method inside all interactions<p>\n";
if($method eq 'SVM'){
$whichscore='scoreSVM';
$RFminscore=0;
}
if( $method eq 'RF'){
$whichscore='scoreRF';
$RFminscore=$mscore;
}
if( $method eq 'RF and SVM'){
$whichscore='scoreSVM';
$RFminscore=0.5;
}
my $post_genelist=$pre_genelist;
$post_genelist=~s/\s+|\t/','/g;
$post_genelist="('".$post_genelist."')";
#print "post=$post_genelist\n";
#print "pre_genelist=$pre_genelist";
###make a string with a proper array
my $string = qq(SELECT * FROM pred
WHERE (protein2 IN $post_genelist
OR protein1 IN $post_genelist)
AND $whichscore > $mscore
AND scoreRF > $RFminscore
ORDER BY $whichscore DESC);
$sth_query = $dbh->prepare($string);
#print "$string<p>\n";
return($sth_query);
}
##############################################################################
##get amongst
#######################################
sub get_amongst_interactions {
my ($dbh, $pre_genelist, $method, $mscore, $intnum) = @_;
my $sth_query=undef;
my @genelist= split(/\s+/,$pre_genelist);
my $whichscore;
my $RFminscore;
# print "Method $method inside amongst interactions<p>\n";
if($method eq 'SVM'){
$whichscore='scoreSVM';
$RFminscore=0;
}
if( $method eq 'RF'){
$whichscore='scoreRF';
$RFminscore=$mscore;
}
if( $method eq 'RF and SVM'){
$whichscore='scoreSVM';
$RFminscore=0.5;
}
my $post_genelist=$pre_genelist;
$post_genelist=~s/\s+|\t/','/g;
$post_genelist="('".$post_genelist."')";
#print "post=$post_genelist\n";
###make a string with a proper array
my $string = qq(SELECT * FROM pred
WHERE protein2 IN $post_genelist
AND protein1 IN $post_genelist
AND $whichscore > $mscore
AND scoreRF > $RFminscore
ORDER BY $whichscore DESC);
$sth_query = $dbh->prepare($string);
#print "$string\n";
return($sth_query);
}
################
#########################################################print results
sub print_results_table{
my ($sth_query, $method, $mscore, $intnum, $pre_genelist,$common, $product, $protcer, $protpb, $genpb, $gencer)=@_;
(my %common)=%$common;
(my %product)=%$product;
(my %protcer)=%$protcer;
(my %protpb)=%$protpb;
(my %genpb)=%$genpb;
(my %gencer)=%$gencer;
$sth_query->execute();
my @test=$sth_query->fetchrow();
#print "@test<p>\n";
if (! defined @test){
print "There are no predicted interactions.<p>\n";
}
else{
my $count=1;
#print "Test $pre_genelist\t $test[1]\tcomm $common{$test[1]}\t prod $product{$test[1]}<p>\n";
#print"$method<p>\n";
print "<table border='1' ><tr>
<th>Rank</th>
<th>protein 1</th>
<th>protein 2</th>
<th>common name 1</th>
<th>common name 2</th>
<th>product 1</th>
<th>product 2</th>";
if($method eq 'SVM' ){
print"<th>SVM score</th></tr>";
}
if($method eq 'RF'){
print"<th>RF score</th></tr>";
}
if($method eq 'RF and SVM'){
print"<th>SVM score</th><th>RF score</th></tr>";
}
####try accessing file in tmp directory
#my $fin="/var/www/htdocs/PInt/tmp/try.txt";
#open(INFILE, "$fin") or die();
#my @filein=<INFILE>;
#print ("File @filein\n");
##try writing file to the directory
#my $fouttry="/var/www/htdocs/PInt/tmp/tryout.txt";
#open(OUTFILE ,">$fouttry") or die();
#print (OUTFILE "The test now writes to the file\n");
#close(OUTFILE);
##start hash
my %nodes;
my %edges;
###set output files:
#prepare text file name
my @time=localtime;
# my $fout="/var/www/PInt/tmp/interactions".$time[0].$time[1].$time[2].$time[3].$time[4].$time[5].".txt";
# my $foutname="/var/www/PInt/tmp/interactions_onlyname".$time[0].$time[1].$time[2].$time[3].$time[4].$time[5].".txt";
my $fout="/var/www/htdocs/PInt/tmp/interactions".$time[0].$time[1].$time[2].".txt";
my $fouthash="/var/www/htdocs/PInt/tmp/hash".$time[0].$time[1].$time[2].".txt";
my $foutname="/var/www/htdocs/PInt/tmp/interactions_onlyname".$time[0].$time[1].$time[2].".txt";
open(OUTFILE , ">$fout") or die("Cannot open $fout");
print (OUTFILE "##Interactions predicted with score above $mscore\n");
print (OUTFILE "##ID1\tID2\tcommon_name1\tcommon_name2\tproduct1\tproduct2\tRFscore\tSVMscore\n");
open(OUTFILEname , ">$foutname") or die("Cannot open $foutname");
print (OUTFILEname "##Interactions predicted with score above $mscore\n");
print (OUTFILEname "##common_name1\tcommon_name2\tRFscore\tSVMscore\n");
###############print data from the test: very inelegant but if not like this the first prediction is always lost...
## could write a count query separate from the retrieval one.
####for text file:
$nodes{"$common{$test[1]}"}=1;
$nodes{"$common{$test[2]}"}=1;
if($pre_genelist=~/$test[2]/i and $pre_genelist!~/$test[1]/i){
print (OUTFILE "$test[2]\t$test[1]\t$common{$test[2]}\t$common{$test[1]}\t$product{$test[2]}\t$product{$test[1]}\t$test[3]\t$test[4]\t\n");
print (OUTFILEname "$common{$test[2]}\t$common{$test[1]}\t$test[3]\t$test[4]\n");
}
if($pre_genelist=~/$test[1]/i ){
print (OUTFILE "$test[1]\t$test[2]\t$common{$test[1]}\t$common{$test[2]}\t$product{$test[1]}\t$product{$test[2]}\t$test[3]\t$test[4]\n");
print (OUTFILEname "$common{$test[1]}\t$common{$test[2]}\t$test[3]\t$test[4]\n");
$nodes{"$common{$test[1]}"}="query";
}
if($pre_genelist=~/$test[2]/i){
$nodes{"$common{$test[2]}"}="query";
}
#$edges{"$common{$test[1]}TO$common{$test[2]}"}=($test[3]+$test[4])/2;
#$edges{"$common{$test[2]}TO$common{$test[1]}"}=1;
#### end text file print
#print "<p>Proteins here are $test[1] and $test[2]<p>\n";
#if(defined $protpb}{"$test[1],$test[2]"}){
#print ("Seen inside database\n<p>");
#}
#print qq(a$test[1]and$test[2]a<p>\n);
#my @keysprot=keys%protpb;
#print "<p>$keysprot[0]<p>\n";
#print "<p>$keysprot[1]<p>\n";
#print "<p>$keysprot[2]<p>\n";
#print "keys inside results table are $#keysprot<p>\n";
#for my $i(0..$#keysprot){
#if($keysprot[$i]=~/"SPAC19D5.01"/){
#print "LKeys of protpb: $keysprot[1],$protpb{$keysprot[1]}<p>\n";
#}
#}
#if(($test[1]=~/SPAC19D5.01/ && $test[2]=~/SPAC24B11.06C/) ||($test[2]=~/SPAC19D5.01/ && $test[1]=~/SPAC24B11.06C/) ){
# print "<p>pyp2 and sty1 found in databases withint print !!!\n";
# }
my $color="#FFFFFF";
my $int="";
if(defined $gencer{"$test[1],$test[2]"}){
$color="#FFCCCC";
$int="gencer";
}
if(defined $protcer{"$test[1],$test[2]"}){
$color="#FFFF99";
$int="protcer";
}
if(defined $genpb{"$test[1],$test[2]"}){
$color="#CCFFFF";
$int="genpb";
}
if(defined $protpb{"$test[1],$test[2]"}){
$color="#99FF99";
$int="protpb";
#print "Found pombe ints!!!!!!!!!!!!!!<p>\n";
}
if($count<=$intnum){
print qq(<tr bgcolor=$color>
<td>).$count."</td>";
if($pre_genelist =~/$test[2]/i and $pre_genelist!~/$test[1]/){
print "<td>".$test[2]."</td>
<td>".$test[1]."</td>
<td>".$common{$test[2]}."</td>
<td>".$common{$test[1]}."</td>
<td>".$product{$test[2]}."</td>
<td>".$product{$test[1]}."</td>";
}
if($pre_genelist=~/$test[1]/i ){
print "<td>".$test[1]."</td>
<td>".$test[2]."</td>
<td>".$common{$test[1]}."</td>
<td>".$common{$test[2]}."</td>
<td>".$product{$test[1]}."</td>
<td>".$product{$test[2]}."</td>";
}
if($method eq 'SVM' ){
print"<td>".$test[4]."</td></tr>";
$edges{"$common{$test[1]}TO$common{$test[2]}INT$int"}=$test[4];
}
if($method eq 'RF'){
print"<td>".$test[3]."</td></tr>";
$edges{"$common{$test[1]}TO$common{$test[2]}INT$int"}=$test[3];
}
if($method eq 'RF and SVM'){
print"<td>".$test[4]."</td><td>".$test[3]."</td></tr>";
$edges{"$common{$test[1]}TO$common{$test[2]}INT$int"}=($test[3]+$test[4])/2;
}
}
$count=$count+1;
################now retrieve data in loop
while( my @row = $sth_query->fetchrow()){
####for text file:
if($pre_genelist=~/$row[2]/i and $pre_genelist!~/$row[1]/i){
print (OUTFILE "$row[2]\t$row[1]\t$common{$row[2]}\t$common{$row[1]}\t$product{$row[2]}\t$product{$row[1]}\t$row[3]\t$row[4]\t\n");
print (OUTFILEname "$common{$row[2]}\t$common{$row[1]}\t$row[3]\t$row[4]\n");
}
if($pre_genelist=~/$row[1]/i ){
print (OUTFILE "$row[1]\t$row[2]\t$common{$row[1]}\t$common{$row[2]}\t$product{$row[1]}\t$product{$row[2]}\t$row[3]\t$row[4]\n");
print (OUTFILEname "$common{$row[1]}\t$common{$row[2]}\t$row[3]\t$row[4]\n");
}
# $nodes{"$common{$row[1]}"}=1;
# $nodes{"$common{$row[2]}"}=1;
# $edges{"$common{$row[1]}TO$common{$row[2]}"}=1;
#$edges{"$common{$row[2]}TO$common{$row[1]}"}=1;
#### end text file print
#print "Proteins here are $test[1] and $test[2]<p>\n";
#if(($test[1]=~/SPAC19D5.01/ && $test[2]=~/SPAC24B11.06C/) ||($test[2]=~/SPAC19D5.01/ && $test[1]=~/SPAC24B11.06C/) ){
# print "<p>pyp2 and sty1 found in databases withint print !!!\n";
# }
my $color="#FFFFFF";
my $int="";
if(defined $gencer{"$row[1],$row[2]"}){
$color="#FFCCCC";
$int="gencer";
#print "Found pombe ints!!!!!!!!!!!!!!<p>\n";
}
if(defined $protcer{"$row[1],$row[2]"}){
$color="#FFFF99";
$int="protcer";
}
if(defined $genpb{"$row[1],$row[2]"}){
$color="#CCFFFF";
$int="genpb";
}
if(defined $protpb{"$row[1],$row[2]"}){
$color="#99FF99";
$int="protpb";
#print "Found pombe ints!!!!!!!!!!!!!!<p>\n";
}
if($count<=$intnum){
$nodes{"$common{$row[1]}"}=1;
$nodes{"$common{$row[2]}"}=1;
#$edges{"$common{$test[1]}TO$common{$test[2]}"}.="INT$int";
#$edges{"$common{$row[2]}TO$common{$row[1]}"}=1;
print qq(<tr bgcolor=$color>
<td>).$count."</td>";
if($pre_genelist =~/$row[2]/i and $pre_genelist!~/$row[1]/){
print "<td>".$row[2]."</td>
<td>".$row[1]."</td>
<td>".$common{$row[2]}."</td>
<td>".$common{$row[1]}."</td>
<td>".$product{$row[2]}."</td>
<td>".$product{$row[1]}."</td>";
}
if($pre_genelist=~/$row[1]/i ){
print "<td>".$row[1]."</td>
<td>".$row[2]."</td>
<td>".$common{$row[1]}."</td>
<td>".$common{$row[2]}."</td>
<td>".$product{$row[1]}."</td>
<td>".$product{$row[2]}."</td>";
$nodes{"$common{$row[1]}"}="query";
}
if($pre_genelist=~/$row[2]/i ){
$nodes{"$common{$row[2]}"}="query";
}
if($method eq 'SVM' ){
print"<td>".$row[4]."</td></tr>";
$edges{"$common{$row[1]}TO$common{$row[2]}INT$int"}=$row[4];
}
if($method eq 'RF'){
print"<td>".$row[3]."</td></tr>";
$edges{"$common{$row[1]}TO$common{$row[2]}INT$int"}=$row[3];
}
if($method eq 'RF and SVM'){
print"<td>".$row[4]."</td><td>".$row[3]."</td></tr>";
$edges{"$common{$row[1]}TO$common{$row[2]}INT$int"}=($row[3]+$row[4])/2;
}
}##end if
$count=$count+1;
}## end while
print("</table>");
close(OUTFILE);
close(OUTFILENAME);
my $fout2=$fout;
$fout2=~s/\/var\/www\/htdocs//g;
my $foutname2=$foutname;
$foutname2=~s/\/var\/www\/htdocs//g;
$count=$count-1;
print "<p>There are a total of $count predictions with $method above $mscore.<p>";
print qq(<p><a name="download"><a href=$fout2>Download</a> all the predictions as a tab separated text file with
IDs,
common names and gene ontology definition</p>);
print qq(<p><a href=$foutname2>Download</a> all the predictions as a tab separated text file only with common names</p>);
#print qq(<p>If you want to visualize the predicted interaction network, save the file only with names and open it in the BioLayout viewer: <a href="http://www.biolayout.org/downloads/BioLayoutExpress3DWebStart.php"><img src="/PInt/webstart-launch-button.png" alt="Start BioLayout Express 3D" width="88" height="23"></a></p>);
my $res_net_data="";
open(OUTFILE , ">$fouthash") or die("Cannot open $fouthash");
print(OUTFILE "nodes: [");
$res_net_data.="nodes: [";
my @ke=keys%nodes;
for my $key(0..$#ke-1){
print (OUTFILE "{id: \"$ke[$key]\", label: \"$ke[$key]\", query: \"$nodes{$ke[$key]}\"},");
$res_net_data.="{id: \"$ke[$key]\", label: \"$ke[$key]\", query: \"$nodes{$ke[$key]}\"},";
}
print(OUTFILE "{id: \"$ke[$#ke]\",label: \"$ke[$#ke]\", query: \"$nodes{$ke[$#ke]}\"}],\nedges: [");
$res_net_data.="{id: \"$ke[$#ke]\",label: \"$ke[$#ke]\", query: \"$nodes{$ke[$#ke]}\"}],\nedges: [";
@ke=keys%edges;
for my $key(0..$#ke-1){
(my $tar,my $sour, my $int )=split(/TO|INT/,$ke[$key]);
print (OUTFILE "{id: \"$tar TO$sour\", target: \"$tar\", source: \"$sour\", weight: $edges{$ke[$key]} , type: \"$int\"},");
$res_net_data.="{id: \"$tar TO$sour\", target: \"$tar\", source: \"$sour\", weight: $edges{$ke[$key]}, type: \"$int\"},";
}
(my $tar,my $sour, my $int )=split(/TO|INT/,$ke[$#ke]);
print(OUTFILE "{id: \"$tar TO$sour\", target: \"$tar\", source: \"$sour\", weight: $edges{$ke[$#ke]}, type: \"$int\"}]");
$res_net_data.="{id: \"$tar TO$sour\", target: \"$tar\", source: \"$sour\", weight: $edges{$ke[$#ke]}, type: \"$int\"}]";
my $cyto=loadcytoweb($res_net_data);
return($res_net_data);
}### successful prediction
}
###############################################################print results for single protein
sub print_results_single_table{
my ($sth_query, $method, $mscore, $intnum, $pre_genelist,$common, $product, $protcer, $protpb, $genpb, $gencer)=@_;
(my %common)=%$common;
(my %product)=%$product;
(my %protcer)=%$protcer;
(my %protpb)=%$protpb;
(my %genpb)=%$genpb;
(my %gencer)=%$gencer;
$sth_query->execute();
my %nodes;
my %edges;
my @test=$sth_query->fetchrow();
#print "@test<p>\n";
if (! defined @test){
print "There are no predicted interactions.<p>\n";
}
else{
my $count=1;
#print "Test $pre_genelist\t $test[1]\tcomm $common{$test[1]}\t prod $product{$test[1]}<p>\n";
#print"$method<p>\n";
print "<table border='1' ><tr>
<th>Rank</th>
<th>protein</th>
<th>common name</th>
<th>product</th>";
if($method eq 'SVM' ){
print"<th>SVM score</th></tr>";
}
if($method eq 'RF'){
print"<th>RF score</th></tr>";
}
if($method eq 'RF and SVM'){
print"<th>SVM score</th><th>RF score</th></tr>";
}
###set output files:
#prepare text file name
my @time=localtime;
my $fout="/var/www/htdocs/PInt/tmp/interactions".$time[0].$time[1].$time[2]."txt";
my $fouthash="/var/www/htdocs/PInt/tmp/hash".$time[0].$time[1].$time[2]."txt";
my $foutname="/var/www/htdocs/PInt/tmp/interactions_onlyname".$time[0].$time[1].$time[2]."txt";
open(OUTFILE , ">$fout") or die("Cannot open $fout");
print (OUTFILE "##Interactions predicted with score above $mscore\n");
print (OUTFILE "##ID1\tID2\tcommon_name1\tcommon_name2\tproduct1\tproduct2\tRFscore\tSVMscore\n");
open(OUTFILEname , ">$foutname") or die("Cannot open $foutname");
print (OUTFILEname "##Interactions predicted with score above $mscore\n");
print (OUTFILEname "##common_name1\tcommon_name2\tRFscore\tSVMscore\n");
###############print data from the test: very inelegant but if not like this the first prediction is always lost...
## could write a count query separate from the retrieval one.
####for text file:
$nodes{"$common{$test[1]}"}=1;
$nodes{"$common{$test[2]}"}=1;
if($pre_genelist=~/$test[2]/i and $pre_genelist!~/$test[1]/i){
print (OUTFILE "$test[2]\t$test[1]\t$common{$test[2]}\t$common{$test[1]}\t$product{$test[2]}\t$product{$test[1]}\t$test[3]\t$test[4]\t\n");
print (OUTFILEname "$common{$test[2]}\t$common{$test[1]}\t$test[3]\t$test[4]\n");
}
if($pre_genelist=~/$test[1]/i ){
print (OUTFILE "$test[1]\t$test[2]\t$common{$test[1]}\t$common{$test[2]}\t$product{$test[1]}\t$product{$test[2]}\t$test[3]\t$test[4]\n");
print (OUTFILEname "$common{$test[1]}\t$common{$test[2]}\t$test[3]\t$test[4]\n");
$nodes{"$common{$test[1]}"}="query";
}
if($pre_genelist=~/$test[2]/i ){
$nodes{"$common{$test[2]}"}="query";
}
#$edges{"$common{$test[1]}TO$common{$test[2]}INT$int"}=($test[3]+$test[4])/2;
#### end text file print
#print "Proteins here are $test[1] and $test[2]<p>\n";
#if(($test[1]=~/SPAC19D5.01/ && $test[2]=~/SPAC24B11.06C/) ||($test[2]=~/SPAC19D5.01/ && $test[1]=~/SPAC24B11.06C/) ){