-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcga.js
290 lines (267 loc) · 10.1 KB
/
tcga.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
/* Javascript methods for the Tissue Finder 2.0 *
* Coder: Stefano Pirro'
* Institution: Barts Cancer Institute
* Details: all the javascript behaviours of the BOB portal, are included here. */
// loading frame
var loading = "<div>\
<img id='loading' src=\"images/loading.svg\">\
<br>\
<h2> Loading the results... </h2>\
</div>";
// webiste for loading iframe
var tcga_iframe_url = "http://bioinformatics.breastcancertissuebank.org:9003/sample_finder/queries/tcga/";
function LoadTCGATabs() {
$("#tcga_results.container").tabs();
}
function LoadScoreSlider(el_name) {
$( "div#"+el_name+"" ).slider({
range: true,
step: 0.1,
min: 0,
max: 1,
values: [ 0.4, 0.8],
slide: function( event, ui ) {
$( "#min_thr_label" ).val( "" + ui.values[ 0 ] + "");
$( "#max_thr_label" ).val( "" + ui.values[ 1 ] + "");
}
});
// initilizing values on load
$( "#min_thr_label" ).val(""+$("div#"+el_name+"").slider("values",0)+"");
$( "#max_thr_label" ).val(""+$("div#"+el_name+"").slider("values",1)+"");
}
function LoadTCGATabs() {
$("#tcga_results.container").tabs();
}
// function to load MultiGeneSelector
// this function takes as input the name of html element to call,
// the array express id and PMID id (to call the right expression matrix)
function LoadGeneSelector(el_name, ae, pmid, type_analysis) {
$.fn.select2.defaults.set("theme", "classic");
$.fn.select2.defaults.set("ajax--cache", false);
// we decided to implement an ajax-based search
$( "#"+el_name+"" ).select2({
width:'50%',
ajax: {
url: "scripts/RetrieveGeneList.php?ae="+ae+"&pmid="+pmid+"&type_analysis="+type_analysis+"",
dataType: "json",
delay: 250,
data: function (params) {
if (params.term === undefined) {
q = "A";
} else {
return {
q: params.term, // search term
};
}
},
processResults: function (data, params) {
return {
results: data
};
var q = '';
},
cache: false
}
});
}
// this function launch the Rscript to create the expression profile plot for the selected gene
// the function takes three parameter
// -- el_name: html element to call
// -- ae: array_express id
// -- pmid : pubmed id
// Please note, for security reasons, the launch of Rscript and all system commands are delegated to
// a php function ("LaunchCommand.php")
function LoadAnalysis(genebox, el_name, ae, pmid, type_analysis, random_code) {
if (type_analysis == "tcga_gene_expression") {
$("#"+el_name+"").click(function() {
var gene = $("#"+genebox+"").val();
// launching ajax call to retrieve the expression plot for the selected gene
$.ajax( {
url:"scripts/LaunchCommand.php?TypeAnalysis="+type_analysis+"&Genes="+gene+"&rc="+random_code+"",
type:"get",
beforeSend: function()
{
$("div#loading").html(loading);
$("div#loading").show();
},
success: function(data) {
$("iframe#"+genebox+"_box.results").attr("src", ""+tcga_iframe_url+random_code+".live.box.html");
$("iframe#"+genebox+"_bar.results").attr("src", ""+tcga_iframe_url+random_code+".live.bar.html");
$(".gea_tcga").show();
$("div#loading").hide();
$("div#loading").empty();
}
});
});
} else if (type_analysis == "tcga_co_expression") {
$("#"+el_name+"").click(function() {
var genes_sel = $("#"+genebox+"").val();
// loading text area (gene list selector)
var genes_list = $("#text"+genebox+"").val().toUpperCase();
// splitting genes list by wide space chars
var genes_list_array = genes_list.split(/\s+/);
// pushing gene list into the genes array
var genes = genes_sel.concat(genes_list_array)
// checking the length of the uploaded genes
if (genes.length > 2 && genes.length <= 50) {
var genes_string = genes.join(",");
// launching ajax call to retrieve the expression plot for the selected gene
$.ajax( {
url:"scripts/LaunchCommand.php?TypeAnalysis="+type_analysis+"&Genes="+genes_string+"&rc="+random_code+"",
type:"get",
beforeSend: function()
{
$("div#loading").html(loading);
$("div#loading").show();
},
success: function(data) {
$("iframe#"+genebox+"_hm.results").attr("src", ""+tcga_iframe_url+random_code+".live.corr_hm.html");
$(".cea_tcga").show();
$("div#loading").hide();
$("div#loading").empty();
},
error: function(data) {
alert("Sorry, there is an error in the analysis...\n\
Probably the number of genes submitted to the analysis is less then 3.");
$("div#loading").hide();
$("div#loading").empty();
}
});
} else {
alert("Please select at least 3 genes (max 50)");
return false
}
});
} else if (type_analysis == "tcga_survival") {
$("#"+el_name+"").click(function() {
// loading selected genes
var genes = $("#"+genebox+"").val();
var genes_string = genes.join(",");
// checking the length of the uploaded genes
if (genes.length >= 1 && genes.length < 4) {
// launching ajax call to retrieve the expression plot for the selected gene
$.ajax( {
url:"scripts/LaunchCommand.php?TypeAnalysis="+type_analysis+"&Genes="+genes_string+"&rc="+random_code+"",
type:"get",
beforeSend: function()
{
$("div#loading").html(loading);
$("div#loading").show();
},
success: function(data) {
//alert(data);
// loading survival table
var table = $('table#survival_details').DataTable( {
dom: 'Bfrtip',
buttons: [
'copyHtml5',
'excelHtml5',
'csvHtml5',
'pdfHtml5'
],
"processing": false,
"serverSide": false,
"destroy": true,
"ajax": {
"url": ""+tcga_iframe_url+random_code+".multivariate.json",
}
});
// remove all the images inside the div
$('div.surv_tcga_container > center').remove();
// append the new images
$.each( genes, function( index, sg) {
d = new Date();
$(".surv_tcga_container").append("<center><img src='"+tcga_iframe_url+random_code+".live.KMplot."+sg+".png?"+d.getTime()+"'></center>");
});
$(".surv_tcga_container").show();
$("div#loading").hide();
$("div#loading").empty();
}
});
} else {
alert("Please select a maximum number of 3 genes and at least one molecular subtype");
return false
}
});
} else if (type_analysis == "tcga_gene_network") {
$("#"+el_name+"").click(function() {
// getting genes of interest
var genes = $("#"+genebox+"").val();
var genes_string = genes.join(",");
// getting min and max score thresolds
var min_thr = $("input#min_thr_label").val();
var max_thr = $("input#max_thr_label").val();
// checking the length of the uploaded genes
if (genes.length >= 1 && genes.length < 6) {
// launching ajax call to retrieve the expression plot for the selected gene
$.ajax( {
url:"scripts/LaunchCommand.php?TypeAnalysis="+type_analysis+"&Genes="+genes+"&rc="+random_code+"&min_thr="+min_thr+"&max_thr="+max_thr+"",
type:"get",
beforeSend: function()
{
//console.log("scripts/LaunchCommand.php?TypeAnalysis="+type_analysis+"&Genes="+genes+"&rc="+random_code+"&min_thr="+min_thr+"&max_thr="+max_thr+"");
$("div#loading").html(loading);
$("div#loading").show();
},
error: function(data) {
console.log(data);
},
success: function(data) {
//alert(data);
$("div#loading").hide();
$("div#loading").empty();
$("input#random_code").val(random_code);
$("iframe#network_container.results").attr("src", ""+tcga_iframe_url+random_code+".live.network0.html");
var table = $('table#network_details').DataTable( {
dom: 'Bfrtip',
buttons: [
'copyHtml5',
'excelHtml5',
'csvHtml5',
'pdfHtml5'
],
"processing": false,
"serverSide": false,
"destroy": true,
"ajax": {
"url": ""+tcga_iframe_url+random_code+".live.network0.json", // we visualize the first network as default
}
});
$(".network_container").show();
}
});
} else {
alert("Please select a maximum number of 5 genes");
return false
}
});
}
}
// function for scrolling page to the bottom
function scrollSmoothToBottom (id) {
var div = document.getElementById(id);
$('body').animate({
scrollTop: document.body.scrollHeight
}, 1000);
}
// function for loading the results accordion
function LoadResultAcc() {
$("#res_acc").accordion({
heightStyle: "content",
active: false,
collapsible: true
});
}
// function to adjust the size of the results iframe according to the content
function resizeIframe(obj){
obj.style.height = 0;
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}
function LoadNetworkGraph(random_code, index) {
$("iframe#network_container.results").attr("src", ""+tcga_iframe_url+random_code+".live.network"+index+".html");
$('table#network_details').DataTable().ajax.url(""+tcga_iframe_url+random_code+".live.network"+index+".json").load();
}
function LoadLegend() {
$( "#net_legend" ).dialog();
$( "#net_legend" ).show();
}