-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_output.php
443 lines (394 loc) · 10.2 KB
/
view_output.php
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
<?php
session_start();
include('variables.php');
include('bio_utils.php');
include('php_utils.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" href="style.css"/>
<title>Viewing a job</title>
</head>
<body>
<?php include('top_bar.php'); ?>
<noscript>
It seems javascript isn't enabled. This website uses it for
many fuctionalities (some navigation buttons, sorting and so on),
so please enable javascript if you want to have full functionality !
</noscript>
<?php
// Getting $job and $status
$params = _test2(get_GET_parameters(array('job')));
$job = $params['job'];
// Getting actual content
$raw = _test2(fimo_get_raw_output(session_id(), $job));
// Formatting output for display
// Note: $raw[0] = '#', so we eliminate it
$raw[0] = '';
$output = split_into_matrix($raw);
$titles = $output[0];
$data = array_slice($output, 1);
?>
<p>
Select filters:<br/>
Score limit: <input type="text" id="text_score"><br/>
p-value limit:
<select id="select_p-value">
<option value="0.0001">10⁻⁴</option>
<option value="0.00001">10⁻⁵</option>
<option value="0.000001">10⁻⁵</option>
<option value="0.0000001">10⁻⁷</option>
</select><br/>
<!-- q-value limit:-->
<select id="select_q-value" hidden="true">
<option value="0.0001">10⁻⁴</option>
<option value="0.00001">10⁻⁵</option>
<option value="0.000001">10⁻⁵</option>
<option value="0.0000001">10⁻⁷</option>
</select><br/>
<button id="filter_button" onclick="filter_button_onclick()">Filter !</button>
</p>
<p>
Sort by:
<select id="select_sort" onchange="sort_onchange()">
<option value="42">Don't sort</option>
<option value="score">score</option>
<option value="p-value">p-value</option>
<!-- <option value="q-value">q-value</option>-->
<option value="occurrence">gene occurrence</option>
</select>
<select id="select_order">
<option value="<">from smallest to biggest</option>
<option value=">">from biggest to smallest</option>
</select>
<button id="sort_button" onclick="sort_button_onclick()">Sort !</button>
</p>
<p>
<!-- <button id="back_to_jobs_button" onclick="back_to_jobs_button_onclick()">Back to the jobs</button>-->
<button id="download_button" onclick="download_button_onclick()">Download output</button>
<button id="nice_view_button" onclick="nice_view_button_onclick()">Visualisation</button>
</p>
<table id="output_table">
<tr><th>
<?php
echo implode('</th><th>', $titles);
?>
</th></tr>
<?php
$i = 0;
foreach ($data as $line)
{
echo "<tr id=\"$i\">";
foreach ($line as $el)
{
echo "<td>$el</td>";
}
echo '</tr>';
$i++;
}
?>
</table>
<script type="text/javascript">
var g_n_entries = <?php echo sizeof($output) - 1;?>;
var g_download_name="fimo_output.txt";
(function(){
var select_order = document.getElementById("select_order");
select_order.disabled = true;
if (!String.prototype.ltrim)
{
String.prototype.ltrim = function() { return this.replace(/^\s+/, ''); };
}
})();
function get_score(id)
{
var parent = document.getElementById(id);
var cell = parent.childNodes[5];
var score = cell.firstChild.data;
return parseFloat(score);
}
function get_pvalue(id)
{
var parent = document.getElementById(id);
var cell = parent.childNodes[6];
var pvalue = cell.firstChild.data;
return parseFloat(pvalue);
}
function get_qvalue(id)
{
var parent = document.getElementById(id);
var cell = parent.childNodes[7];
var qvalue = cell.firstChild.data;
return parseFloat(qvalue);
}
function get_genename(id)
{
var parent = document.getElementById(id);
var cell = parent.childNodes[9];
var gene = cell.firstChild.data;
return gene;
}
function hide_entries_by(l_score, l_pvalue, l_qvalue)
{
for (var i = 0; i < g_n_entries; i++)
{
var parent = document.getElementById(i);
var score = get_score(i);
var pvalue = get_pvalue(i);
var qvalue = get_qvalue(i);
parent.hidden = (score < l_score || pvalue > l_pvalue/* || qvalue > l_qvalue*/);
}
}
function filter_button_onclick()
{
var score = document.getElementById("text_score").value;
var pvalue = document.getElementById("select_p-value").value;
var qvalue = document.getElementById("select_q-value").value;
/* if (isNaN(score))
{
score = 42;
}*/
hide_entries_by(score, pvalue, qvalue);
}
function swap_rows(i1, i2)
{
var r1 = document.getElementById(i1);
var r2 = document.getElementById(i2);
var t = r1.innerHTML;
r1.innerHTML = r2.innerHTML;
r2.innerHTML = t;
}
function get_entries()
{
var ret = [];
for (var i = 0; i < g_n_entries; i++)
ret[i] = document.getElementById(i);
return ret;
}
function get_scores()
{
var ret = [];
for (var i = 0; i < g_n_entries; i++)
ret[i] = get_score(i);
return ret;
}
function get_pvalues()
{
var ret = [];
for (var i = 0; i < g_n_entries; i++)
ret[i] = get_pvalue(i);
return ret;
}
function get_qvalues()
{
var ret = [];
for (var i = 0; i < g_n_entries; i++)
ret[i] = get_qvalue(i);
return ret;
}
function get_genenames()
{
var ret = [];
for (var i = 0; i < g_n_entries; i++)
ret[i] = get_genename(i);
return ret;
}
function get_occurrences()
{
var ret = {};
for (var i = 0; i < g_n_entries; i++)
{
var name = get_genename(i);
if (ret[name])
ret[name] += 1;
else
ret[name] = 1;
}
return ret;
}
function array_unique(multi)
{
var ret = [];
for (var i = 0; i < g_n_entries; i++)
{
if (ret[ret.length - 1] != multi[i])
ret.push(multi[i]);
}
return ret;
}
function array_indicesof(el, input)
{
var ret = [];
for (var i = 0; i < g_n_entries; i++)
{
if (el == input[i])
ret.push(i);
}
return ret;
}
function get_substitutions(unsorted, orderfunc)
{
var ret = [];
var sorted = unsorted.slice(0);
sorted.sort(orderfunc);
sorted = array_unique(sorted);
for (var i = 0; i < sorted.length; i++)
ret = ret.concat(array_indicesof(sorted[i], unsorted));
return ret;
}
function sort_onchange()
{
var select_sort = document.getElementById("select_sort");
var select_order = document.getElementById("select_order");
switch (select_sort.value)
{
case "score":
select_order.value = ">";
break;
case "p-value":
select_order.value = "<";
break;
case "q-value":
select_order.value = "<";
break;
case "occurrence":
select_order.value = ">";
break;
default:
break;
}
select_order.disabled = (select_sort.value == "42");
}
function sort_button_onclick()
{
var select_sort = document.getElementById("select_sort").value;
var select_order = document.getElementById("select_order").value;
var entries = get_entries();
switch (select_sort)
{
case "score":
var to_order = get_scores();
break;
case "p-value":
var to_order = get_pvalues();
break;
case "q-value":
var to_order = get_qvalues();
break;
case "occurrence":
var to_order = get_occurrences();
break;
default:
return;
}
if (select_sort == "occurrence")
{
if (select_order == "<")
var orderfunc = function(a, b) { return to_order[a] - to_order[b]; };
else if (select_order == ">")
var orderfunc = function(a, b) { return to_order[b] - to_order[a]; };
else
return;
// Getting keys from 'to_order' as 'genes' ;
// array necessary when trying to sort
var genes = [];
for (var gene in to_order)
genes.push(gene);
var genes_unsorted = get_genenames();
genes.sort(orderfunc);
var substitutions = [];
for (var i = 0; i < genes.length; i++)
substitutions = substitutions.concat(array_indicesof(genes[i], genes_unsorted));
}
else
{
if (select_order == "<")
var orderfunc = function(a, b) { return a - b; };
else if (select_order == ">")
var orderfunc = function(a, b) { return b - a; };
else
return;
var substitutions = get_substitutions(to_order, orderfunc);
}
var entries_new = [];
for (var i = 0; i < g_n_entries; i++)
entries_new.push(entries[substitutions[i]].innerHTML);
for (var i = 0; i < g_n_entries; i++)
entries[i].innerHTML = entries_new[i];
}
function is_str_empty(str)
{
return (!str || 0 === str.length);
}
function is_str_not_empty(str)
{
return !is_str_empty(str);
}
function str_ltrim(str)
{
return str.ltrim();
}
function get_output_table()
{
var table = document.getElementById("output_table");
var html = table.innerHTML.split("\n").map(str_ltrim).join("");
var headers = [];
var content = [];
var lines = [];
var th_bounds = /<th>(.*?)<\/th>/g;
var tr_bounds = /<tr\sid=["'][0-9]+["']>(.*?)<\/tr>/g;
var td_bounds = /<td>(.*?)<\/td>/g;
var match;
// First getting the headers
while (match = th_bounds.exec(html))
{
headers.push(match[1]);
}
// Then dividing the rest of the table into lines
while (match = tr_bounds.exec(html))
{
lines.push(match[1]);
}
// Before we put the whole thing into content
for (var i = 0; i < lines.length; i++)
{
var temp = [];
while (match = td_bounds.exec(lines[i]))
{
temp.push(match[1]);
}
content.push(temp);
}
return [headers, content];
}
function download_button_onclick()
{
var table = get_output_table();
var content = [table[0]].concat(table[1]);
var output = "#";
for (var i = 0; i < content.length; i++)
{
output += content[i].join("\t") + "\n";
}
var blob = new Blob([output], {type:'text/plain'});
var link = document.createElement("a");
link.download = g_download_name;
link.innerHTML = "Download as file";
link.href = window.URL.createObjectURL(blob);
link.onclick = function(event) { document.body.removeChild(event.target); };
link.style.display = "none";
document.body.appendChild(link);
link.click();
}
function back_to_jobs_button_onclick()
{
window.location = "<?php echo "http://$LAB_ADDRESS/view_jobs.php"; ?>";
}
function nice_view_button_onclick()
{
window.location = "<?php echo "http://$LAB_ADDRESS/visualisation.php?job=$job"; ?>";
}
</script>
</body>
</html>