-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
232 lines (195 loc) · 7.81 KB
/
main.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
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
const loadSpliceJunctionTrack = (name, coverageFilePath, junctionsFilePath) => {
console.log('Loading coverageFilePath', coverageFilePath)
console.log('Loading junctionsFilePath', junctionsFilePath)
let minUniquelyMappedReads = parseInt(document.getElementById('minUniquelyMappedReads').value);
let minTotalReads = parseInt(document.getElementById('minTotalReads').value);
let maxFractionMultiMappedReads = parseInt(document.getElementById('maxFractionMultiMappedReads').value);
let minSplicedAlignmentOverhang = parseInt(document.getElementById('minSplicedAlignmentOverhang').value);
let labelIsAnnotatedJunction = document.getElementById('labelIsAnnotatedJunction').value;
let thicknessBasedOn = document.getElementById('thicknessBasedOn').value;
let bounceHeightBasedOn = document.getElementById('bounceHeightBasedOn').value;
let colorBy = document.getElementById('colorBy').value;
let hideAnnotatedJunctions = document.getElementById('hideAnnotatedJunctions').checked;
let hideUnannotatedJunctions = document.getElementById('hideUnannotatedJunctions').checked;
/*
minUniquelyMappedReads: 1,
minTotalReads: 1,
maxFractionMultiMappedReads: 1,
minSplicedAlignmentOverhang: 0,
thicknessBasedOn: 'numUniqueReads', //options: numUniqueReads (default), numReads, isAnnotatedJunction
bounceHeightBasedOn: 'random', //options: random (default), distance, thickness
colorBy: 'isAnnotatedJunction', //options: numUniqueReads (default), numReads, isAnnotatedJunction, strand
labelUniqueReadCount: true,
labelMultiMappedReadCount: true,
labelTotalReadCount: false,
labelIsAnnotatedJunction: " [A]",
hideAnnotatedJunctions: false,
hideUnannotatedJunctions: false,
*/
igv.getBrowser().loadTrack({
type: 'merged',
name: name,
height: 175,
tracks: [
{
type: 'wig',
format: "bigwig",
url: coverageFilePath,
//oauthToken: token,
},
{
type: 'junctions',
format: 'bed',
url: junctionsFilePath,
indexURL: `${junctionsFilePath}.tbi`,
displayMode: 'COLLAPSED',
//oauthToken: token,
minUniquelyMappedReads: minUniquelyMappedReads,
minTotalReads: minTotalReads,
maxFractionMultiMappedReads: maxFractionMultiMappedReads,
minSplicedAlignmentOverhang: minSplicedAlignmentOverhang,
thicknessBasedOn: thicknessBasedOn, //options: numUniqueReads (default), numReads, isAnnotatedJunction
bounceHeightBasedOn: bounceHeightBasedOn, //options: random (default), distance, thickness
colorBy: colorBy, //options: numUniqueReads (default), numReads, isAnnotatedJunction, strand
labelUniqueReadCount: true,
labelMultiMappedReadCount: true,
labelTotalReadCount: false,
labelIsAnnotatedJunction: labelIsAnnotatedJunction,
hideAnnotatedJunctions: hideAnnotatedJunctions,
hideUnannotatedJunctions: hideUnannotatedJunctions,
},
],
})
}
const initCheckboxesAndTracks = (parentDiv, sampleInfo) => {
parentDiv.innerHTML = '';
sampleInfo.forEach(({name, description, junctions, coverage}) => {
let divElem = document.createElement("div")
let labelElem = document.createElement("label")
let checkboxElem = document.createElement("input")
checkboxElem.setAttribute("type", "checkbox")
checkboxElem.setAttribute("class", "sample-checkbox")
checkboxElem.setAttribute("data-checkbox-track-name", name)
labelElem.appendChild(checkboxElem)
labelElem.appendChild(document.createTextNode(name))
divElem.appendChild(labelElem)
parentDiv.appendChild(divElem)
if (description) {
labelElem.insertAdjacentHTML('beforeend', `<div class="tooltip"><span class="help-icon"> ? </span><span class="tooltiptext">${description}</span></div>`)
}
if (isTrackShown(name)) {
checkboxElem.setAttribute("checked", true)
loadSpliceJunctionTrack(name, coverage, junctions)
}
checkboxElem.addEventListener("click", (e) => {
if (e.target.checked) {
updateTrack(name, true)
loadSpliceJunctionTrack(name, coverage, junctions)
} else {
igv.getBrowser().removeTrackByName(name)
}
})
})
}
const initSignOutButton = async () => {
let divElem = document.createElement("div")
divElem.insertAdjacentHTML('beforeend', `<p>Signed in as ${await getGoogleUserEmail()}</p>`)
let buttonElem = document.createElement("input")
buttonElem.setAttribute("type", "button")
buttonElem.setAttribute("value", "Sign Out")
buttonElem.addEventListener("click", async (e) => {
await googleSignOut()
await googleSignIn()
})
divElem.appendChild(buttonElem)
document.getElementById("left-bar").appendChild(divElem)
}
const handleFileSelect = (e) => {
console.log(e.target.files)
for (let x of e.target.files) {
console.log(x.type, x.name)
}
/*
igvBrowser.loadTrack({
type:
format:
url:
})
*/
}
const initIGV = async () => {
let options = {
genome: 'hg38',
locus: getLocus(),
tracks: [],
}
// create IGV browser
const igvDiv = document.getElementById("igv-div")
const igvBrowser = await igv.createBrowser(igvDiv, options)
igvBrowser.on('locuschange', ({chr, start, end, label: locus_string}) => {
//save the new location
updateLocus(locus_string)
})
igvBrowser.on('trackremoved', (track) => {
const trackName = track.name
//update state
updateTrack(trackName, false)
// reset checkboxes
document.querySelectorAll(`input[data-checkbox-track-name="${trackName}"]`).forEach(checkboxElem => {
if(checkboxElem.checked) {
checkboxElem.checked = false
}
})
})
}
const initClearAllSamplesButton = () => {
document.getElementById("clear-all-samples-button").addEventListener('click', () => {
const reference_track_names = REFERENCE_TRACKS.map(t => t.name)
getTrackList().filter(trackName => reference_track_names.indexOf(trackName) === -1).forEach(trackName => {
// remove tracks from IGV
igv.getBrowser().removeTrackByName(trackName)
})
})
}
const initControls = () => {
['minUniquelyMappedReads', 'minTotalReads', 'maxFractionMultiMappedReads', 'minSplicedAlignmentOverhang',
'labelIsAnnotatedJunction', 'thicknessBasedOn', 'bounceHeightBasedOn', 'colorBy',
'hideAnnotatedJunctions', 'hideUnannotatedJunctions'].forEach(elemId => {
document.getElementById(elemId).addEventListener("change", () => {
getTrackList().forEach(trackName => {
igv.getBrowser().removeTrackByName(trackName)
document.querySelectorAll(`input[data-checkbox-track-name="${trackName}"]`).forEach(checkboxElem => {
checkboxElem.setAttribute("checked", "false");
checkboxElem.click()
})
})
})
})
}
const initApp = async () => {
initGlobalProperties()
try {
await initGoogleClient()
await googleSignIn()
igv.oauth.google.setToken(getGoogleAccessToken)
} catch(e) {
console.error("Couldn't authenticate to google", e)
}
await initIGV()
initCheckboxesAndTracks(document.getElementById('reference-tracks'), REFERENCE_TRACKS)
initCheckboxesAndTracks(document.getElementById('samples'), SAMPLE_TRACKS)
initClearAllSamplesButton()
try {
await initSignOutButton()
} catch(e) {
console.error("Couldn't init SignOut button", e)
}
initControls()
//init local files input
//document.getElementById('local-files').addEventListener('change', handleFileSelect, false)
//https://cloud.google.com/storage/docs/json_api/v1/
//const storage = await listGoogleStorageFiles('gs://macarthurlab-rnaseq/test_data')
//if (window.File && window.FileReader && window.FileList)
//console.log("#getGoogleStorageFiles", storage)
}
document.addEventListener("DOMContentLoaded", initApp)