-
Notifications
You must be signed in to change notification settings - Fork 0
/
soba_multi.js
executable file
·384 lines (358 loc) · 23.2 KB
/
soba_multi.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
// javascript for form at ~azurebrd/public_html/cgi-bin/forms/community_gene_description.cgi
// autocomplete (not forced) on genes and species, enter PMIDs and use those plus previous matches of pmid-title to look up new pmid titles to add to list of pmid-titles in readonly textarea. 2013 06 02
var cgiUrl = 'soba_multi.cgi';
YAHOO.util.Event.addListener(window, "load", function() { // on load assign listeners
setAutocompleteListeners(); // add listener for gene, species, pmids
}); // YAHOO.util.Event.addListener(window, "load", function()
// window.onscroll = function () {
// // delay(function(){
// var termInfoBox = document.getElementById("term_info_box");
// var bodyTop = window.pageYOffset; // vertical offset of window
// if (bodyTop > 20) { // scrolled more than 20
// var setTop = 95 - bodyTop; // from default 95 minus the offset, move it
// if (setTop < 20) { setTop = 20; } // move no less than 20px from the top
// termInfoBox.style.top = setTop + 'px';
// }
// else {
// termInfoBox.style.top = '95px'; // if window not scrolled much, set to default 95px
// }
// // }, 5 );
// };
function setAutocompleteListeners() { // add listener for gene, species, pmids
var whichPage = document.getElementById('which_page').value;
if (whichPage === 'pickOneGenePage') {
var field = 'Gene';
settingAutocompleteListeners = function() {
var taxons = [];
var arrCheckbox = document.getElementsByClassName("taxon");
for (var i = 0; arrCheckbox[i]; i++) {
if (arrCheckbox[i].checked) {
taxons.push('taxon_label:"'+ arrCheckbox[i].value + '"');
}
} // for (i = arrCheckbox.length - 1; i > -1; i--)
var taxonFq = taxons.join('+OR+');
// alert(taxonFq);
var datatypeValue = 'phenotype';
var radioDatatypeElements = document.getElementsByName("radio_datatype");
for (var i = 0, length = radioDatatypeElements.length; i < length; i++) {
if (radioDatatypeElements[i].checked) {
datatypeValue = radioDatatypeElements[i].value; } }
// var sUrl = cgiUrl + "?action=autocompleteXHR&taxonFq=" + taxonFq + "&field=" + field + "&"; // ajax calls need curator and datatype
// var sUrl = cgiUrl + "?action=autocompleteXHR&datatype=" + datatypeValue + "&taxonFq=" + taxonFq + "&field=Gene&"; // good until 2019 11 01
// var sUrl = cgiUrl + "?action=autocompleteTazendraXHR&objectType=gene&"; // to try to get from tazendra OA through cgi
var sUrl = "https://tazendra.caltech.edu/~azurebrd/cgi-bin/forms/datatype_objects.cgi?action=autocompleteXHR&objectType=gene&"; // to try to get from tazendra OA
var oDS = new YAHOO.util.XHRDataSource(sUrl); // Use an XHRDataSource
oDS.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT; // Set the responseType
oDS.responseSchema = { // Define the schema of the delimited results
recordDelim: "\n",
fieldDelim: "\t"
};
oDS.maxCacheEntries = 5; // Enable caching
var forcedOrFree = "forced";
var inputElement = document.getElementById('input_'+field);
var containerElement = document.getElementById(forcedOrFree + field + "Container");
var forcedOAC = new YAHOO.widget.AutoComplete(inputElement, containerElement, oDS);
forcedOAC.queryQuestionMark = false; // don't add a ? to the sUrl query since it's been built with some other values
forcedOAC.queryDelay = 0.1; // add a delay to wait for user to stop typing
forcedOAC.maxResultsDisplayed = 500;
forcedOAC.forceSelection = true;
forcedOAC.generateRequest = function(sQuery) { return "userValue=" + sQuery ; }; // instead of sending 'query' to form, use 'userValue'
forcedOAC.itemSelectEvent.subscribe(onAutocompleteItemSelect);
// Don't needs this because don't need action on these, if it was necessary, would have to create functions like in the OA
// forcedOAC.selectionEnforceEvent.subscribe(onAutocompleteSelectionEnforce);
// forcedOAC.itemArrowToEvent.subscribe(onAutocompleteItemHighlight);
// forcedOAC.itemMouseOverEvent.subscribe(onAutocompleteItemHighlight);
return {
oDS: oDS,
forcedOAC: forcedOAC
}
}();
} // if (whichPage === 'pickOneGenePage')
else if (whichPage === 'pickOneGeneBiggoPage') {
var field = 'Gene';
settingAutocompleteListeners = function() {
// to select from checkboxes instead of drop down
// var taxons = [];
// var arrCheckbox = document.getElementsByClassName("taxon");
// for (var i = 0; arrCheckbox[i]; i++) {
// if (arrCheckbox[i].checked) {
// taxons.push('taxon_label:"'+ arrCheckbox[i].value + '"'); } }
// var taxonFq = taxons.join('+OR+');
var taxonFq = '';
if (document.getElementById("taxon_all").value === 'All') { taxonFq = ''; }
else { taxonFq = 'taxon_label:"' + document.getElementById("taxon_all").value + '"'; }
var datatypeValue = 'biggo';
var sUrl = cgiUrl + "?action=autocompleteXHR&datatype=" + datatypeValue + "&taxonFq=" + taxonFq + "&field=Gene&"; // for biggo
var oDS = new YAHOO.util.XHRDataSource(sUrl); // Use an XHRDataSource
oDS.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT; // Set the responseType
oDS.responseSchema = { // Define the schema of the delimited results
recordDelim: "\n",
fieldDelim: "\t"
};
oDS.maxCacheEntries = 5; // Enable caching
var forcedOrFree = "forced";
var inputElement = document.getElementById('input_'+field);
var containerElement = document.getElementById(forcedOrFree + field + "Container");
var forcedOAC = new YAHOO.widget.AutoComplete(inputElement, containerElement, oDS);
forcedOAC.queryQuestionMark = false; // don't add a ? to the sUrl query since it's been built with some other values
forcedOAC.queryDelay = 0.1; // add a delay to wait for user to stop typing
forcedOAC.maxResultsDisplayed = 500;
forcedOAC.forceSelection = true;
forcedOAC.generateRequest = function(sQuery) { return "userValue=" + sQuery ; }; // instead of sending 'query' to form, use 'userValue'
forcedOAC.itemSelectEvent.subscribe(onAutocompleteItemSelect);
return {
oDS: oDS,
forcedOAC: forcedOAC
}
}();
} // else if (whichPage === 'pickOneGeneBiggoPage')
else if (whichPage === 'pickTwoGenesBiggoPage') {
var autocompleteFieldsArray = ['One', 'Two'];
for (var j = 0; j < autocompleteFieldsArray.length; j++) { // for each field to autocomplete
var fieldCount = autocompleteFieldsArray[j];
var field = 'Gene' + fieldCount;
settingAutocompleteListeners = function() {
// to select from checkboxes instead of drop down
// var taxons = [];
// var arrCheckbox = document.getElementsByClassName("taxon" + fieldCount);
// for (var i = 0; arrCheckbox[i]; i++) {
// if (arrCheckbox[i].checked) {
// taxons.push('taxon_label:"'+ arrCheckbox[i].value + '"'); } }
// var taxonFq = taxons.join('+OR+');
var taxonFq = '';
if (document.getElementById("taxon" + fieldCount).value === 'All') { taxonFq = ''; }
else { taxonFq = 'taxon_label:"' + document.getElementById("taxon" + fieldCount).value + '"'; }
var datatypeValue = 'biggo';
var sUrl = cgiUrl + "?action=autocompleteXHR&datatype=" + datatypeValue + "&taxonFq=" + taxonFq + "&field=Gene&"; // for biggo
var oDS = new YAHOO.util.XHRDataSource(sUrl); // Use an XHRDataSource
oDS.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT; // Set the responseType
oDS.responseSchema = { // Define the schema of the delimited results
recordDelim: "\n",
fieldDelim: "\t"
};
oDS.maxCacheEntries = 5; // Enable caching
var forcedOrFree = "forced";
var inputElement = document.getElementById('input_'+field);
var containerElement = document.getElementById(forcedOrFree + field + "Container");
var forcedOAC = new YAHOO.widget.AutoComplete(inputElement, containerElement, oDS);
forcedOAC.queryQuestionMark = false; // don't add a ? to the sUrl query since it's been built with some other values
forcedOAC.queryDelay = 0.1; // add a delay to wait for user to stop typing
forcedOAC.maxResultsDisplayed = 500;
forcedOAC.forceSelection = true;
forcedOAC.generateRequest = function(sQuery) { return "userValue=" + sQuery ; }; // instead of sending 'query' to form, use 'userValue'
forcedOAC.itemSelectEvent.subscribe(onAutocompleteItemSelect);
return {
oDS: oDS,
forcedOAC: forcedOAC
}
}();
} // for (var j = 0; j < autocompleteFieldsArray.length; j++) // for each field to autocomplete
} // else if (whichPage === 'pickTwoGenesBiggoPage')
else if (whichPage === 'pickTwoGenesPage') {
var autocompleteFieldsArray = ['One', 'Two'];
for (var j = 0; j < autocompleteFieldsArray.length; j++) { // for each field to autocomplete
var fieldCount = autocompleteFieldsArray[j];
var field = 'Gene' + fieldCount;
settingAutocompleteListeners = function() {
var taxons = [];
var arrCheckbox = document.getElementsByClassName("taxon" + fieldCount);
for (var i = 0; arrCheckbox[i]; i++) {
if (arrCheckbox[i].checked) {
taxons.push('taxon_label:"'+ arrCheckbox[i].value + '"');
}
} // for (i = arrCheckbox.length - 1; i > -1; i--)
var taxonFq = taxons.join('+OR+');
// alert(taxonFq);
var datatypeValue = 'phenotype';
var radioDatatypeElements = document.getElementsByName("radio_datatype");
for (var i = 0, length = radioDatatypeElements.length; i < length; i++) {
if (radioDatatypeElements[i].checked) {
datatypeValue = radioDatatypeElements[i].value; } }
// var sUrl = cgiUrl + "?action=autocompleteXHR&datatype=" + datatypeValue + "&taxonFq=" + taxonFq + "&field=Gene&";
// var sUrl = cgiUrl + "?action=autocompleteTazendraXHR&objectType=gene&"; // to try to get from tazendra OA through cgi
var sUrl = "https://tazendra.caltech.edu/~azurebrd/cgi-bin/forms/datatype_objects.cgi?action=autocompleteXHR&objectType=gene&"; // to try to get from tazendra OA
var oDS = new YAHOO.util.XHRDataSource(sUrl); // Use an XHRDataSource
oDS.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT; // Set the responseType
oDS.responseSchema = { // Define the schema of the delimited results
recordDelim: "\n",
fieldDelim: "\t"
};
oDS.maxCacheEntries = 5; // Enable caching
var forcedOrFree = "forced";
var inputElement = document.getElementById('input_'+field);
var containerElement = document.getElementById(forcedOrFree + field + "Container");
var forcedOAC = new YAHOO.widget.AutoComplete(inputElement, containerElement, oDS);
forcedOAC.queryQuestionMark = false; // don't add a ? to the sUrl query since it's been built with some other values
forcedOAC.queryDelay = 0.1; // add a delay to wait for user to stop typing
forcedOAC.maxResultsDisplayed = 500;
forcedOAC.forceSelection = true;
forcedOAC.generateRequest = function(sQuery) { return "userValue=" + sQuery ; }; // instead of sending 'query' to form, use 'userValue'
forcedOAC.itemSelectEvent.subscribe(onAutocompleteItemSelect);
// if (fieldCount === 'One') {
// forcedOAC.itemSelectEvent.subscribe(onAutocompleteItemSelectOne); }
// else if (fieldCount === 'Two') {
// forcedOAC.itemSelectEvent.subscribe(onAutocompleteItemSelectTwo); }
return {
oDS: oDS,
forcedOAC: forcedOAC
}
}();
} // for (var j = 0; j < autocompleteFieldsArray.length; j++) // for each field to autocomplete
} // else if (whichPage === 'pickTwoGenesPage')
// from http://stackoverflow.com/questions/1909441/jquery-keyup-delay
var delay = (function(){ // delay executing a function until user has stopped typing for a timeout amount
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
} // function setAutocompleteListeners()
function radioDatatypeClick(whichPage) {
if (whichPage === 'TwoGenes') {
validateGeneDatatype('GeneOne');
validateGeneDatatype('GeneTwo'); }
console.log('clicked radio');
} // function radioDatatypeClick('whichPage')
function onAutocompleteItemSelect(oSelf , elItem) { // if an item is highlighted from arrows or mouseover, populate obo
var match = elItem[0]._sName.match(/input_(.*)/); // get the key and value
var field = match[1];
console.log('field: ' + field);
if (field === 'Gene') {
var value = elItem[1].innerHTML; // get the selected value
var datatypeValue = 'phenotype';
var radioDatatypeElements = document.getElementsByName("radio_datatype");
for (var i = 0, length = radioDatatypeElements.length; i < length; i++) {
if (radioDatatypeElements[i].checked) {
datatypeValue = radioDatatypeElements[i].value; } }
var url = 'soba_multi.cgi?action=annotSummaryCytoscape&filterForLcaFlag=1&filterLongestFlag=1&showControlsFlag=0&datatype=' + datatypeValue + '&autocompleteValue=' + value;
// window.location = url; // uncomment to load graph automatically
}
else if (field === 'GeneOne') {
validateGeneDatatype('GeneOne');
document.getElementById('controlsOne').style.display = 'none';
document.getElementById('controlsTwo').style.display = ''; }
else if (field === 'GeneTwo') {
console.log('genetwo');
validateGeneDatatype('GeneTwo');
// to automaticaly load graph on selection of gene two
// var geneOneValue = document.getElementById('input_GeneOne').value;
// var url = 'soba_multi.cgi?action=annotSummaryCytoscape&filterForLcaFlag=1&filterLongestFlag=1&showControlsFlag=0&datatype=' + datatypeValue + '&geneOneValue=' + geneOneValue + '&autocompleteValue=' + value;
// console.log('genetwo: ' + url);
// window.location = url; // uncomment to load graph automatically
}
} // function onAutocompleteItemSelect(oSelf , elItem)
function validateGeneDatatype(whichGene) {
let datatypeValue = getSelectedDatatype();
let elMatch = document.getElementById('input_'+whichGene).value.match(/\( (.*?) \)/);
if (elMatch !== null) {
let geneId = 'WB:' + elMatch[1];
console.log('geneId: ' + geneId + ' datatype: ' + datatypeValue);
asyncCheckGeneDatatype(whichGene, geneId, datatypeValue); }
} // function validateGeneDatatype(whichGene)
function getSelectedDatatype() {
let datatypeValue = 'phenotype';
var radioDatatypeElements = document.getElementsByName("radio_datatype");
for (var i = 0, length = radioDatatypeElements.length; i < length; i++) {
if (radioDatatypeElements[i].checked) {
datatypeValue = radioDatatypeElements[i].value; } }
return datatypeValue;
} // function getSelectedDatatype()
function asyncCheckGeneDatatype(whichGene, geneId, datatypeValue) {
var callbacks = {
success : function (o) { // Successful XHR response handler
if (o.responseText !== undefined) {
if (o.responseText === 'no data') {
document.getElementById('message'+whichGene).style.color = 'red';
document.getElementById('message'+whichGene).innerHTML = o.responseText; }
else if (o.responseText === 'has data') {
document.getElementById('message'+whichGene).style.color = 'green';
document.getElementById('message'+whichGene).innerHTML = o.responseText; }
else {
document.getElementById('message'+whichGene).style.color = 'orange';
document.getElementById('message'+whichGene).innerHTML = 'unexpected response'; }
// console.log('SUCCESS!');
} }, };
// value = convertDisplayToUrlFormat(value); // convert <newValue> to URL format by escaping characters
// var sUrl = cgiUrl + "?action=asyncTermInfo&field="+field+"&termid="+value;
// let sUrl = 'http://wobr2.caltech.edu:8080/solr/' + datatypeValue + '/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'; // CORS does not allow this nor localhost:8080
let sUrl = 'soba_multi.cgi?action=validateGeneDatatype&datatype=' + datatypeValue + '&gene=' + geneId;
console.log('send ' + sUrl);
YAHOO.util.Connect.asyncRequest('GET', sUrl, callbacks); // Make the call to the server for term info data
} // function function asyncTermInfo(field, value)
// http://wobr2.caltech.edu:8080/solr/phenotype/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:WBGene00003009%22
// function asyncWbdescription(wbgene) {
// var callbacks = {
// success : function (o) { // Successful XHR response handler
// if (o.responseText !== undefined) {
// // document.getElementById('wbDescription').innerHTML = o.responseText + "<br/> ";
// var jsonData = [];
// try { jsonData = YAHOO.lang.JSON.parse(o.responseText); } // Use the JSON Utility to parse the data returned from the server
// catch (x) { alert("JSON Parse failed!"); return; }
// var one = jsonData.shift();
// var two = jsonData.shift();
// var three = jsonData.shift();
// var four = jsonData.shift();
// var five = jsonData.shift();
// document.getElementById('wbDescription').value = two;
// document.getElementById('wbDescriptionDiv').innerHTML = two;
// document.getElementById('concisedescription').innerHTML = two;
// document.getElementById('wbDescriptionGuide').value = three;
// document.getElementById('wbDescriptionGuideSpan').innerHTML = three;
// if (four !== 'noperson') {
// document.getElementById('contributedBy').value = four;
// document.getElementById('contributedByDiv').innerHTML = four;
// document.getElementById('contributedByGuideSpan').innerHTML = five;
// } else {
// document.getElementById('contributedBy').value = '';
// document.getElementById('contributedByDiv').innerHTML = '';
// document.getElementById('contributedByGuideSpan').innerHTML = '';
// }
//
// } }, };
// wbgene = convertDisplayToUrlFormat(wbgene); // convert <newValue> to URL format by escaping characters
// var sUrl = cgiUrl + "?action=asyncWbdescription&wbgene=" + wbgene + "&";
// // alert(sUrl);
// YAHOO.util.Connect.asyncRequest('GET', sUrl, callbacks); // Make the call to the server for term info data
// } // function function asyncWbdescription(field, value)
//
//
// function onAutocompleteItemHighlight(sType, aArgs) { // if an item is highlighted from arrows or mouseover, populate obo
// // var value = elItem[1].innerHTML;
// // document.getElementById('wbDescription').innerHTML = value;
// var match = aArgs[0]._sName.match(/input_(.*)/); // get the key and value
// var field = match[1];
// var myAC = aArgs[0]; // reference back to the AC instance
// var elLI = aArgs[1]; // reference to the selected LI element
// if (field === 'person') {
// document.getElementById('term_info').parentNode.style.display = '';
// if (elLI.innerHTML.match(/\( (.*?) \)/) ) { // match wb id in span and parenthesis
// match = myAC._sName.match(/input_(.*)/);
// var field = match[1];
// var elMatch = elLI.innerHTML.match(/\( (.*?) \)/);
// var wbid = elMatch[1];
// document.getElementById('termid_person').value = wbid;
// asyncTermInfo(field, wbid);
// }
// }
// } // function onAutocompleteItemHighlight(oSelf , elItem)
//
// function asyncTermInfo(field, value) {
// var callbacks = {
// success : function (o) { // Successful XHR response handler
// if (o.responseText !== undefined) { document.getElementById('term_info').innerHTML = o.responseText + "<br/> "; } }, };
// value = convertDisplayToUrlFormat(value); // convert <newValue> to URL format by escaping characters
// var sUrl = cgiUrl + "?action=asyncTermInfo&field="+field+"&termid="+value;
// YAHOO.util.Connect.asyncRequest('GET', sUrl, callbacks); // Make the call to the server for term info data
// } // function function asyncTermInfo(field, value)
//
//
//
// function convertDisplayToUrlFormat(value) {
// if (value !== undefined) { // if there is a display value replace stuff
// if (value.match(/\n/)) { value = value.replace(/\n/g, " "); } // replace linebreaks with <space>
// if (value.match(/\+/)) { value = value.replace(/\+/g, "%2B"); } // replace + with escaped +
// if (value.match(/\#/)) { value = value.replace(/\#/g, "%23"); } // replace # with escaped #
// }
// return value; // return value in format for URL
// } // function convertDisplayToUrlFormat(value)