console.log($("#hyperreference1"));
function pwncors(site) {
var xmlSource = site
var yqlURL = [ "http://query.yahooapis.com/v1/public/yql", "?q=" + encodeURIComponent("select * from xml where url='" + xmlSource + "'"), "&format=xml&callback=?" ].join(""); console.log("putting..."); $.getJSON('http://allorigins.us/get?url=' + encodeURIComponent(site) + '&callback=?', function(data){
console.log(data);
}); console.log("done!");
}
pwncors("http://blast.ncbi.nlm.nih.gov/blast/Blast.cgi?CMD=put&DATABASE=swissprot&PROGRAM=blastp&QUERY=AAAAAAAAAA");
$("#hyperreference1").on('click', function() {
var fastain = $('#push_sequence').val(); var fastaout = ""; var start = 0; //Fastain contains either a FASTA or a blank seqeunce if(fastain.startsWith('>')){ start = 1; } fastain = fastain.split('\n'); for(var i = start; i < fastain.length; i++){ fastaout += fastain[i]; }
$("#first_input").append('<a target="_blank" href="http://blast.ncbi.nlm.nih.gov/blast/Blast.cgi?CMD=put&DATABASE=swissprot&PROGRAM=blastp&QUERY=' + fastaout + '" id="link1" style="display: none">Link to NCBI</a>'); $('#link1')[0].click();
});
$("#hyperreference0").click(function() {
var fastain = $('#push_sequence').val(); var fastaout = ""; var start = 0; //Fastain contains either a FASTA or a blank seqeunce if(fastain.startsWith('>')){ start = 1; } fastain = fastain.split('\n'); for(var i = start; i < fastain.length; i++){ fastaout += fastain[i]; }
pwncors("http://blast.ncbi.nlm.nih.gov/blast/Blast.cgi?CMD=put&DATABASE=swissprot&PROGRAM=blastp&QUERY=" + fastaout);
});
$("#hyperreference2").one('click', function() {
var ncbi_rid = $('#get_sequence').val(); $("#second_input").append('<a target="_blank" href="http://blast.ncbi.nlm.nih.gov/blast/Blast.cgi?CMD=get&FORMAT_TYPE=text&RID=' + ncbi_rid + '" id="link2" style="display: none">Link to NCBI Text</a>'); $("#link2")[0].click();
});
$("#hyperreference3").one('click', function() {
var ncbi_text_file = $('#get_safety').val(); getShit(ncbi_text_file);
});
function getShit(msg) {
var child_node = msg;
var regexp = />|Gaps/g;
var msd = []; while (regexp.exec(child_node) !== null) { msd.push(regexp.lastIndex); } var regexp_brackets = /\[(.+?)\]/g; var organism_match = []; var functionalities = []; var e_values = []; var identities_arr = []; var safety_arr = []; var safety_onko = []; var ids = []; var mbd = []; var names = []; var GOs = []; var k=0; //Get results names & results_ID for(var i=0; i<=msd.length-1;i+=1) { var substring = child_node.substring(msd[i],msd[i+1]); var get_length = substring.search('Length'); var header = substring.substring(0, get_length); var header_split = header.split(" "); var body = substring.substring(get_length); var body_split = body.split(" "); var expect = body_split.indexOf('Expect'); var identities = body_split.indexOf('Identities'); var search_recname = header_split.indexOf('RecName:'); var search_altname = header_split.indexOf('AltName:'); if(search_recname!=-1){
var search_result_ID = header_split[0].substring(0,header_split[search_recname-1].length-2); var name = ""; if(search_altname !=-1) { for(var t=1; t<search_altname-search_recname; t++) { name += header_split[search_recname+t] + " "; } } else { for(var s=1; s<header_split.length-search_recname; s++) { name += header_split[search_recname+s] + " "; } } name = name.replace( /\n/g, " " ).substring(5, name.length); var recname = name.search('RecName:'); var altname = name.search('AltName:'); var result_name = ""; if(recname !=-1) { var next_split = name.split(" "); for(var r=0; r<next_split.indexOf('RecName:')-1; r++) { result_name += next_split[r] + " "; } } else if(altname !=-1) { result_name = name.substring(0, altname); } else { result_name = name; } var comma = result_name.search(';'); if(comma != -1) { result_name = result_name.replace( /;/g, " " ); } names.push(result_name); ids.push(search_result_ID); getProtein(search_result_ID); var expect_value = body_split[expect+2].substring(0,body_split[expect+2].length-1); e_values.push(expect_value); var identities_value = body_split[identities+3].substring(1, body_split[identities+3].length-2); identities_arr.push(identities_value); } }
setTimeout(function() {
console.log(organism_match); console.log(safety_arr); console.log(names); var functionalities_safety = []; console.log(functionalities.length); for(var q=0; q<functionalities.length; q++) { var pusher = [1]; functionalities_safety.push(pusher); } console.log(functionalities); console.log(functionalities_safety); console.log(ids); console.log(e_values); console.log(identities_arr); createTable(names, organism_match, safety_arr, functionalities, functionalities_safety, ids, identities_arr, e_values, safety_onko); }, 1000);
function getProtein (id) { $.ajax({
type: 'GET', url: 'http://www.uniprot.org/uniprot/'+id+'.txt', dataType: 'Text', async: 'false', success: function(result){ console.log(result); var organism_safety = ""; var _GOs = get_GOs(result); var GO_string = ""; for(var x=0; x<2;x++) { GO_string = GO_string + Object.values(_GOs[x]) + ", "; } GO_string = GO_string.substring(0, GO_string.length-2); if(GO_string.charAt(GO_string.length-2) == ',') { GO_string = GO_string.substring(0, GO_string.length-2); } functionalities.push(GO_string); organism_match.push(_GOs[2][0]); organism_safety = _GOs[2][0].substring(0, _GOs[2][0].indexOf('(')-1);
getSafety(organism_safety); getOnkogene(_GOs[3][0]); },error: function (request, status, error) { alert(request.responseText); }
});
}
function get_GOs(result) { uniprot_dict_F = {}; uniprot_dict_P = {}; curr_prot_id = ""; curr_GOs_F = []; curr_GOs_P = []; curr_GOs_functions = []; curr_GOs_pathways = []; organisms = []; onkogenes = [];
var lines = result.split("\n"); var organism = ""; var onkogene = ""; for(var a in lines) {
var fields = lines[a].split(" ").filter(function(e) {return e.trim().length > 0;}); flag = fields[0]; if(flag == 'DR' && fields.length >=2){ var target_line = fields.slice(1,fields.length); var target_line = fields.slice(1,fields.length); if(target_line[0] == 'GO;' && target_line[2].startsWith("F")) { curr_GOs_F.push(target_line[1].slice(3, -1)); var function_name = ""; for(var i=2; i<target_line.length-1; i++) { function_name += target_line[i] + " "; } curr_GOs_functions.push(function_name.slice(2, function_name.length-2)); } else if(target_line[0] == 'GO;' && target_line[2].startsWith("P")) { curr_GOs_P.push(target_line[1].slice(3, -1)); var pathway_name = ""; for(var i=2; i<target_line.length-1; i++) { pathway_name += target_line[i] + " "; } curr_GOs_pathways.push(pathway_name.slice(2, pathway_name.length-2)); } } else if(flag == 'OS') { for(var l=1; l<fields.length; l++) { organism += fields[l] + " "; }
} else if(flag == 'GN') { onkogene = fields[1].substring(5, onkogene.length-1); }
} organisms.push(organism.substring(0, organism.length-2)); onkogenes.push(onkogene); for(var i=0; i< curr_GOs_F.length; i++) {
uniprot_dict_F[curr_GOs_F[i]]=curr_GOs_functions[i];
} for(var i=0; i< curr_GOs_P.length; i++) {
uniprot_dict_P[curr_GOs_P[i]]=curr_GOs_pathways[i];
} return [uniprot_dict_F, uniprot_dict_P, organisms, onkogenes]; }
function getSafety(blast_organism) { $.getJSON('Organisms.json', function(json_organisms) { if(Object.keys(json_organisms).indexOf(blast_organism) >=0 ) { var safety_values = Object.values(json_organisms[blast_organism]); safety_arr.push(safety_values); } else { safety_arr.push(['safe', 1]); } }); } function getOnkogene(onkogene) { $.getJSON('Organisms.json', function(json_onkogenes) { if(Object.keys(json_onkogenes).indexOf(onkogene) >=0 ) { var safety_values = Object.values(json_onkogenes[onkogene]); safety_onko.push(safety_values); } else { safety_onko.push('No Onkogene'); } }); } // Create Interactive HTML table
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'];
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<7; i++) { var td_head = document.createElement('td'); 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] = organism_safety[j][0]; 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]>1 && k==2 ) { td_body.style.backgroundColor = 'red'; } else if(organism_safety[j][1]<=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"; div.appendChild(table);
} }