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');
$(div).empty();
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"; var goredimg = ""; var gogreenimg = ""; $("#deeprotein_results").empty(); $("#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; } } var gocolor = isEvil ? gored : gogreen; var goevil = isEvil ? "Potentially Dangerous" : "Safe"; var goimage = document.createElement("img"); goimage.src = isEvil ? goredimg : gogreenimg; goimage.class = "card-image"; goimage.style = "width: 100%"; var gotitle = document.createElement("h4"); gotitle.class = "card-title"; $(gotitle).text(goevil); var gocontent = document.createElement("p"); gocontent.class = "card-content"; $(gocontent).text(goterms[idx].name); var gobody = document.createElement("div"); gobody.class = "card-body"; gobody.appendChild(gotitle); gobody.appendChild(gocontent); var gocard = document.createElement("div"); gocard.className = "card"; gocard.style = "border-left: 10px solid; border-color: " + gocolor; gocard.appendChild(goimage); gocard.appendChild(gobody); var gocol = document.createElement("div"); gocol.className = "col-lg-4 col-md-4 col-xs-12"; gocol.appendChild(gocard); card_section.appendChild(gocol); } $("#deep_results").append(card_section);
}
function safetyblast_register_handlers() {
$("#fastablast").on("change", function() { let file = $("#fastablast")[0].files[0]; var reader = new FileReader(); reader.onload = function() { var res = this.result.replace(/ /g, ""); res = res.replace(/\t/g, ""); 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]; } } console.log(res); $("#blast_sequence").val(res); }; reader.readAsText(file); }); $("#blastit").on("click", function() { sequence = $("#blast_sequence")[0].value.replace(/ /g, "").replace(/\t/g, ""); $("#blast_status").text("Starting..."); $("#blast_status").css("cssText", "background-color: black !important"); 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); $("#blast_status").text("Done!"); $("#blast_status").css("cssText", "background-color: green !important"); }); }); $("#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.ready(); $("#download").on("click", function() { top.location.href = "https://static.igem.org/mediawiki/2017/f/fd/T--Heidelberg--2017_DeeProteinWeights.zip"; }); $("#deepweights").on("change", function() { var status = $("#deep_status"); status.text("Loading Weights ..."); var file = $("#deepweights")[0].files[0]; ctx.loadWeightsFromFile(file); }); $("#fastadeep").on("change", function() { let file = $("#fastadeep")[0].files[0]; var reader = new FileReader(); reader.onload = function() { var res = this.result.replace(/ /g, ""); res = res.replace(/\t/g, ""); 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]; } } console.log(res); $("#deep_sequence").val(res); }; reader.readAsText(file); }); $("#deepit").on("click", function() { var status = $("#deeprotein_status"); status.text("Inferring ..."); let string = $("#deep_sequence")[0].value; ctx.infer(string); }); ctx.onready = function() { var status = $("#deeprotein_status"); status.css("cssText", "background-color: black !important"); status.text("Initialized ..."); }; ctx.onloadfile = function() { var status = $("#deep_status"); status.css("cssText", "background-color: blue !important"); status.text("Weights loaded ...") }; ctx.oninfer = function(result) { var status = $("#deep_status"); safetynet_create_table(result); console.log(result); status.css("cssText", "background-color: green !important"); status.text("Inferred!"); };
}
$(document).ready(function() {
safetyblast_register_handlers(); safetynet_register_handlers();
});