Lukas Adam (Talk | contribs) |
Lukas Adam (Talk | contribs) |
||
Line 140: | Line 140: | ||
} | } | ||
− | $(document).ready(function() { | + | $( document ).ready(function() { |
+ | console.log("READY!"); | ||
register_handlers(); | register_handlers(); | ||
}); | }); |
Revision as of 21:26, 26 October 2017
function createTable(name, organism, organism_safety, functionality,
functionality_safety, id, identity, e_value, onkogenes) {
var table_head = [ 'Name', 'Organism', 'Group', 'Functionality', 'ID', 'Identity', 'E-Value', 'Onkogenicity' ];
var div = document.getElementById('safety_table'); var table = document.createElement('table'); var thead = document.createElement('thead'); var tbody = document.createElement('tbody');
var tr_head = document.createElement('tr'); for (var i = 0; i < 8; i++) { var td_head = document.createElement('th'); td_head.append(document.createTextNode(table_head[i])); tr_head.appendChild(td_head); } thead.appendChild(tr_head);
for (var j = 0; j < organism.length; j++) { var table_body = [];
table_body[0] = name[j]; table_body[1] = organism[j]; table_body[2] = "S" + organism_safety[j].toString(); table_body[3] = functionality[j];
table_body[4] = id[j]; table_body[5] = identity[j]; table_body[6] = e_value[j]; table_body[7] = onkogenes[j];
var tr_body = document.createElement('tr'); for (var k = 0; k < 8; k++) { var td_body = document.createElement('td');
if (k == 3) {
var inner_func = table_body[k].split(','); for (var w = 0; w < functionality[j].split(',').length; w++) { var tr_inner = document.createElement('tr'); var td_inner = document.createElement('td'); td_inner.append(document.createTextNode(inner_func[w])); tr_inner.appendChild(td_inner); td_body.appendChild(tr_inner); }
} else { td_body.append(document.createTextNode(table_body[k])); if (organism_safety[j] > 1 && k == 2) { td_body.style.backgroundColor = 'red'; } else if (organism_safety[j] <= 1 && k == 2) { td_body.style.backgroundColor = 'green'; } else { // Nothing } }
if (functionality_safety[j][0] > 1 && k == 3) { td_body.style.backgroundColor = 'red'; } else if (functionality_safety[j][0] <= 1 && k == 3) { td_body.style.backgroundColor = 'green'; } else { // Nothing } tr_body.appendChild(td_body); } tbody.appendChild(tr_body); }
table.appendChild(thead); table.appendChild(tbody); table.className = "table table-bordered mdl-shadow--4dp"; div.appendChild(table);
}
function register_handlers() {
$("#hyperreference1").one("click", function() { sequence = $("#push_sequence")[0].value; doSafetyQuery(sequence).then(function(result) { console.log(result); nhits = result.hits.length; name = []; organism = []; organism_safety = []; functionality = []; functionality_safety = []; id = []; identity = []; e_value = []; onkogenes = []; console.log("ORGANISMS: ", result.organisms); for (idx = 0; idx < nhits; ++idx) { name.push(result.functions[idx]); organism.push(result.matches[idx]); organism_safety.push(result.organisms[idx][1]); functionality.push(result.functions[idx]); functionality_safety.push(result.onkogenes[idx]); id.push(result.hits[idx].id); identity.push(result.hits[idx].identity); e_value.push(result.hits[idx].evalue); onkogenes.push(result.onkogenes[idx]); } createTable(name, organism, organism_safety, functionality, functionality_safety, id, identity, e_value, onkogenes); }); }); $("#hyperreference2").one("click", function() { rid = $("#get_sequence")[0].value; doSafetyQueryWithRID(rid).then(function(result) { console.log(result); let nhits = result.hits.length; var name = []; var organism = []; var organism_safety = []; var functionality = []; var functionality_safety = []; var id = []; var identity = []; var e_value = []; var onkogenes = []; for (idx = 0; idx < nhits; ++idx) { console.log("ORGANISMS: ", result.organisms[idx][1]); name.push(result.functions[idx]); organism.push(result.matches[idx]); organism_safety.push(result.organisms[idx][1]); functionality.push(result.functions[idx]); functionality_safety.push(result.onkogenes[idx]); id.push(result.hits[idx].id); identity.push(result.hits[idx].identity); e_value.push(result.hits[idx].evalue); onkogenes.push(result.onkogenes[idx]); } createTable(name, organism, organism_safety, functionality, functionality_safety, id, identity, e_value, onkogenes); }); });
}
$( document ).ready(function() {
console.log("READY!"); register_handlers();
});