-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoba_go.cgi
More file actions
executable file
·1260 lines (1163 loc) · 71 KB
/
soba_go.cgi
File metadata and controls
executable file
·1260 lines (1163 loc) · 71 KB
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
use CGI;
use strict;
use HTML::Entities; # for untainting with encode_entities()
use LWP::Simple;
use LWP::UserAgent;
use JSON;
use Storable qw(dclone); # copy hash of hashes
use Time::HiRes qw( time );
my $startTime = time; my $prevTime = time;
$startTime =~ s/(\....).*$/$1/;
$prevTime =~ s/(\....).*$/$1/;
# use DBI;
# my $dbh = DBI->connect ( "dbi:Pg:dbname=testdb;host=", "postgres", "") or die "Cannot connect to database!\n"; # for remote access
# my $result;
my $json = JSON->new->allow_nonref;
my $query = new CGI;
my $base_solr_url = 'http://localhost:8080/solr/'; # raymond dev URL 2015 07 24
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'; }
# &printHtmlHeader();
# print "If you're using this, talk to Juancarlos<br/>";
if ($action eq 'annotSummaryCytoscape') { &annotSummaryCytoscape('all_roots'); }
elsif ($action eq 'annotSummaryGraph') { &annotSummaryGraph(); }
# elsif ($action eq 'update graph') { &annotSummaryCytoscape(); }
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
else { 1; } # no action, show dag by default
} # sub process
sub getSolrUrl {
my ($focusTermId) = @_;
my ($identifierType) = $focusTermId =~ m/^(\w+):/;
my %idToSubdirectory;
$idToSubdirectory{"WBbt"} = "anatomy";
$idToSubdirectory{"DOID"} = "disease";
$idToSubdirectory{"GO"} = "go";
$idToSubdirectory{"WBls"} = "lifestage";
$idToSubdirectory{"WBPhenotype"} = "phenotype";
my $solr_url = $base_solr_url . $idToSubdirectory{$identifierType} . '/';
} # sub getSolrUrl
sub getTopoHash {
my ($focusTermId) = @_;
my ($solr_url) = &getSolrUrl($focusTermId);
my $url = $solr_url . "select?qt=standard&fl=*&version=2.2&wt=json&indent=on&rows=1&q=id:%22" . $focusTermId . "%22&fq=document_category:%22ontology_class%22";
my $page_data = get $url;
my $perl_scalar = $json->decode( $page_data );
my %jsonHash = %$perl_scalar;
my $topoHashref = $json->decode( $jsonHash{"response"}{"docs"}[0]{"topology_graph_json"} );
# return ($topoHashref);
my $transHashref = $json->decode( $jsonHash{"response"}{"docs"}[0]{"regulates_transitivity_graph_json"} ); # need this for inferred Tree View
return ($topoHashref, $transHashref);
} # sub getTopoHash
sub getTopoChildrenParents {
my ($focusTermId, $topoHref) = @_;
my %topo = %$topoHref;
my %children; # children of the wanted focusTermId, value is relationship type (predicate) ; are the corresponding nodes on an edge where the object is the focusTermId
my %parents; # direct parents of the wanted focusTermId, value is relationship type (predicate) ; are the corresponding nodes on an edge where the subject is the focusTermId
my %child; # for any term, each subkey is a child
my (@edges) = @{ $topo{"edges"} };
for my $index (0 .. @edges) {
my ($sub, $obj, $pred) = ('', '', '');
if ($edges[$index]{'sub'}) { $sub = $edges[$index]{'sub'}; }
if ($edges[$index]{'obj'}) { $obj = $edges[$index]{'obj'}; }
if ($edges[$index]{'pred'}) { $pred = $edges[$index]{'pred'}; }
if ($obj eq $focusTermId) { $children{$sub} = $pred; } # track children here
if ($sub eq $focusTermId) { $parents{$obj} = $pred; } # track parents here
}
return (\%children, \%parents);
} # sub getTopoChildrenParents
sub calcNodeWidth {
my ($nodeCount, $maxAnyCount) = @_;
unless ($maxAnyCount) { $maxAnyCount = 1; }
my $nodeWidth = 1; my $nodeScale = 1.5; my $nodeMinSize = 0.01; my $logScaler = .6;
# $nodeWidth = ( log($annotationCounts{$id}{'any'})/log($maxAnyCount) * $nodeScale ) + $nodeMinSize;
# $nodeWidth = ( log(sqrt($annotationCounts{$id}{'any'}+$logScaler))/log(sqrt($maxAnyCount+$logScaler)) * $nodeScale ) + $nodeMinSize;
$nodeWidth = ( sqrt($nodeCount)/sqrt($maxAnyCount) * $nodeScale ) + $nodeMinSize;
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/;
# print qq(START $start NOW $now PREV $prev DIFFPREV $diffPrev E<br/>);
$prevTime = $now;
$message = qq($diffStart seconds from start, $diffPrev seconds from previous check. Now $message);
return ($message);
} # sub getDiffTime
sub populateGeneNamesFromFlatfile {
my %geneNameToId; my %geneIdToName;
my $infile = '/home/azurebrd/cron/gin_names/gin_names.txt';
open (IN, "<$infile") or die "Cannot open $infile : $!";
while (my $line = <IN>) {
chomp $line;
my ($id, $name, $primary) = split/\t/, $line;
if ($primary eq 'primary') { $geneIdToName{$id} = $name; }
my ($lcname) = lc($name);
$geneNameToId{$lcname} = $id; }
close (IN) or die "Cannot close $infile : $!";
return (\%geneNameToId, \%geneIdToName);
} # sub populateGeneNamesFromFlatfile
sub populateGeneNamesFromPostgres {
my %geneNameToId; my %geneIdToName;
# my @tables = qw( gin_locus );
my @tables = qw( gin_wbgene gin_seqname gin_synonyms gin_locus );
# my @tables = qw( gin_seqname gin_synonyms gin_locus );
foreach my $table (@tables) {
my $result = $dbh->prepare( "SELECT * FROM $table;" );
$result->execute();
while (my @row = $result->fetchrow()) {
my $id = "WBGene" . $row[0];
my $name = $row[1];
my ($lcname) = lc($name);
$geneIdToName{$id} = $name;
$geneNameToId{$lcname} = $id; } }
return (\%geneNameToId, \%geneIdToName);
} # sub populateGeneNamesFromPostgres
sub calculateNodesAndEdges {
my ($focusTermId, $datatype, $rootsChosen, $filterForLcaFlag) = @_;
my (@parentNodes) = split/,/, $rootsChosen;
unless ($datatype) { $datatype = 'phenotype'; } # later will need to change based on different datatypes
my ($var, $radio_iea) = &getHtmlVar($query, 'radio_iea');
my $toReturn = '';
# my ($solr_url) = &getSolrUrl($focusTermId);
my $solr_url = $base_solr_url . 'go/';
# link 1, from wbgene get wbphenotypes from "grouped":{ "annotation_class":{ "matches":12, "ngroups":4, "groups":[{ "groupValue":"WBPhenotype:0000674", # }]}}
# my $rootId = 'GO:0008150';
# my $rootId = 'GO:0005575';
# my $rootId = 'GO:0003674';
# if ($datatype eq 'phenotype') { $rootId = 'GO:0008150'; }
my %allLca; # all nodes that are LCA to any pair of annotated terms
my %nodes;
my %edgesPtc; # edges from parent to child
my $nodeWidth = 1;
my $weightedNodeWidth = 1;
my $unweightedNodeWidth = 1;
my %annotationCounts; # get annotation counts from evidence type
my %phenotypes; my @annotPhenotypes; # array of annotated terms to loop and do pairwise comparisons
# 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'; # for phenotype
my $annotation_count_solr_url = $solr_url . 'select?qt=standard&indent=on&wt=json&version=2.2&rows=1000000&fl=regulates_closure,id,annotation_class&q=document_category:annotation&fq=-qualifier:%22not%22&fq=bioentity:%22WB:' . $focusTermId . '%22';
# $toReturn .= qq(BAEARE $radio_iea RADIO_IEA<br>\n);
if ($radio_iea eq 'radio_excludeiea') { $annotation_count_solr_url = $solr_url . 'select?qt=standard&indent=on&wt=json&version=2.2&rows=1000000&fl=regulates_closure,id,annotation_class&q=document_category:annotation&fq=-qualifier:%22not%22&fq=-id:*IEA*WBPhenotype*&fq=bioentity:%22WB:' . $focusTermId . '%22'; }
my $page_data = get $annotation_count_solr_url; # get the URL
my $perl_scalar = $json->decode( $page_data ); # get the solr data
my %jsonHash = %$perl_scalar;
foreach my $doc (@{ $jsonHash{'response'}{'docs'} }) {
my $phenotype = $$doc{'annotation_class'};
$phenotypes{$phenotype}++;
my $id = $$doc{'id'};
my (@idarray) = split/\t/, $id;
my $type = $idarray[6];
# $annotationCounts{$phenotype}{'any'}++; $annotationCounts{$phenotype}{$type}++;
# $nodes{$phenotype}{'counts'}{'any'}++; $nodes{$phenotype}{'counts'}{$type}++;
foreach my $goid (@{ $$doc{'regulates_closure'} }) {
$annotationCounts{$goid}{'any'}++; $annotationCounts{$goid}{$type}++;
$nodes{$goid}{'counts'}{'any'}++; $nodes{$goid}{'counts'}{$type}++; }
# my $varCount = 0; my $rnaiCount = 0;
# if ($id =~ m/WB:WBVar\d+/) { my (@wbvar) = $id =~ m/(WB:WBVar\d+)/g; $varCount = scalar @wbvar; }
# if ($id =~ m/WB:WBRNAi\d+/) { my (@wbrnai) = $id =~ m/(WB:WBRNAi\d+)/g; $rnaiCount = scalar @wbrnai; }
# foreach my $phenotype (@{ $$doc{'regulates_closure'} }) {
# if ($varCount) { for (1 .. $varCount) { $annotationCounts{$phenotype}{'any'}++; $annotationCounts{$phenotype}{'Allele'}++;
# $nodes{$phenotype}{'counts'}{'any'}++; $nodes{$phenotype}{'counts'}{'Allele'}++; } }
# if ($rnaiCount) { for (1 .. $rnaiCount) { $annotationCounts{$phenotype}{'any'}++; $annotationCounts{$phenotype}{'RNAi'}++;
# $nodes{$phenotype}{'counts'}{'any'}++; $nodes{$phenotype}{'counts'}{'RNAi'}++; } }
# }
}
foreach my $phenotypeId (sort keys %phenotypes) {
push @annotPhenotypes, $phenotypeId;
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 $page_data = get $phenotype_solr_url; # get the URL
my $perl_scalar = $json->decode( $page_data ); # get the solr data
my %jsonHash = %$perl_scalar;
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{$phenotypeId}{$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"; # node label should have full id, not stripped of :, which is required for edge title text
$nodes{$id}{label} = $lbl;
next unless ($transNodes{$id});
# $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 ($annotationCounts{$id}) { # if there are annotation counts to variation and/or rnai, add them to the box
my @annotCounts;
foreach my $evidenceType (sort keys %{ $annotationCounts{$id} }) {
next if ($evidenceType eq 'any'); # skip 'any', only used for relative size to max value
push @annotCounts, qq($annotationCounts{$id}{$evidenceType} $evidenceType); }
my $annotCounts = join"; ", @annotCounts;
$label = qq(LINEBREAK<br\/>$label<br\/><font color="transparent">$annotCounts<\/font>); # add html line break and annotation counts to the label
}
if ($id && $lbl) {
$nodesAll{$phenotypeId}{$id} = $lbl;
}
}
} # foreach my $phenotypeId (sort keys %phenotypes)
if (!$filterForLcaFlag) {
foreach my $annotTerm (sort keys %nodesAll) {
$nodes{$annotTerm}{annot}++;
foreach my $phenotype (sort keys %{ $nodesAll{$annotTerm} }) {
my $url = "http://www.wormbase.org/species/all/go_term/$phenotype"; # URL to link to wormbase page for object
$allLca{$phenotype}++;
unless ($phenotypes{$phenotype}) { # only add lca nodes that are not annotated terms
$nodes{$phenotype}{lca}++; } } } }
else {
while (@annotPhenotypes) {
my $ph1 = shift @annotPhenotypes; # compare each annotated term node to all other annotated term nodes
my $url = "http://www.wormbase.org/species/all/go_term/$ph1"; # URL to link to wormbase page for object
my $xlabel = $ph1; # FIX
$nodes{$ph1}{annot}++;
foreach my $ph2 (@annotPhenotypes) { # compare each annotated term node to all other annotated term nodes
my $lcaHashref = &calculateLCA($ph1, $ph2);
my %lca = %$lcaHashref;
foreach my $lca (sort keys %lca) {
$url = "http://www.wormbase.org/species/all/go_term/$lca"; # URL to link to wormbase page for object
$allLca{$lca}++;
unless ($phenotypes{$lca}) { # only add lca nodes that are not annotated terms
$xlabel = $lca; # FIX
$nodes{$lca}{lca}++;
}
} # foreach my $lca (sort keys %lca)
} # foreach my $ph2 (@annotPhenotypes) # compare each annotated term node to all other annotated term nodes
} # while (@annotPhenotypes)
}
my %edgesLca; # edges that exist in graph generated from annoated terms + lca terms + root
# my @parentNodes = ($rootId); # nodes that are parents, at first root, later any nodes that should be in graph
# my @parentNodes = ('GO:0008150', 'GO:0005575', 'GO:0003674');
# my @parentNodes = ('GO:0008150'); # cannot compute to fake root, edges LCA creates wrong edges going to fake root from other terms, like GO:0005622 to fake root for WBGene0000899
while (@parentNodes) { # while there are parent nodes, go through them
my $parent = shift @parentNodes; # take a parent
my %edgesPtcCopy = %{ dclone(\%edgesPtc) }; # make a temp copy since edges will be getting deleted per parent
while (scalar keys %{ $edgesPtcCopy{$parent} } > 0) { # while parent has children
foreach my $child (sort keys %{ $edgesPtcCopy{$parent} }) { # each child of parent
if ($allLca{$child} || $phenotypes{$child}) { # good node, keep edge when child is an lca or annotated term
delete $edgesPtcCopy{$parent}{$child}; # remove from %edgesPtc, does not need to be checked further
push @parentNodes, $child; # child is a good node, add to parent list to check its children
# print qq(EDGES LCA PARENT $parent CHILD $child E<br/>\n);
$edgesLca{$parent}{$child}++; } # add parent-child edge to final graph
else { # bad node, remove and reconnect edges
delete $edgesPtcCopy{$parent}{$child}; # remove parent-child edge
foreach my $grandchild (sort keys %{ $edgesPtcCopy{$child} }) { # take each grandchild of child
delete $edgesPtcCopy{$child}{$grandchild}; # remove child-grandchild edge
$edgesPtcCopy{$parent}{$grandchild}++; } } # make replacement edge between parent and grandchild
} # foreach my $child (sort keys %{ $edgesPtcCopy{$parent} })
} # while (scalar keys %{ $edgesPtcCopy{$parent} } > 0)
} # while (@parentNodes)
foreach my $parent (sort keys %edgesLca) {
my $parent_placeholder = $parent;
$parent_placeholder =~ s/:/_placeholderColon_/g; # edges won't have proper title text if ids have : in them
foreach my $child (sort keys %{ $edgesLca{$parent} }) {
my $child_placeholder = $child;
$child_placeholder =~ s/:/_placeholderColon_/g; # edges won't have proper title text if ids have : in them
# $toReturn .= qq(EDGE $parent TO $child E<br/>\n);
# $gviz_lca_edges->add_edge(from => "$parent_placeholder", to => "$child_placeholder", dir => "$direction", color => "$edgecolor", fontcolor => "$edgecolor", style => "$style", arrowsize => ".3");
# $gviz_lca_unweighted->add_edge(from => "$parent_placeholder", to => "$child_placeholder", dir => "$direction", color => "$edgecolor", fontcolor => "$edgecolor", style => "$style", arrowsize => ".3");
# $gviz_homogeneous->add_edge(from => "$parent_placeholder", to => "$child_placeholder", dir => "$direction", color => "$edgecolor", fontcolor => "$edgecolor", style => "$style", arrowsize => ".3");
} # foreach my $child (sort keys %{ $edgesLca{$parent} })
} # foreach my $parent (sort keys %edgesLca)
# foreach my $node (sort keys %nodes) {
# if ($nodes{$node}{annot}) { $toReturn .= qq($node annot<br/>); }
# elsif ($nodes{$node}{lca}) { $toReturn .= qq($node lca<br/>); }
# }
return ($toReturn, \%nodes, \%edgesLca);
} # sub calculateNodesAndEdges
sub annotSummaryJsonp {
# http://131.215.12.204/~azurebrd/cgi-bin/amigo.cgi?action=annotSummaryJsonp&focusTermId=WBGene00000899
# print qq(Content-type: application/json\n\n); # this was for json
# for cross domain access, needs to be jsonp with header below, content-type is different, json has a function wrapped around it.
print $query->header(
-type => 'application/javascript',
-access_control_allow_origin => '*',
);
&annotSummaryJsonCode();
} # sub annotSummaryJsonp
sub annotSummaryJson { # temporarily keep this for the live www.wormbase going through the fake phenotype_graph_json widget
# http://131.215.12.204/~azurebrd/cgi-bin/amigo.cgi?action=annotSummaryJson&focusTermId=WBGene00000899
print qq(Content-type: application/json\n\n); # this was for json
&annotSummaryJsonCode();
} # sub annotSummaryJson
sub annotSummaryJsonCode {
my ($var, $focusTermId) = &getHtmlVar($query, 'focusTermId');
my ($var, $datatype) = &getHtmlVar($query, 'datatype');
my ($var, $fakeRootFlag) = &getHtmlVar($query, 'fakeRootFlag');
my ($var, $filterLongestFlag) = &getHtmlVar($query, 'filterLongestFlag');
my ($var, $filterForLcaFlag) = &getHtmlVar($query, 'filterForLcaFlag');
my ($var, $rootsChosen) = &getHtmlVar($query, 'rootsChosen');
my (@rootsChosen) = split/,/, $rootsChosen;
my ($return, $nodesHashref, $edgesLcaHashref) = &calculateNodesAndEdges($focusTermId, $datatype, $rootsChosen, $filterForLcaFlag);
if ($return) { print qq(RETURN $return ENDRETURN\n); }
my %nodes = %$nodesHashref;
my %edgesLca = %$edgesLcaHashref;
if ($fakeRootFlag) {
my $fakeRoot = 'GO:0000000';
$nodes{$fakeRoot}{label} = 'Gene Ontology';
$nodesAll{$fakeRoot}{label} = 'Gene Ontology';
foreach my $sub (@rootsChosen) {
$edgesLca{$fakeRoot}{$sub}++; # any existing edge, parent to child
# my @branchNodes = ('GO:0008150', 'GO:0005575', 'GO:0003674');
# foreach my $sub (@branchNodes) {
# $edgesLca{$fakeRoot}{$sub}++; # any existing edge, parent to child
# print qq(EDGES LCA fr $fakeRoot S $sub E<br/>\n);
} }
my @nodes = ();
my %rootNodes;
# $rootNodes{'GO:0008150'}++; $rootNodes{'GO:0005575'}++; $rootNodes{'GO:0003674'}++;
foreach my $root (@rootsChosen) { $rootNodes{$root}++; }
if ($fakeRootFlag) { $rootNodes{'GO:0000000'}++; }
my $rootNode = 'GO:0008150';
# my $rootNode = 'GO:0005575';
# my $rootNode = 'GO:0003674';
my $diameterMultiplier = 60;
my %edgesFromLongest; # find edges that belong to the longest path from all nodes to each of their children (to remove indirect nodes, like a grandchild directly to the grandparent, bypassing the parent)
# foreach my $source (@rootsChosen)
foreach my $source (sort keys %nodes) { # for all nodes, calculate longest paths to each child and add to %edgesFromLongest
foreach my $target (sort keys %{ $edgesLca{$source } }) {
# print qq(ROOT $source TO $target E\n);
%paths = ();
foreach my $source (sort keys %edgesLca) {
foreach my $target (sort keys %{ $edgesLca{$source } }) {
$paths{"childToParent"}{$target}{$source}++; } }
my ($edgesFromFinalPathHashref) = &getLongestPathAndTransitivity($source, $target);
my %edgesFromFinalPath = %$edgesFromFinalPathHashref;
foreach my $source (sort keys %{ $edgesFromFinalPath{'longest'} }) {
foreach my $target (sort keys %{ $edgesFromFinalPath{'longest'}{$source} }) {
# print qq(EFILTERED $source TO $target E\n);
$edgesFromLongest{$source}{$target}++; } }
} # foreach my $target (sort keys %{ $edgesLca{$source } })
} # foreach my $source (@rootsChosen)
my @edges = ();
my %nodesWithEdges;
foreach my $source (sort keys %edgesLca) {
foreach my $target (sort keys %{ $edgesLca{$source } }) {
if ( ($filterLongestFlag) && !($edgesFromLongest{$target}{$source}) ) { next; }
# next unless ($edgesFromLongest{$target}{$source}); # only show edges that belong in longest path for some relationship
my $lineColor = '#ddd'; if ($source eq 'GO:0000000') { $lineColor = '#fff'; }
my $cSource = $source; $cSource =~ s/GO://;
my $cTarget = $target; $cTarget =~ s/GO://;
$nodesWithEdges{"GO:$cSource"}++; $nodesWithEdges{"GO:$cTarget"}++;
my $name = $cSource . $cTarget;
# print qq(SOURCE $cSource TARGET $cTarget END<br/>\n);
push @edges, qq({ "data" : { "id" : "$name", "weight" : 1, "source" : "$cSource", "target" : "$cTarget", "lineColor" : "$lineColor" } }); } }
# push @edges, qq({ "data" : { "id" : "legend_nodirect_legend_yesdirect", "weight" : 1, "source" : "legend_nodirect", "target" : "legend_yesdirect" } });
# push @edges, qq({ "data" : { "id" : "legend_root_legend_nodirect", "weight" : 1, "source" : "legend_root", "target" : "legend_nodirect" } });
# push @edges, qq({ "data" : { "id" : "legend_legend_legend_root", "weight" : 1, "source" : "legend_legend", "target" : "legend_root" } });
my $edges = join",\n", @edges;
foreach my $node (sort keys %nodes) {
next unless ($nodesWithEdges{$node});
my $name = $nodes{$node}{label};
# print qq(NODE $node NAME $name END<br/>\n);
$name =~ s/ /\\n/g;
my @annotCounts;
foreach my $evidenceType (sort keys %{ $nodes{$node}{'counts'} }) {
next if ($evidenceType eq 'any'); # skip 'any', only used for relative size to max value
# my $annotationCount = $nodes{$node}{'counts'}{$evidenceType}; my $type = $evidenceType;
# if ($annotationCount > 1) { $type .= 's'; }
# push @annotCounts, qq($annotationCount $type);
push @annotCounts, qq($nodes{$node}{'counts'}{$evidenceType} $evidenceType); }
my $annotCounts = join"; ", @annotCounts;
my $diameter = $diameterMultiplier * &calcNodeWidth($nodes{$node}{'counts'}{'any'}, $nodes{"$rootNode"}{'counts'}{'any'});
my $diameter_unweighted = 40;
my $diameter_weighted = $diameter;
my $fontSize = $diameter * .2; if ($fontSize < 4) { $fontSize = 4; }
my $fontSize_weighted = $fontSize;
my $fontSize_unweighted = 6;
my $borderWidth = 2;
my $borderWidth_weighted = $borderWidth;
my $borderWidth_unweighted = 2; # scaled diameter and fontSize to keep borderWidth the same, but passing values in case we ever want to change them, we won't have to change the cytoscape receiving the json
my $borderWidthRoot = 8;
my $borderWidthRoot_weighted = 4 * $borderWidth;
my $borderWidthRoot_unweighted = 8; # scaled diameter and fontSize to keep borderWidth the same, but passing values in case we ever want to change them, we won't have to change the cytoscape receiving the json
my $labelColor = 'black'; if ($node eq 'GO:0000000') { $labelColor = '#fff'; }
if ($rootNodes{$node}) {
my $nodeColor = 'blue'; if ($node eq 'GO:0000000') { $nodeColor = '#fff'; }
# print qq(ROOT NODE $node\n);
$node =~ s/GO://; push @nodes, qq({ "data" : { "id" : "$node", "name" : "$name", "annotCounts" : "$annotCounts", "borderStyle" : "dashed", "labelColor" : "$labelColor", "nodeColor" : "$nodeColor", "borderWidthUnweighted" : "$borderWidthRoot_unweighted", "borderWidthWeighted" : "$borderWidthRoot_weighted", "borderWidth" : "$borderWidthRoot", "fontSizeUnweighted" : "$fontSize_unweighted", "fontSizeWeighted" : "$fontSize_weighted", "fontSize" : "$fontSize", "diameter" : $diameter, "diameter_weighted" : $diameter_weighted, "diameter_unweighted" : $diameter_unweighted, "nodeShape" : "rectangle" } }); }
elsif ($nodes{$node}{lca}) {
# print qq(LCA NODE $node\n);
$node =~ s/GO://; push @nodes, qq({ "data" : { "id" : "$node", "name" : "$name", "annotCounts" : "$annotCounts", "borderStyle" : "dashed", "labelColor" : "$labelColor", "nodeColor" : "blue", "borderWidthUnweighted" : "$borderWidth_unweighted", "borderWidthWeighted" : "$borderWidth_weighted", "borderWidth" : "$borderWidth", "fontSizeUnweighted" : "$fontSize_unweighted", "fontSizeWeighted" : "$fontSize_weighted", "fontSize" : "$fontSize", "diameter" : $diameter, "diameter_weighted" : $diameter_weighted, "diameter_unweighted" : $diameter_unweighted, "nodeShape" : "ellipse" } }); }
elsif ($nodes{$node}{annot}) {
# print qq(ANNOT NODE $node\n);
$node =~ s/GO://; push @nodes, qq({ "data" : { "id" : "$node", "name" : "$name", "annotCounts" : "$annotCounts", "borderStyle" : "solid", "labelColor" : "$labelColor", "nodeColor" : "red", "borderWidthUnweighted" : "$borderWidth_unweighted", "borderWidthWeighted" : "$borderWidth_weighted", "borderWidth" : "$borderWidth", "fontSizeUnweighted" : "$fontSize_unweighted", "fontSizeWeighted" : "$fontSize_weighted", "fontSize" : "$fontSize", "diameter" : $diameter, "diameter_weighted" : $diameter_weighted, "diameter_unweighted" : $diameter_unweighted, "nodeShape" : "ellipse" } }); }
else {
# print qq(OTHER NODE $node\n);
}
}
my $nodes = join",\n", @nodes;
print qq({ "elements" : {\n);
print qq("nodes" : [\n);
print qq($nodes\n);
print qq(],\n);
print qq("edges" : [\n);
print qq($edges\n);
print qq(]\n);
print qq(} }\n);
} # sub annotSummaryJsonCode
sub annotSummaryCytoscape {
# http://131.215.12.204/~azurebrd/cgi-bin/amigo.cgi?action=annotSummaryCytoscape&focusTermId=WBGene00000899
my ($all_roots) = @_;
my ($var, $focusTermId) = &getHtmlVar($query, 'focusTermId');
my ($var, $datatype) = &getHtmlVar($query, 'datatype');
my ($var, $fakeRootFlag) = &getHtmlVar($query, 'fakeRootFlag');
my ($var, $filterLongestFlag) = &getHtmlVar($query, 'filterLongestFlag');
my ($var, $filterForLcaFlag) = &getHtmlVar($query, 'filterForLcaFlag');
my ($var, $radio_iea) = &getHtmlVar($query, 'radio_iea');
my ($var, $root_bp) = &getHtmlVar($query, 'root_bp');
my ($var, $root_mf) = &getHtmlVar($query, 'root_mf');
my ($var, $root_cc) = &getHtmlVar($query, 'root_cc');
my $toPrint = ''; my $return = '';
my $checked_radio_withiea = 'checked="checked"'; my $checked_radio_excludeiea = '';
if ($radio_iea eq 'radio_excludeiea') { $checked_radio_withiea = ''; $checked_radio_excludeiea = 'checked="checked"'; }
my $checked_root_bp = ''; my $checked_root_cc = ''; my $checked_root_mf = '';
my @roots;
if ($all_roots eq 'all_roots') {
push @roots, "GO:0008150"; push @roots, "GO:0005575"; push @roots, "GO:0003674";
$checked_root_bp = 'checked="checked"'; $checked_root_cc = 'checked="checked"'; $checked_root_mf = 'checked="checked"'; }
else {
if ($root_bp) { $checked_root_bp = 'checked="checked"'; push @roots, $root_bp; }
if ($root_cc) { $checked_root_cc = 'checked="checked"'; push @roots, $root_cc; }
if ($root_mf) { $checked_root_mf = 'checked="checked"'; push @roots, $root_mf; } }
my $roots = join",", @roots;
# my $jsonUrl = 'http://131.215.12.204/~azurebrd/wbgene00000899b.json';
# my $jsonUrl = 'http://131.215.12.204/~azurebrd/cgi-bin/amigo.cgi?action=annotSummaryJson&focusTermId=' . $focusTermId;
my $jsonUrl = 'soba_go.cgi?action=annotSummaryJson&focusTermId=' . $focusTermId . '&radio_iea=' . $radio_iea . '&rootsChosen=' . $roots;
unless ($fakeRootFlag) { $fakeRootFlag = 0; }
$jsonUrl .= "&fakeRootFlag=$fakeRootFlag";
unless ($filterForLcaFlag) { $filterForLcaFlag = 0; }
$jsonUrl .= "&filterForLcaFlag=$filterForLcaFlag";
unless ($filterLongestFlag) { $filterLongestFlag = 0; }
$jsonUrl .= "&filterLongestFlag=$filterLongestFlag";
my $checked_fakeRoot = ''; my $checked_filterLca = ''; my $checked_filterLongest = '';
if ($fakeRootFlag) { $checked_fakeRoot = 'checked="checked"'; }
if ($filterForLcaFlag) { $checked_filterLca = 'checked="checked"'; }
if ($filterLongestFlag) { $checked_filterLongest = 'checked="checked"'; }
print << "EndOfText";
Content-type: text/html\n
<!DOCTYPE html>
<html>
<head>
<link href="http://131.215.12.204/~azurebrd/work/cytoscape/style.css" rel="stylesheet" />
<link href="http://cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.0/jquery.qtip.min.css" rel="stylesheet" type="text/css" />
<meta charset=utf-8 />
<meta name="viewport" content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">
<title>$focusTermId Cytoscape view</title>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="http://131.215.12.204/~azurebrd/javascript/cytoscape.min.js"></script>
<script src="http://131.215.12.204/~azurebrd/javascript/dagre.min.js"></script>
<script src="https://cdn.rawgit.com/cytoscape/cytoscape.js-dagre/1.1.2/cytoscape-dagre.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.0/jquery.qtip.min.js"></script>
<script src="https://cdn.rawgit.com/cytoscape/cytoscape.js-qtip/2.2.5/cytoscape-qtip.js"></script>
<script type="text/javascript">
\$(function(){
var elesJson = {
nodes: [
{ data: { id: 'a', foo: 3, bar: 5, baz: 7 } },
{ data: { id: 'b', foo: 7, bar: 1, baz: 3 } },
{ data: { id: 'c', foo: 2, bar: 7, baz: 6 } },
{ data: { id: 'd', foo: 9, bar: 5, baz: 2 } },
{ data: { id: 'e', foo: 2, bar: 4, baz: 5 } }
],
edges: [
{ data: { id: 'ae', weight: 1, source: 'a', target: 'e' } },
{ data: { id: 'ab', weight: 3, source: 'a', target: 'b' } },
{ data: { id: 'be', weight: 4, source: 'b', target: 'e' } },
{ data: { id: 'bc', weight: 5, source: 'b', target: 'c' } },
{ data: { id: 'ce', weight: 6, source: 'c', target: 'e' } },
{ data: { id: 'cd', weight: 2, source: 'c', target: 'd' } },
{ data: { id: 'de', weight: 7, source: 'd', target: 'e' } }
]
};
\$('#cy2').cytoscape({
style: cytoscape.stylesheet()
.selector('node')
.css({
'background-color': '#6272A3',
'shape': 'rectangle',
'width': 'mapData(foo, 0, 10, 10, 30)',
'height': 'mapData(bar, 0, 10, 10, 50)',
'content': 'data(id)'
})
.selector('edge')
.css({
'width': 'mapData(weight, 0, 10, 3, 9)',
'line-color': '#B1C1F2',
'target-arrow-color': '#B1C1F2',
'target-arrow-shape': 'triangle',
'opacity': 0.8
})
.selector(':selected')
.css({
'background-color': 'black',
'line-color': 'black',
'target-arrow-color': 'black',
'source-arrow-color': 'black',
'opacity': 1
}),
elements: elesJson,
layout: {
name: 'breadthfirst',
directed: true,
padding: 10
},
ready: function(){
// ready 2
}
});
// get exported json from cytoscape desktop via ajax
var graphP = \$.ajax({
url: '$jsonUrl', // wine-and-cheese.json
type: 'GET',
dataType: 'json'
});
Promise.all([ graphP ]).then(initCy);
function initCy( then ){
var elements = then[0].elements;
var cyPhenGraph = window.cyPhenGraph = cytoscape({
container: document.getElementById('cyPhenGraph'),
layout: { name: 'dagre', padding: 10, nodeSep: 5 },
style: cytoscape.stylesheet()
.selector('node')
.css({
'content': 'data(name)',
'background-color': 'white',
'color': 'data(labelColor)',
'shape': 'data(nodeShape)',
'border-color': 'data(nodeColor)',
'border-style': 'data(borderStyle)',
'border-width': 'data(borderWidth)',
'width': 'data(diameter)',
'height': 'data(diameter)',
'text-valign': 'center',
'text-wrap': 'wrap',
'min-zoomed-font-size': 8,
'border-opacity': 0.3,
'font-size': 'data(fontSize)'
})
.selector('edge')
.css({
'target-arrow-shape': 'none',
'source-arrow-shape': 'triangle',
'width': 2,
'line-color': 'data(lineColor)',
'target-arrow-color': 'data(lineColor)',
'source-arrow-color': 'data(lineColor)'
})
.selector('.highlighted')
.css({
'background-color': '#61bffc',
'line-color': '#61bffc',
'target-arrow-color': '#61bffc',
'transition-property': 'background-color, line-color, target-arrow-color',
'transition-duration': '0.5s'
})
.selector('.faded')
.css({
'opacity': 0.25,
'text-opacity': 0
}),
elements: elements,
wheelSensitivity: 0.2,
ready: function(){
window.cyPhenGraph = this;
cyPhenGraph.elements().unselectify();
cyPhenGraph.on('tap', 'node', function(e){
var node = e.cyTarget;
var nodeId = node.data('id');
var neighborhood = node.neighborhood().add(node);
cyPhenGraph.elements().addClass('faded');
neighborhood.removeClass('faded');
var node = e.cyTarget;
var nodeId = node.data('id');
var nodeName = node.data('name');
var annotCounts = node.data('annotCounts');
var qtipContent = annotCounts + '<br/><a target="_blank" href="http://www.wormbase.org/species/all/go_term/GO:' + nodeId + '#03--10">' + nodeName + '</a>';
node.qtip({
position: {
my: 'top center',
at: 'bottom center'
},
style: {
classes: 'qtip-bootstrap',
tip: {
width: 16,
height: 8
}
},
content: qtipContent,
show: {
e: e.type,
ready: true
},
hide: {
e: 'mouseout unfocus'
}
}, e);
});
cyPhenGraph.on('tap', function(e){
if( e.cyTarget === cyPhenGraph ){
cyPhenGraph.elements().removeClass('faded');
}
});
cyPhenGraph.on('mouseover', 'node', function(event) {
var node = event.cyTarget;
var nodeId = node.data('id');
var nodeName = node.data('name');
var annotCounts = node.data('annotCounts');
var qtipContent = annotCounts + '<br/><a target="_blank" href="http://www.wormbase.org/species/all/go_term/GO:' + nodeId + '#03--10">' + nodeName + '</a>';
\$('#info').html( qtipContent );
});
var nodeCount = cyPhenGraph.nodes().length;
if (\$('#fakeRootFlag').is(':checked')) { nodeCount--; }
\$('#nodeCount').html('node count: ' + nodeCount);
var edgeCount = cyPhenGraph.edges().length;
\$('#edgeCount').html('edge count: ' + edgeCount);
}
});
}
\$('#radio_weighted').on('click', function(){
var nodes = cyPhenGraph.nodes();
for( var i = 0; i < nodes.length; i++ ){
var node = nodes[i];
var nodeId = node.data('id');
var diameterWeighted = node.data('diameter_weighted');
cyPhenGraph.\$('#' + nodeId).data('diameter', diameterWeighted);
var fontSizeWeighted = node.data('fontSizeWeighted');
cyPhenGraph.\$('#' + nodeId).data('fontSize', fontSizeWeighted);
}
cyPhenGraph.layout();
});
\$('#radio_unweighted').on('click', function(){
var nodes = cyPhenGraph.nodes();
for( var i = 0; i < nodes.length; i++ ){
var node = nodes[i];
var nodeId = node.data('id');
var diameterUnweighted = node.data('diameter_unweighted');
var diameterWeighted = node.data('diameter_weighted');
cyPhenGraph.\$('#' + nodeId).data('diameter', diameterUnweighted);
var fontSizeUnweighted = node.data('fontSizeUnweighted');
var fontSizeWeighted = node.data('fontSizeWeighted');
cyPhenGraph.\$('#' + nodeId).data('fontSize', fontSizeUnweighted);
}
cyPhenGraph.layout();
});
\$('#view_png_button').on('click', function(){
var png64 = cyPhenGraph.png({full: true, maxWidth: 8000, maxHeight: 8000, bg: 'white'});
\$('#png-export').attr('src', png64);
\$('#png-export').show();
\$('#exportdiv').show();
\$('#cyPhenGraph').hide();
\$('#weightstate').hide();
\$('#view_png_button').hide();
\$('#view_edit_button').show();
\$('#info').text('drag image to desktop, or right-click and save image as');
});
\$('#view_edit_button').on('click', function(){
\$('#png-export').hide();
\$('#exportdiv').hide();
\$('#cyPhenGraph').show();
\$('#weightstate').show();
\$('#view_png_button').show();
\$('#view_edit_button').hide();
});
var updatingElements = ['radio_withiea', 'radio_excludeiea', 'fakeRootFlag', 'filterForLcaFlag', 'filterLongestFlag', 'root_bp', 'root_cc', 'root_mf'];
// var updatingElements = ['radio_withiea', 'radio_excludeiea', 'fakeRootFlag', 'root_bp', 'root_cc', 'root_mf'];
updatingElements.forEach(function(element) {
\$('#'+element).on('click', updateElements); });
function updateElements() {
\$('#controldiv').hide(); \$('#loadingdiv').show();
var radioExcludeIea = \$('input[name=radio_iea]:checked').val();
var rootsPossible = ['root_bp', 'root_cc', 'root_mf'];
var rootsChosen = [];
var fakeRootFlagValue = '0'; if (\$('#fakeRootFlag').is(':checked')) { fakeRootFlagValue = 1; }
var filterForLcaFlagValue = '0'; if (\$('#filterForLcaFlag').is(':checked')) { filterForLcaFlagValue = 1; }
var filterLongestFlagValue = '0'; if (\$('#filterLongestFlag').is(':checked')) { filterLongestFlagValue = 1; }
rootsPossible.forEach(function(rootTerm) {
if (document.getElementById(rootTerm).checked) { rootsChosen.push(document.getElementById(rootTerm).value); } });
var rootsChosenGroup = rootsChosen.join(',');
var url = 'soba_go.cgi?action=annotSummaryJson&focusTermId=$focusTermId&radio_iea=' + radioExcludeIea + '&rootsChosen=' + rootsChosenGroup + '&fakeRootFlag=' + fakeRootFlagValue + '&filterLongestFlag=' + filterLongestFlagValue + '&filterForLcaFlag=' + filterForLcaFlagValue;
// alert(url);
var graphPNew = \$.ajax({
url: url,
type: 'GET',
dataType: 'json'
});
Promise.all([ graphPNew ]).then(newCy);
function newCy( then ){
// cyPhenGraph.elements('node').hide(); // hide all nodes
var elementsNew = then[0].elements;
cyPhenGraph.json( { elements: elementsNew } );
cyPhenGraph.elements().layout({ name: 'dagre', padding: 10, nodeSep: 5 });
\$('#controldiv').show(); \$('#loadingdiv').hide();
var nodeCount = cyPhenGraph.nodes().length;
if (\$('#fakeRootFlag').is(':checked')) { nodeCount--; }
\$('#nodeCount').html('node count: ' + nodeCount);
var edgeCount = cyPhenGraph.edges().length;
\$('#edgeCount').html('edge count: ' + edgeCount);
// var nodeHash = new Object(); // put nodes here that have an edge that shows
// var arrayEdges = cyPhenGraph.elements('edge'); // get the edges in an array
// for (k = 0; k < arrayEdges.length; k++) { // for each edge
// nodeHash[arrayEdges[k].data().source]++ // add the source node to hash of nodes to show
// nodeHash[arrayEdges[k].data().target]++ // add the target node to hash of nodes to show
// }
// var toAlert = '';
// var arrayNodes = cyPhenGraph.elements('node'); // get the edges in an array
// for (k = 0; k < arrayNodes.length; k++) { // for each edge
// var thisNode = arrayNodes[k].data().id;
// toAlert += ' ' + thisNode;
// }
// alert(toAlert);
// cyPhenGraph.elements('node').hide(); // hide all nodes
// cyPhenGraph.elements('node').filter(function(i, ele){ // filter on nodes
// if (nodeHash.hasOwnProperty(ele.id())) { // if the node is is in the hash of nodes to show
// ele.show(); // show the node
// }
// });
// cyPhenGraph.elements().layout({ name: 'dagre', padding: 10, nodeSep: 5 });
}
}
});
</script>
</head>
<body>
<div style="width: 1705px;">
<div id="cyPhenGraph" style="border: 1px solid #aaa; float: left; position: relative; height: 1050px; width: 1050px;"></div>
<div id="exportdiv" style="width: 1050px; height: 1050px; position: relative; float: left; display: none;"><img id="png-export" style="border: 1px solid #ddd; display: none; max-width: 1050px; max-height: 1050px"></div>
<div id="loading">
<span class="fa fa-refresh fa-spin"></span>
</div>
<!--<div id="cy2" style="border: 1px solid #aaa; float: left; position: relative; height: 1050px; width: 400px;"></div>-->
<!--<div id="cy" style="height: 100%; width: 100%; position: absolute;"></div>-->
<div id="loadingdiv" style="z-index: 9999; border: 1px solid #aaa; position: relative; float: left; width: 200px; display: none;">Loading <img src="loading.gif" /></div>
<div id="controldiv" style="z-index: 9999; border: 1px solid #aaa; position: relative; float: left; width: 200px;">
<div id="exportdiv" style="z-index: 9999; position: relative; top: 0; left: 0; width: 200px;">
<button id="view_png_button">export png</button>
<button id="view_edit_button" style="display: none;">go back</button><br/>
</div>
<div id="legenddiv" style="z-index: 9999; position: relative; top: 0; left: 0; width: 200px;">
<span id="nodeCount">node count</span><br/>
<span id="edgeCount">edge count</span><br/>
Legend :<br/>
<table>
<tr><td valign="center"><svg width="22pt" height="22pt" viewBox="0.00 0.00 44.00 44.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 40)">
<polygon fill="white" stroke="none" points="-4,4 -4,-40 40,-40 40,4 -4,4"/>
<g id="node1" class="node"><title></title>
<polygon fill="none" stroke="blue" stroke-dasharray="5,2" points="36,-36 0,-36 0,-0 36,-0 36,-36"/></g></g></svg></td><td valign="center">Root</td></tr>
<tr><td valign="center"><svg width="22pt" height="22pt" viewBox="0.00 0.00 44.00 44.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 40)">
<polygon fill="white" stroke="none" points="-4,4 -4,-40 40,-40 40,4 -4,4"/>
<g id="node1" class="node"><title></title>
<ellipse fill="none" stroke="blue" stroke-dasharray="5,2" cx="18" cy="-18" rx="18" ry="18"/></g></g></svg></td><td valign="center">Without Direct Annotation</td></tr>
<tr><td valign="center"><svg width="22pt" height="22pt" viewBox="0.00 0.00 44.00 44.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 40)">
<polygon fill="white" stroke="none" points="-4,4 -4,-40 40,-40 40,4 -4,4"/>
<g id="node1" class="node"><title></title>
<ellipse fill="none" stroke="red" cx="18" cy="-18" rx="18" ry="18"/></g></g></svg></td><td valign="center">With Direct Annotation</td></tr>
</table></div>
<form method="get" action="soba_go.cgi">
<div id="weightstate" style="z-index: 9999; position: relative; top: 0; left: 0; width: 200px;">
<input type="radio" name="radio_type" id="radio_weighted" checked="checked" >Annotation weighted</input><br/>
<input type="radio" name="radio_type" id="radio_unweighted">Annotation unweighted</input><br/>
</div><br/>
<div id="ieastate" style="z-index: 9999; position: relative; top: 0; left: 0; width: 200px;">
<input type="radio" name="radio_iea" id="radio_withiea" value="radio_withiea" $checked_radio_withiea >with IEA</input><br/>
<input type="radio" name="radio_iea" id="radio_excludeiea" value="radio_excludeiea" $checked_radio_excludeiea >exclude IEA</input><br/>
</div><br/>
<div id="rootschosen" style="z-index: 9999; position: relative; top: 0; left: 0; width: 200px;">
<input type="checkbox" name="root_bp" id="root_bp" value="GO:0008150" $checked_root_bp >Biological Process</input><br/>
<input type="checkbox" name="root_cc" id="root_cc" value="GO:0005575" $checked_root_cc >Cellular Component</input><br/>
<input type="checkbox" name="root_mf" id="root_mf" value="GO:0003674" $checked_root_mf >Molecular Function</input><br/>
</div><br/>
<!--<input type="submit" name="action" value="update graph"><br/>-->
<input type="hidden" name="focusTermId" value="$focusTermId">
<input type="checkbox" id="fakeRootFlag" name="fakeRootFlag" value="1" $checked_fakeRoot>Fake Root<br/>
<input type="checkbox" id="filterForLcaFlag" name="filterForLcaFlag" value="1" $checked_filterLca>Filter LCA Nodes<br/>
<input type="checkbox" id="filterLongestFlag" name="filterLongestFlag" value="1" $checked_filterLongest>Filter Longest Edges<br/>
</form>
<div id="info" style="z-index: 9999; position: relative; top: 0; left: 0; width: 200px;">Mouseover or click node for more information.</div><br/>
</div>
</div>
<!--<div id="legenddiv" style="z-index: 9999; position: absolute; bottom: 0; left: 0; width: 200px;">
Legend :<br/>
<table>
<tr><td valign="center"><svg width="22pt" height="22pt" viewBox="0.00 0.00 44.00 44.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 40)">
<polygon fill="white" stroke="none" points="-4,4 -4,-40 40,-40 40,4 -4,4"/>
<g id="node1" class="node"><title></title>
<polygon fill="none" stroke="blue" stroke-dasharray="5,2" points="36,-36 0,-36 0,-0 36,-0 36,-36"/></g></g></svg></td><td valign="center">Root</td></tr>
<tr><td valign="center"><svg width="22pt" height="22pt" viewBox="0.00 0.00 44.00 44.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 40)">
<polygon fill="white" stroke="none" points="-4,4 -4,-40 40,-40 40,4 -4,4"/>
<g id="node1" class="node"><title></title>
<ellipse fill="none" stroke="blue" stroke-dasharray="5,2" cx="18" cy="-18" rx="18" ry="18"/></g></g></svg></td><td valign="center">Without Direct Annotation</td></tr>
<tr><td valign="center"><svg width="22pt" height="22pt" viewBox="0.00 0.00 44.00 44.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 40)">
<polygon fill="white" stroke="none" points="-4,4 -4,-40 40,-40 40,4 -4,4"/>
<g id="node1" class="node"><title></title>
<ellipse fill="none" stroke="red" cx="18" cy="-18" rx="18" ry="18"/></g></g></svg></td><td valign="center">With Direct Annotation</td></tr>
</table>
<svg width="60pt" height="200pt"
viewBox="0.00 0.00 94.27 288.13" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 284.134)">
<title>test0</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-284.134 90.267,-284.134 90.267,4 -4,4"/>
<g id="node1" class="node"><title>With\nDirect\nAnnotation</title>
<ellipse fill="none" stroke="red" cx="43.1335" cy="-43.1335" rx="43.2674" ry="43.2674"/>
<text text-anchor="middle" x="43.1335" y="-54.4335" font-family="Times,serif" font-size="14.00">With</text>
<text text-anchor="middle" x="43.1335" y="-39.4335" font-family="Times,serif" font-size="14.00">Direct</text>
<text text-anchor="middle" x="43.1335" y="-24.4335" font-family="Times,serif" font-size="14.00">Annotation</text>
</g>
<g id="node2" class="node"><title>Without\nDirect\nAnnotation</title>
<ellipse fill="none" stroke="blue" stroke-dasharray="5,2" cx="43.1335" cy="-147.134" rx="43.2674" ry="43.2674"/>
<text text-anchor="middle" x="43.1335" y="-158.434" font-family="Times,serif" font-size="14.00">Without</text>
<text text-anchor="middle" x="43.1335" y="-143.434" font-family="Times,serif" font-size="14.00">Direct</text>
<text text-anchor="middle" x="43.1335" y="-128.434" font-family="Times,serif" font-size="14.00">Annotation</text>
</g>
<g id="node3" class="node"><title>Root</title>
<polygon fill="none" stroke="blue" stroke-dasharray="5,2" points="79.1335,-280.134 7.13351,-280.134 7.13351,-208.134 79.1335,-208.134 79.1335,-280.134"/>
<text text-anchor="middle" x="43.1335" y="-240.434" font-family="Times,serif" font-size="14.00">Root</text>
</g>
</g>
</svg></div><br/>-->
EndOfText
print qq($return);
print qq($toPrint);
print qq(</body></html>);
} # sub annotSummaryCytoscape
# horizontal
# <svg width="288pt" height="94pt"
# viewBox="0.00 0.00 288.13 94.27" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
# <g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 90.267)">
# <title>test0</title>
# <polygon fill="white" stroke="none" points="-4,4 -4,-90.267 284.134,-90.267 284.134,4 -4,4"/>
# <!-- With\nDirect\nAnnotation -->
# <g id="node1" class="node"><title>With\nDirect\nAnnotation</title>
# <ellipse fill="none" stroke="red" cx="43.1335" cy="-43.1335" rx="43.2674" ry="43.2674"/>
# <text text-anchor="middle" x="43.1335" y="-54.4335" font-family="Times,serif" font-size="14.00">With</text>
# <text text-anchor="middle" x="43.1335" y="-39.4335" font-family="Times,serif" font-size="14.00">Direct</text>
# <text text-anchor="middle" x="43.1335" y="-24.4335" font-family="Times,serif" font-size="14.00">Annotation</text>
# </g>
# <!-- Without\nDirect\nAnnotation -->
# <g id="node2" class="node"><title>Without\nDirect\nAnnotation</title>
# <ellipse fill="none" stroke="blue" stroke-dasharray="5,2" cx="147.134" cy="-43.1335" rx="43.2674" ry="43.2674"/>
# <text text-anchor="middle" x="147.134" y="-54.4335" font-family="Times,serif" font-size="14.00">Without</text>
# <text text-anchor="middle" x="147.134" y="-39.4335" font-family="Times,serif" font-size="14.00">Direct</text>
# <text text-anchor="middle" x="147.134" y="-24.4335" font-family="Times,serif" font-size="14.00">Annotation</text>
# </g>
# <!-- Root -->
# <g id="node3" class="node"><title>Root</title>
# <polygon fill="none" stroke="blue" stroke-dasharray="5,2" points="280.134,-79.1335 208.134,-79.1335 208.134,-7.13351 280.134,-7.13351 280.134,-79.1335"/>
# <text text-anchor="middle" x="244.134" y="-39.4335" font-family="Times,serif" font-size="14.00">Root</text>
# </g>
# </g>
# </svg>
sub svgCleanup {
my ($svgGenerated, $focusTermId) = @_;
my ($svgMarkup) = $svgGenerated =~ m/(<svg.*<\/svg>)/s; # capture svg markup
# print STDERR qq($svgMarkup\n);
my ($height, $width) = ('', '');
if ($svgMarkup =~ m/<svg width="(\d+)pt" height="(\d+)pt"/) { $width = $1; $height = $2; }
my $hwratio = $height / $width;
my $widthResolution = 960;
if ($width > $widthResolution) {
my $newwidth = $widthResolution;
my $newheight = int($newwidth * $hwratio);
$svgMarkup =~ s/<svg width="${width}pt" height="${height}pt"/<svg width="${newwidth}pt" height="${newheight}pt"/g;
}
# $svgMarkup =~ s/<title>legend_legend--legend_root<\/title>//g; # remove automatic title
# $svgMarkup =~ s/<title>legend_legend<\/title>//g; # remove automatic title
# $svgMarkup =~ s/<title>legend_root<\/title>//g; # remove automatic title
# $svgMarkup =~ s/<title>legend_nodirect<\/title>//g; # remove automatic title
$svgMarkup =~ s/<title>[^<]*?<\/title>/<title>${focusTermId}Phenotypes<\/title>/g; # remove automatic title
$svgMarkup =~ s/<title>test<\/title>//g; # remove automatic title
$svgMarkup =~ s/<title>Perl<\/title>//g; # remove automatic title
$svgMarkup =~ s/_placeholderColon_/:/g; # ids can't be created with a : in them, so have to add the : after the svg is generated
$svgMarkup =~ s/LINEBREAK//g; # remove leading hidden linebreak to offset counts of rnai and variation in transparent line afterward
$svgMarkup =~ s/fill="#fffffe"/fill="rgba\(0,0,0,0.01\)"/g; # cannot set opacity value directly at creating, so setting fontcolor to transparent, which becomes #fffffe which we can replace with an rgba with very low opacity
my (@xlinkTitle) = $svgMarkup =~ m/xlink:title="(.*?)"/g;
foreach my $xlt (@xlinkTitle) {
# print STDERR qq($xlt\n);
my $xltEdited = $xlt;
$xltEdited =~ s/<br\/>/\n/g;
$xltEdited =~ s/<\/?b>//g;
$xltEdited =~ s/<font color="transparent">//g;
$xltEdited =~ s/<\/font>//g;
# $xltEdited =~ s/<[^&]*?>//g;