7423 |
14 Nov 23 |
nicklas |
var ViewVariants = function() |
7423 |
14 Nov 23 |
nicklas |
2 |
{ |
7423 |
14 Nov 23 |
nicklas |
var vgt = {}; |
7423 |
14 Nov 23 |
nicklas |
var debug = 0; |
7423 |
14 Nov 23 |
nicklas |
5 |
|
7423 |
14 Nov 23 |
nicklas |
var AA = [ |
7423 |
14 Nov 23 |
nicklas |
['A', /Ala/g], // Alanine GCA, GCC, GCG, GCT |
7423 |
14 Nov 23 |
nicklas |
['B', /Asx/g], // Asparagine or Aspartic acid AAC, AAT, GAC, GAT |
7423 |
14 Nov 23 |
nicklas |
['C', /Cys/g], // Cysteine TGC, TGT |
7423 |
14 Nov 23 |
nicklas |
['D', /Asp/g], // Aspartic acid GAC, GAT |
7423 |
14 Nov 23 |
nicklas |
['E', /Glu/g], // Glutamic acid GAA, GAG |
7423 |
14 Nov 23 |
nicklas |
['F', /Phe/g], // Phenylalanine TTC, TTT |
7423 |
14 Nov 23 |
nicklas |
['G', /Gly/g], // Glycine GGA, GGC, GGG, GGT |
7423 |
14 Nov 23 |
nicklas |
['H', /His/g], // Histidine CAC, CAT |
7423 |
14 Nov 23 |
nicklas |
['I', /Ile/g], // Isoleucine ATA, ATC, ATT |
7423 |
14 Nov 23 |
nicklas |
['K', /Lys/g], // Lysine AAA, AAG |
7423 |
14 Nov 23 |
nicklas |
['L', /Leu/g], // Leucine CTA, CTC, CTG, CTT, TTA, TTG |
7423 |
14 Nov 23 |
nicklas |
['M', /Met/g], // Methionine ATG |
7423 |
14 Nov 23 |
nicklas |
['N', /Asn/g], // Asparagine AAC, AAT |
7423 |
14 Nov 23 |
nicklas |
['P', /Pro/g], // Proline CCA, CCC, CCG, CCT |
7423 |
14 Nov 23 |
nicklas |
['Q', /Gln/g], // Glutamine CAA, CAG |
7423 |
14 Nov 23 |
nicklas |
['R', /Arg/g], // Arginine AGA, AGG, CGA, CGC, CGG, CGT |
7423 |
14 Nov 23 |
nicklas |
['S', /Ser/g], // Serine AGC, AGT, TCA, TCC, TCG, TCT |
7423 |
14 Nov 23 |
nicklas |
['T', /Thr/g], // Threonine ACA, ACC, ACG, ACT |
7423 |
14 Nov 23 |
nicklas |
['V', /Val/g], // Valine GTA, GTC, GTG, GTT |
7423 |
14 Nov 23 |
nicklas |
['W', /Trp/g], // Tryptophan TGG |
7423 |
14 Nov 23 |
nicklas |
['Y', /Tyr/g], // Tyrosine TAC, TAT |
7423 |
14 Nov 23 |
nicklas |
['Z', /Glx/g], // Glutamine or Glutamic acid CAA, CAG, GAA, GAG |
7423 |
14 Nov 23 |
nicklas |
['*', /Ter/g] // Stop codon |
7423 |
14 Nov 23 |
nicklas |
30 |
] |
7423 |
14 Nov 23 |
nicklas |
31 |
|
7423 |
14 Nov 23 |
nicklas |
32 |
|
7423 |
14 Nov 23 |
nicklas |
vgt.initPage = function() |
7423 |
14 Nov 23 |
nicklas |
34 |
{ |
7423 |
14 Nov 23 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7423 |
14 Nov 23 |
nicklas |
36 |
|
7423 |
14 Nov 23 |
nicklas |
var url = '../WgsVariantCalling.servlet?ID='+App.getSessionId(); |
7423 |
14 Nov 23 |
nicklas |
url += '&cmd=GetVcfStatistics'; |
7423 |
14 Nov 23 |
nicklas |
url += '&fileId='+Data.int('page-data', 'file-id'); |
7423 |
14 Nov 23 |
nicklas |
url += '&itemId='+Data.int('page-data', 'item-id'); |
7423 |
14 Nov 23 |
nicklas |
41 |
|
7423 |
14 Nov 23 |
nicklas |
Wizard.showLoadingAnimation('Loading VCF file...'); |
7423 |
14 Nov 23 |
nicklas |
Wizard.asyncJsonRequest(url, vgt.onFilesLoaded); |
7423 |
14 Nov 23 |
nicklas |
44 |
} |
7423 |
14 Nov 23 |
nicklas |
45 |
|
7423 |
14 Nov 23 |
nicklas |
vgt.onFilesLoaded = function(response) |
7423 |
14 Nov 23 |
nicklas |
47 |
{ |
7423 |
14 Nov 23 |
nicklas |
var rba = response.rawbioassay; |
7423 |
14 Nov 23 |
nicklas |
var snpData = response.snpData; |
7423 |
14 Nov 23 |
nicklas |
50 |
|
7423 |
14 Nov 23 |
nicklas |
var varSearchHome = Data.get('page-data', 'varsearch-home'); |
7423 |
14 Nov 23 |
nicklas |
52 |
|
7423 |
14 Nov 23 |
nicklas |
var numIns = 0; |
7423 |
14 Nov 23 |
nicklas |
var numDel = 0; |
7423 |
14 Nov 23 |
nicklas |
var numSnv = 0; |
7423 |
14 Nov 23 |
nicklas |
var numAlt = 0; |
7423 |
14 Nov 23 |
nicklas |
57 |
|
7423 |
14 Nov 23 |
nicklas |
var html = ''; |
7423 |
14 Nov 23 |
nicklas |
for (var snpNo = 0; snpNo < snpData.length; snpNo++) |
7423 |
14 Nov 23 |
nicklas |
60 |
{ |
7423 |
14 Nov 23 |
nicklas |
var snp = snpData[snpNo].snp; |
7423 |
14 Nov 23 |
nicklas |
var gt = snpData[snpNo].gtTumor || { 'GT': '', 'AD': '' }; |
7423 |
14 Nov 23 |
nicklas |
var gtNormal = snpData[snpNo].gtNormal || { 'GT': '', 'AD': '' }; |
7423 |
14 Nov 23 |
nicklas |
var info = snp.info; |
7426 |
14 Nov 23 |
nicklas |
var cosmicId = info['cosmic_ID'] || info['cosmic_nc_ID']; |
7423 |
14 Nov 23 |
nicklas |
var dbSnpId = info['dbsnp_ID']; |
7426 |
14 Nov 23 |
nicklas |
var type = info['TYPE'] || vgt.getType(snp.ref, snp.alt); |
7423 |
14 Nov 23 |
nicklas |
var isAlt = gt.GT && gt.GT != '0/0' && gt.GT != '0|0'; |
7423 |
14 Nov 23 |
nicklas |
var isNoData = !gt.GT; |
7423 |
14 Nov 23 |
nicklas |
if (isAlt) numAlt++; |
7423 |
14 Nov 23 |
nicklas |
if (type == 'SNV') numSnv++; |
7423 |
14 Nov 23 |
nicklas |
else if (type == 'Insertion') numIns++; |
7423 |
14 Nov 23 |
nicklas |
else if (type == 'Deletion') numDel++; |
7423 |
14 Nov 23 |
nicklas |
html += '<tr class="snp highlight'+(isNoData?' no-data':'')+'">'; |
7423 |
14 Nov 23 |
nicklas |
html += '<td>'+Strings.encodeTags(snp.chromosome+':'+snp.position)+'</td>'; |
7423 |
14 Nov 23 |
nicklas |
html += '<td class="dottedleft ref">'+vgt.getRefAndAlt(snp.ref, snp.alt)+'</td>'; |
7423 |
14 Nov 23 |
nicklas |
html += '<td class="dottedleft">'+Strings.encodeTags(type)+'</td>'; |
7423 |
14 Nov 23 |
nicklas |
html += '<td class="dottedleft">'+vgt.getGenes(info['ncbiRefSeq'])+'</td>'; |
7423 |
14 Nov 23 |
nicklas |
html += '<td class="dottedleft gt">'+(gt.GT||'./.')+'</td>'; |
7423 |
14 Nov 23 |
nicklas |
html += '<td class="dottedleft ad">'+gt.AD+'</td>'; |
7423 |
14 Nov 23 |
nicklas |
html += '<td class="dottedleft gt">'+(gtNormal.GT||'./.')+'</td>'; |
7423 |
14 Nov 23 |
nicklas |
html += '<td class="dottedleft ad">'+gtNormal.AD+'</td>'; |
7423 |
14 Nov 23 |
nicklas |
html += '<td class="dottedleft">'+vgt.getHGVSc(info['ANN.HGVS.c[0]'] || info['cosmic_CDS'])+'</td>'; |
7423 |
14 Nov 23 |
nicklas |
html += '<td class="dottedleft">'+vgt.getHGVSp(info['ANN.HGVS.p[0]'] || info['cosmic_AA'])+'</td>'; |
7423 |
14 Nov 23 |
nicklas |
html += '<td class="dottedleft">'+vgt.getCosmicLink(cosmicId)+'</td>'; |
7423 |
14 Nov 23 |
nicklas |
html += '<td class="dottedleft">'+vgt.getDbSnpLink(dbSnpId)+'</td>'; |
7423 |
14 Nov 23 |
nicklas |
html += '<td class="zoom">'; |
7423 |
14 Nov 23 |
nicklas |
if (varSearchHome) |
7423 |
14 Nov 23 |
nicklas |
89 |
{ |
7423 |
14 Nov 23 |
nicklas |
// TODO -- there is not yet any support for this in the variant search extension |
7423 |
14 Nov 23 |
nicklas |
//html += '<img src="'+varSearchHome+'/images/zoom.svg" class="link view-variant" data-line-no="'+snp.id+'" title="More information...">'; |
7423 |
14 Nov 23 |
nicklas |
92 |
} |
7423 |
14 Nov 23 |
nicklas |
html += '</td>'; |
7423 |
14 Nov 23 |
nicklas |
html += '</tr>'; |
7423 |
14 Nov 23 |
nicklas |
95 |
} |
7423 |
14 Nov 23 |
nicklas |
Doc.element('snp-list').innerHTML = html; |
7423 |
14 Nov 23 |
nicklas |
Doc.show('snp-table', 'table'); |
7423 |
14 Nov 23 |
nicklas |
98 |
|
7423 |
14 Nov 23 |
nicklas |
var zoom = document.getElementsByClassName('view-variant'); |
7423 |
14 Nov 23 |
nicklas |
for (var zoomNo = 0; zoomNo < zoom.length; zoomNo++) |
7423 |
14 Nov 23 |
nicklas |
101 |
{ |
7423 |
14 Nov 23 |
nicklas |
Events.addEventHandler(zoom[zoomNo], 'click', vgt.viewVariantInVarSearch); |
7423 |
14 Nov 23 |
nicklas |
103 |
} |
7423 |
14 Nov 23 |
nicklas |
104 |
|
7423 |
14 Nov 23 |
nicklas |
var summary = snpData.length + ' passed filter (' |
7423 |
14 Nov 23 |
nicklas |
+ numSnv + ' SNV; ' |
7423 |
14 Nov 23 |
nicklas |
+ vgt.counted(numIns, 'insertion', ' insertions')+'; ' |
7423 |
14 Nov 23 |
nicklas |
+ vgt.counted(numDel, 'deletion', ' deletions')+'); ' |
7423 |
14 Nov 23 |
nicklas |
+ vgt.counted(rba.VariantsRaw, 'raw variant', ' raw variants'); |
7423 |
14 Nov 23 |
nicklas |
110 |
|
7423 |
14 Nov 23 |
nicklas |
Doc.element('snp-count').innerHTML = summary; |
7423 |
14 Nov 23 |
nicklas |
112 |
} |
7423 |
14 Nov 23 |
nicklas |
113 |
|
7423 |
14 Nov 23 |
nicklas |
// TODO -- this is not yet supported |
7423 |
14 Nov 23 |
nicklas |
vgt.viewVariantInVarSearch = function(event) |
7423 |
14 Nov 23 |
nicklas |
116 |
{ |
7423 |
14 Nov 23 |
nicklas |
var url = Data.get('page-data', 'varsearch-home')+'/hit-details.jsp'; |
7423 |
14 Nov 23 |
nicklas |
url += '?ID='+App.getSessionId(); |
7423 |
14 Nov 23 |
nicklas |
url += '&rbaId='+Data.int('page-data', 'item-id'); |
7423 |
14 Nov 23 |
nicklas |
url += '&fileId='+Data.int('page-data', 'file-id'); |
7423 |
14 Nov 23 |
nicklas |
121 |
|
7423 |
14 Nov 23 |
nicklas |
url += '&lineNo='+Data.get(event.currentTarget, 'line-no'); |
7423 |
14 Nov 23 |
nicklas |
url += '&idx=somatic'; |
7423 |
14 Nov 23 |
nicklas |
124 |
|
7423 |
14 Nov 23 |
nicklas |
Dialogs.openPopup(url, 'VarSearchHit', 600, 400); |
7423 |
14 Nov 23 |
nicklas |
126 |
} |
7423 |
14 Nov 23 |
nicklas |
127 |
|
7423 |
14 Nov 23 |
nicklas |
vgt.getAnnValues = function(info, key) |
7423 |
14 Nov 23 |
nicklas |
129 |
{ |
7423 |
14 Nov 23 |
nicklas |
var list = []; |
7423 |
14 Nov 23 |
nicklas |
var numAnnEntries = info['ANN#']; |
7423 |
14 Nov 23 |
nicklas |
for (var i = 0; i < numAnnEntries; i++) |
7423 |
14 Nov 23 |
nicklas |
133 |
{ |
7423 |
14 Nov 23 |
nicklas |
var val = info['ANN.'+key+'['+i+']']; |
7423 |
14 Nov 23 |
nicklas |
if (val) list[list.length] = val; |
7423 |
14 Nov 23 |
nicklas |
136 |
} |
7423 |
14 Nov 23 |
nicklas |
137 |
|
7423 |
14 Nov 23 |
nicklas |
return Strings.encodeTags(list.join(', ')); |
7423 |
14 Nov 23 |
nicklas |
139 |
} |
7423 |
14 Nov 23 |
nicklas |
140 |
|
7423 |
14 Nov 23 |
nicklas |
vgt.getGenes = function(genes) |
7423 |
14 Nov 23 |
nicklas |
142 |
{ |
7423 |
14 Nov 23 |
nicklas |
if (!genes) return ''; |
7423 |
14 Nov 23 |
nicklas |
return Strings.encodeTags(genes.split(',').join(', ')); |
7423 |
14 Nov 23 |
nicklas |
145 |
} |
7423 |
14 Nov 23 |
nicklas |
146 |
|
7423 |
14 Nov 23 |
nicklas |
vgt.getHGVSc = function(hgvsc) |
7423 |
14 Nov 23 |
nicklas |
148 |
{ |
7423 |
14 Nov 23 |
nicklas |
if (!hgvsc) return ''; |
7434 |
15 Nov 23 |
nicklas |
hgvsc = Strings.encodeTags(hgvsc.replace(/c\./g, '').split(',').join(', ')); |
7434 |
15 Nov 23 |
nicklas |
if (hgvsc.length > 20) hgvsc = '<span title="'+hgvsc+'">'+hgvsc.substring(0, 20)+'...</span>'; |
7434 |
15 Nov 23 |
nicklas |
return hgvsc; |
7423 |
14 Nov 23 |
nicklas |
153 |
} |
7423 |
14 Nov 23 |
nicklas |
154 |
|
7423 |
14 Nov 23 |
nicklas |
vgt.getHGVSp = function(hgvsp) |
7423 |
14 Nov 23 |
nicklas |
156 |
{ |
7423 |
14 Nov 23 |
nicklas |
if (!hgvsp) return ''; |
7423 |
14 Nov 23 |
nicklas |
158 |
|
7423 |
14 Nov 23 |
nicklas |
hgvsp = hgvsp.replace(/p\./g, ''); // Remove 'p.' prefix |
7423 |
14 Nov 23 |
nicklas |
hgvsp = hgvsp.replace(/\?/g, ''); // Remove '?' |
7423 |
14 Nov 23 |
nicklas |
161 |
|
7423 |
14 Nov 23 |
nicklas |
for (var i = 0; i < AA.length; i++) |
7423 |
14 Nov 23 |
nicklas |
163 |
{ |
7423 |
14 Nov 23 |
nicklas |
hgvsp = hgvsp.replace(AA[i][1], AA[i][0]); |
7423 |
14 Nov 23 |
nicklas |
165 |
} |
7423 |
14 Nov 23 |
nicklas |
166 |
|
7423 |
14 Nov 23 |
nicklas |
var all = hgvsp.split(','); |
7423 |
14 Nov 23 |
nicklas |
for (var i = 0; i < all.length; i++) |
7423 |
14 Nov 23 |
nicklas |
169 |
{ |
7423 |
14 Nov 23 |
nicklas |
var aa = all[i]; |
7423 |
14 Nov 23 |
nicklas |
if (aa=='') |
7423 |
14 Nov 23 |
nicklas |
172 |
{ |
7423 |
14 Nov 23 |
nicklas |
all.splice(i, 1); // Skip empty entries |
7423 |
14 Nov 23 |
nicklas |
i--; |
7423 |
14 Nov 23 |
nicklas |
175 |
} |
7423 |
14 Nov 23 |
nicklas |
else if (aa.length > 2 && aa.charAt(0)==aa.charAt(aa.length-1)) |
7423 |
14 Nov 23 |
nicklas |
177 |
{ |
7423 |
14 Nov 23 |
nicklas |
all[i] = aa.substring(0, aa.length-2)+'='; |
7423 |
14 Nov 23 |
nicklas |
179 |
} |
7423 |
14 Nov 23 |
nicklas |
180 |
} |
7423 |
14 Nov 23 |
nicklas |
return all.join(', '); |
7423 |
14 Nov 23 |
nicklas |
182 |
} |
7423 |
14 Nov 23 |
nicklas |
183 |
|
7426 |
14 Nov 23 |
nicklas |
// Get the variant type: SNV, Insertion, Deletion or Complex |
7426 |
14 Nov 23 |
nicklas |
vgt.getType = function(ref, alt) |
7426 |
14 Nov 23 |
nicklas |
186 |
{ |
7426 |
14 Nov 23 |
nicklas |
var refLen = ref.length; |
7426 |
14 Nov 23 |
nicklas |
var altLen = alt.length; |
7426 |
14 Nov 23 |
nicklas |
if (refLen==1 && altLen==1) return 'SNV'; |
7426 |
14 Nov 23 |
nicklas |
if (refLen==1 && altLen > 1) return 'Insertion'; |
7426 |
14 Nov 23 |
nicklas |
if (altLen==1 && refLen > 1) return 'Deletion'; |
7426 |
14 Nov 23 |
nicklas |
return 'Complex'; |
7426 |
14 Nov 23 |
nicklas |
193 |
} |
7423 |
14 Nov 23 |
nicklas |
194 |
|
7423 |
14 Nov 23 |
nicklas |
vgt.getRefAndAlt = function(ref, alt) |
7423 |
14 Nov 23 |
nicklas |
196 |
{ |
7423 |
14 Nov 23 |
nicklas |
if (ref.length > 6) ref = '<span title="'+ref+'">'+ref.substring(0, 5)+'...</span>'; |
7423 |
14 Nov 23 |
nicklas |
if (alt.length > 6) alt = '<span title="'+alt+'">'+alt.substring(0, 5)+'...</span>'; |
7423 |
14 Nov 23 |
nicklas |
return ref + ' › ' + alt; |
7423 |
14 Nov 23 |
nicklas |
200 |
} |
7423 |
14 Nov 23 |
nicklas |
201 |
|
7423 |
14 Nov 23 |
nicklas |
vgt.getCosmicLink = function(cosmicId) |
7423 |
14 Nov 23 |
nicklas |
203 |
{ |
7423 |
14 Nov 23 |
nicklas |
if (!cosmicId) return ''; |
7423 |
14 Nov 23 |
nicklas |
205 |
|
7423 |
14 Nov 23 |
nicklas |
var tmp = cosmicId.split(','); |
7423 |
14 Nov 23 |
nicklas |
var links = []; |
7423 |
14 Nov 23 |
nicklas |
for (var i = 0; i < tmp.length; i++) |
7423 |
14 Nov 23 |
nicklas |
209 |
{ |
7423 |
14 Nov 23 |
nicklas |
var link = '<a target="_blank" title="View in COSMIC (new window)"'; |
7423 |
14 Nov 23 |
nicklas |
link += ' href="https://cancer.sanger.ac.uk/cosmic/search?q='+encodeURIComponent(tmp[i])+'">'; |
7423 |
14 Nov 23 |
nicklas |
link += Strings.encodeTags(tmp[i])+'</a>'; |
7423 |
14 Nov 23 |
nicklas |
213 |
|
7423 |
14 Nov 23 |
nicklas |
links[i] = link; |
7423 |
14 Nov 23 |
nicklas |
215 |
} |
7423 |
14 Nov 23 |
nicklas |
return links.join(', '); |
7423 |
14 Nov 23 |
nicklas |
217 |
} |
7423 |
14 Nov 23 |
nicklas |
218 |
|
7423 |
14 Nov 23 |
nicklas |
vgt.getDbSnpLink = function(rsId) |
7423 |
14 Nov 23 |
nicklas |
220 |
{ |
7423 |
14 Nov 23 |
nicklas |
if (!rsId) return ''; |
7423 |
14 Nov 23 |
nicklas |
222 |
|
7423 |
14 Nov 23 |
nicklas |
var tmp = rsId.split(','); |
7423 |
14 Nov 23 |
nicklas |
var links = []; |
7423 |
14 Nov 23 |
nicklas |
for (var i = 0; i < tmp.length; i++) |
7423 |
14 Nov 23 |
nicklas |
226 |
{ |
7423 |
14 Nov 23 |
nicklas |
var link = '<a target="_blank" title="View in dbSNP (new window)"'; |
7423 |
14 Nov 23 |
nicklas |
link += ' href="https://www.ncbi.nlm.nih.gov/snp/'+encodeURIComponent(tmp[i])+'">'; |
7423 |
14 Nov 23 |
nicklas |
link += Strings.encodeTags(tmp[i])+'</a>'; |
7423 |
14 Nov 23 |
nicklas |
230 |
|
7423 |
14 Nov 23 |
nicklas |
links[i] = link; |
7423 |
14 Nov 23 |
nicklas |
232 |
} |
7423 |
14 Nov 23 |
nicklas |
return links.join(', '); |
7423 |
14 Nov 23 |
nicklas |
234 |
} |
7423 |
14 Nov 23 |
nicklas |
235 |
|
7423 |
14 Nov 23 |
nicklas |
vgt.counted = function(n, one, many) |
7423 |
14 Nov 23 |
nicklas |
237 |
{ |
7423 |
14 Nov 23 |
nicklas |
return n+' '+(n == 1 ? one : many); |
7423 |
14 Nov 23 |
nicklas |
239 |
} |
7423 |
14 Nov 23 |
nicklas |
240 |
|
7423 |
14 Nov 23 |
nicklas |
return vgt; |
7423 |
14 Nov 23 |
nicklas |
242 |
}(); |
7423 |
14 Nov 23 |
nicklas |
243 |
|
7423 |
14 Nov 23 |
nicklas |
Doc.onLoad(ViewVariants.initPage); |