-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutation.html
513 lines (459 loc) · 20.5 KB
/
mutation.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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
<html>
<head>
<style>
@import url('https://fonts.googleapis.com/css?family=Roboto');
* {
font-family: 'Roboto', sans-serif;
box-sizing: border-box;
}
body {
padding: 50px;
background: url('polyBkgGreen.svg');
background-size: cover;
}
.main-table {
padding: 20px;
background: #fff;
border-radius: 10px;
width: 100%;
}
h1 {
margin: 0px 40px 0px 40px;
color: #ddd;
font-size: 1.8em;
text-align: center;
}
button {
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 12px !important;
font-weight: 400;
line-height: 17px;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
color: #fff;
background-color: #337ab7;
border-color: #2e6da4;
}
svg text[onclick],
svg path[onclick] {
cursor: pointer;
}
svg path[fill="rgba(0,0,0,0)"] {
cursor: cell;
}
.gene-container {
padding: 20px;
margin: 20px;
border-radius: 10px;
}
.fixed {
background: #bbb;
}
.flexible {
background: #eee;
}
.half-size {
width: 45%;
}
.protein-container {
display: flex;
flex-direction: row;
justify-content: space-between;
}
h3 {
margin-top: 0px;
}
</style>
<script>
var pCount = 'A';
function $(e) {
return document.querySelector(e);
}
function $$(e) {
return document.querySelectorAll(e);
}
function nextPos(angle) {
currentProteinPos.rotation += angle;
var rot = currentProteinPos.rotation * Math.PI / 180;
currentProteinPos.x += currentProteinPos.length * Math.cos(rot);
currentProteinPos.y += currentProteinPos.length * Math.sin(rot);
return currentProteinPos;
}
var currentProteinPos = {};
var pos = {
x: 0,
y: 0,
rotation: 0,
length: 72.5,
}
var aminoAcids = {
'Methionine': {
shortname: 'Met',
abbreviation: 'M',
codons: ['AUG'],
rotation: -25,
svg: '<path fill="#d0f" stroke="#000" d="Mxxx yyym1 50c-26 29-50-45-14-53 21-5 36 21 69 22a6 6 1 1 1 0 12c-33-1-38 0-55 19z"/>'
},
'Alanine': {
shortname: 'Ala',
abbreviation: 'A',
codons: ['GCA', 'GCC', 'GCG', 'GCU'],
rotation: 0,
svg: '<path fill="#f50" stroke="#000" d="Mxxx yyyc-41-13-47 56-1 54 22-1 23-21 56-23a5.5 5.5 1 1 0 0 -11c-33 0-30-12-55-20z"/>'
},
'Cysteine': {
shortname: 'Cys',
abbreviation: 'C',
codons: ['UGC', 'UGU'],
rotation: 5,
svg: '<path fill="#0fb" stroke="#000" d="Mxxx yyym-18 -3c-17-5 0 24-5 35-5 17-6 23 22 22 22-1 23-21 56-23a5.5 5.5 1 1 0 0 -11c-33 0-48-15-73-23z"/>'
},
'Aspartic acid': {
shortname: 'Asp',
abbreviation: 'D',
codons: ['GAC', 'GAU'],
rotation: -5,
svg: '<path fill="#a0f" stroke="#000" d="Mxxx yyym-26 4c-8 15 14 17 11 29-6 17-13 22 14 21 22-1 23-21 56-23a5.5 5.5 1 1 0 0 -11c-13 0-26-22-35-25-14-5-38-4-46 9z"/>'
},
'Glutamic acid': {
shortname: 'Glu',
abbreviation: 'E',
codons: ['GAA', 'GAG'],
rotation: 10,
svg: '<path fill="#f0b" stroke="#000" d="Mxxx yyyc-26-29-50 45-14 53 21 5 36-21 69-22a6 6 1 1 0 0 -12c-33 1-38 0-55-19z"/>'
},
'Phenylalanine': {
shortname: 'Phe',
abbreviation: 'F',
codons: ['UUC', 'UUU'],
rotation: -10,
svg: '<path fill="#f90" stroke="#000" d="Mxxx yyyc-59-45-41 53-1 54 29 0 21-21 56-23a6 6 1 1 0 0 -12c-33 1-35-4-55-19z"/>'
},
'Glycine': {
shortname: 'Gly',
abbreviation: 'G',
codons: ['GGA', 'GGC', 'GGG', 'GGU'],
rotation: 15,
svg: '<path fill="#70f" stroke="#000" d="Mxxx yyyc-70 2-14 21-15 28-2 14-46 25 15 26 21 0 22-21 56-23a6 6 1 1 0 0 -12c-33 1-29-20-55-19z"/>'
},
'Histidine': {
shortname: 'His',
abbreviation: 'H',
codons: ['CAC', 'CAU'],
rotation: -15,
svg: '<path fill="#0df" stroke="#000" d="Mxxx yyym11 11c-11 34-25-69-43 17-3 13 15 27 33 25 21-1 22-21 55-22a6 6 1 1 0 0 -12c-33 1-38-33-45-8z"/>'
},
'Isoleucine': {
shortname: 'Ile',
abbreviation: 'I',
codons: ['AUA', 'AUC', 'AUU'],
rotation: 20,
svg: '<path fill="#f10" stroke="#000" d="Mxxx yyym1 50c-41 14-47-55-1-53 22 1 23 21 56 23a5.5 5.5 1 1 1 0 11c-33 0-30 12-55 19z"/>'
},
'Lysine': {
shortname: 'Lys',
abbreviation: 'K',
codons: ['AAA', 'AAG'],
rotation: -20,
svg: '<path fill="#0f8" stroke="#000" d="Mxxx yyym-17 53c-17 6 0-23-5-35-5-16-6-22 22-21 22 1 23 21 56 23a5.5 5.5 1 1 1 0 11c-33-1-48 14-73 22z"/>'
},
'Leucine': {
shortname: 'Leu',
abbreviation: 'L',
codons: ['UUA', 'UUG', 'CUA', 'CUC', 'CUG', 'CUU'],
rotation: 25,
svg: '<path fill="#70f" stroke="#000" d="Mxxx yyym-25 47c-8-15 14-18 11-29-6-17-13-23 14-21 22 1 23 21 56 22a6 6 1 1 1 0 12c-13 0-26 22-35 25-14 5-38 4-46-9z"/>'
},
'Asparagine': {
shortname: 'Asn',
abbreviation: 'N',
codons: ['AAC', 'AAU'],
rotation: 30,
svg: '<path fill="#f70" stroke="#000" d="Mxxx yyym1 50c-59 45-41-53-1-54 29 0 21 21 56 23a5.5 5.5 1 1 1 0 11c-33 0-35 4-55 20z"/>'
},
'Proline': {
shortname: 'Pro',
abbreviation: 'P',
codons: ['CCA', 'CCC', 'CCG', 'CCU'],
rotation: -30,
svg: '<path fill="#20f" stroke="#000" d="Mxxx yyym0 50c-70-2-14-21-15-29-2-13-46-24 15-25 21-1 22 21 56 23a5.5 5.5 1 1 1 0 11c-33-1-29 20-56 20z"/>'
},
'Glutamine': {
shortname: 'Gln',
abbreviation: 'Q',
codons: ['CAA', 'CAG'],
rotation: 35,
svg: '<path fill="#0fd" stroke="#000" d="Mxxx yyym11 38c-11-33-25 70-43-16-3-14 15-27 33-26 21 2 22 21 55 23a5.5 5.5 1 1 1 0 11c-33 0-38 33-45 8z"/>'
},
'Arginine': {
shortname: 'Arg',
abbreviation: 'R',
codons: ['AGA', 'AGG', 'CGA', 'CGC', 'CGG', 'CGU'],
rotation: -35,
svg: '<path fill="#f06" stroke="#000" d="Mxxx yyym1 0c-43 5-41 30-1 54 13 7 23-22 56-23a5.5 5.5 1 1 0 0 -11c-33 1-46-20-55-20z"/>'
},
'Serine': {
shortname: 'Ser',
abbreviation: 'S',
codons: ['AGC', 'AGU', 'UCA', 'UCC', 'UCG', 'UCU'],
rotation: 40,
svg: '<path fill="#0f3" stroke="#000" d="Mxxx yyym-17 -4c-18 3-16 21-15 32 2 18 5 26 32 25 22-1 23-21 56-23a5.5 5.5 1 1 0 0 -11c-33 1-31-27-73-23z"/>'
},
'Threonine': {
shortname: 'Thr',
abbreviation: 'T',
codons: ['ACA', 'ACC', 'ACG', 'ACU'],
rotation: -40,
svg: '<path fill="#40f" stroke="#000" d="Mxxx yyym-25 3c-8 16-10 12 11 30 54 41 55-1 70-2a5.5 5.5 1 1 0 0 -11c-13 0-26-22-35-26-14-4-38-3-46 9z"/>'
},
'Valine': {
shortname: 'Val',
abbreviation: 'V',
codons: ['GUA', 'GUC', 'GUG', 'GUU'],
rotation: 45,
svg: '<path fill="#f0f" stroke="#000" d="Mxxx yyym10 19c-43-64-70 1-23 33 18 12 36-21 69-22a5.5 5.5 1 1 0 0 -11c-33 1-31 23-46 0z"/>'
},
'Tryptophan': {
shortname: 'Trp',
abbreviation: 'W',
codons: ['UGG'],
rotation: -45,
svg: '<path fill="#f40" stroke="#000" d="Mxxx yyym1 -2c-24-11-44 14-47 25-4 13 13 12 43 20 29 7 25-11 59-13a5.5 5.5 1 1 0 0 -11c-33 1-32-8-55-21z"/>'
},
'Tyrosine': {
shortname: 'Tyr',
abbreviation: 'Y',
codons: ['UAC', 'UAU'],
rotation: 50,
svg: '<path fill="#06f" stroke="#000" d="Mxxx yyym-6 0c-53 12-29 44-17 18 8-17 13 18-10 23-14 2-28 12 33 13 21 0 22-21 56-23a5.5 5.5 1 1 0 0 -11c-33 0-36-27-62-20z"/>'
},
'Stop': {
shortname: 'Stop',
abbreviation: '-',
codons: ['UGA', 'UAG', 'UAA']
}
}
function newRNA(size) {
var aminoAcid = [];
for (aaKeys in aminoAcids) {
aminoAcid.push(aaKeys);
}
var rnaOutput = [aminoAcids[aminoAcid[0]].codons[0]];
for (i = 0; i < size; i++) {
var aa = Math.floor(Math.random() * 19) + 1;
var aAcid = aminoAcids[aminoAcid[aa]];
var cc = Math.floor(Math.random() * aAcid.codons.length);
rnaOutput.push(aAcid.codons[cc]);
}
rnaOutput.push(aminoAcids['Stop'].codons[Math.floor(Math.random() * 3)]);
var outputBases = rnaOutput.join('');
buildRNA(outputBases);
return outputBases;
}
function findCodon(codon) {
codon = codon.toUpperCase().replace(/[^AUGC]/g, '');
var aminoAcid = null;
for (amino in aminoAcids) {
if (aminoAcids[amino].codons.indexOf(codon) > -1) {
aminoAcid = {
codon: codon,
name: amino,
shortname: aminoAcids[amino].shortname,
abbreviation: aminoAcids[amino].abbreviation,
svg: aminoAcids[amino].svg,
rotation: aminoAcids[amino].rotation
};
break;
}
}
return aminoAcid;
}
function findProtein(bases) {
var protein = [];
for (var i = 0; i < bases.length; i += 3) {
var codon = bases[i] + (bases[i + 1] || 'A') + (bases[i + 2] || 'A');
protein.push(findCodon(codon));
}
return protein;
}
var currentRNA = [];
function buildRNA(bases) {
bases = bases.toUpperCase().replace(/[^AUGC]/g, '').split('');
currentRNA = bases;
var svgText = `<svg id="rna-strand-${pCount}" xmlns="http://www.w3.org/2000/svg" viewBox="0 120 www 80">
<g id="ribosome-back" transform="translate(0, 0)"></g>
<path fill="#999" stroke="#000" d="M-10 172hyyyv26h-yyyz"/>
<path fill="#777" stroke="#000" d="M-10 192hyyyv06h-yyyz"/>
<g id="codons-${pCount}">xxx</g>
<g id="trna-${pCount}" transform="translate(0, 0)"></g>
<g id="aminos-${pCount}" transform="translate(0, 0)"></p>
<g id="ribosome-front" transform="translate(0, 0)"></g>
</svg>`;
var baseShapes = {
'G': `<path id="bp-${pCount}-www" fill="#f00" onclick="editRna(this)" stroke="#000" d="Mxxx 138c13 12 14 17 25 0v43c-6 5-22 5-25 0z"/><path id="cp-${pCount}-www" fill="rgba(0,0,0,0)" onclick="editRna(this)" d="Mxxx 140h-10v30h10z"/><text id="t-${pCount}-www" onclick="editRna(this)" x="zzz" y="177" font-family="sans-serif" font-size="26" font-weight="700">G</text>`,
'U': `<path id="bp-${pCount}-www" fill="#ff0" onclick="editRna(this)" stroke="#000" d="Mxxx 139c15-13 15-16 25 0v42c-5 5-22 5-25 0z"/><path id="cp-${pCount}-www" fill="rgba(0,0,0,0)" onclick="editRna(this)" d="Mxxx 140h-10v30h10z"/><text id="t-${pCount}-www" onclick="editRna(this)" x="zzz" y="177" font-family="sans-serif" font-size="26" font-weight="700">U</text>`,
'A': `<path id="bp-${pCount}-www" fill="#1f0" onclick="editRna(this)" stroke="#000" d="Mxxx 138c14-12 03 24 25 0v43c-6 5-22 5-25 0z"/><path id="cp-${pCount}-www" fill="rgba(0,0,0,0)" onclick="editRna(this)" d="Mxxx 140h-10v30h10z"/><text id="t-${pCount}-www" onclick="editRna(this)" x="zzz" y="177" font-family="sans-serif" font-size="26" font-weight="700">A</text>`,
'C': `<path id="bp-${pCount}-www" fill="#0bf" onclick="editRna(this)" stroke="#000" d="Mxxx 139c27-22 16 14 25 0v42c-5 5-22 5-25 0z"/><path id="cp-${pCount}-www" fill="rgba(0,0,0,0)" onclick="editRna(this)" d="Mxxx 140h-10v30h10z"/><text id="t-${pCount}-www" onclick="editRna(this)" x="zzz" y="177" font-family="sans-serif" font-size="26" font-weight="700">C</text>`
}
var baseGroup = '';
var k = 0;
bases.forEach((base, idx) => {
baseGroup += baseShapes[base]
.replace(/www/g, idx)
.replace(/xxx/g, (idx * 35 + 30 + Math.floor(idx / 3) * 10))
.replace(/zzz/g, (idx * 35 + 33 + Math.floor(idx / 3) * 10));
k = idx;
});
k++;
baseGroup +=
`<path id="cp-${pCount}-${k}" fill="rgba(0,0,0,0)" onclick="editRna(this)" d="M${k * 35 + 30 + (k % 3 === 0 ? -10 : 0) + Math.floor(k / 3) * 10} 140h-10v30h10z"/>`;
svgText = svgText
.replace(/yyy/g, (bases.length * 35 + 60 + Math.floor(bases.length / 3) * 10))
.replace(/www/g, (bases.length * 35 + 40 + Math.floor(bases.length / 3) * 10))
.replace(/xxx/g, baseGroup);
$('#the-rna').innerHTML = svgText;
buildProtein(bases.join(''));
}
function editRna(e) {
if (window.event.shiftKey === true && (e.id.indexOf('bp-') > -1 || e.id.indexOf('t-') > -1)) {
// Devare a codon
currentRNA.splice(parseInt(e.id.replace(/[^0-9]/g, '')), 1);
} else if (e.id.indexOf('cp-') > -1) {
// Add a codon
currentRNA.splice(parseInt(e.id.replace(/[^0-9]/g, '')), 0, 'G');
} else if ((e.id.indexOf('bp-') > -1 || e.id.indexOf('t-') > -1)) {
// Change a codon
var currentIndex = parseInt(e.id.replace(/[^0-9]/g, ''));
switch (currentRNA[currentIndex]) {
case 'G':
currentRNA[currentIndex] = 'U';
break;
case 'U':
currentRNA[currentIndex] = 'A';
break;
case 'A':
currentRNA[currentIndex] = 'C';
break;
case 'C':
currentRNA[currentIndex] = 'G';
break;
}
}
$('#the-rna').innerHTML = '';
var rnaString = currentRNA.join('');
buildRNA(rnaString);
buildProtein(rnaString);
}
function buildProtein(bases) {
currentProteinPos = pos;
currentProteinPos.rotation = 0;
currentProteinPos.x = 0;
currentProteinPos.y = 0;
var aminos = findProtein(bases);
var vaildChain = true;
aminos.forEach((a, idx) => {
if (a.svg && vaildChain) {
nextPos(a.rotation * 1.5);
} else if (a.shortname === 'Stop') {
vaildChain = false;
}
});
var r = Math.atan2(currentProteinPos.y, currentProteinPos.x) * 180 / Math.PI;
vaildChain = true
currentProteinPos = pos;
currentProteinPos.rotation = -r;
currentProteinPos.x = 0;
currentProteinPos.y = 0;
var svgString =
'<svg id="protein-strand" xmlns="http://www.w3.org/2000/svg" viewBox="-50 -500 1000 1000" ><g id="protein-container">';
aminos.forEach((a, idx) => {
if (a.svg && vaildChain) {
var amino = a.svg
.replace(/<path/g,
`<g id="ga-${idx}"><path id="aa-${idx}" transform="rotate(${currentProteinPos.rotation}, ${currentProteinPos.x + 60}, ${currentProteinPos.y + 25})"`
)
.replace(/xxx/g, currentProteinPos.x)
.replace(/yyy/g, currentProteinPos.y);
amino +=
`</g><text id="at-${idx}" x="0" y="0" font-family="sans-serif" font-size="22" font-weight="700">${a.shortname}</text>`;
nextPos(a.rotation * 1.5);
svgString += amino;
} else if (a.shortname === 'Stop') {
vaildChain = false;
}
});
$('#the-protein').innerHTML = svgString + '</g></svg>';
var c = $('#protein-container').getBBox();
$('#protein-strand').setAttribute('viewBox', `${c.x} ${c.y} ${c.width} ${c.height}`);
var divBoxWidth = $('.gene-container.flexible.half-size').offsetWidth - 60;
if (c.width > divBoxWidth) {
$('#protein-strand').setAttribute('width', divBoxWidth);
} else if (c.height > (divBoxWidth * 0.65)) {
$('#protein-strand').setAttribute('height', (divBoxWidth * 0.65));
} else {
$('#protein-strand').setAttribute('width', c.width);
$('#protein-strand').setAttribute('height', c.height);
}
aminos.forEach((a, idx) => {
var e = $('#ga-' + idx);
if (e) {
var b = e.getBBox();
$('#at-' + idx).setAttribute('x', b.x + 30);
$('#at-' + idx).setAttribute('y', b.y + 60);
}
});
}
function setupRNA(amount) {
newRNA(amount);
$('#fixed-rna').innerHTML = $('#the-rna').innerHTML.replace(/id=".*?"/g, '').replace(/onclick=".*?"/g, '');
$('#fixed-protein').innerHTML = $('#the-protein').innerHTML.replace(/id=".*?"/g, '').replace(
/onclick=".*?"/g, '');
}
</script>
</head>
<body>
<table class="main-table" border="0">
<tr>
<td>
<h2>RNA and Protein Simulator</h2>
<div class="gene-container fixed">
<h3>Original RNA:</h3>
<div id="fixed-rna"></div>
</div>
<div class="gene-container flexible">
<h3>Modified RNA:</h3>
<div id="the-rna"></div>
<p>Click a base (A, G, U, or C) to change it. Hold down the shift key and click a base to delete
it. Click in between bases to add a new base.</p>
</div>
<div class="protein-container">
<div class="gene-container fixed half-size">
<h3>Original Protein:</h3>
<div id="fixed-protein"></div>
</div>
<div class="gene-container flexible half-size">
<h3>Modified Protein:</h3>
<div id="the-protein"></div>
</div>
</div>
</td>
</tr>
</table>
<script>
setupRNA(5);
</script>
</body>
</html>