5730 |
18 Nov 19 |
nicklas |
var ViewVariants = function() |
5730 |
18 Nov 19 |
nicklas |
2 |
{ |
5730 |
18 Nov 19 |
nicklas |
var vgt = {}; |
5730 |
18 Nov 19 |
nicklas |
var debug = 0; |
5730 |
18 Nov 19 |
nicklas |
5 |
|
6387 |
15 Sep 21 |
nicklas |
var AA = [ |
6387 |
15 Sep 21 |
nicklas |
['A', /Ala/g], // Alanine GCA, GCC, GCG, GCT |
6387 |
15 Sep 21 |
nicklas |
['B', /Asx/g], // Asparagine or Aspartic acid AAC, AAT, GAC, GAT |
6387 |
15 Sep 21 |
nicklas |
['C', /Cys/g], // Cysteine TGC, TGT |
6387 |
15 Sep 21 |
nicklas |
['D', /Asp/g], // Aspartic acid GAC, GAT |
6387 |
15 Sep 21 |
nicklas |
['E', /Glu/g], // Glutamic acid GAA, GAG |
6387 |
15 Sep 21 |
nicklas |
['F', /Phe/g], // Phenylalanine TTC, TTT |
6387 |
15 Sep 21 |
nicklas |
['G', /Gly/g], // Glycine GGA, GGC, GGG, GGT |
6387 |
15 Sep 21 |
nicklas |
['H', /His/g], // Histidine CAC, CAT |
6387 |
15 Sep 21 |
nicklas |
['I', /Ile/g], // Isoleucine ATA, ATC, ATT |
6387 |
15 Sep 21 |
nicklas |
['K', /Lys/g], // Lysine AAA, AAG |
6387 |
15 Sep 21 |
nicklas |
['L', /Leu/g], // Leucine CTA, CTC, CTG, CTT, TTA, TTG |
6387 |
15 Sep 21 |
nicklas |
['M', /Met/g], // Methionine ATG |
6387 |
15 Sep 21 |
nicklas |
['N', /Asn/g], // Asparagine AAC, AAT |
6387 |
15 Sep 21 |
nicklas |
['P', /Pro/g], // Proline CCA, CCC, CCG, CCT |
6387 |
15 Sep 21 |
nicklas |
['Q', /Gln/g], // Glutamine CAA, CAG |
6387 |
15 Sep 21 |
nicklas |
['R', /Arg/g], // Arginine AGA, AGG, CGA, CGC, CGG, CGT |
6387 |
15 Sep 21 |
nicklas |
['S', /Ser/g], // Serine AGC, AGT, TCA, TCC, TCG, TCT |
6387 |
15 Sep 21 |
nicklas |
['T', /Thr/g], // Threonine ACA, ACC, ACG, ACT |
6387 |
15 Sep 21 |
nicklas |
['V', /Val/g], // Valine GTA, GTC, GTG, GTT |
6387 |
15 Sep 21 |
nicklas |
['W', /Trp/g], // Tryptophan TGG |
6387 |
15 Sep 21 |
nicklas |
['Y', /Tyr/g], // Tyrosine TAC, TAT |
6387 |
15 Sep 21 |
nicklas |
['Z', /Glx/g], // Glutamine or Glutamic acid CAA, CAG, GAA, GAG |
6387 |
15 Sep 21 |
nicklas |
['*', /Ter/g] // Stop codon |
6387 |
15 Sep 21 |
nicklas |
30 |
] |
6387 |
15 Sep 21 |
nicklas |
31 |
|
6387 |
15 Sep 21 |
nicklas |
32 |
|
5730 |
18 Nov 19 |
nicklas |
vgt.initPage = function() |
5730 |
18 Nov 19 |
nicklas |
34 |
{ |
5730 |
18 Nov 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
5730 |
18 Nov 19 |
nicklas |
36 |
|
5730 |
18 Nov 19 |
nicklas |
var url = '../VariantCalling.servlet?ID='+App.getSessionId(); |
5730 |
18 Nov 19 |
nicklas |
url += '&cmd=GetVcfStatistics'; |
5730 |
18 Nov 19 |
nicklas |
url += '&fileId='+Data.int('page-data', 'file-id'); |
5730 |
18 Nov 19 |
nicklas |
url += '&itemId='+Data.int('page-data', 'item-id'); |
5730 |
18 Nov 19 |
nicklas |
41 |
|
5730 |
18 Nov 19 |
nicklas |
Wizard.showLoadingAnimation('Loading VCF file...'); |
5730 |
18 Nov 19 |
nicklas |
Wizard.asyncJsonRequest(url, vgt.onFilesLoaded); |
5730 |
18 Nov 19 |
nicklas |
44 |
} |
5730 |
18 Nov 19 |
nicklas |
45 |
|
5730 |
18 Nov 19 |
nicklas |
vgt.onFilesLoaded = function(response) |
5730 |
18 Nov 19 |
nicklas |
47 |
{ |
5730 |
18 Nov 19 |
nicklas |
var rba = response.rawbioassay; |
5730 |
18 Nov 19 |
nicklas |
var snpData = response.snpData; |
6387 |
15 Sep 21 |
nicklas |
var target = response.TargetedGenotype; |
5730 |
18 Nov 19 |
nicklas |
51 |
|
6391 |
15 Sep 21 |
nicklas |
var varSearchHome = Data.get('page-data', 'varsearch-home'); |
6391 |
15 Sep 21 |
nicklas |
53 |
|
5812 |
16 Jan 20 |
nicklas |
var numIns = 0; |
5812 |
16 Jan 20 |
nicklas |
var numDel = 0; |
5812 |
16 Jan 20 |
nicklas |
var numSnv = 0; |
6387 |
15 Sep 21 |
nicklas |
var numAlt = 0; |
5812 |
16 Jan 20 |
nicklas |
58 |
|
5730 |
18 Nov 19 |
nicklas |
var html = ''; |
5730 |
18 Nov 19 |
nicklas |
for (var snpNo = 0; snpNo < snpData.length; snpNo++) |
5730 |
18 Nov 19 |
nicklas |
61 |
{ |
6387 |
15 Sep 21 |
nicklas |
var snp = snpData[snpNo].snp; |
6387 |
15 Sep 21 |
nicklas |
var gt = snpData[snpNo].gt || { 'GT': '', 'AD': '' };; |
5730 |
18 Nov 19 |
nicklas |
var info = snp.info; |
5735 |
19 Nov 19 |
nicklas |
var cosmicId = info['cosmic_ID']; |
5805 |
09 Jan 20 |
nicklas |
var dbSnpId = info['dbsnp_ID']; |
5812 |
16 Jan 20 |
nicklas |
var type = info['TYPE']; |
6394 |
16 Sep 21 |
nicklas |
var isAlt = gt.GT && gt.GT != '0/0'; |
6394 |
16 Sep 21 |
nicklas |
var isNoData = !gt.GT; |
6387 |
15 Sep 21 |
nicklas |
if (isAlt) numAlt++; |
5812 |
16 Jan 20 |
nicklas |
if (type == 'SNV') numSnv++; |
5812 |
16 Jan 20 |
nicklas |
else if (type == 'Insertion') numIns++; |
5812 |
16 Jan 20 |
nicklas |
else if (type == 'Deletion') numDel++; |
6394 |
16 Sep 21 |
nicklas |
html += '<tr class="snp highlight'+(target && isAlt?' is-variant':'')+(isNoData?' no-data':'')+'">'; |
5730 |
18 Nov 19 |
nicklas |
html += '<td>'+Strings.encodeTags(snp.chromosome+':'+snp.position)+'</td>'; |
5812 |
16 Jan 20 |
nicklas |
html += '<td class="dottedleft ref">'+vgt.getRefAndAlt(snp.ref, snp.alt)+'</td>'; |
5812 |
16 Jan 20 |
nicklas |
html += '<td class="dottedleft">'+Strings.encodeTags(type)+'</td>'; |
5812 |
16 Jan 20 |
nicklas |
html += '<td class="dottedleft">'+vgt.getGenes(info['ncbiRefSeq'])+'</td>'; |
6387 |
15 Sep 21 |
nicklas |
html += '<td class="dottedleft gt">'+(gt.GT||'./.')+'</td>'; |
6387 |
15 Sep 21 |
nicklas |
html += '<td class="dottedleft ad">'+gt.AD+'</td>'; |
6387 |
15 Sep 21 |
nicklas |
html += '<td class="dottedleft">'+vgt.getHGVSc(info['ANN.HGVS.c[0]'] || info['cosmic_CDS'])+'</td>'; |
6387 |
15 Sep 21 |
nicklas |
html += '<td class="dottedleft">'+vgt.getHGVSp(info['ANN.HGVS.p[0]'] || info['cosmic_AA'])+'</td>'; |
5730 |
18 Nov 19 |
nicklas |
html += '<td class="dottedleft">'+vgt.getCosmicLink(cosmicId)+'</td>'; |
5805 |
09 Jan 20 |
nicklas |
html += '<td class="dottedleft">'+vgt.getDbSnpLink(dbSnpId)+'</td>'; |
6391 |
15 Sep 21 |
nicklas |
html += '<td class="zoom">'; |
6391 |
15 Sep 21 |
nicklas |
if (varSearchHome) |
6391 |
15 Sep 21 |
nicklas |
87 |
{ |
6391 |
15 Sep 21 |
nicklas |
html += '<img src="'+varSearchHome+'/images/zoom.svg" class="link view-variant" data-line-no="'+snp.id+'" title="More information...">'; |
6391 |
15 Sep 21 |
nicklas |
89 |
} |
6391 |
15 Sep 21 |
nicklas |
html += '</td>'; |
5730 |
18 Nov 19 |
nicklas |
html += '</tr>'; |
5730 |
18 Nov 19 |
nicklas |
92 |
} |
5730 |
18 Nov 19 |
nicklas |
Doc.element('snp-list').innerHTML = html; |
5730 |
18 Nov 19 |
nicklas |
Doc.show('snp-table', 'table'); |
6387 |
15 Sep 21 |
nicklas |
95 |
|
6391 |
15 Sep 21 |
nicklas |
var zoom = document.getElementsByClassName('view-variant'); |
6391 |
15 Sep 21 |
nicklas |
for (var zoomNo = 0; zoomNo < zoom.length; zoomNo++) |
6391 |
15 Sep 21 |
nicklas |
98 |
{ |
6391 |
15 Sep 21 |
nicklas |
Events.addEventHandler(zoom[zoomNo], 'click', vgt.viewVariantInVarSearch); |
6391 |
15 Sep 21 |
nicklas |
100 |
} |
6391 |
15 Sep 21 |
nicklas |
101 |
|
6387 |
15 Sep 21 |
nicklas |
if (target) |
6387 |
15 Sep 21 |
nicklas |
103 |
{ |
6387 |
15 Sep 21 |
nicklas |
Doc.element('targeted-genotype').innerHTML = Strings.encodeTags(target.description); |
6387 |
15 Sep 21 |
nicklas |
105 |
} |
6387 |
15 Sep 21 |
nicklas |
106 |
|
6387 |
15 Sep 21 |
nicklas |
var summary = ''; |
6387 |
15 Sep 21 |
nicklas |
if (Data.get('page-data', 'mode')=='genotype') |
6387 |
15 Sep 21 |
nicklas |
109 |
{ |
6387 |
15 Sep 21 |
nicklas |
summary = 'Found '+vgt.counted(numAlt, 'variant', 'variants') |
6387 |
15 Sep 21 |
nicklas |
+ ' in '+vgt.counted(snpData.length, 'genotyped location', 'genotyped locations'); |
6387 |
15 Sep 21 |
nicklas |
112 |
} |
6387 |
15 Sep 21 |
nicklas |
else |
6387 |
15 Sep 21 |
nicklas |
114 |
{ |
6387 |
15 Sep 21 |
nicklas |
summary = snpData.length + ' passed filter (' |
6387 |
15 Sep 21 |
nicklas |
+ numSnv + ' SNV; ' |
6387 |
15 Sep 21 |
nicklas |
+ vgt.counted(numIns, 'insertion', ' insertions')+'; ' |
6387 |
15 Sep 21 |
nicklas |
+ vgt.counted(numDel, 'deletion', ' deletions')+'); ' |
6387 |
15 Sep 21 |
nicklas |
+ vgt.counted(rba.VariantsRaw, 'raw variant', ' raw variants'); |
6387 |
15 Sep 21 |
nicklas |
120 |
} |
6387 |
15 Sep 21 |
nicklas |
Doc.element('snp-count').innerHTML = summary; |
5730 |
18 Nov 19 |
nicklas |
122 |
} |
5730 |
18 Nov 19 |
nicklas |
123 |
|
6391 |
15 Sep 21 |
nicklas |
vgt.viewVariantInVarSearch = function(event) |
6391 |
15 Sep 21 |
nicklas |
125 |
{ |
6391 |
15 Sep 21 |
nicklas |
var url = Data.get('page-data', 'varsearch-home')+'/hit-details.jsp'; |
6391 |
15 Sep 21 |
nicklas |
url += '?ID='+App.getSessionId(); |
6391 |
15 Sep 21 |
nicklas |
url += '&rbaId='+Data.int('page-data', 'item-id'); |
6391 |
15 Sep 21 |
nicklas |
url += '&fileId='+Data.int('page-data', 'file-id'); |
6391 |
15 Sep 21 |
nicklas |
130 |
|
6391 |
15 Sep 21 |
nicklas |
url += '&lineNo='+Data.get(event.currentTarget, 'line-no'); |
6391 |
15 Sep 21 |
nicklas |
url += '&idx='+(Data.get('page-data', 'mode')=='genotype'?'targeted':'filtered'); |
6391 |
15 Sep 21 |
nicklas |
133 |
|
6391 |
15 Sep 21 |
nicklas |
Dialogs.openPopup(url, 'VarSearchHit', 600, 400); |
6391 |
15 Sep 21 |
nicklas |
135 |
} |
6391 |
15 Sep 21 |
nicklas |
136 |
|
5730 |
18 Nov 19 |
nicklas |
vgt.getAnnValues = function(info, key) |
5730 |
18 Nov 19 |
nicklas |
138 |
{ |
5730 |
18 Nov 19 |
nicklas |
var list = []; |
5730 |
18 Nov 19 |
nicklas |
var numAnnEntries = info['ANN#']; |
5730 |
18 Nov 19 |
nicklas |
for (var i = 0; i < numAnnEntries; i++) |
5730 |
18 Nov 19 |
nicklas |
142 |
{ |
5730 |
18 Nov 19 |
nicklas |
var val = info['ANN.'+key+'['+i+']']; |
5730 |
18 Nov 19 |
nicklas |
if (val) list[list.length] = val; |
5730 |
18 Nov 19 |
nicklas |
145 |
} |
5730 |
18 Nov 19 |
nicklas |
146 |
|
5730 |
18 Nov 19 |
nicklas |
return Strings.encodeTags(list.join(', ')); |
5730 |
18 Nov 19 |
nicklas |
148 |
} |
5730 |
18 Nov 19 |
nicklas |
149 |
|
5812 |
16 Jan 20 |
nicklas |
vgt.getGenes = function(genes) |
5812 |
16 Jan 20 |
nicklas |
151 |
{ |
5812 |
16 Jan 20 |
nicklas |
if (!genes) return ''; |
5812 |
16 Jan 20 |
nicklas |
return Strings.encodeTags(genes.split(',').join(', ')); |
5812 |
16 Jan 20 |
nicklas |
154 |
} |
5812 |
16 Jan 20 |
nicklas |
155 |
|
6387 |
15 Sep 21 |
nicklas |
vgt.getHGVSc = function(hgvsc) |
6387 |
15 Sep 21 |
nicklas |
157 |
{ |
6387 |
15 Sep 21 |
nicklas |
if (!hgvsc) return ''; |
6387 |
15 Sep 21 |
nicklas |
return hgvsc.replace(/c\./g, '').split(',').join(', '); |
6387 |
15 Sep 21 |
nicklas |
160 |
} |
6387 |
15 Sep 21 |
nicklas |
161 |
|
6387 |
15 Sep 21 |
nicklas |
vgt.getHGVSp = function(hgvsp) |
6387 |
15 Sep 21 |
nicklas |
163 |
{ |
6387 |
15 Sep 21 |
nicklas |
if (!hgvsp) return ''; |
6387 |
15 Sep 21 |
nicklas |
165 |
|
6387 |
15 Sep 21 |
nicklas |
hgvsp = hgvsp.replace(/p\./g, ''); // Remove 'p.' prefix |
6387 |
15 Sep 21 |
nicklas |
hgvsp = hgvsp.replace(/\?/g, ''); // Remove '?' |
6387 |
15 Sep 21 |
nicklas |
168 |
|
6387 |
15 Sep 21 |
nicklas |
for (var i = 0; i < AA.length; i++) |
6387 |
15 Sep 21 |
nicklas |
170 |
{ |
6387 |
15 Sep 21 |
nicklas |
hgvsp = hgvsp.replace(AA[i][1], AA[i][0]); |
6387 |
15 Sep 21 |
nicklas |
172 |
} |
6387 |
15 Sep 21 |
nicklas |
173 |
|
6387 |
15 Sep 21 |
nicklas |
var all = hgvsp.split(','); |
6387 |
15 Sep 21 |
nicklas |
for (var i = 0; i < all.length; i++) |
6387 |
15 Sep 21 |
nicklas |
176 |
{ |
6387 |
15 Sep 21 |
nicklas |
var aa = all[i]; |
6387 |
15 Sep 21 |
nicklas |
if (aa=='') |
6387 |
15 Sep 21 |
nicklas |
179 |
{ |
6387 |
15 Sep 21 |
nicklas |
all.splice(i, 1); // Skip empty entries |
6387 |
15 Sep 21 |
nicklas |
i--; |
6387 |
15 Sep 21 |
nicklas |
182 |
} |
6387 |
15 Sep 21 |
nicklas |
else if (aa.length > 2 && aa.charAt(0)==aa.charAt(aa.length-1)) |
6387 |
15 Sep 21 |
nicklas |
184 |
{ |
6387 |
15 Sep 21 |
nicklas |
all[i] = aa.substring(0, aa.length-2)+'='; |
6387 |
15 Sep 21 |
nicklas |
186 |
} |
6387 |
15 Sep 21 |
nicklas |
187 |
} |
6387 |
15 Sep 21 |
nicklas |
return all.join(', '); |
6387 |
15 Sep 21 |
nicklas |
189 |
} |
6387 |
15 Sep 21 |
nicklas |
190 |
|
6387 |
15 Sep 21 |
nicklas |
191 |
|
5812 |
16 Jan 20 |
nicklas |
vgt.getRefAndAlt = function(ref, alt) |
5812 |
16 Jan 20 |
nicklas |
193 |
{ |
5812 |
16 Jan 20 |
nicklas |
if (ref.length > 6) ref = '<span title="'+ref+'">'+ref.substring(0, 5)+'...</span>'; |
5812 |
16 Jan 20 |
nicklas |
if (alt.length > 6) alt = '<span title="'+alt+'">'+alt.substring(0, 5)+'...</span>'; |
5812 |
16 Jan 20 |
nicklas |
return ref + ' › ' + alt; |
5812 |
16 Jan 20 |
nicklas |
197 |
} |
5812 |
16 Jan 20 |
nicklas |
198 |
|
5730 |
18 Nov 19 |
nicklas |
vgt.getCosmicLink = function(cosmicId) |
5730 |
18 Nov 19 |
nicklas |
200 |
{ |
5730 |
18 Nov 19 |
nicklas |
if (!cosmicId) return ''; |
5730 |
18 Nov 19 |
nicklas |
202 |
|
5730 |
18 Nov 19 |
nicklas |
var tmp = cosmicId.split(','); |
5730 |
18 Nov 19 |
nicklas |
var links = []; |
5730 |
18 Nov 19 |
nicklas |
for (var i = 0; i < tmp.length; i++) |
5730 |
18 Nov 19 |
nicklas |
206 |
{ |
5730 |
18 Nov 19 |
nicklas |
var link = '<a target="_blank" title="View in COSMIC (new window)"'; |
5730 |
18 Nov 19 |
nicklas |
link += ' href="https://cancer.sanger.ac.uk/cosmic/search?q='+encodeURIComponent(tmp[i])+'">'; |
5730 |
18 Nov 19 |
nicklas |
link += Strings.encodeTags(tmp[i])+'</a>'; |
5730 |
18 Nov 19 |
nicklas |
210 |
|
5730 |
18 Nov 19 |
nicklas |
links[i] = link; |
5730 |
18 Nov 19 |
nicklas |
212 |
} |
5730 |
18 Nov 19 |
nicklas |
return links.join(', '); |
5730 |
18 Nov 19 |
nicklas |
214 |
} |
5730 |
18 Nov 19 |
nicklas |
215 |
|
5805 |
09 Jan 20 |
nicklas |
vgt.getDbSnpLink = function(rsId) |
5805 |
09 Jan 20 |
nicklas |
217 |
{ |
5805 |
09 Jan 20 |
nicklas |
if (!rsId) return ''; |
5805 |
09 Jan 20 |
nicklas |
219 |
|
5805 |
09 Jan 20 |
nicklas |
var tmp = rsId.split(','); |
5805 |
09 Jan 20 |
nicklas |
var links = []; |
5805 |
09 Jan 20 |
nicklas |
for (var i = 0; i < tmp.length; i++) |
5805 |
09 Jan 20 |
nicklas |
223 |
{ |
5805 |
09 Jan 20 |
nicklas |
var link = '<a target="_blank" title="View in dbSNP (new window)"'; |
5805 |
09 Jan 20 |
nicklas |
link += ' href="https://www.ncbi.nlm.nih.gov/snp/'+encodeURIComponent(tmp[i])+'">'; |
5805 |
09 Jan 20 |
nicklas |
link += Strings.encodeTags(tmp[i])+'</a>'; |
5805 |
09 Jan 20 |
nicklas |
227 |
|
5805 |
09 Jan 20 |
nicklas |
links[i] = link; |
5805 |
09 Jan 20 |
nicklas |
229 |
} |
5805 |
09 Jan 20 |
nicklas |
return links.join(', '); |
5805 |
09 Jan 20 |
nicklas |
231 |
} |
5805 |
09 Jan 20 |
nicklas |
232 |
|
6387 |
15 Sep 21 |
nicklas |
vgt.counted = function(n, one, many) |
6387 |
15 Sep 21 |
nicklas |
234 |
{ |
6387 |
15 Sep 21 |
nicklas |
return n+' '+(n == 1 ? one : many); |
6387 |
15 Sep 21 |
nicklas |
236 |
} |
6387 |
15 Sep 21 |
nicklas |
237 |
|
5730 |
18 Nov 19 |
nicklas |
return vgt; |
5730 |
18 Nov 19 |
nicklas |
239 |
}(); |
5730 |
18 Nov 19 |
nicklas |
240 |
|
5730 |
18 Nov 19 |
nicklas |
Doc.onLoad(ViewVariants.initPage); |