-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathrtx.js
8157 lines (7042 loc) · 268 KB
/
rtx.js
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
var input_qg = { "edges": {}, "nodes": {} };
var workflow = { 'workflow' : [], 'message' : {} };
var qgids = [];
var cyobj = [];
var cytodata = {};
var predicates = {};
var all_predicates = [];
var all_nodes = {};
var summary_table_html = '';
var summary_score_histogram = {};
var summary_tsv = [];
var compare_tsv = [];
var columnlist = [];
var response_cache = {};
var UIstate = {};
// defaults
var base = "";
var baseAPI = base + "api/arax/v1.4";
var araxQuery = '';
// possibly imported by calling page (e.g. index.html)
if (typeof config !== 'undefined') {
if (config.base)
base = config.base;
if (config.query_endpoint)
araxQuery = config.query_endpoint;
if (config.baseAPI)
baseAPI = config.baseAPI;
}
if (!araxQuery)
araxQuery = baseAPI + '/query';
var providers = {
"ARAX" : { "url" : baseAPI },
"ARAXQ": { "url" : araxQuery },
"ARS" : { "url" : "https://ars-prod.transltr.io/ars/api/submit" },
"EXT" : { "url" : "https://translator.broadinstitute.org/molepro/trapi/v1.4" }
};
// these attributes are floats; truncate them
const attributes_to_truncate = [
"Contribution",
"chi_square",
"confidence",
"fisher_exact_test_p-value",
"jaccard_index",
"ln_ratio",
"ngd",
"normalized_google_distance",
"observed_expected_ratio",
"pValue",
"paired_concept_freq",
"paired_concept_frequency",
"probability",
"probability_drug_treats",
"relative_frequency_object",
"relative_frequency_subject"
];
function main() {
UIstate["submitter"] = 'ARAX GUI';
UIstate['autorefresh'] = true;
UIstate["timeout"] = '30';
UIstate["pruning"] = '50';
UIstate["pid"] = null;
UIstate["viewing"] = null;
UIstate["version"] = checkUIversion(false);
UIstate["scorestep"] = 0.1;
UIstate["maxresults"] = 1000;
UIstate["maxsyns"] = 1000;
UIstate["prevtimestampobj"] = null;
document.getElementById("menuapiurl").href = providers["ARAX"].url + "/ui/";
load_meta_knowledge_graph();
populate_dsl_commands();
populate_wf_operations();
populate_wfjson();
display_list('A');
display_list('B');
add_status_divs();
cytodata['QG'] = 'dummy';
for (var prov in providers) {
document.getElementById(prov+"_url").value = providers[prov].url;
document.getElementById(prov+"_url_button").disabled = true;
}
for (var setting of ["submitter","timeout","pruning","maxresults","maxsyns"]) {
document.getElementById(setting+"_url").value = UIstate[setting];
document.getElementById(setting+"_url_button").disabled = true;
}
var tab = getQueryVariable("tab") || "query";
var syn = getQueryVariable("term") || null;
var rec = getQueryVariable("recent") || null;
var pks = getQueryVariable("latest") || null;
var sys = getQueryVariable("systest") || null;
var sai = getQueryVariable("smartapi") || getQueryVariable("smartAPI") || null;
retrieveTestRunnerResultsList(sys);
var response_id = getQueryVariable("r") || getQueryVariable("id") || null;
if (response_id) {
response_id.trim();
var statusdiv = document.getElementById("statusdiv");
statusdiv.innerHTML = '';
statusdiv.appendChild(document.createTextNode("You have requested response id = " + response_id));
statusdiv.appendChild(document.createElement("br"));
document.getElementById("devdiv").innerHTML = "Requested response id = " + response_id + "<br>";
retrieve_response(providers['ARAX'].url+'/response/'+response_id,response_id,"all");
pasteId(response_id);
selectInput("qid");
}
else {
add_cyto(99999,"QG");
}
if (syn) {
tab = "synonym";
lookup_synonym(syn,false);
}
else if (rec) {
document.getElementById("qftime").value = rec;
tab = "recentqs";
retrieveRecentQs(false);
}
else if (pks) {
document.getElementById("howmanylatest").value = pks;
var from = getQueryVariable("from") || 'test';
if (!from.startsWith("ars"))
from = 'ars.' + from;
if (!from.endsWith(".transltr.io"))
from += '.transltr.io';
document.getElementById("wherefromlatest").value = from;
selectInput("qnew");
retrieveRecentResps();
}
else if (sai) {
tab = "kpinfo";
retrieveKPInfo();
}
else if (sys) {
tab = "systest";
if (sys != "1")
var timeout = setTimeout(function() { retrieveSysTestResults("ARSARS_"+sys); }, 50 ); // give it time...
else
retrieveSysTestResults();
}
openSection(tab);
dragElement(document.getElementById('nodeeditor'));
dragElement(document.getElementById('edgeeditor'));
}
function sesame(head,content) {
if (head == "openmax") {
content.style.maxHeight = content.scrollHeight + "px";
return;
}
else if (head == "collapse") {
content.style.maxHeight = null;
return;
}
else if (head) {
head.classList.toggle("openaccordion");
}
if (content.style.maxHeight)
content.style.maxHeight = null;
else
content.style.maxHeight = content.scrollHeight + "px";
}
function openSection(sect) {
if (!document.getElementById(sect+"Menu") || !document.getElementById(sect+"Div"))
sect = "query";
display_qg_popup('node','hide');
display_qg_popup('edge','hide');
var e = document.getElementsByClassName("menucurrent");
if (e) e[0].className = "menuleftitem";
document.getElementById(sect+"Menu").className = "menucurrent";
for (var e of document.getElementsByClassName("pagesection")) {
e.style.maxHeight = null;
e.style.visibility = 'hidden';
}
document.getElementById(sect+"Div").style.maxHeight = "none";
document.getElementById(sect+"Div").style.visibility = 'visible';
window.scrollTo(0,0);
}
// somehow merge with above? eh...
function selectInput (input_id) {
var e = document.getElementsByClassName("slink_on");
if (e[0]) { e[0].classList.remove("slink_on"); }
document.getElementById(input_id+"_link").classList.add("slink_on");
display_qg_popup('node','hide');
display_qg_popup('edge','hide');
for (var s of ['qgraph_input','qjson_input','qdsl_input','qwf_input','qid_input','resp_input','qnew_input']) {
document.getElementById(s).style.maxHeight = null;
document.getElementById(s).style.visibility = 'hidden';
}
document.getElementById(input_id+"_input").style.maxHeight = "100%";
document.getElementById(input_id+"_input").style.visibility = 'visible';
}
function clearJSON() {
document.getElementById("jsonText").value = '';
}
function clearDSL() {
document.getElementById("dslText").value = '';
}
function clearResponse() {
document.getElementById("responseText").value = '';
}
function pasteSyn(word) {
document.getElementById("newsynonym").value = word;
}
function pasteId(id) {
document.getElementById("idForm").elements["idText"].value = id;
document.getElementById("qid").value = '';
document.getElementById("qid").blur();
}
function pasteExample(type) {
if (type == "DSL") {
document.getElementById("dslText").value = '# This program creates two query nodes and a query edge between them, looks for matching edges in the KG,\n# overlays NGD metrics, and returns the top 30 results\nadd_qnode(name=acetaminophen, key=n0)\nadd_qnode(categories=biolink:Protein, key=n1)\nadd_qedge(subject=n0, object=n1, key=e0)\nexpand()\noverlay(action=compute_ngd, virtual_relation_label=N1, subject_qnode_key=n0, object_qnode_key=n1)\nresultify()\nfilter_results(action=limit_number_of_results, max_results=30)\n';
}
else if (type == "JSON1") {
document.getElementById("jsonText").value = '{\n "edges": {\n "e00": {\n "subject": "n00",\n "object": "n01",\n "predicates": ["biolink:interacts_with"]\n }\n },\n "nodes": {\n "n00": {\n "ids": ["CHEMBL.COMPOUND:CHEMBL112"]\n },\n "n01": {\n "categories": ["biolink:Protein"]\n }\n }\n}\n';
}
else if (type == "JSON2") {
document.getElementById("jsonText").value = '{\n "edges": {\n "t_edge": {\n "attribute_constraints": [],\n "knowledge_type": "inferred",\n "object": "on",\n "predicates": [\n "biolink:treats"\n ],\n "qualifier_constraints": [],\n "subject": "sn"\n }\n },\n "nodes": {\n "on": {\n "categories": [\n "biolink:Disease"\n ],\n "constraints": [],\n "ids": [\n "MONDO:0015564"\n ],\n "is_set": false\n },\n "sn": {\n "categories": [\n "biolink:ChemicalEntity"\n ],\n "constraints": [],\n "is_set": false\n }\n }\n}\n';
}
else if (type == "JSON3") {
document.getElementById("jsonText").value = '{\n "edges": {\n "t_edge": {\n "knowledge_type": "inferred",\n "object": "on",\n "predicates": [\n "biolink:affects"\n ],\n "qualifier_constraints": [\n {\n "qualifier_set": [\n {\n "qualifier_type_id": "biolink:object_aspect_qualifier",\n "qualifier_value": "activity_or_abundance"\n },\n {\n "qualifier_type_id": "biolink:object_direction_qualifier",\n "qualifier_value": "increased"\n }\n ]\n }\n ],\n "subject": "sn"\n }\n },\n "nodes": {\n "on": {\n "categories": [\n "biolink:Gene"\n ],\n "ids": [\n "NCBIGene:51341"\n ]\n },\n "sn": {\n "categories": [\n "biolink:ChemicalEntity"\n ]\n }\n }\n}\n';
}
}
function reset_vars() {
add_status_divs();
checkUIversion(true);
if (cyobj[0]) {cyobj[0].elements().remove();}
display_qg_popup('node','hide');
display_qg_popup('edge','hide');
document.getElementById("queryplan_container").innerHTML = "";
if (document.getElementById("queryplan_stream")) {
document.getElementById("queryplan_streamhead").remove();
document.getElementById("queryplan_stream").remove();
}
document.getElementById("result_container").innerHTML = "";
document.getElementById("summary_container").innerHTML = "";
document.getElementById("provenance_container").innerHTML = "";
document.getElementById("menunummessages").innerHTML = "--";
document.getElementById("menunummessages").className = "numold menunum";
document.getElementById("menunumresults").innerHTML = "--";
document.getElementById("menunumresults").className = "numold menunum";
summary_table_html = '';
summary_score_histogram = {};
summary_tsv = [];
columnlist = [];
all_nodes = {};
cyobj = [];
cytodata['QG'] = 'dummy';
}
function viewResponse() {
var resp = document.getElementById("responseText").value;
if (!resp) return;
reset_vars();
var jsonInput;
try {
jsonInput = JSON.parse(resp);
}
catch(e) {
statusdiv.appendChild(document.createElement("br"));
if (e.name == "SyntaxError")
statusdiv.innerHTML += "<b>Error</b> parsing JSON response input. Please correct errors and resubmit: ";
else
statusdiv.innerHTML += "<b>Error</b> processing response input. Please correct errors and resubmit: ";
statusdiv.appendChild(document.createElement("br"));
statusdiv.innerHTML += "<span class='error'>"+e+"</span>";
return;
}
render_response(jsonInput,true);
}
function postQuery(qtype,agent) {
var queryObj = {};
reset_vars();
var statusdiv = document.getElementById("statusdiv");
// assemble QueryObject
if (qtype == "DSL") {
statusdiv.innerHTML = "Posting DSL. Looking for answer...";
statusdiv.appendChild(document.createElement("br"));
var dslArrayOfLines = document.getElementById("dslText").value.split("\n");
queryObj["message"] = {};
queryObj["operations"] = { "actions": dslArrayOfLines};
}
else if (qtype == "WorkFlow") {
statusdiv.innerHTML = "Posting Workflow JSON. Awaiting response...";
statusdiv.appendChild(document.createElement("br"));
update_wfjson();
queryObj = workflow;
}
else if (qtype == "JSON") {
statusdiv.innerHTML = "Posting JSON. Looking for answer...";
statusdiv.appendChild(document.createElement("br"));
var jsonInput;
try {
jsonInput = JSON.parse(document.getElementById("jsonText").value);
}
catch(e) {
statusdiv.appendChild(document.createElement("br"));
if (e.name == "SyntaxError")
statusdiv.innerHTML += "<b>Error</b> parsing JSON input. Please correct errors and resubmit: ";
else
statusdiv.innerHTML += "<b>Error</b> processing input. Please correct errors and resubmit: ";
statusdiv.appendChild(document.createElement("br"));
statusdiv.innerHTML += "<span class='error'>"+e+"</span>";
return;
}
if (jsonInput.message)
queryObj = jsonInput;
else
queryObj.message = { "query_graph": jsonInput };
//queryObj.max_results = 100;
qg_new(false,false);
}
else { // qGraph
statusdiv.innerHTML = "Posting graph. Looking for answer...";
statusdiv.appendChild(document.createElement("br"));
qg_clean_up(true);
queryObj.message = { "query_graph": input_qg };
//queryObj.bypass_cache = bypass_cache;
//queryObj.max_results = 100;
qg_new(false,false);
}
queryObj.submitter = UIstate["submitter"];
if (agent == 'ARS')
postQuery_ARS(queryObj);
else if (agent == 'EXT')
postQuery_EXT(queryObj);
else
postQuery_ARAX(qtype,queryObj);
}
function postQuery_ARS(queryObj) {
document.getElementById("statusdiv").innerHTML += " - contacting ARS...";
document.getElementById("statusdiv").appendChild(document.createElement("br"));
fetch(providers["ARS"].url, {
method: 'post',
body: JSON.stringify(queryObj),
headers: { 'Content-type': 'application/json' }
}).then(response => {
if (response.ok) return response.json();
else throw new Error('Something went wrong');
})
.then(data => {
var message_id = data['pk'];
document.getElementById("statusdiv").innerHTML += " - got message_id = "+message_id;
document.getElementById("statusdiv").appendChild(document.createElement("br"));
pasteId(message_id);
selectInput("qid");
retrieve_response(providers['ARAX'].url+"/response/"+message_id,message_id,"all");
})
.catch(error => {
document.getElementById("statusdiv").innerHTML += " - ERROR:: "+error;
});
return;
}
function postQuery_EXT(queryObj) {
document.getElementById("statusdiv").innerHTML += " - contacting 3rd party API...";
document.getElementById("statusdiv").appendChild(document.createElement("br"));
fetch(providers["EXT"].url + "/query", {
method: 'post',
body: JSON.stringify(queryObj),
headers: { 'Content-type': 'application/json' }
}).then(response => {
if (response.ok) return response.json();
else throw new Error('Something went wrong');
}).then(data => {
var dev = document.getElementById("devdiv");
dev.appendChild(document.createElement("br"));
dev.appendChild(document.createTextNode('='.repeat(80)+" RESPONSE MESSAGE::"));
var pre = document.createElement("pre");
pre.id = "responseJSON";
pre.appendChild(document.createTextNode(JSON.stringify(data,null,2)));
dev.appendChild(pre);
if (data["description"])
statusdiv.appendChild(document.createTextNode(data["description"])); // italics?
else
statusdiv.appendChild(document.createTextNode(" - JSON response received")); // italics?
statusdiv.appendChild(document.createElement("br"));
sesame('openmax',statusdiv);
if (!data["status"] || data["status"] == "OK" || data["status"] == "Success") {
input_qg = { "edges": {}, "nodes": {} };
render_response(data, true);
}
else if (data["status"] == "QueryGraphZeroNodes") {
qg_new(false,false);
}
else if (data["logs"]) {
process_log(data["logs"]);
}
else {
statusdiv.innerHTML += "<br><span class='error'>An error was encountered while parsing the response from the remote server (no log; code:"+data.status+")</span>";
document.getElementById("devdiv").innerHTML += "------------------------------------ error with capturing QUERY:<br>"+data;
sesame('openmax',statusdiv);
}
}).catch(error => {
document.getElementById("statusdiv").innerHTML += " - ERROR:: "+error;
});
return;
}
// use fetch and stream
function postQuery_ARAX(qtype,queryObj) {
queryObj.stream_progress = true;
if (UIstate["timeout"]) {
if (!queryObj.query_options)
queryObj.query_options = {};
queryObj.query_options['kp_timeout'] = UIstate["timeout"];
}
if (UIstate["pruning"]) {
if (!queryObj.query_options)
queryObj.query_options = {};
queryObj.query_options['prune_threshold'] = UIstate["pruning"];
}
var cmddiv = document.createElement("div");
cmddiv.id = "cmdoutput";
statusdiv.appendChild(cmddiv);
// statusdiv.appendChild(document.createElement("br"));
statusdiv.appendChild(document.createTextNode("Processing step "));
var span = document.createElement("span");
span.id = "finishedSteps";
span.style.fontWeight = "bold";
// span.className = "menunum numnew";
span.appendChild(document.createTextNode("0"));
statusdiv.appendChild(span);
statusdiv.appendChild(document.createTextNode(" of "));
span = document.createElement("span");
span.id = "totalSteps";
// span.className = "menunum";
span.appendChild(document.createTextNode("??"));
statusdiv.appendChild(span);
span = document.createElement("span");
span.className = "progress";
var span2 = document.createElement("span");
span2.id = "progressBar";
span2.className = "bar";
span2.appendChild(document.createTextNode("0%"));
span.appendChild(span2);
statusdiv.appendChild(span);
statusdiv.appendChild(document.createElement("br"));
statusdiv.appendChild(document.createElement("br"));
sesame('openmax',statusdiv);
add_to_dev_info("Posted to QUERY",queryObj);
fetch(providers["ARAXQ"].url, {
method: 'post',
body: JSON.stringify(queryObj),
headers: { 'Content-type': 'application/json' }
}).then(function(response) {
var reader = response.body.getReader();
var partialMsg = '';
var enqueue = false;
var numCurrMsgs = 0;
var totalSteps = 0;
var finishedSteps = 0;
var decoder = new TextDecoder();
var respjson = '';
function scan() {
return reader.read().then(function(result) {
partialMsg += decoder.decode(result.value || new Uint8Array, {
stream: !result.done
});
var completeMsgs = partialMsg.split("}\n");
//console.log("================ completeMsgs::");
//console.log(completeMsgs);
if (!result.done) {
// Last msg is likely incomplete; hold it for next time
partialMsg = completeMsgs[completeMsgs.length - 1];
// Remove it from our complete msgs
completeMsgs = completeMsgs.slice(0, -1);
}
for (var msg of completeMsgs) {
msg = msg.trim();
if (msg == null) continue;
//console.log("================ msg::");
//console.log(msg);
if (enqueue) {
respjson += msg;
}
else {
msg += "}"; // lost in the split, above
var jsonMsg = JSON.parse(msg);
if (jsonMsg.logs) { // was:: (jsonMsg.description) {
enqueue = true;
respjson += msg;
}
else if (jsonMsg.message) {
if (jsonMsg.message.match(/^Parsing action: [^\#]\S+/)) {
totalSteps++;
}
else if (totalSteps>0) {
document.getElementById("totalSteps").innerHTML = totalSteps;
if (numCurrMsgs < 99)
numCurrMsgs++;
if (finishedSteps == totalSteps)
numCurrMsgs = 1;
document.getElementById("progressBar").style.width = (800*(finishedSteps+0.5*Math.log10(numCurrMsgs))/totalSteps)+"px";
document.getElementById("progressBar").innerHTML = Math.round(99*(finishedSteps+0.5*Math.log10(numCurrMsgs))/totalSteps)+"%\u00A0\u00A0";
if (jsonMsg.message.match(/^Processing action/)) {
finishedSteps++;
document.getElementById("finishedSteps").innerHTML = finishedSteps;
numCurrMsgs = 0;
}
}
cmddiv.appendChild(document.createTextNode(jsonMsg.timestamp+'\u00A0'+jsonMsg.level+':\u00A0'+jsonMsg.message));
cmddiv.appendChild(document.createElement("br"));
cmddiv.scrollTop = cmddiv.scrollHeight;
}
else if (jsonMsg.qedge_keys) {
var div;
if (document.getElementById("queryplan_stream"))
div = document.getElementById("queryplan_stream");
else {
div = document.createElement("div");
div.id = "queryplan_streamhead";
div.className = 'statushead';
div.appendChild(document.createTextNode("Expansion Progress"));
document.getElementById("status_container").before(div);
div = document.createElement("div");
div.id = "queryplan_stream";
div.className = 'status';
document.getElementById("status_container").before(div);
}
div.innerHTML = '';
div.appendChild(document.createElement("br"));
render_queryplan_table(jsonMsg, div);
div.appendChild(document.createElement("br"));
}
else if (jsonMsg.pid) {
UIstate["pid"] = jsonMsg;
display_kill_button();
}
else if (jsonMsg.detail) {
cmddiv.appendChild(document.createElement("br"));
cmddiv.appendChild(document.createTextNode("ERROR:\u00A0"+jsonMsg.detail));
throw new Error(jsonMsg.detail);
}
else {
console.log("bad msg:"+JSON.stringify(jsonMsg,null,2));
}
}
}
if (result.done) {
//console.log(respjson);
return respjson;
}
return scan();
})
}
return scan();
})
.then(response => {
var data = JSON.parse(response);
var dev = document.getElementById("devdiv");
dev.appendChild(document.createElement("br"));
dev.appendChild(document.createTextNode('='.repeat(80)+" RESPONSE MESSAGE::"));
var pre = document.createElement("pre");
pre.id = "responseJSON";
pre.appendChild(document.createTextNode(JSON.stringify(data,null,2)));
dev.appendChild(pre);
if (document.getElementById("killquerybutton"))
document.getElementById("killquerybutton").remove();
document.getElementById("progressBar").style.width = "800px";
if (data.status == "OK" || data.status == "Success")
document.getElementById("progressBar").innerHTML = "Finished\u00A0\u00A0";
else {
document.getElementById("progressBar").classList.add("barerror");
document.getElementById("progressBar").innerHTML = "Error\u00A0\u00A0";
document.getElementById("finishedSteps").classList.add("menunum","numnew","msgERROR");
there_was_an_error();
}
statusdiv.appendChild(document.createTextNode(data["description"])); // italics?
statusdiv.appendChild(document.createElement("br"));
sesame('openmax',statusdiv);
if (data["status"] == "QueryGraphZeroNodes") {
qg_new(false,false);
}
else if (data["status"] == "OK" || data["status"] == "Success") {
input_qg = { "edges": {}, "nodes": {} };
render_response(data,qtype == "DSL");
}
else if (data["logs"]) {
process_log(data["logs"]);
}
else {
statusdiv.innerHTML += "<br><span class='error'>An error was encountered while parsing the response from the server (no log; code:"+data.status+")</span>";
document.getElementById("devdiv").innerHTML += "------------------------------------ error with capturing QUERY:<br>"+data;
sesame('openmax',statusdiv);
}
})
.catch(function(err) {
if (document.getElementById("killquerybutton"))
document.getElementById("killquerybutton").remove();
statusdiv.innerHTML += "<br><span class='error'>An error was encountered while contacting the server ("+err+")</span>";
document.getElementById("devdiv").innerHTML += "------------------------------------ error with parsing QUERY:<br>"+err;
sesame('openmax',statusdiv);
if (err.log)
process_log(err.log);
console.log(err.message);
there_was_an_error();
});
}
function display_kill_button() {
var button = document.createElement("input");
button.id = 'killquerybutton';
button.className = 'questionBox button';
button.style.background = "#c40";
button.type = 'button';
button.name = 'action';
button.value = 'Terminate Query!';
button.title = 'Kill this request (pid='+UIstate["pid"].pid+')';
button.setAttribute('onclick', 'kill_query();');
document.getElementById("status_container").before(button);
}
function kill_query() {
if (!UIstate["pid"].pid || !UIstate["pid"].authorization) {
document.getElementById("killquerybutton").replaceWith('No PID or authorization; cannot terminate query');
return;
}
fetch(providers["ARAX"].url + "/status?terminate_pid="+UIstate["pid"].pid+"&authorization="+UIstate["pid"].authorization)
.then(response => {
if (response.ok) return response.json();
else throw new Error('Something went wrong with termination...');
})
.then(data => {
if (data.status == 'OK' || data.status == 'Success') {
document.getElementById("killquerybutton").id = 'killquerybuttondead';
addCheckBox(document.getElementById("killquerybuttondead"),true);
var timeout = setTimeout(function() { document.getElementById("killquerybuttondead").remove(); } , 1500 );
statusdiv.innerHTML += "<br><span class='error'>Query terminated by user</span>";
if (document.getElementById("cmdoutput")) {
var cmddiv = document.getElementById("cmdoutput");
cmddiv.appendChild(document.createElement("br"));
cmddiv.appendChild(document.createTextNode(data.description));
cmddiv.appendChild(document.createElement("br"));
cmddiv.scrollTop = cmddiv.scrollHeight;
for (var e of document.getElementsByClassName("working")) {
e.classList.remove('working');
e.classList.remove('p5');
e.classList.add('barerror');
}
document.getElementById("progressBar").classList.add("barerror");
document.getElementById("progressBar").innerHTML += " (terminated)\u00A0\u00A0";
}
}
else if (data.status == 'ERROR') {
document.getElementById("killquerybutton").after('Cannot terminate query');
console.warn('Query termination attempt error: '+data.description);
}
else throw new Error('Something went wrong while attempting to terminate query...');
})
.catch(error => {
var span = document.createElement("span");
span.className = 'error';
span.innerHTML = error;
document.getElementById("killquerybutton").after(span);
});
}
function lookup_synonym(syn,open) {
document.getElementById("newsynonym").value = syn.trim();
sendSyn();
if (open)
openSection("synonym");
}
async function sendSyn() {
var word = document.getElementById("newsynonym").value.trim();
if (!word) return;
var syndiv = document.getElementById("synonym_result_container");
syndiv.innerHTML = "";
var maxsyn = UIstate["maxsyns"];
var allweknow = await check_entity(word,true,maxsyn,document.getElementById("showConceptGraph").checked);
if (0) { // set to 1 if you just want full JSON dump instead of html tables
syndiv.innerHTML = "<pre>"+JSON.stringify(allweknow,null,2)+"</pre>";
return;
}
var div, text, table, tr, td;
div = document.createElement("div");
div.className = "statushead";
div.appendChild(document.createTextNode("Synonym Results"));
text = document.createElement("a");
text.target = '_blank';
text.title = 'link to this synonym entry';
text.href = "http://"+ window.location.hostname + window.location.pathname + "?term=" + word;
text.innerHTML = "[ Direct link to this entry ]";
text.style.float = "right";
div.appendChild(text);
syndiv.appendChild(div);
div = document.createElement("div");
div.className = "status";
text = document.createElement("h2");
text.className = "qprob p9";
text.appendChild(document.createTextNode(word));
div.appendChild(text);
//div.appendChild(document.createElement("br"));
if (!allweknow[word]) {
text.className = "qprob p1";
div.appendChild(document.createElement("br"));
div.appendChild(document.createTextNode("Entity not found."));
div.appendChild(document.createElement("br"));
div.appendChild(document.createElement("br"));
syndiv.appendChild(div);
return;
}
if (allweknow[word].id) {
table = document.createElement("table");
table.className = 'sumtab';
for (var syn in allweknow[word].id) {
tr = document.createElement("tr");
tr.className = 'hoverable';
td = document.createElement("td")
td.style.fontWeight = 'bold';
td.appendChild(document.createTextNode(syn));
tr.appendChild(td);
td = document.createElement("td")
if (syn == "identifier")
td.appendChild(link_to_identifiers_dot_org(allweknow[word].id[syn]));
td.appendChild(document.createTextNode(allweknow[word].id[syn]));
tr.appendChild(td);
table.appendChild(tr);
}
if (allweknow[word].synonyms) {
tr = document.createElement("tr");
tr.className = 'hoverable';
td = document.createElement("td")
td.style.fontWeight = 'bold';
td.appendChild(document.createTextNode('synonyms (all)'));
tr.appendChild(td);
td = document.createElement("td")
var comma = '';
for (var syn in allweknow[word].synonyms) {
td.appendChild(document.createTextNode(comma + syn + " (" +allweknow[word].synonyms[syn] + ")"));
comma = ", ";
}
tr.appendChild(td);
table.appendChild(tr);
}
if (allweknow[word].categories) {
tr = document.createElement("tr");
tr.className = 'hoverable';
td = document.createElement("td")
td.style.fontWeight = 'bold';
td.appendChild(document.createTextNode('categories (all)'));
tr.appendChild(td);
td = document.createElement("td")
var comma = '';
for (var cat in allweknow[word].categories) {
td.appendChild(document.createTextNode(comma + cat + " (" +allweknow[word].categories[cat] + ")"));
comma = ", ";
}
tr.appendChild(td);
table.appendChild(tr);
}
div.appendChild(table);
}
if (allweknow[word].nodes) {
text = document.createElement("h3");
text.className = "qprob p5";
text.append('Nodes');
if (allweknow[word].total_synonyms > maxsyn) {
text.append(' (truncated to '+maxsyn+' from a total of '+allweknow[word].total_synonyms+")");
text.title = "* You can change this value in the Settings section on the left menu";
var span = document.createElement("span");
span.className = "qprob p9";
span.style.marginLeft = '20px';
span.append('New!');
text.append(span);
span = document.createElement("span");
span.className = 'tiny';
span.style.marginLeft = '15px';
span.append('[ Go to ');
var link =document.createElement("a");
link.href="javascript:openSection('settings');"
link.append('Settings');
span.append(link);
span.append(' to change this value ]');
text.appendChild(span);
}
else
text.append(' ('+allweknow[word].total_synonyms+")");
div.appendChild(text);
table = document.createElement("table");
table.className = 'sumtab';
tr = document.createElement("tr");
for (var head of ["Identifier","Label","Category","KG2pre","KG2pre Name","KG2pre Category","SRI_NN","SRI Name","SRI Category"] ) {
td = document.createElement("th")
td.appendChild(document.createTextNode(head));
tr.appendChild(td);
}
table.appendChild(tr);
for (var syn of allweknow[word].nodes) {
tr = document.createElement("tr");
tr.className = 'hoverable';
td = document.createElement("td")
td.appendChild(link_to_identifiers_dot_org(syn.identifier));
td.appendChild(document.createTextNode(syn.identifier));
tr.appendChild(td);
td = document.createElement("td")
td.appendChild(document.createTextNode(syn.label));
tr.appendChild(td);
td = document.createElement("td")
td.appendChild(document.createTextNode(syn.category));
tr.appendChild(td);
td = document.createElement("td")
text = document.createElement("span");
if (syn.in_kg2pre) {
text.innerHTML = '✓';
text.className = 'explevel p9';
text.title = 'Found in KG2pre';
}
else {
text.innerHTML = '✗';
text.className = 'explevel p0';
text.title = 'NOT found in KG2pre';
}
td.appendChild(text);
tr.appendChild(td);
td = document.createElement("td")
td.appendChild(document.createTextNode(syn.name_kg2pre));
tr.appendChild(td);
td = document.createElement("td")
td.appendChild(document.createTextNode(syn.category_kg2pre));
tr.appendChild(td);
td = document.createElement("td")
text = document.createElement("span");
if (syn.in_sri) {
text.innerHTML = '✓';
text.className = 'explevel p9';
text.title = 'Found in SRI NodeNormalizer';
}
else {
text.innerHTML = '✗';
text.className = 'explevel p0';
text.title = 'NOT found in SRI NodeNormalizer';
}
td.appendChild(text);
tr.appendChild(td);
td = document.createElement("td")
td.appendChild(document.createTextNode(syn.name_sri));
tr.appendChild(td);
td = document.createElement("td")
td.appendChild(document.createTextNode(syn.category_sri));
tr.appendChild(td);
table.appendChild(tr);
}
div.appendChild(table);
}
if (allweknow[word].equivalent_identifiers) {
text = document.createElement("h3");
text.className = "qprob p5";
text.appendChild(document.createTextNode('Equivalent Identifiers'));
div.appendChild(text);
table = document.createElement("table");
table.className = 'sumtab';
tr = document.createElement("tr");
for (var head of ["Identifier","Category","Source"] ) {
td = document.createElement("th")
td.appendChild(document.createTextNode(head));
tr.appendChild(td);
}
table.appendChild(tr);
for (var syn of allweknow[word].equivalent_identifiers) {
tr = document.createElement("tr");
tr.className = 'hoverable';
td = document.createElement("td")
td.appendChild(link_to_identifiers_dot_org(syn.identifier));
td.appendChild(document.createTextNode(syn.identifier));
tr.appendChild(td);
td = document.createElement("td")
td.appendChild(document.createTextNode(syn.category));
tr.appendChild(td);
td = document.createElement("td")
td.appendChild(document.createTextNode(syn.source));
tr.appendChild(td);
table.appendChild(tr);
}
div.appendChild(table);
}
if (allweknow[word].synonym_provenance) {
text = document.createElement("h3");
text.className = "qprob p5";
//text.appendChild(document.createTextNode('\u25BA Synonym Provenance'));
text.appendChild(document.createTextNode('Synonym Provenance'));
div.appendChild(text);
table = document.createElement("table");
table.className = 'sumtab';
tr = document.createElement("tr");
for (var head of ["Name","Curie","Source"] ) {
td = document.createElement("th")
td.appendChild(document.createTextNode(head));
tr.appendChild(td);
}
table.appendChild(tr);
for (var syn in allweknow[word].synonym_provenance) {
tr = document.createElement("tr");