-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprotein-translation.js
40 lines (30 loc) · 1.15 KB
/
protein-translation.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
function translate(sequence, acc = []) {
if (sequence) {
const protein = (() => {
if (sequence.startsWith('AUG')) return 'Methionine';
if (sequence.startsWith('UUU')
|| sequence.startsWith('UUC')) return 'Phenylalanine';
if (sequence.startsWith('UUA')
|| sequence.startsWith('UUG')) return 'Leucine';
if (sequence.startsWith('UCU')
|| sequence.startsWith('UCC')
|| sequence.startsWith('UCA')
|| sequence.startsWith('UCG')) return 'Serine';
if (sequence.startsWith('UAU')
|| sequence.startsWith('UAC')) return 'Tyrosine';
if (sequence.startsWith('UGU')
|| sequence.startsWith('UGC')) return 'Cysteine';
if (sequence.startsWith('UGG')) return 'Tryptophan';
if (sequence.startsWith('UAA')
|| sequence.startsWith('UAG')
|| sequence.startsWith('UGA')) return null;
throw new Error('Invalid codon');
})();
if (protein) {
const sequenceRem = sequence.substr(3);
const newAcc = acc.concat([protein]);
return translate(sequenceRem, newAcc);
} return translate(null, acc);
} return acc;
}
export default translate;