Lukas Adam (Talk | contribs) |
Lukas Adam (Talk | contribs) |
||
Line 126: | Line 126: | ||
function safetyblast_register_handlers() { | function safetyblast_register_handlers() { | ||
− | $("# | + | $("#fastablast").on("change") { |
− | sequence = $("# | + | let file = $("#fastablast").files[0]; |
+ | var reader = new FileReader(); | ||
+ | reader.onload = function() { | ||
+ | var res = this.result; | ||
+ | if (res.indexOf(">") != -1 || res.indexOf("\n") != -1) { | ||
+ | var ressplit = res.split("\n"); | ||
+ | res = ""; | ||
+ | for (let idx = 1; idx < ressplit.length; ++idx) { | ||
+ | res += ressplit[idx]; | ||
+ | } | ||
+ | } | ||
+ | $("#blast_sequence").val(res); | ||
+ | } | ||
+ | } | ||
+ | $("#blastit").one("click", function() { | ||
+ | sequence = $("#blast_sequence")[0].value; | ||
doSafetyQuery(sequence).then(function(result) { | doSafetyQuery(sequence).then(function(result) { | ||
let nhits = result.hits.length; | let nhits = result.hits.length; |
Revision as of 14:15, 1 November 2017
function safetyblast_create_table(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] && k == 3) { td_body.style.backgroundColor = 'red'; } else if (!functionality_safety[j] && 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 safetynet_create_table(goterms) {
return getDatabase().then(function(db) { safetynet_create_table_impl(goterms, db); });
}
function safetynet_create_table_impl(goterms, database) {
var gored = "#9d1c20"; var gogreen = "#009e73"; $("#deeprotein_results") = document.createElement("div"); $("#deeprotein_results").id = "deeprotein_results"; var card_section = document.createElement("section"); card_section.className = "teaser content equal_height"; card_section.style = "padding-top: 100px"; var evilgos = Object.keys(database.functions); for (let idx = 0; idx < goterms.length; ++idx) { var isEvil = false; for (let idy = 0; idy < evilgos.length; ++idy) { if (goterms[idx].go === evilgos[idy]) { isEvil = true; break; } } let gocolor = isEvil ? gored : gogreen; let goevil = isEvil ? "Potentially Dangerous" : "Safe"; let gotitle = document.createElement("h4"); gotitle.class = "card-title"; gotitle.text = goevil; let gocontent = document.createElement("p"); gocontent.class = "card-content"; gocontent.text = goterms[idx].name; let gobody = document.createElement("div"); gobody.class = "card-body"; gobody.appendChild(gotitle); gobody.appendChild(gocontent); let gocard = document.createElement("div"); gocard.className = "card"; gocard.style = "border-left: 10px solid; border-color: " + gocolor; gocard.appendChild(gobody); let gocol = document.createElement("div"); gocol.className = "col-lg-4 col-md-4 col-xs-12"; gocol.appendChild(gocard); } card_section.appendChild(gocol); $("#deeprotein_results").appendChild(gocol);
}
function safetyblast_register_handlers() {
$("#fastablast").on("change") { let file = $("#fastablast").files[0]; var reader = new FileReader(); reader.onload = function() { var res = this.result; if (res.indexOf(">") != -1 || res.indexOf("\n") != -1) { var ressplit = res.split("\n"); res = ""; for (let idx = 1; idx < ressplit.length; ++idx) { res += ressplit[idx]; } } $("#blast_sequence").val(res); } } $("#blastit").one("click", function() { sequence = $("#blast_sequence")[0].value; doSafetyQuery(sequence).then(function(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) { name.push(result.hits[idx].name); organism.push(result.matches[idx]); organism_safety.push(result.organisms[idx][1]); functionality.push(result.functions[idx]); functionality_safety.push(result.functionality_safety[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]); } safetyblast_create_table(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) { 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) { name.push(result.hits[idx].name); organism.push(result.matches[idx]); organism_safety.push(result.organisms[idx][1]); functionality.push(result.functions[idx]); functionality_safety.push(result.functionality_safety[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]); } safetyblast_create_table(name, organism, organism_safety, functionality, functionality_safety, id, identity, e_value, onkogenes); }); });
}
function safetynet_register_handlers() {
window.ctx = newDeeProteinContext(); ctx.onready = function() { var status = $("#deeprotein_status"); status.css({"background-color" : "blue"}); status.text("Initialized ..."); }; ctx.onloadfile = function() { var status = $("#deeprotein_status"); status.css({"background-color" : "green"}); status.text("Weights loaded ...") }; ctx.oninfer = function(result) { safetynet_create_table(result); status.css({"background-color" : "green"}); status.text("Inferred!"); }; $("#push_weights").one("click", function() { var weightfile = $("#weight_file").files[0]; ctx.loadWeightsFromFile(weightfile); });
}
$(document).ready(function() {
safetyblast_register_handlers(); safetynet_register_handlers();
});