-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoba_multi.cgi
executable file
·2733 lines (2492 loc) · 165 KB
/
soba_multi.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/bin/perl
# partially cleaned up amigo.cgi from 12.204 to only produce SObA 2016 12 14
# /~raymond/cgi-bin/soba_biggo.cgi?action=annotSummaryCytoscape&autocompleteValue=F56F4.3%20(Caenorhabditis%20elegans,%20WB:WBGene00018980,%20-,%20-)&showControlsFlag=1
# on wormbase
# root/templates/classes/gene/phenotype_graph.tt2
# lib/WormBase/API/Object/Gene.pm
# root/js/wormbase.js
# anatomy, disease, go, lifestage, and phenotype
# Show "No observed ...", e.g.
# https://wormbase.org/species/c_elegans/gene/WBGene00002159#0b--10
# ZK512.8
# let-4
# WBbt:0006817 0.02
# WBbt:0006814 0.02
# WBbt:0003927 0.02
# WBbt:0006976 0.02
# WBbt:0004096 0.02
# WBbt:0005664 0.02
# WBbt:0003827 0.033
# WBbt:0003826 0.033
# WBbt:0007808 0.033
# WBbt:0007807 0.033
# WBbt:0005668 0.033
# WBbt:0008434 0.033
# WBbt:0008433 0.033
# WBbt:0005661 0.033
# WBbt:0005465 0.036
# WBbt:0005448 0.05
# WBbt:0005835 0.084
# WBbt:0006828 0.087
#
#
# GO:0061458 0.07
# GO:0048569 0.07
# GO:0043632 0.072
# GO:0007568 0.072
# GO:0030163 0.099
use CGI;
use strict;
use HTML::Entities; # for untainting with encode_entities()
use LWP::Simple;
use LWP::UserAgent;
use JSON;
use Tie::IxHash; # allow hashes ordered by item added
use Net::Domain qw(hostname hostfqdn hostdomain);
use URI::Encode qw(uri_encode uri_decode);
use Storable qw(dclone); # copy hash of hashes
use POSIX;
use Time::HiRes qw( time );
my $startTime = time; my $prevTime = time;
$startTime =~ s/(\....).*$/$1/;
$prevTime =~ s/(\....).*$/$1/;
my $hostname = hostname();
my ($cshlHeader, $cshlFooter) = &cshlNew();
# my $top_datatype = 'phenotype';
my $json = JSON->new->allow_nonref;
my $query = new CGI;
# my $base_solr_url = "http://localhost:8080/solr/$top_datatype/"; # big geneontology golr server
my $base_solr_url = "http://localhost:8080/solr/"; # big geneontology golr server
# my $base_solr_url = "http://131.215.12.202:8080/solr/"; # 2020 03 27 - changing this for Raymond
my %paths; # finalpath => array of all (array of nodes of paths that end)
# childToParent -> child node -> parent node => relationship
# # parentToChild -> parent node -> child node => relationship
my %nodesAll; # for an annotated phenotype ID, all nodes in its topological map that have transitivity
my %edgesAll; # for an annotated phenotype ID, all edges in its topological map that have transitivity
my %ancestorNodes;
&process();
sub process {
my $action; # what user clicked
unless ($action = $query->param('action')) { $action = 'none'; }
# http://wobr2.caltech.edu/~azurebrd/cgi-bin/soba_biggo.cgi?radio_datatype=phenotype&gene=let-23+%28Caenorhabditis+elegans%2C+WB%3AWBGene00002299%2C+-%2C+ZK1067.1%29&gene=lin-3+%28Caenorhabditis+elegans%2C+WB%3AWBGene00002992%2C+-%2C+F36H1.4%29&action=Graph+Two+Genes
if ($action eq 'annotSummaryCytoscape') { &annotSummaryCytoscape('source_gene'); }
elsif ($action eq 'annotSummaryGraph') { &annotSummaryGraph(); }
elsif ($action eq 'annotSummaryJson') { &annotSummaryJson(); } # temporarily keep this for the live www.wormbase going through the fake phenotype_graph_json widget
elsif ($action eq 'annotSummaryJsonp') { &annotSummaryJsonp(); } # new jsonp widget to get directly from .wormbase without fake widget
elsif ($action eq 'frontPage') { &frontPage(); } # autocomplete on gene names
elsif ($action eq 'Analyze Terms') { &annotSummaryCytoscape('source_ontology'); } # autocomplete on gene names
elsif ($action eq 'autocompleteXHR') { &autocompleteXHR(); }
elsif ($action eq 'autocompleteTazendraXHR') { &autocompleteTazendraXHR(); }
elsif ($action eq 'validateGeneDatatype') { &validateGeneDatatype(); }
elsif ($action eq 'One Gene to SObA Graph') { &pickOneGenePage(); }
elsif ($action eq 'One Gene to Big GO SObA Graph') { &pickOneGeneBiggoPage(); }
elsif ($action eq 'Gene Pair to Big GO SObA Graph') { &pickTwoGenesBiggoPage(); }
elsif ($action eq 'Gene Pair to SObA Graph') { &pickTwoGenesPage(); }
elsif ($action eq 'Terms to SObA Graph') { &pickOntologyTermsPage(); }
elsif ($action eq 'Graph Two Genes') { &annotSummaryCytoscape('source_gene'); }
elsif ($action eq 'Graph One Gene') { &annotSummaryCytoscape('source_gene'); }
else { &frontPage(); } # no action, show dag by default
} # sub process
sub autocompleteXHR {
print "Content-type: text/html\n\n";
my ($var, $words) = &getHtmlVar($query, 'query');
unless ($words) { ($var, $words) = &getHtmlVar($query, 'userValue'); }
($var, my $field) = &getHtmlVar($query, 'field');
if ($field eq 'Gene') { &autocompleteGene($words); }
} # sub autocompleteXHR
sub autocompleteTazendraXHR {
print "Content-type: text/html\n\n";
my ($var, $words) = &getHtmlVar($query, 'query');
($var, my $objectType) = &getHtmlVar($query, 'objectType');
if ($objectType eq 'gene') {
my $url = 'https://tazendra.caltech.edu/~azurebrd/cgi-bin/forms/datatype_objects.cgi?action=autocompleteXHR&objectType=gene&userValue=' . $words;
my $page_data = get $url;
if ($page_data) { print qq($page_data\n); } }
} # sub autocompleteTazendraXHR
sub validateGeneDatatype {
print "Content-type: text/html\n\n";
my ($var, $datatype) = &getHtmlVar($query, 'datatype');
($var, my $gene) = &getHtmlVar($query, 'gene');
my $url = $base_solr_url . $datatype . '/select?qt=standard&indent=on&wt=json&version=2.2&rows=100000&fl=regulates_closure,id,annotation_class&q=document_category:annotation&fq=-qualifier:%22not%22&fq=bioentity:%22' . $gene . '%22';
my $page_data = get $url;
my $perl_scalar = $json->decode( $page_data );
my %jsonHash = %$perl_scalar;
if ($jsonHash{'response'}{'numFound'} == 0) { print qq(no data); }
else { print qq(has data); }
} # sub validateGeneDatatype
sub autocompleteGene {
my ($words) = @_;
my ($var, $taxonFq) = &getHtmlVar($query, 'taxonFq');
my ($var, $datatype) = &getHtmlVar($query, 'datatype');
my $max_results = 20;
my $escapedWords = $words;
my $lcwords = lc($escapedWords);
my $ucwords = uc($escapedWords);
$escapedWords =~ s/ /%5C%20/g;
$escapedWords =~ s/:/\\:/g;
my %matches; my $t = tie %matches, "Tie::IxHash"; # sorted hash to filter results
my $datatype_solr_url = $base_solr_url . $datatype . '/';
# Exact match (case sensitive)
my $solr_gene_url = $datatype_solr_url . 'select?qt=standard&fl=score,id,bioentity_internal_id,synonym,bioentity_label,bioentity_name,taxon,taxon_label&version=2.2&wt=json&rows=' . $max_results . '&indent=on&q=*:*&fq=document_category:%22bioentity%22&fq=(bioentity_internal_id:' . $escapedWords . '+OR+bioentity_label:' . $escapedWords . '+OR+bioentity_name:' . $escapedWords . '+OR+synonym:' . $escapedWords . ')';
if ($taxonFq) { $solr_gene_url .= "&fq=($taxonFq)"; }
# print qq($solr_gene_url<br><br>\n\n);
my ($matchesHashref) = &solrSearch( $solr_gene_url, \%matches, $max_results);
%matches = %$matchesHashref;
# String wildcard match (case sensitive)
my $matchesCount = scalar keys %matches;
if ($matchesCount < $max_results) {
my $extraMatchesCount = $max_results - $matchesCount;
$solr_gene_url = $datatype_solr_url . 'select?qt=standard&fl=score,id,bioentity_internal_id,synonym,bioentity_label,bioentity_name,taxon,taxon_label&version=2.2&wt=json&rows=' . $max_results . '&indent=on&q=*:*&fq=document_category:%22bioentity%22&fq=(bioentity_internal_id:' . $escapedWords . '*+OR+bioentity_label:' . $escapedWords . '*+OR+bioentity_name:' . $escapedWords . '*+OR+synonym:' . $escapedWords . '*)';
if ($taxonFq) { $solr_gene_url .= "&fq=($taxonFq)"; }
my ($matchesHashref) = &solrSearch( $solr_gene_url, \%matches, $max_results);
%matches = %$matchesHashref;
}
my @words; my $isPhrase = 0;
if ($words =~ m/[\s\-]/) {
$isPhrase++;
(@words) = split/[\s\-]/, $words; }
if ($isPhrase) {
my $lastWord = pop @words;
my $firstWord = join" ", @words;
my $extraMatchesCount = $max_results - $matchesCount;
$solr_gene_url = $datatype_solr_url . 'select?qt=standard&fl=score,id,bioentity_internal_id,synonym,bioentity_label,bioentity_name,taxon,taxon_label&version=2.2&wt=json&rows=' . $max_results . '&indent=on&q=*:*&fq=document_category:%22bioentity%22&fq=((bioentity_internal_id_searchable:"' . $firstWord . '"+AND+bioentity_internal_id_searchable:' . $lastWord . '*)+OR+(bioentity_name_searchable:"' . $firstWord . '"+AND+bioentity_name_searchable:' . $lastWord . '*)+OR+(bioentity_label_searchable:"' . $firstWord . '"+AND+bioentity_label_searchable:' . $lastWord . '*)+OR+(synonym_searchable:"' . $firstWord . '"+AND+synonym_searchable:' . $lastWord . '*))';
# :8080/solr/$datatype/select?qt=standard&fl=score,id,bioentity_internal_id,bioentity_label,bioentity_name,synonym,taxon,taxon_label&version=2.2&wt=json&rows=500&indent=on&q=*:*&fq=document_category:%22bioentity%22&fq=
if ($taxonFq) { $solr_gene_url .= "&fq=($taxonFq)"; }
my ($matchesHashref) = &solrSearch( $solr_gene_url, \%matches, $max_results);
%matches = %$matchesHashref;
} else { # not a phrase
# Exact match (case insensitive _searchable)
$matchesCount = scalar keys %matches;
if ($matchesCount < $max_results) {
my $extraMatchesCount = $max_results - $matchesCount;
$solr_gene_url = $datatype_solr_url . 'select?qt=standard&fl=score,id,bioentity_internal_id,synonym,bioentity_label,bioentity_name,taxon,taxon_label&version=2.2&wt=json&rows=' . $max_results . '&indent=on&q=*:*&fq=document_category:%22bioentity%22&fq=(bioentity_internal_id_searchable:' . $escapedWords . '+OR+bioentity_label_searchable:' . $escapedWords . '+OR+bioentity_name_searchable:' . $escapedWords . '+OR+synonym_searchable:' . $escapedWords . ')';
if ($taxonFq) { $solr_gene_url .= "&fq=($taxonFq)"; }
my ($matchesHashref) = &solrSearch( $solr_gene_url, \%matches, $max_results);
%matches = %$matchesHashref;
}
# Starting with word Wildcard match (case insensitive _searchable)
$matchesCount = scalar keys %matches;
if ($matchesCount < $max_results) {
my $extraMatchesCount = $max_results - $matchesCount;
$solr_gene_url = $datatype_solr_url . 'select?qt=standard&fl=score,id,bioentity_internal_id,synonym,bioentity_label,bioentity_name,taxon,taxon_label&version=2.2&wt=json&rows=' . $max_results . '&indent=on&q=*:*&fq=document_category:%22bioentity%22&fq=(bioentity_internal_id_searchable:' . $escapedWords . '*+OR+bioentity_label_searchable:' . $escapedWords . '*+OR+bioentity_name_searchable:' . $escapedWords . '*+OR+synonym_searchable:' . $escapedWords . '*)';
if ($taxonFq) { $solr_gene_url .= "&fq=($taxonFq)"; }
my ($matchesHashref) = &solrSearch( $solr_gene_url, \%matches, $max_results);
%matches = %$matchesHashref;
}
}
my $matches = join"\n", keys %matches;
print $matches;
} # sub autocompleteGene
sub validateListTermsQvalue {
my ($data) = @_;
my (@termsQvalue) = split/\n/, $data;
my %types;
my %termsQvalue = ();
my $errorMessage = '';
foreach my $termQvalue (@termsQvalue) {
if ($termQvalue =~ m/\s+$/) { $termQvalue =~ s/\s+$//; }
my ($term, $qvalue) = ('', undef);
my $orig_qvalue = '';
if ($termQvalue =~ m/^(\S+)\s+(.*?)$/) {
($term, $qvalue) = $termQvalue =~ m/^(\S+)\s+(.*?)$/;
if ($qvalue) { $orig_qvalue = $qvalue; }
if ($qvalue == 0) { $qvalue = 1e-100; $orig_qvalue = "zero"; } # for a value of zero
}
elsif ($termQvalue =~ m/^(\S+)\s+$/) {
$term = $1; }
else {
$term = $termQvalue; }
my ($datatype) = &getDatatypeFromObject($term);
$types{$datatype}++;
if ($qvalue == undef) { $qvalue = 0.367879; }
elsif ($qvalue < 1e-100) { $qvalue = 1e-100; }
$termsQvalue{$term}{qvalue} = $qvalue;
$termsQvalue{$term}{orig_qvalue} = $orig_qvalue;
} # foreach my $termQvalue (@termsQvalue)
my @datatypes = keys %types;
my $datatype = join", ", @datatypes;
if ($errorMessage) {
return (0, $errorMessage, \%termsQvalue);
} elsif (scalar @datatypes == 1) {
return (1, $datatype, \%termsQvalue);
} else {
return (0, qq(ERROR invalid datatype "$datatype" found.), \%termsQvalue);
}
} # validateListTermsQvalue
sub getDatatypeFromObject {
my ($focusTermId) = @_;
my ($identifierType) = $focusTermId =~ m/^(\w+):/;
my $lcIdentifierType = lc($identifierType);
my %idToDatatype;
$idToDatatype{"wbbt"} = "anatomy";
$idToDatatype{"doid"} = "disease";
$idToDatatype{"go"} = "go";
$idToDatatype{"wbls"} = "lifestage";
$idToDatatype{"wbphenotype"} = "phenotype";
$idToDatatype{"WBbt"} = "anatomy";
$idToDatatype{"DOID"} = "disease";
$idToDatatype{"GO"} = "go";
$idToDatatype{"WBls"} = "lifestage";
$idToDatatype{"WBPhenotype"} = "phenotype";
if ($idToDatatype{$identifierType}) { return $idToDatatype{$identifierType}; }
elsif ($idToDatatype{$lcIdentifierType}) { return $idToDatatype{$lcIdentifierType}; }
else { return "$focusTermId"; }
} # sub getSolrUrl
sub solrSearch {
my ($solr_gene_url, $matchesHashref, $max_results) = @_;
my $matchesCount = scalar keys %$matchesHashref;
if ($matchesCount < $max_results) {
my $page_data = get $solr_gene_url;
unless ($page_data) { return $matchesHashref; }
my $perl_scalar = $json->decode( $page_data );
my %jsonHash = %$perl_scalar;
foreach my $geneHash (@{ $jsonHash{"response"}{"docs"} }) {
my %geneHash = %$geneHash;
my $id = $geneHash{id} || '-';
my $synonym = '-';
my $synonymRef = $geneHash{synonym} || '';
if ($synonymRef) {
my (@syns) = @$synonymRef;
$synonym = join ", ", @syns; }
my $taxon_label = $geneHash{taxon_label} || '-';
my $bioentity_label = $geneHash{bioentity_label} || '-';
my $bioentity_name = $geneHash{bioentity_name} || '-';
my $entry = qq($bioentity_label ($taxon_label, $id, $bioentity_name, $synonym));
unless ($$matchesHashref{$entry}) { $$matchesHashref{$entry}++; }
}
if (scalar (@{ $jsonHash{"response"}{"docs"} }) >= $max_results) { $$matchesHashref{"more results not shown; narrow your search"}++; }
} # if (scalar keys %matches < $max_results)
return $matchesHashref;
} # sub solrSearch
sub frontPage {
# print "Content-type: text/html\n\n";
# my $header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><HTML><HEAD>';
# $header .= "<title>$title</title>\n";
# $header .= "</head>";
# $header .= '<body class="yui-skin-sam">';
# print qq($header);
my $title = 'SObA options page';
&printHtmlHeader($title);
print qq(<body class="yui-skin-sam">);
print qq(<form method="get" action="soba_multi.cgi">);
print << "EndOfText";
One Gene to SObA Graph:<br/>
Enter one gene name to obtain a SObA Graph that illustrates annotations.<br/>
<input type="submit" name="action" value="One Gene to SObA Graph"><br/><br/><br/>
Terms to SObA Graph:<br/>
Enter a list of enriched ontology terms (Anatomy, GO or Phenotype, but not mixed), and associated Q (corrected-P) values to obtain a SObA Graph.<br/>
<input type="submit" name="action" value="Terms to SObA Graph"><br/><br/><br/>
Gene Pair to SObA Graph:<br/>
Enter two gene names to obtain a SObA Graph that illustrates their combined annotations.<br/>
<input type="submit" name="action" value="Gene Pair to SObA Graph"><br/><br/><br/>
Big GO One Gene to SObA Graph:<br/>
Enter one gene name to obtain a SObA Graph that illustrates annotations.<br/>
<input type="submit" name="action" value="One Gene to Big GO SObA Graph"><br/><br/><br/>
Big GO Gene Pair to SObA Graph:<br/>
Enter two gene names to obtain a SObA Graph that illustrates their combined annotations.<br/>
<input type="submit" name="action" value="Gene Pair to Big GO SObA Graph"><br/><br/><br/>
EndOfText
print qq(</body></html>);
} # sub frontPage
sub pickOntologyTermsPage {
# print "Content-type: text/html\n\n";
my $title = 'SObA pick a gene';
# my $header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><HTML><HEAD>';
# $header .= "<title>$title</title>\n";
# print qq($header);
&printHtmlHeader($title);
print qq(<body class="yui-skin-sam">);
# my $exampleData = qq(WBbt:0006817 0.00026\nWBbt:0006814 0.00028\nWBbt:0003927 0.00031\nWBbt:0003737 0.00034\nWBbt:0003721 0.00034\nWBbt:0003740 0.00034\nWBbt:0003724 0.00043\nWBbt:0006762 0.00067\nWBbt:0006764 0.0007\nWBbt:0006763 0.00072\n);
my $exampleData = qq(WBPhenotype:0000012 0.0001\nWBPhenotype:0002056 0.00042\nWBPhenotype:0000462 0.005\nWBPhenotype:0001621 0.049\nWBPhenotype:0000200 0.07\nWBPhenotype:0000033 0.093\n);
print qq(<form method="post" action="soba_multi.cgi">);
print qq(<h3>SObA terms - Enter a list of ontology terms (of the same type) and their associated statistical (correct-P or Q) values for a SObA graph</h3>\n);
print qq(<a href="https://wiki.wormbase.org/index.php/User_Guide/SObA#Pair_of_genes" target="_blank">user guide</a><br/><br/>\n);
print qq(Enter datatype objects paired with q-values on separate lines:<br/>\n);
print qq(<textarea rows="8" cols="80" placeholder="$exampleData" name="objectsQvalue" id="objectsQvalue"></textarea>);
print qq(<input type="hidden" name="filterForLcaFlag" id="filterForLcaFlag" value="1">);
print qq(<input type="hidden" name="filterLongestFlag" id="filterLongestFlag" value="1">);
print qq(<input type="hidden" name="showControlsFlag" id="showControlsFlag" value="0">);
print qq(<input type="submit" name="action" id="analyzePairsButton" value="Analyze Terms"><br/><br/><br/>);
print qq(</form>);
print qq(</body></html>);
} # sub pickOntologyTermsPage
sub pickTwoGenesPage {
# print "Content-type: text/html\n\n";
my $title = 'SObA pick two genes';
&printHtmlHeader($title);
my $header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><HTML><HEAD>';
$header .= "<style type=\"text/css\">#forcedPersonAutoComplete { width:25em; padding-bottom:2em; } .div-autocomplete { padding-bottom:1.5em; }</style>";
$header .= qq(<style type="text/css">#forcedProcessAutoComplete { width:30em; padding-bottom:2em; } </style>);
$header .= <<"EndOfText";
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/autocomplete/assets/skins/sam/autocomplete.css" />
<link rel="stylesheet" type="text/css" href="https://tazendra.caltech.edu/~azurebrd/stylesheets/jex.css" />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/fonts/fonts-min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/connection/connection-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/datasource/datasource-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/autocomplete/autocomplete-min.js"></script>
<script type="text/javascript" src="javascript/soba_multi.js"></script>
EndOfText
# $header .= "<title>$title</title>\n";
$header .= "</head>";
$header .= '<body class="yui-skin-sam">';
print qq($header);
print qq(<input type="hidden" name="which_page" id="which_page" value="pickTwoGenesPage">\n);
# my $datatype = 'biggo'; # by defalt for front page
my $datatype = 'phenotype'; # by defalt for front page
my $solr_taxon_url = $base_solr_url . $datatype . '/select?qt=standard&fl=id,taxon,taxon_label&version=2.2&wt=json&rows=0&indent=on&q=*:*&facet=true&facet.field=taxon_label&facet.mincount=1&fq=document_category:%22bioentity%22';
my $page_data = get $solr_taxon_url;
my $perl_scalar = $json->decode( $page_data );
my %jsonHash = %$perl_scalar;
print qq(<form method="get" action="soba_multi.cgi">\n);
print qq(<h3>SObA Gene Pair - combines and compares ontology annotations of a pair of genes</h3>\n);
print qq(<a href="https://wiki.wormbase.org/index.php/User_Guide/SObA#Pair_of_genes" target="_blank">user guide</a><br/><br/>\n);
print qq(Select an ontology to display.<br/>\n);
# UNDO for biggo
# my @datatypes = qw( anatomy disease biggo go lifestage phenotype );
my @datatypes = qw( anatomy disease go lifestage phenotype );
foreach my $datatype (@datatypes) {
my $checked = '';
if ($datatype eq 'phenotype') { $checked = qq(checked="checked"); }
# print qq(<input type="radio" name="radio_datatype" id="radio_datatype" value="$datatype" $checked onclick="setAutocompleteListeners();" >$datatype</input><br/>\n);
print qq(<input type="radio" name="radio_datatype" id="radio_datatype" value="$datatype" $checked onclick="radioDatatypeClick('TwoGenes');" >$datatype</input><br/>\n); }
print qq(<br/>);
my @fieldCount = ('One', 'Two');
my $fieldName = 'geneOneValue';
foreach my $fieldCount (@fieldCount) {
my $countGene = 'first'; if ($fieldCount eq 'Two') { $countGene = 'second'; $fieldName = 'autocompleteValue'; }
print << "EndOfText";
<B>Choose the $countGene gene <!--<span style="color: red;">*</span>--></B>
<font size="-2" color="#3B3B3B">Start typing in a gene and choose from the drop-down.</font>
<span id="messageGene${fieldCount}"></span>
<span id="containerForcedGene${fieldCount}AutoComplete">
<div id="forcedGene${fieldCount}AutoComplete">
<input size="50" name="$fieldName" id="input_Gene${fieldCount}" type="text" style="max-width: 444px; width: 99%; background-color: #E1F1FF;" value="">
<div id="forcedGene${fieldCount}Container"></div>
</div></span><br/><br/>
EndOfText
# UNDO for biggo / species selection
next;
my $div_display = ''; if ($fieldCount eq 'Two') { $div_display = 'style="display: none"'; }
print qq(<div id="controls$fieldCount" $div_display>\n);
print qq(<br/>Prioritize search by selecting one or more species.<br/>\n);
print qq(<select>\n);
my %taxons;
my @priorityTaxons = ( 'Homo sapiens', 'Arabidopsis thaliana', 'Caenorhabditis elegans', 'Danio rerio', 'Drosophila melanogaster', 'Escherichia coli K-12', 'Mus musculus', 'Rattus norvegicus', 'Saccharomyces cerevisiae S288c' );
my %priorityTaxons;
foreach my $taxon (@priorityTaxons) {
$priorityTaxons{$taxon}++;
my $taxon_plus = $taxon; $taxon_plus =~ s/ /+/g;
# print qq(<input type="checkbox" class="taxon${fieldCount}" name="${fieldCount}$taxon" id="${fieldCount}$taxon" value="$taxon_plus" onclick="setAutocompleteListeners();">$taxon</input><br/>\n);
print qq(<option value="$taxon_plus" onclick="setAutocompleteListeners();">$taxon</option>\n);
}
# print qq(<br/>);
# print qq(<br/>Additional species.<br/>);
while (scalar (@{ $jsonHash{"facet_counts"}{"facet_fields"}{"taxon_label"} }) > 0) {
my $taxon = shift @{ $jsonHash{"facet_counts"}{"facet_fields"}{"taxon_label"} };
my $someNumber = shift @{ $jsonHash{"facet_counts"}{"facet_fields"}{"taxon_label"} };
next if ($priorityTaxons{$taxon}); # already entered before
my $taxon_plus = $taxon; $taxon_plus =~ s/ /+/g;
$taxons{$taxon} = $taxon_plus;
# $taxons{qq(<input type="checkbox" class="taxon${fieldCount}" name="${fieldCount}$taxon" id="${fieldCount}$taxon" value="$taxon_plus" onclick="setAutocompleteListeners();">$taxon</input><br/>\n)}++;
}
foreach my $taxon (sort keys %taxons) {
print qq(<option value="$taxons{$taxon}" onclick="setAutocompleteListeners();">$taxon</option>\n);
# print $taxon;
}
print qq(</select>\n);
print qq(</div>\n);
print qq(<br/><br/>\n);
}
print qq(<input type="hidden" name="filterForLcaFlag" value="1">\n);
print qq(<input type="hidden" name="filterLongestFlag" value="1">\n);
print qq(<input type="hidden" name="showControlsFlag" value="0">\n);
print qq(<input type="submit" name="action" value="Graph Two Genes" ></input><br/><br/>\n);
print qq(<input name="reset" type="reset" value="Reset Gene Inputs" onclick="document.getElementById('input_GeneOne').value=''; document.getElementById('input_GeneTwo').value=''; document.getElementById('messageGeneOne').innerHTML =''; document.getElementById('messageGeneTwo').innerHTML ='';"><br/>\n);
print qq(</form>\n);
print qq(</body></html>);
} # sub pickTwoGenesPage
sub pickTwoGenesBiggoPage {
# print "Content-type: text/html\n\n";
my $title = 'SObA pick two genes';
&printHtmlHeader($title);
my $header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><HTML><HEAD>';
$header .= "<style type=\"text/css\">#forcedPersonAutoComplete { width:25em; padding-bottom:2em; } .div-autocomplete { padding-bottom:1.5em; }</style>";
$header .= qq(<style type="text/css">#forcedProcessAutoComplete { width:30em; padding-bottom:2em; } </style>);
$header .= <<"EndOfText";
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/autocomplete/assets/skins/sam/autocomplete.css" />
<link rel="stylesheet" type="text/css" href="https://tazendra.caltech.edu/~azurebrd/stylesheets/jex.css" />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/fonts/fonts-min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/connection/connection-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/datasource/datasource-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/autocomplete/autocomplete-min.js"></script>
<script type="text/javascript" src="javascript/soba_multi.js"></script>
EndOfText
$header .= "</head>";
$header .= '<body class="yui-skin-sam">';
print qq($header);
print qq(<input type="hidden" name="which_page" id="which_page" value="pickTwoGenesBiggoPage">\n);
my $datatype = 'biggo'; # by defalt for biggo page
my $solr_taxon_url = $base_solr_url . $datatype . '/select?qt=standard&fl=id,taxon,taxon_label&version=2.2&wt=json&rows=0&indent=on&q=*:*&facet=true&facet.field=taxon_label&facet.mincount=1&fq=document_category:%22bioentity%22';
my $page_data = get $solr_taxon_url;
my $perl_scalar = $json->decode( $page_data );
my %jsonHash = %$perl_scalar;
print qq(<form method="get" action="soba_multi.cgi">\n);
print qq(<h3>SObA Gene Pair - combines and compares ontology annotations of a pair of genes</h3>\n);
print qq(<a href="https://wiki.wormbase.org/index.php/User_Guide/SObA#Pair_of_genes" target="_blank">user guide</a><br/><br/>\n);
print qq(<input type="hidden" name="radio_datatype" id="radio_datatype" value="biggo">\n);
my @fieldCount = ('One', 'Two');
my $fieldName = 'geneOneValue';
my %taxons;
foreach my $fieldCount (@fieldCount) {
my $countGene = 'first'; if ($fieldCount eq 'Two') { $countGene = 'second'; $fieldName = 'autocompleteValue'; }
print << "EndOfText";
<B>Choose the $countGene gene <!--<span style="color: red;">*</span>--></B>
<font size="-2" color="#3B3B3B">Start typing in a gene and choose from the drop-down.</font>
<span id="messageGene${fieldCount}"></span>
<span id="containerForcedGene${fieldCount}AutoComplete">
<div id="forcedGene${fieldCount}AutoComplete">
<input size="50" name="$fieldName" id="input_Gene${fieldCount}" type="text" style="max-width: 444px; width: 99%; background-color: #E1F1FF;" value="">
<div id="forcedGene${fieldCount}Container"></div>
</div></span><br/><br/>
EndOfText
# next to skip / UNDO for biggo / species selection
my $div_display = ''; # if ($fieldCount eq 'Two') { $div_display = 'style="display: none"'; }
print qq(<div id="controls$fieldCount" $div_display>\n);
print qq(<br/>Prioritize search by selecting a species.<br/>\n);
print qq(<select id="taxon${fieldCount}">\n);
print qq(<option value="All" onclick="setAutocompleteListeners();">All</option>\n);
my @priorityTaxons = ( 'Homo sapiens', 'Arabidopsis thaliana', 'Caenorhabditis elegans', 'Danio rerio', 'Drosophila melanogaster', 'Escherichia coli K-12', 'Mus musculus', 'Rattus norvegicus', 'Saccharomyces cerevisiae S288c' );
my %priorityTaxons;
foreach my $taxon (@priorityTaxons) {
$priorityTaxons{$taxon}++;
my $taxon_plus = $taxon; $taxon_plus =~ s/ /+/g;
print qq(<option value="$taxon_plus" onclick="setAutocompleteListeners();">$taxon</option>\n);
# to use checkboxes instead of dropdown
# print qq(<input type="checkbox" class="taxon${fieldCount}" name="${fieldCount}$taxon" id="${fieldCount}$taxon" value="$taxon_plus" onclick="setAutocompleteListeners();">$taxon</input><br/>\n);
}
print qq(<br/>);
print qq(<br/>Additional species.<br/>);
while (scalar (@{ $jsonHash{"facet_counts"}{"facet_fields"}{"taxon_label"} }) > 0) {
my $taxon = shift @{ $jsonHash{"facet_counts"}{"facet_fields"}{"taxon_label"} };
my $someNumber = shift @{ $jsonHash{"facet_counts"}{"facet_fields"}{"taxon_label"} };
next if ($priorityTaxons{$taxon}); # already entered before
my $taxon_plus = $taxon; $taxon_plus =~ s/ /+/g;
$taxons{$taxon} = $taxon_plus;
# to use checkboxes instead of dropdown
# $taxons{qq(<input type="checkbox" class="taxon${fieldCount}" name="${fieldCount}$taxon" id="${fieldCount}$taxon" value="$taxon_plus" onclick="setAutocompleteListeners();">$taxon</input><br/>\n)}++;
}
foreach my $taxon (sort keys %taxons) {
print qq(<option value="$taxons{$taxon}" onclick="setAutocompleteListeners();">$taxon</option>\n);
# to use checkboxes instead of dropdown
# print $taxon;
}
print qq(</select>\n);
print qq(</div>\n);
print qq(<br/><br/>\n);
}
print qq(<input type="hidden" name="filterForLcaFlag" value="1">\n);
print qq(<input type="hidden" name="filterLongestFlag" value="1">\n);
print qq(<input type="hidden" name="showControlsFlag" value="0">\n);
print qq(<input type="submit" name="action" value="Graph Two Genes" ></input><br/><br/>\n);
print qq(<input name="reset" type="reset" value="Reset Gene Inputs" onclick="document.getElementById('input_GeneOne').value=''; document.getElementById('input_GeneTwo').value=''; document.getElementById('messageGeneOne').innerHTML =''; document.getElementById('messageGeneTwo').innerHTML ='';"><br/>\n);
print qq(</form>\n);
print qq(</body></html>);
} # sub pickTwoGenesBiggoPage
sub pickOneGeneBiggoPage {
# print "Content-type: text/html\n\n";
my $title = 'SObA pick a Big GO gene';
&printHtmlHeader($title);
my $header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><HTML><HEAD>';
$header .= "<title>$title</title>\n";
$header .= "<style type=\"text/css\">#forcedPersonAutoComplete { width:25em; padding-bottom:2em; } .div-autocomplete { padding-bottom:1.5em; }</style>";
$header .= qq(<style type="text/css">#forcedProcessAutoComplete { width:30em; padding-bottom:2em; } </style>);
$header .= <<"EndOfText";
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/autocomplete/assets/skins/sam/autocomplete.css" />
<link rel="stylesheet" type="text/css" href="https://tazendra.caltech.edu/~azurebrd/stylesheets/jex.css" />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/fonts/fonts-min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/connection/connection-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/datasource/datasource-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/autocomplete/autocomplete-min.js"></script>
<script type="text/javascript" src="javascript/soba_multi.js"></script>
EndOfText
$header .= "</head>";
$header .= '<body class="yui-skin-sam">';
print qq($header);
print qq(<input type="hidden" name="which_page" id="which_page" value="pickOneGeneBiggoPage">\n);
my $datatype = 'biggo'; # by defalt for front page
# my $datatype = 'phenotype'; # by defalt for front page
my $solr_taxon_url = $base_solr_url . $datatype . '/select?qt=standard&fl=id,taxon,taxon_label&version=2.2&wt=json&rows=0&indent=on&q=*:*&facet=true&facet.field=taxon_label&facet.mincount=1&fq=document_category:%22bioentity%22';
my $page_data = get $solr_taxon_url;
my $perl_scalar = $json->decode( $page_data );
my %jsonHash = %$perl_scalar;
print qq(<form method="get" action="soba_multi.cgi">\n);
print qq(<input type="hidden" name="radio_datatype" id="radio_datatype" value="biggo"\n);
print << "EndOfText";
<B>Choose a gene <!--<span style="color: red;">*</span>--></B>
<font size="-2" color="#3B3B3B">Start typing in a gene and choose from the drop-down.</font>
<span id="containerForcedGeneAutoComplete">
<div id="forcedGeneAutoComplete">
<input size="50" name="autocompleteValue" id="input_Gene" type="text" style="max-width: 444px; width: 99%; background-color: #E1F1FF;" value="">
<div id="forcedGeneContainer"></div>
</div></span><br/><br/>
EndOfText
print qq(Prioritize search by selecting a species.<br/>\n);
my %taxons;
print qq(<select id="taxon_all">\n);
print qq(<option value="All" onclick="setAutocompleteListeners();">All</option>\n);
# print qq(<input type="checkbox" class="taxon_all" name="taxon_all" id="taxon_all" value="all" checked="checked">All Taxons</input><br/>\n);
my @priorityTaxons = ( 'Homo sapiens', 'Arabidopsis thaliana', 'Caenorhabditis elegans', 'Danio rerio', 'Drosophila melanogaster', 'Escherichia coli K-12', 'Mus musculus', 'Rattus norvegicus', 'Saccharomyces cerevisiae S288c' );
my %priorityTaxons;
foreach my $taxon (@priorityTaxons) {
$priorityTaxons{$taxon}++;
my $taxon_plus = $taxon; $taxon_plus =~ s/ /+/g;
print qq(<option value="$taxon_plus" onclick="setAutocompleteListeners();">$taxon</option>\n);
# to use checkboxes instead of dropdown
# print qq(<input type="checkbox" class="taxon" name="$taxon" id="$taxon" value="$taxon_plus" onclick="setAutocompleteListeners();">$taxon</input><br/>\n);
}
print qq(<br/>);
print qq(<br/>Additional species.<br/>);
while (scalar (@{ $jsonHash{"facet_counts"}{"facet_fields"}{"taxon_label"} }) > 0) {
my $taxon = shift @{ $jsonHash{"facet_counts"}{"facet_fields"}{"taxon_label"} };
my $someNumber = shift @{ $jsonHash{"facet_counts"}{"facet_fields"}{"taxon_label"} };
next if ($priorityTaxons{$taxon}); # already entered before
my $taxon_plus = $taxon; $taxon_plus =~ s/ /+/g;
$taxons{$taxon} = $taxon_plus;
# to use checkboxes instead of dropdown
# $taxons{qq(<input type="checkbox" class="taxon" name="$taxon" id="$taxon" value="$taxon_plus" onclick="setAutocompleteListeners();">$taxon</input><br/>\n)}++;
}
foreach my $taxon (sort keys %taxons) {
print qq(<option value="$taxons{$taxon}" onclick="setAutocompleteListeners();">$taxon</option>\n);
# to use checkboxes instead of dropdown
print $taxon;
}
print qq(</select><br/><br/>\n);
print qq(<input type="hidden" name="filterForLcaFlag" value="1">\n);
print qq(<input type="hidden" name="filterLongestFlag" value="1">\n);
print qq(<input type="hidden" name="showControlsFlag" value="0">\n);
print qq(<input type="submit" name="action" value="Graph One Gene"><br/><br/>\n);
print qq(<input name="reset" type="reset" value="Reset Gene Input" onclick="document.getElementById('input_Gene').value='';"><br/>\n);
print qq(</form>\n);
print qq(</body></html>);
} # sub pickOneGeneBiggoPage
sub pickOneGenePage {
# print "Content-type: text/html\n\n";
my $title = 'SObA pick a gene';
&printHtmlHeader($title);
my $header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><HTML><HEAD>';
$header .= "<title>$title</title>\n";
# $header .= '<link rel="stylesheet" href="https://tazendra.caltech.edu/~azurebrd/stylesheets/jex.css" />';
# $header .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"http://yui.yahooapis.com/2.7.0/build/autocomplete/assets/skins/sam/autocomplete.css\" />";
$header .= "<style type=\"text/css\">#forcedPersonAutoComplete { width:25em; padding-bottom:2em; } .div-autocomplete { padding-bottom:1.5em; }</style>";
$header .= qq(<style type="text/css">#forcedProcessAutoComplete { width:30em; padding-bottom:2em; } </style>);
# <link rel="stylesheet" type="text/css" href="../yui/2.7.0/build/autocomplete/assets/skins/sam/autocomplete.css" />
# <link rel="stylesheet" type="text/css" href="../stylesheets/jex.css" />
# <link rel="stylesheet" type="text/css" href="../yui/2.7.0/build/fonts/fonts-min.css" />
# <script type="text/javascript" src="../yui/2.7.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
# <script type="text/javascript" src="../yui/2.7.0/build/connection/connection-min.js"></script>
# <script type="text/javascript" src="../yui/2.7.0/build/datasource/datasource-min.js"></script>
# <script type="text/javascript" src="../yui/2.7.0/build/autocomplete/autocomplete-min.js"></script>
# <script type="text/javascript" src="../javascript/soba_multi.js"></script>
$header .= <<"EndOfText";
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/autocomplete/assets/skins/sam/autocomplete.css" />
<link rel="stylesheet" type="text/css" href="https://tazendra.caltech.edu/~azurebrd/stylesheets/jex.css" />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/fonts/fonts-min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/connection/connection-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/datasource/datasource-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/yui/2.7.0/autocomplete/autocomplete-min.js"></script>
<script type="text/javascript" src="javascript/soba_multi.js"></script>
EndOfText
$header .= "</head>";
$header .= '<body class="yui-skin-sam">';
print qq($header);
print qq(<input type="hidden" name="which_page" id="which_page" value="pickOneGenePage">\n);
# my $datatype = 'biggo'; # by defalt for front page
my $datatype = 'phenotype'; # by defalt for front page
my $solr_taxon_url = $base_solr_url . $datatype . '/select?qt=standard&fl=id,taxon,taxon_label&version=2.2&wt=json&rows=0&indent=on&q=*:*&facet=true&facet.field=taxon_label&facet.mincount=1&fq=document_category:%22bioentity%22';
my $page_data = get $solr_taxon_url;
my $perl_scalar = $json->decode( $page_data );
my %jsonHash = %$perl_scalar;
print qq(<form method="get" action="soba_multi.cgi">\n);
print qq(Select a datatype to display.<br/>\n);
# UNDO for biggo
# my @datatypes = qw( anatomy disease biggo go lifestage phenotype );
my @datatypes = qw( anatomy disease go lifestage phenotype );
foreach my $datatype (@datatypes) {
my $checked = '';
if ($datatype eq 'phenotype') { $checked = qq(checked="checked"); }
print qq(<input type="radio" name="radio_datatype" id="radio_datatype" value="$datatype" $checked onclick="setAutocompleteListeners();" >$datatype</input><br/>\n); }
print qq(<br/>);
print << "EndOfText";
<B>Choose a gene <!--<span style="color: red;">*</span>--></B>
<font size="-2" color="#3B3B3B">Start typing in a gene and choose from the drop-down.</font>
<span id="containerForcedGeneAutoComplete">
<div id="forcedGeneAutoComplete">
<input size="50" name="autocompleteValue" id="input_Gene" type="text" style="max-width: 444px; width: 99%; background-color: #E1F1FF;" value="">
<div id="forcedGeneContainer"></div>
</div></span><br/><br/>
EndOfText
print qq(<input type="hidden" name="filterForLcaFlag" value="1">\n);
print qq(<input type="hidden" name="filterLongestFlag" value="1">\n);
print qq(<input type="hidden" name="showControlsFlag" value="0">\n);
print qq(<input type="submit" name="action" value="Graph One Gene"><br/><br/>\n);
print qq(<input name="reset" type="reset" value="Reset Gene Input" onclick="document.getElementById('input_Gene').value='';"><br/>\n);
print qq(<div style="display:none">);
print qq(<br/>Prioritize search by selecting one or more species.<br/>\n);
my %taxons;
# print qq(<input type="checkbox" class="taxon_all" name="taxon_all" id="taxon_all" value="all" checked="checked">All Taxons</input><br/>\n);
my @priorityTaxons = ( 'Homo sapiens', 'Arabidopsis thaliana', 'Caenorhabditis elegans', 'Danio rerio', 'Drosophila melanogaster', 'Escherichia coli K-12', 'Mus musculus', 'Rattus norvegicus', 'Saccharomyces cerevisiae S288c' );
my %priorityTaxons;
foreach my $taxon (@priorityTaxons) {
$priorityTaxons{$taxon}++;
my $taxon_plus = $taxon; $taxon_plus =~ s/ /+/g;
print qq(<input type="checkbox" class="taxon" name="$taxon" id="$taxon" value="$taxon_plus" onclick="setAutocompleteListeners();">$taxon</input><br/>\n);
}
print qq(<br/>);
print qq(<br/>Additional species.<br/>);
while (scalar (@{ $jsonHash{"facet_counts"}{"facet_fields"}{"taxon_label"} }) > 0) {
my $taxon = shift @{ $jsonHash{"facet_counts"}{"facet_fields"}{"taxon_label"} };
my $someNumber = shift @{ $jsonHash{"facet_counts"}{"facet_fields"}{"taxon_label"} };
next if ($priorityTaxons{$taxon}); # already entered before
my $taxon_plus = $taxon; $taxon_plus =~ s/ /+/g;
$taxons{qq(<input type="checkbox" class="taxon" name="$taxon" id="$taxon" value="$taxon_plus" onclick="setAutocompleteListeners();">$taxon</input><br/>\n)}++;
}
foreach my $taxon (sort keys %taxons) {
print $taxon;
}
print qq(</div>);
print qq(</form>\n);
print qq(</body></html>);
} # sub pickOneGenePage
sub calcNodeWidth {
my ($nodeCount, $maxAnyCount) = @_;
unless ($nodeCount) { $nodeCount = 1; } # some values generated from enrichment don't have a count, default to smallest
unless ($maxAnyCount) { $maxAnyCount = 1; }
my $nodeWidth = 1; my $nodeScale = 1.5; my $nodeMinSize = 0.01;
# my $logScaler = .6;
$nodeWidth = ( sqrt($nodeCount)/sqrt($maxAnyCount) * $nodeScale ) + $nodeMinSize;
# print qq(NC $nodeCount MAC $maxAnyCount NW $nodeWidth E\n);
return $nodeWidth;
} # sub calcNodeWidth
sub getDiffTime {
my ($start, $prev, $message) = @_;
my $now = time;
$now =~ s/(\....).*$/$1/;
my $diffStart = $now - $startTime;
$diffStart =~ s/(\....).*$/$1/;
my $diffPrev = $now - $prevTime;
$diffPrev =~ s/(\....).*$/$1/;
$prevTime = $now;
$message = qq($diffStart seconds from start, $diffPrev seconds from previous check. Now $message);
return ($message);
} # sub getDiffTime
sub calculateNodesAndEdges {
my ($focusTermId, $geneOneId, $objectsQvalue, $datatype, $rootsChosen, $filterForLcaFlag, $maxDepth, $maxNodes) = @_;
my (@parentNodes) = split/,/, $rootsChosen;
unless ($datatype) { $datatype = 'phenotype'; } # later will need to change based on different datatypes
# if ($datatype eq 'phenotype') { # FIX should come from function call
# @parentNodes = ( 'WBPhenotype:0000886'); # TESTING , doesn't work 2019 03 01
# }
# # radio_etgo=radio_etgo_withiea&rootsChosen=&maxNodes=0&maxDepth=0&filterLongestFlag=0&filterForLcaFlag=1
# # radio_etgo=radio_etgo_withiea&rootsChosen= &showControlsFlag=1&fakeRootFlag=0&filterForLcaFlag=1&filterLongestFlag=0&maxNodes=0&maxDepth=0
# # radio_etgo= &rootsChosen=WBPhenotype:0000886&showControlsFlag=1 &filterForLcaFlag=0&filterLongestFlag=0&maxNodes=0&maxDepth=0
my ($var, $radio_etgo) = &getHtmlVar($query, 'radio_etgo');
my ($var, $radio_etp) = &getHtmlVar($query, 'radio_etp');
my ($var, $radio_etd) = &getHtmlVar($query, 'radio_etd');
my ($var, $radio_eta) = &getHtmlVar($query, 'radio_eta');
my $toReturn = '';
my $solr_url = $base_solr_url . $datatype . '/';
# link 1, from wbgene get wbphenotypes from "grouped":{ "annotation_class":{ "matches":12, "ngroups":4, "groups":[{ "groupValue":"WBPhenotype:0000674", # }]}}
my %allLca; # all nodes that are LCA to any pair of annotated terms
my %nodes; # node -> 'counts' -> $whichGene/'anygene' -> $evidenceType/'anytype'
# node -> qvalue
# node -> orig_qvalue
# node -> label
# node -> annot annotated node
# node -> lca lca node
my %edgesPtc; # edges from parent to child
my $nodeWidth = 1;
my $weightedNodeWidth = 1;
my $unweightedNodeWidth = 1;
my %annotationNodeidWhichgene = (); # annotation state 'annot' vs 'any' -> nodeid -> which gene 'geneOne' or 'geneTwo'
my @annotNodeIds; # array of annotated terms to loop and do pairwise comparisons
my %termsQvalue; # map term to qvalue from user input
# START
my @geneIds = ();
if ($focusTermId) {
push @geneIds, $focusTermId;
if ($geneOneId) { push @geneIds, $geneOneId; }
foreach my $geneId (@geneIds) {
my $whichGene = 'geneOne';
if ($geneId eq $focusTermId) { $whichGene = 'geneTwo'; }
# print qq(FT $focusTermId E\n);
my $annotation_count_solr_url = $solr_url . 'select?qt=standard&indent=on&wt=json&version=2.2&rows=100000&fl=regulates_closure,id,annotation_class&q=document_category:annotation&fq=-qualifier:%22not%22&fq=bioentity:%22' . $geneId . '%22';
if ($radio_etgo) {
if ($radio_etgo eq 'radio_etgo_excludeiea') { $annotation_count_solr_url = $solr_url . 'select?qt=standard&indent=on&wt=json&version=2.2&rows=100000&fl=regulates_closure,id,annotation_class&q=document_category:annotation&fq=-qualifier:%22not%22&fq=-evidence_type:IEA&fq=bioentity:%22' . $geneId . '%22'; }
elsif ($radio_etgo eq 'radio_etgo_onlyiea') { $annotation_count_solr_url = $solr_url . 'select?qt=standard&indent=on&wt=json&version=2.2&rows=100000&fl=bioentity,regulates_closure,id,annotation_class&q=document_category:annotation&fq=-qualifier:%22not%22&fq=evidence_type:(EXP+IDA+IPI+IMP+IGI+IEP)&fq=bioentity:%22' . $geneId . '%22'; } }
if ($radio_etp) {
if ($radio_etp eq 'radio_etp_onlyvariation') { $annotation_count_solr_url = $solr_url . 'select?qt=standard&indent=on&wt=json&version=2.2&rows=100000&fl=regulates_closure,id,annotation_class&q=document_category:annotation&fq=-qualifier:%22not%22&fq=evidence_type:Variation&fq=bioentity:%22' . $geneId . '%22'; }
elsif ($radio_etp eq 'radio_etp_onlyrnai') { $annotation_count_solr_url = $solr_url . 'select?qt=standard&indent=on&wt=json&version=2.2&rows=100000&fl=regulates_closure,id,annotation_class&q=document_category:annotation&fq=-qualifier:%22not%22&fq=evidence_type:RNAi&fq=bioentity:%22' . $geneId . '%22'; } }
if ($radio_etd) {
if ($radio_etd eq 'radio_etd_excludeiea') { $annotation_count_solr_url = $solr_url . 'select?qt=standard&indent=on&wt=json&version=2.2&rows=100000&fl=regulates_closure,id,annotation_class&q=document_category:annotation&fq=-qualifier:%22not%22&fq=-evidence_type:IEA&fq=bioentity:%22' . $geneId . '%22'; } }
if ($radio_eta) {
if ($radio_eta eq 'radio_eta_onlyexprcluster') { $annotation_count_solr_url = $solr_url . 'select?qt=standard&indent=on&wt=json&version=2.2&rows=100000&fl=regulates_closure,id,annotation_class&q=document_category:annotation&fq=-qualifier:%22not%22&fq=id:(*WB\:WBPaper*)&fq=bioentity:%22' . $geneId . '%22'; }
elsif ($radio_eta eq 'radio_eta_onlyexprpattern') { $annotation_count_solr_url = $solr_url . 'select?qt=standard&indent=on&wt=json&version=2.2&rows=100000&fl=regulates_closure,id,annotation_class&q=document_category:annotation&fq=-qualifier:%22not%22&fq=id:(*WB\:Expr*+*WB\:Marker*)&fq=bioentity:%22' . $geneId . '%22'; } }
# Anatomy, Expr and Expression_cluster (ref.
# https://wormbase.org/tools/ontology_browser/show_genes?focusTermName=Anatomy&focusTermId=WBbt:0005766).
# There are three groups of objects WB:Expr***, WBMarker*** (these are Expression patterns), WB:WBPaper*** (these are Expression profiles).
# amigo.cgi query
# $annotation_count_solr_url = $solr_url . 'select?qt=standard&indent=on&wt=json&version=2.2&rows=100000&fl=regulates_closure,id,annotation_class&q=document_category:annotation&fq=-qualifier:%22not%22&fq=bioentity:%22WB:' . $geneId . '%22';
my $page_data = get $annotation_count_solr_url; # get the URL
# print qq( annotation_count_solr_url $annotation_count_solr_url\n); # get the URL
# numFound == 0
my $perl_scalar = $json->decode( $page_data ); # get the solr data
my %jsonHash = %$perl_scalar;
# if ($jsonHash{'response'}{'numFound'} == 0) { return ($toReturn, \%nodes, \%nodes); } # return nothing if there are no annotations found
next if ($jsonHash{'response'}{'numFound'} == 0); # skip if there are no annotations found, can't return because could have 2 genes
foreach my $doc (@{ $jsonHash{'response'}{'docs'} }) {
my $nodeIdAnnotated = $$doc{'annotation_class'};
$annotationNodeidWhichgene{'annot'}{$nodeIdAnnotated}{$whichGene}++;
$annotationNodeidWhichgene{'any'}{$nodeIdAnnotated}{$whichGene}++;
my $id = $$doc{'id'};
my (@idarray) = split/\t/, $id;
if ($datatype eq 'anatomy') {
my @entries = split/\|/, $idarray[7];
foreach my $entry (@entries) {
my $evidenceType = '';
if ($entry =~ m/^WB:Expr/) { $evidenceType = 'Expression Pattern'; }
elsif ($entry =~ m/^WBMarker/) { $evidenceType = 'Expression Pattern'; }
elsif ($entry =~ m/^WB:WBPaper/) { $evidenceType = 'Expression Cluster'; }
if ($evidenceType) {
# FIX ? nodeIdInferred -> nodeIdAnnotany ?
foreach my $nodeIdInferred (@{ $$doc{'regulates_closure'} }) {
# print qq(NODE whichGene $whichGene GOID $nodeIdInferred 1\n);
$annotationNodeidWhichgene{'any'}{$nodeIdInferred}{$whichGene}++; # track which gene inferred nodes came from
# $nodes{$nodeIdInferred}{'counts'}{'any'}++; $nodes{$nodeIdInferred}{'counts'}{$evidenceType}++;
$nodes{$nodeIdInferred}{'counts'}{'anygene'}{'anytype'}++; $nodes{$nodeIdInferred}{'counts'}{'anygene'}{$evidenceType}++;
$nodes{$nodeIdInferred}{'counts'}{$whichGene}{'anytype'}++; $nodes{$nodeIdInferred}{'counts'}{$whichGene}{$evidenceType}++; } } } }
else {
my $evidenceType = $idarray[6];
if ($datatype eq 'lifestage') { if ($evidenceType eq 'IDA') { $evidenceType = 'Gene Expression'; } }
foreach my $nodeIdInferred (@{ $$doc{'regulates_closure'} }) {
# print qq(NODE whichGene $whichGene GOID $nodeIdInferred 2\n);
$annotationNodeidWhichgene{'any'}{$nodeIdInferred}{$whichGene}++; # track which gene inferred nodes came from
# $nodes{$nodeIdInferred}{'counts'}{'any'}++; $nodes{$nodeIdInferred}{'counts'}{$evidenceType}++;
$nodes{$nodeIdInferred}{'counts'}{'anygene'}{'anytype'}++; $nodes{$nodeIdInferred}{'counts'}{'anygene'}{$evidenceType}++;
$nodes{$nodeIdInferred}{'counts'}{$whichGene}{'anytype'}++; $nodes{$nodeIdInferred}{'counts'}{$whichGene}{$evidenceType}++; } }
} # foreach my $doc (@{ $jsonHash{'response'}{'docs'} })
} # foreach my $geneId (@geneIds)
} # if ($focusTermId)
elsif ($objectsQvalue) {
my ($is_ok, $termsQvalue_datatype, $termsQvalueHref) = &validateListTermsQvalue($objectsQvalue);
if ($is_ok) {
my $whichGene = 'geneOne';
%termsQvalue = %$termsQvalueHref;
foreach my $term (sort keys %termsQvalue) {
my $qvalue = $termsQvalue{$term}{qvalue};
my $orig_qvalue = $termsQvalue{$term}{orig_qvalue};
$qvalue = $qvalue + 0; # for some reason this has a linebreak after it, needs to be a number for json
if ($qvalue == 0) { $qvalue = 0.1; }
my $scaling = 0;
# $scaling = 1 / $qvalue;
# $scaling = -1 * log($qvalue);
if ($qvalue) {
$scaling = -1 * log($qvalue); }
$nodes{$term}{'counts'}{'anygene'}{'anytype'} = $scaling;
$nodes{$term}{'qvalue'} = $qvalue;
$nodes{$term}{'orig_qvalue'} = $orig_qvalue;
# print qq(TERM $term V $termsQvalue{$term}{qvalue} S $scaling E\n);
$annotationNodeidWhichgene{'annot'}{$term}{$whichGene}++;
$annotationNodeidWhichgene{'any'}{$term}{$whichGene}++;
} # foreach my $term (sort keys %termsQvalue)
}
else { print qq(Terms did not validate properly. $termsQvalue_datatype<br>\n); }
}
# END
# amigo.cgi
# my $annotation_count_solr_url = $solr_url . 'select?qt=standard&indent=on&wt=json&version=2.2&rows=100000&fl=regulates_closure,id,annotation_class&q=document_category:annotation&fq=-qualifier:%22not%22&fq=bioentity:%22WB:' . $focusTermId . '%22';
# my $phenotype_solr_url = $solr_url . 'select?qt=standard&fl=regulates_transitivity_graph_json,topology_graph_json&version=2.2&wt=json&indent=on&rows=1&fq=-is_obsolete:true&fq=document_category:%22ontology_class%22&q=id:%22' . $phenotypeId . '%22';
my $errorMessage = '';
foreach my $nodeIdAnnotated (sort keys %{ $annotationNodeidWhichgene{'annot'} }) {
push @annotNodeIds, $nodeIdAnnotated;
my $phenotype_solr_url = $solr_url . 'select?qt=standard&fl=regulates_transitivity_graph_json,topology_graph_json&version=2.2&wt=json&indent=on&rows=1&fq=-is_obsolete:true&fq=document_category:%22ontology_class%22&q=id:%22' . $nodeIdAnnotated . '%22';
my $page_data = get $phenotype_solr_url; # get the URL
# print qq( phenotype_solr_url $phenotype_solr_url\n);
my $perl_scalar = $json->decode( $page_data ); # get the solr data
my %jsonHash = %$perl_scalar;
if ($jsonHash{'response'}{'numFound'} == 0) { $errorMessage .= qq($nodeIdAnnotated not found<br/>); }
next unless ($jsonHash{"response"}{"docs"}[0]{"regulates_transitivity_graph_json"} ); # term must have data to extra json from it
my $transHashref = $json->decode( $jsonHash{"response"}{"docs"}[0]{"regulates_transitivity_graph_json"} );
my %transHash = %$transHashref;
my (@nodes) = @{ $transHash{"nodes"} };
my %transNodes; # track transitivity nodes as nodes to keep from topology data
for my $index (0 .. @nodes) { if ($nodes[$index]{'id'}) { my $id = $nodes[$index]{'id'}; $transNodes{$id}++; } }
my $topoHashref = $json->decode( $jsonHash{"response"}{"docs"}[0]{"topology_graph_json"} );
my %topoHash = %$topoHashref;
my (@edges) = @{ $topoHash{"edges"} };
for my $index (0 .. @edges) { # for each edge, add to graph
my ($sub, $obj, $pred) = ('', '', ''); # subject object predicate from topology_graph_json
if ($edges[$index]{'sub'}) { $sub = $edges[$index]{'sub'}; }
if ($edges[$index]{'obj'}) { $obj = $edges[$index]{'obj'}; }
next unless ( ($transNodes{$sub}) && ($transNodes{$obj}) );
if ($edges[$index]{'pred'}) { $pred = $edges[$index]{'pred'}; }
# my $direction = 'back'; my $style = 'solid'; # graph arror direction and style
if ($sub && $obj && $pred) { # if subject + object + predicate
$edgesAll{$nodeIdAnnotated}{$sub}{$obj}++; # for an annotated term's edges, each child to its parents
$edgesPtc{$obj}{$sub}++; # any existing edge, parent to child
} # if ($sub && $obj && $pred)
} # for my $index (0 .. @edges)
my (@nodes) = @{ $topoHash{"nodes"} };
for my $index (0 .. @nodes) { # for each node, add to graph
my ($id, $lbl) = ('', ''); # id and label
if ($nodes[$index]{'id'}) { $id = $nodes[$index]{'id'}; }
if ($nodes[$index]{'lbl'}) { $lbl = $nodes[$index]{'lbl'}; }
next unless ($id);
# UNDO THIS
# $lbl = "$id - $lbl"; # for debugging to find IDs in graph
$nodes{$id}{label} = $lbl;
next unless ($transNodes{$id}); # skip adding node if it's not in transitivity (otherwise, e.g. biggo WBGene00002992 gets GO:0031224 is LCA of GO:0016020 and GO:0016021)
# # $lbl =~ s/ /<br\/>/g; # replace spaces with html linebreaks in graph for more-square boxes
# my $label = "$lbl"; # node label should have full id, not stripped of :, which is required for edge title text
# if ($nodes{$id}) { # if there are annotation counts to variation and/or rnai, add them to the box
# my $annotCounts = '';
# foreach my $whichGene (sort keys %{ $nodes{$id}{'counts'} }) {
# next if ($whichGene eq 'anygene'); # skip 'anygene', only use geneOne / geneTwo
# $annotCounts .= $whichGene . ' - ';
# my @annotCounts;
# foreach my $evidenceType (sort keys %{ $nodes{$id}{'counts'}{$whichGene} }) {
# next if ($evidenceType eq 'anytype'); # skip 'anytype', only used for relative size to max value
# push @annotCounts, qq($nodes{$id}{'counts'}{$whichGene}{$evidenceType} $evidenceType); }
# $annotCounts .= join"; ", @annotCounts; }
# $annotCounts .= "\n";
# $label = qq(LINEBREAK<br\/>$label<br\/><font color="transparent">$annotCounts<\/font>); # add html line break and annotation counts to the label
# }
# print qq(ID $id LBL $lbl E\n);
if ($id && $lbl) {
# if ( ($nodeIdAnnotated eq 'GO:0016021') || ($nodeIdAnnotated eq 'GO:0016020') ) { print qq(ADDING $nodeIdAnnotated TO $id LBL $lbl\n); }
$nodesAll{$nodeIdAnnotated}{$id} = $lbl;
# print qq(nodesAll $nodeIdAnnotated ID $id LBL $lbl E\n);
}
}
} # foreach my $nodeIdAnnotated (sort keys %{ $annotationNodeidWhichgene{'annot'} })