-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata.js
More file actions
235 lines (202 loc) · 8.1 KB
/
data.js
File metadata and controls
235 lines (202 loc) · 8.1 KB
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
// Functions for accessing the data
// Find a given gene name, returns a promise containing the cleaned up version of the name
function searchGeneAsync(searchTerm) {
var promise = Promise.resolve($.getJSON("http://rest.genenames.org/search/" + searchTerm + "*"));
return promise.then(function (data) {
try {
return data;
} catch (error) {
var message = "Gene " + searchTerm + " not found";
alert(message);
throw Error(message);
}
});
}
var processGeneResults = function(data) {
// Wipe the previous results
$("#tbl_results").html("");
var symbol_result, li_result, a_result, i;
if (data.response.docs.length > 1) {
$("#result_header").html("Please select an approved gene symbol:");
for (i = 0; !!(symbol_result = data.response.docs[i]); i = i + 1) {
// only show up to the first 10 results
if (i === 10) { break; }
a_result = document.createElement("A");
a_result.href = "#";
a_result.innerHTML = symbol_result.symbol;
a_result.geneName = symbol_result.symbol;
a_result.onclick = function() {
// hide dropdown
$(this).parent().parent().hide();
loadGeneAsync(this.geneName)
.then(function (geneData) {
dataModel = new DataModel(geneData);
numAA = dataModel.numAminoAcids;
xScale = xScale.domain([1, numAA]);
generateAnnotationPanels(dataModel);
resetZoom();
resetDetails();
});
return false;
};
li_result = document.createElement("LI");
li_result.appendChild(a_result);
document.getElementById("tbl_results").appendChild(li_result);
}
$("#tbl_results").show();
}
else if (data.response.docs.length == 1) {
var geneName = data.response.docs[0].symbol;
loadGeneAsync(geneName)
.then(function (geneData) {
dataModel = new DataModel(geneData);
numAA = dataModel.numAminoAcids;
xScale = xScale.domain([1, numAA]);
generateAnnotationPanels(dataModel);
resetZoom();
resetDetails();
});
}
else {
a_result = document.createElement("A");
a_result.href = "#";
a_result.innerHTML = "<strong>None found, please try again.</strong>";
a_result.onclick = function() {
// hide dropdown
$(this).parent().parent().hide();
};
li_result = document.createElement("LI");
li_result.appendChild(a_result);
document.getElementById("tbl_results").appendChild(li_result);
$("#tbl_results").show();
}
}
// Returns a promise containing the JSON information about a given gene
// enriched by the FASTA sequence (if available)
function loadGeneAsync(geneName) {
var promise = Promise.resolve(
$.getJSON("json/" + geneName + ".json")
.error(function() {
// Wipe the previous gene view
// HOW? THIS FUNCTION WOULD NEED the main graph/data model to be passed to it...
// Update the user
var message = "JSON file for " + geneName + " not found!";
alert(message);
throw Error(message);
})
);
var withDoCM = promise.then(function (data) {
data.DoCM = [];
var url = "http://www.docm.info/api/v1/variants.json?genes=" + geneName + "&version=3.2";
return Promise.resolve($.getJSON( url ))
.then(function (docm) {
var d, i;
for (i = 0; i < docm.length; i++) {
d = docm[i];
var re1 = /^(p.)/;
var re2 = /([A-Z]+)(\d+)([A-Z]+)/;
var mut = d.amino_acid.replace(re1, '');
var new_data = { mut: mut,
ref: mut.replace(re2, '$1'),
pos: mut.replace(re2, '$2'),
alt: mut.replace(re2, '$3'),
disease: mut + ' in: ' + d.diseases.join([separator = ', ']),
pmid: d.pubmed_sources.join([separator = ','])
};
data.DoCM.push(new_data);
}
//console.log(data.DoCM);
return data;
})
.catch(function(err) {
console.log("No DoCM data available!");
return data;
});
});
var withMutD = promise.then(function (data) {
data.MutD = [];
var url = 'http://54.146.11.205:8487/MutD/finder/'+ geneName;
var request = new XMLHttpRequest();
request.open("GET", url, false);
request.send();
var xml = request.responseXML;
var annots = xml.getElementsByTagName("Annotation");
for(var i = 0; i < annots.length; i++) {
var ann = annots[i];
var names = ann.getElementsByTagName("MutationNorm"); //p|SUB|G|128|E
var dises = ann.getElementsByTagName("DiseaseName"); //ATS|arterial tortuosity syndrome
var pmids = ann.getElementsByTagName("PubMedID"); //19028722
for(var j = 0; j < names.length; j++) {
var mutNormData = names[j].childNodes[0].nodeValue.split("|"); // normalized data
var mutDisease = dises[j].childNodes[0].nodeValue; // phenotypes and diseases
var mutDiseaseUnique = Array.from(new Set(mutDisease.toLowerCase().split("|")) );
var mutPMID = pmids[j].childNodes[0].nodeValue;
//console.log( Array.from(new Set("" + mutPMID)) );
//console.log( mutPMID.toString() );
//var annString = "i = " + i + "; " + "j = " + j + "; " + mutNormData[3] + mutNormData[2] + '>' + mutNormData[4] + " in " + mutDisease + " from PMID" + mutPMID;
//console.log(annString);
var new_data = { pos: mutNormData[3],
ref: mutNormData[2],
alt: mutNormData[4],
disease: mutDiseaseUnique.join("|"),
pmid: mutPMID
};
data.MutD.push(new_data);
}
}
//console.log(data.MutD);
//console.log(data.MutD.length);
//console.log(k);
return data;
});
var withFasta = promise.then(function (data) {
if (data.hasOwnProperty('UniProt_ID')) {
var url = 'https://www.uniprot.org/uniprot/' + data['UniProt_ID'] + ".fasta";
return Promise.resolve($.ajax({ url: url,
type: 'GET',
contentType: 'text/plain',
dataType: 'text'
}))
.then(function (fasta) {
var tmp = fasta.split('\n');
tmp.splice(0, 1);
sequence = tmp.join('');
data.sequence = sequence;
return data;
});
} else {
return data;
}
});
var withAlignments = withFasta.then(function (data) {
// Handle options for which MSA file to show data from
var MSA_SEQ = msa_seq_type.value;
var MSA_ANN = msa_ann_type.value;
var msa_file = '';
if ( (MSA_SEQ == "Paralogs") && (MSA_ANN == "Sites") ){
msa_file = "json/" + geneName + ".Patho.canonical.json";
} else if ( (MSA_SEQ == "Paralogs") && (MSA_ANN == "Regions") ){
msa_file = '';
} else if ( (MSA_SEQ == "Orthologs") && (MSA_ANN == "Sites") ){
msa_file = 'json/' + geneName + ".Patho.ortholog_v1.json";
} else if ( (MSA_SEQ == "Orthologs") && (MSA_ANN == "Regions") ){
msa_file = '';
}
if (msa_file === ''){
alert( "The combination of MSA annotations for: '" + MSA_SEQ +
"' and '" + MSA_ANN + "' is not yet implemented" );
}
// Update data model with the alignment data
return Promise.resolve($.getJSON( msa_file ))
.then(function (alignments) {
data.alignments = alignments;
return data;
})
.catch(function(err) {
console.log("No alignment data available!");
//alert('No MSA available for this gene and "' + MSA_SEQ + '"');
return data;
});
});
return withAlignments;
}