forked from molstar/pdbe-molstar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
341 lines (286 loc) · 12.9 KB
/
index.html
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<title>EMDB Molstar</title>
<!-- Molstar CSS & JS -->
<link rel="stylesheet" type="text/css" href="build/emdb-molstar-0.9.0.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.msp-plugin ::-webkit-scrollbar-thumb {
background-color: #474748 !important;
}
body {
padding: 30px;
}
h2 {
margin-bottom: 20px;
}
h3 {
margin-bottom: 2px;
}
h4 {
margin-top: 6px;
margin-bottom: 2px;
}
h4:first-child {
margin-top: 0px;
}
.content {
display: flex;
gap: 30px;
}
.controlsSection {
width: 300px;
}
.controlBox {
border: 1px solid lightgray;
padding: 10px;
margin-bottom: 20px;
}
.viewerSection {
width: 100%;
}
.row {
display: flex;
align-items: center;
}
#myViewer {
width: 100%;
height: 600px;
position: relative;
}
input {
margin-right: 8px;
padding: 1px;
padding-inline: 4px;
}
button {
margin-right: 8px;
padding: 1px;
padding-inline: 4px;
}
</style>
</head>
<body>
<h2>EMDB Molstar</h2>
<div class="content">
<div class="controlsSection">
<h3>EMDB control buttons</h3>
<div class="controlBox">
<h4>Load model by ID</h4>
<div class="row">
<input type="text" id="moleculeId" placeholder="Enter molecule ID" />
<button onclick="viewerInstance.loadPdb(document.getElementById('moleculeId').value)">Load</button>
<button onclick="viewerInstance.toogleStructureVisibility(document.getElementById('moleculeId').value, 'show')">Show</button>
<button onclick="viewerInstance.toogleStructureVisibility(document.getElementById('moleculeId').value, 'hide')">Hide</button>
</div>
<h4>Load EM primary map by ID</h4>
<div class="row">
<input type="text" id="mapId" placeholder="Enter map ID" />
<button onclick="viewerInstance.loadEmdb(document.getElementById('mapId').value, 3.5, 0.3)">Load</button>
<button onclick="viewerInstance.toggleVolumeVisibility(document.getElementById('mapId').value, 'show')">Show</button>
<button onclick="viewerInstance.toggleVolumeVisibility(document.getElementById('mapId').value, 'hide')">Hide</button>
</div>
<h4>Controls</h4>
<button onclick="viewerInstance.clear()">Clear</button>
<h4>Colours</h4>
<button onclick="viewerInstance.showModelByComponentId('models')">Models</button>
<button onclick="viewerInstance.showModelByComponentId('chains')">Chains</button>
<button onclick="viewerInstance.showModelByComponentId('qscore')">Q-Score</button>
<button onclick="viewerInstance.showModelByComponentId('atomInclusion')">Atom Inclusion</button>
<button onclick="viewerInstance.showModelByComponentId('localResolution')">Local Resolution</button>
</div>
</div>
<div class="viewerSection">
<h3>EMDB Mol* JS Plugin Demo</h3>
<!-- Molstar container -->
<div id="myViewer"></div>
</div>
</div>
<script type="text/javascript" src="build/emdb-molstar-plugin-0.9.0.js"></script>
<script>
viewerInstance = null;
function extractScores(data, pdbId, dataKey, scoreKey) {
let annotations = [];
for (const key in data) {
if (!isNaN(key)) {
let modelScores = data[key];
if (modelScores['name'] === `${pdbId}.cif`) {
const modelData = modelScores[dataKey];
let i = 0;
while (i < modelData["residue"].length) {
const regex = /([A-Z]):(\d+)\s*([A-Z0-9]{2,3})/;
const residue = modelData["residue"][i];
const match = residue.match(regex);
let chain, residueNumber, aminoAcid;
if (match) {
[, chain, residueNumber, aminoAcid] = match;
}
if (chain === undefined) {
console.log(residue);
}
const score = modelData[scoreKey][i];
const color = modelData["color"][i];
const annotation = {
chain: chain,
number: parseInt(residueNumber),
aminoAcid: aminoAcid,
color: color,
score: score
};
annotations.push(annotation);
i++;
}
break;
}
}
}
return annotations;
}
function getChains(data, pdbId) {
let chains = [];
for (const key in data) {
if (!isNaN(key)) {
let modelChains = data[key];
if (modelChains['name'] === `${pdbId}.cif`) {
const modelData = modelChains['chainaiscore'];
for (const chain in modelData) {
chains.push(chain);
}
break;
}
}
}
return chains;
}
async function createMVSAnnotations(emdbId, pdbIds, contourLevel) {
let modelAnnotations = [];
contourLevel = contourLevel.toString();
for (const pdbId of pdbIds) {
let annotations = [];
try {
const response = await fetch(`https://www.ebi.ac.uk/emdb/api/analysis/${emdbId}?information=all`);
const data = await response.json();
const numericId = parseInt(emdbId.split('-')[1]);
const selectedData = data[numericId];
// Models
annotations.push({
'metric': 'Models'
});
// Chains
annotations.push({
'metric': 'Chains',
'chains': getChains(selectedData['atom_inclusion_by_level'], pdbId)
});
// Q-Score
let allQScores = selectedData['qscore'];
let qscores = extractScores(allQScores, pdbId, 'data', 'qscore');
annotations.push({
'metric': 'Q-Score',
'residues': qscores
});
// Atom Inclusion
let allAtomInclusion = selectedData['residue_inclusion'];
let atomInclusion = extractScores(allAtomInclusion, pdbId, contourLevel, 'inclusion');
annotations.push({
'metric': 'Atom Inclusion',
'residues': atomInclusion
});
// Local Resolution
if ("residue_local_resolution" in selectedData) {
let allLocalResolution = selectedData['residue_local_resolution'];
let localResolution = extractScores(allLocalResolution, pdbId, 'data', 'localResolution');
annotations.push({
'metric': 'Local Resolution',
'residues': localResolution
});
}else {
console.log("No local resolution data for", pdbId);
}
modelAnnotations.push({
'pdbId': pdbId,
'modelAnnotations': annotations
})
} catch (error) {
console.error("Error:", error);
}
}
return modelAnnotations;
}
function getParam(name, regex) {
var r = new RegExp(name + '=' + '(' + regex + ')[&]?', 'i');
return decodeURIComponent(((window.location.search || '').match(r) || [])[1] || '');
}
var debugMode = getParam('debug-mode', '[^&]+').trim() === '1';
if (debugMode) molstar.setDebugMode(debugMode);
var timingMode = getParam('timing-mode', '[^&]+').trim() === '1';
if (timingMode) molstar.setTimingMode(timingMode);
var hideControls = getParam('hide-controls', '[^&]+').trim() === '1';
var collapseLeftPanel = getParam('collapse-left-panel', '[^&]+').trim() === '1';
var pdbProvider = getParam('pdb-provider', '[^&]+').trim().toLowerCase();
var emdbProvider = getParam('emdb-provider', '[^&]+').trim().toLowerCase();
var mapProvider = getParam('map-provider', '[^&]+').trim().toLowerCase();
var pixelScale = getParam('pixel-scale', '[^&]+').trim();
var pickScale = getParam('pick-scale', '[^&]+').trim();
var pickPadding = getParam('pick-padding', '[^&]+').trim();
var disableWboit = getParam('disable-wboit', '[^&]+').trim() === '1';
var enableDpoit = getParam('enable-dpoit', '[^&]+').trim() === '1';
var preferWebgl1 = getParam('prefer-webgl1', '[^&]+').trim() === '1' || void 0;
var allowMajorPerformanceCaveat = getParam('allow-major-performance-caveat', '[^&]+').trim() === '1';
var powerPreference = getParam('power-preference', '[^&]+').trim().toLowerCase();
Viewer.create('myViewer', {
disabledExtensions: [], // anything from Object.keys(molstar.ExtensionMap)
layoutShowControls: !hideControls,
viewportShowExpand: true,
collapseLeftPanel: true,
pdbProvider: pdbProvider || 'pdbe',
emdbProvider: emdbProvider || 'pdbe',
// volumeStreamingServer: (mapProvider || 'pdbe') === 'rcsb'
// ? 'https://maps.rcsb.org'
// : 'https://www.ebi.ac.uk/pdbe/densities',
volumeStreamingServer: 'https://www.ebi.ac.uk/emdb/VolumeServer',
pixelScale: parseFloat(pixelScale) || 1,
pickScale: parseFloat(pickScale) || 0.25,
pickPadding: isNaN(parseFloat(pickPadding)) ? 1 : parseFloat(pickPadding),
enableWboit: (disableWboit || enableDpoit) ? false : void 0, // use default value if disable-wboit is not set
enableDpoit: enableDpoit ? true : void 0,
preferWebgl1: preferWebgl1,
allowMajorPerformanceCaveat: allowMajorPerformanceCaveat,
powerPreference: powerPreference || 'high-performance',
}).then(viewer => {
viewerInstance = viewer;
const opacity = 0.6;
// Single model
// const emdbId = 'EMD-8117';
// const pdbIds = ['5irx'];
// const contourLevel = 3.5;
const emdbId = 'EMD-11638';
const pdbIds = ['7a4m'];
const contourLevel = 0.116;
// Multiple models
// const emdbId = 'EMD-10162';
// const pdbIds = ['6sfw', '6sfx'];
// const defaultState = 'Models';
// const contourLevel = 0.02;
(async () => {
const modelStates = await createMVSAnnotations(emdbId, pdbIds, contourLevel);
console.log(modelStates);
viewer.loadEmdb(emdbId, contourLevel, opacity, "absolute");
await viewer.createMvsStates(modelStates);
//viewer.renderMvsState(defaultState); // TODO: Default by models if multiple models, otherwise by chains
viewer.showModelByComponentId("chains");
})();
window.addEventListener('unload', () => {
// to aid GC
viewer.dispose();
});
});
</script>
</body>
</html>