-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtomasz.js
167 lines (154 loc) · 5.54 KB
/
tomasz.js
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
console.log('progressive genomic series being compiled at ',new Date())
// http://ibl.github.io/vcf/?then=tomasz.js#features=CP000255.1.txt
vcfUi.innerHTML='<h4 style="color:blue">Compiling incremental genomic variation ...</h4>'
tomasz=function(){
vcfUi.innerHTML='<h4 style="color:navy">Incremental genomic variation</h4>'
// compilation div
var srcDiv=document.createElement('div')
srcDiv.id = "sourcesCompiled"
vcfUi.appendChild(srcDiv)
var h=new Date()
h+='<p>Source files</p>'
if(VCF.dir.ids.slice(-1)[0].match('^sra_data')){ // if this is Tomasz data, sort it accordingly
//x = x.slice(-1).concat(x.slice(0,-1))
VCF.dir.ids = VCF.dir.ids.slice(-1).concat(VCF.dir.ids.slice(0,-1))
VCF.dir.vcfs = VCF.dir.vcfs.slice(-1).concat(VCF.dir.vcfs.slice(0,-1))
}
VCF.dir.ids.forEach(function(fid){
h+='<li style="color:green">'+fid+'</li>'
})
srcDiv.innerHTML=h
// differential genomic variation div
var difDiv=document.createElement('div')
difDiv.id = "differentialVariation"
vcfUi.appendChild(difDiv)
// full list of variations
var posAll=[]
VCF.dir.vcfs.forEach(function(vcf){
//console.log(vcf.data.body.POS)
posAll=posAll.concat(vcf.data.body.POS)
})
posAll=jmat.unique(posAll).map(function(p){
return parseInt(p)
})
posAll=jmat.sort(posAll)[0].map(function(p){
return ''+p
})
// index variations in each vcf
VCF.dir.vcfs.forEach(function(vcf,i){
var ind={}
vcf.data.body.POS.forEach(function(pos){
ind[pos]=vcf.data.body.POS.indexOf(pos)
})
VCF.dir.vcfs[i].ind=ind
})
// build table
var tbl = document.createElement('table')
tbl.cellPadding="5px"
difDiv.appendChild(tbl)
var thead = document.createElement('thead')
tbl.appendChild(thead)
var h='<tr><td>Position</td>'
VCF.dir.vcfs.forEach(function(vcf){
//h+='<td style="color:blue;transform:rotate(90deg);g-origin:50% 50%">'+vcf.id.slice(0,15)+'...</td>'
h+='<td style="color:blue">'+vcf.id.slice(0,10)+'...</td>'
})
h+='</tr>'
thead.innerHTML=h
var tbody = document.createElement('tbody')
tbl.appendChild(tbody)
// one row per variation
VCF.dir.onFeature=function(that){
console.log('on',that)
that.textContent=that.textContent.slice(0,-1)+"-"
that.onclick=function(){VCF.dir.offFeature(that)}
var pre = document.createElement('pre')
that.parentNode.appendChild(pre)
var pos=parseInt(that.textContent.match(/[0-9]*/)[0])
var h = '>Feature <a href="http://www.ncbi.nlm.nih.gov/nuccore/87125858?report=graph&mk='+pos+'|'+pos+'&v='+(pos-10000)+':'+(pos+10000)+'" target="_blank">gb|CP000255.1|'+pos+'</a>'
var ind = NaN
VCF.dir.features.posStart.forEach(function(pStart,i){
var pEnd=VCF.dir.features.posEnd[i]
if((pStart<=pos)&&(pEnd>=pos)){
ind=i-1
}
})
if(isNaN(ind)){
console.log('not found')
}else{
console.log('found it:',VCF.dir.features.posStart[ind],VCF.dir.features.posEnd[ind])
h+='\n>'+VCF.dir.features.txt[ind].replace(/;\s*/g,'; ')
h+='\n>'+VCF.dir.features.txt[ind+1].replace(/;\s*/g,'; ')
4
}
pre.innerHTML=h
//lala=that
}
VCF.dir.offFeature=function(that){
console.log('off',that)
that.onclick=function(){VCF.dir.onFeature(that)}
that.textContent=that.textContent.slice(0,-1)+"+"
$('pre',that.parentElement).remove()
}
VCF.getUrlParms()
if(VCF.urlParms.features){
$.get(VCF.urlParms.features).then(function(txt){
if(!VCF.dir.features){
VCF.dir.features={}
}
//VCF.dir.features[VCF.urlParms.features]={}
L = txt.split('\n')
Ft={
head:L[0],
posStart:[],
posEnd:[],
txt:[]
}
n=L.length, j=-1, val=[], Li='' // i lines, j features
///*
//div.dt.body.features=div.dt.body.ID.map(function(x,i){
// return '+'
//})
for(var i=1 ; i<n ; i++){
Li=L[i]
if(Li[0]!=='\t'){ // it's a feature position'
j++
val=Li.split(/\t/)
Ft.posStart[j]=parseInt(val[0])
Ft.posEnd[j]=parseInt(val[1])
Ft.txt[j]=val[2]
}else{
//console.log(Li)
Ft.txt[j]=Ft.txt[j]+'; '+Li
}
}
VCF.dir.features=Ft
//if(fun){}
})
}
posAll.forEach(function(pos){
var tr = document.createElement('tr')
tr.id='pos_'+pos
tr.pos = pos
var h = '<td><span style="color:blue" onclick="VCF.dir.onFeature(this)">'+pos+'+</span></td>'
tr.innerHTML=h
tbody.appendChild(tr)
})
// ready to fill the table
VCF.dir.vcfs.forEach(function(vcf){
posAll.forEach(function(pos){
var tr = document.getElementById('pos_'+pos)
var td = document.createElement('td')
tr.appendChild(td)
posInd = vcf.data.body.POS.indexOf(pos)
if(posInd>-1){
td.textContent=vcf.data.body.QUAL[posInd]+' ('+vcf.data.body.REF[posInd]+'>'+vcf.data.body.ALT[posInd]+')'
}
4
})
4
})
}
setTimeout(function(){
tomasz()
},1000)