interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / exercises / protein-translation / .meta / example.om

105 lines · 1920 bytes Raw Blame History
1note Exercism-style exercise "protein-translation": https://exercism.org/tracks/python/exercises/protein-translation
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3note proteins translates the RNA strand codon by codon into o, protein names joined by commas:
4note AUG Methionine; UUU UUC Phenylalanine; UUA UUG Leucine; UCU UCC UCA UCG Serine; UAU UAC
5note Tyrosine; UGU UGC Cysteine; UGG Tryptophan; UAA UAG UGA stop translation. Returns the number
6note of bytes written, or -1 when a codon before the first stop is invalid or incomplete.
7note Check it with: sh exercise.sh exercises/protein-translation
8om2
9text pn0 "Methionine"
10text pn1 "Phenylalanine"
11text pn2 "Leucine"
12text pn3 "Serine"
13text pn4 "Tyrosine"
14text pn5 "Cysteine"
15text pn6 "Tryptophan"
16fn app o edit uchar * p ulong s view uchar * to ulong
17q = p
18for i ulong len s
19put o q get s i
20q = add q 1
21end
22ret q
23end
24note codon id: 0 .. 6 a protein as in pn0 .. pn6, 7 stop, 8 invalid
25fn codon a uchar b uchar c uchar to ulong
26if and and eq a 65 eq b 85 eq c 71
27ret 0
28end
29if ne a 85
30ret 8
31end
32if not or or or eq c 85 eq c 67 eq c 65 eq c 71
33ret 8
34end
35if eq b 85
36if or eq c 85 eq c 67
37ret 1
38end
39ret 2
40end
41if eq b 67
42ret 3
43end
44if eq b 65
45if or eq c 85 eq c 67
46ret 4
47end
48ret 7
49end
50if eq b 71
51if or eq c 85 eq c 67
52ret 5
53end
54if eq c 71
55ret 6
56end
57ret 7
58end
59ret 8
60end
61fn appname o edit uchar * p ulong k ulong to ulong
62if eq k 0
63ret app o p pn0
64end
65if eq k 1
66ret app o p pn1
67end
68if eq k 2
69ret app o p pn2
70end
71if eq k 3
72ret app o p pn3
73end
74if eq k 4
75ret app o p pn4
76end
77if eq k 5
78ret app o p pn5
79end
80ret app o p pn6
81end
82fn proteins strand view uchar * o edit uchar * to long
83p = ulong 0
84i = ulong 0
85n = len strand
86while lt i n bound 999999
87if gt add i 3 n
88ret -1
89end
90k = codon get strand i get strand add i 1 get strand add i 2
91if eq k 8
92ret -1
93end
94if eq k 7
95break
96end
97if gt p 0
98put o p 44
99p = add p 1
100end
101p = appname o p k
102i = add i 3
103end
104ret long p
105end