@@ -14,18 +14,24 @@ local def contains (needle: []u8) (haystack: [][]u8): bool =
14
14
in
15
15
result
16
16
17
+ local def is_stop (codon : []u8 ): bool =
18
+ contains codon [" UAA" , " UAG" , " UGA" ]
19
+
20
+ local def translate (codon : []u8 ): amino_acid =
21
+ if contains codon [" AUG" ] then #methionine else
22
+ if contains codon [" UUU" , " UUC" ] then #phenylalanine else
23
+ if contains codon [" UUA" , " UUG" ] then #leucine else
24
+ if contains codon [" UCU" , " UCC" , " UCA" , " UCG" ] then #serine else
25
+ if contains codon [" UAU" , " UAC" ] then #tyrosine else
26
+ if contains codon [" UGU" , " UGC" ] then #cysteine else
27
+ assert (contains codon [" UGG" ]) #tryptophan
28
+
17
29
def proteins (strand : []u8 ): []amino_acid =
18
30
let (result , _ ) = loop (result , index ) = ([], 0 ) while index < length strand do
19
31
let index = index + 3
20
32
let codon = assert (index <= length strand ) strand [index - 3 :index ]
21
33
in
22
- if contains codon [" AUG" ] then (result ++ [#methionine ], index ) else
23
- if contains codon [" UUU" , " UUC" ] then (result ++ [#phenylalanine ], index ) else
24
- if contains codon [" UUA" , " UUG" ] then (result ++ [#leucine ], index ) else
25
- if contains codon [" UCU" , " UCC" , " UCA" , " UCG" ] then (result ++ [#serine ], index ) else
26
- if contains codon [" UAU" , " UAC" ] then (result ++ [#tyrosine ], index ) else
27
- if contains codon [" UGU" , " UGC" ] then (result ++ [#cysteine ], index ) else
28
- if contains codon [" UGG" ] then (result ++ [#tryptophan ], index ) else
29
- assert (contains codon [" UAA" , " UAG" , " UGA" ]) (result , length strand )
34
+ if is_stop codon then (result , length strand ) else
35
+ (result ++ [translate codon ], index )
30
36
in
31
37
result
0 commit comments