Skip to content

Commit 38d620b

Browse files
committed
Add protein-translation
1 parent 5e75c36 commit 38d620b

9 files changed

Lines changed: 379 additions & 0 deletions

File tree

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,14 @@
338338
"prerequisites": [],
339339
"difficulty": 3
340340
},
341+
{
342+
"slug": "protein-translation",
343+
"name": "Protein Translation",
344+
"uuid": "951babbe-0acb-4ce8-a02a-6b2f2b8db216",
345+
"practices": [],
346+
"prerequisites": [],
347+
"difficulty": 3
348+
},
341349
{
342350
"slug": "proverb",
343351
"name": "Proverb",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
return {
2+
default = {
3+
ROOT = { '.' }
4+
}
5+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Instructions
2+
3+
Your job is to translate RNA sequences into proteins.
4+
5+
RNA strands are made up of three-nucleotide sequences called **codons**.
6+
Each codon translates to an **amino acid**.
7+
When joined together, those amino acids make a protein.
8+
9+
In the real world, there are 64 codons, which in turn correspond to 20 amino acids.
10+
However, for this exercise, you’ll only use a few of the possible 64.
11+
They are listed below:
12+
13+
| Codon | Amino Acid |
14+
| ------------------ | ------------- |
15+
| AUG | Methionine |
16+
| UUU, UUC | Phenylalanine |
17+
| UUA, UUG | Leucine |
18+
| UCU, UCC, UCA, UCG | Serine |
19+
| UAU, UAC | Tyrosine |
20+
| UGU, UGC | Cysteine |
21+
| UGG | Tryptophan |
22+
| UAA, UAG, UGA | STOP |
23+
24+
For example, the RNA string “AUGUUUUCU” has three codons: “AUG”, “UUU” and “UCU”.
25+
These map to Methionine, Phenylalanine, and Serine.
26+
27+
## “STOP” Codons
28+
29+
You’ll note from the table above that there are three **“STOP” codons**.
30+
If you encounter any of these codons, ignore the rest of the sequence — the protein is complete.
31+
32+
For example, “AUGUUUUCUUAAAUG” contains a STOP codon (“UAA”).
33+
Once we reach that point, we stop processing.
34+
We therefore only consider the part before it (i.e. “AUGUUUUCU”), not any further codons after it (i.e. “AUG”).
35+
36+
Learn more about [protein translation on Wikipedia][protein-translation].
37+
38+
[protein-translation]: https://en.wikipedia.org/wiki/Translation_(biology)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"authors": [
3+
"glennj"
4+
],
5+
"files": {
6+
"solution": [
7+
"protein_translation.moon"
8+
],
9+
"test": [
10+
"protein_translation_spec.moon"
11+
],
12+
"example": [
13+
".meta/example.moon"
14+
]
15+
},
16+
"blurb": "Translate RNA sequences into proteins.",
17+
"source": "Tyler Long"
18+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
codon_map =
2+
AUG: 'Methionine'
3+
UUC: 'Phenylalanine'
4+
UUU: 'Phenylalanine'
5+
UUA: 'Leucine'
6+
UUG: 'Leucine'
7+
UCU: 'Serine'
8+
UCC: 'Serine'
9+
UCA: 'Serine'
10+
UCG: 'Serine'
11+
UAU: 'Tyrosine'
12+
UAC: 'Tyrosine'
13+
UGU: 'Cysteine'
14+
UGC: 'Cysteine'
15+
UGG: 'Tryptophan'
16+
UAA: 'STOP'
17+
UAG: 'STOP'
18+
UGA: 'STOP'
19+
20+
translate = (strand) ->
21+
proteins = {}
22+
while #strand > 0
23+
codon, strand = strand\match '(...)(.*)'
24+
switch codon_map[codon]
25+
when nil then error 'Invalid codon'
26+
when 'STOP' then break
27+
else table.insert proteins, codon_map[codon]
28+
proteins
29+
30+
{ proteins: translate }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
string_list = (list) ->
2+
"{#{table.concat [quote word for word in *list], ', '}}"
3+
4+
{
5+
module_imports: {'proteins'},
6+
7+
generate_test: (case, level) ->
8+
local lines
9+
if case.expected.error
10+
lines = {
11+
"f = -> proteins #{quote case.input.strand}",
12+
"assert.has.errors f, #{quote case.expected.error}"
13+
}
14+
else
15+
lines = {
16+
"result = proteins #{quote case.input.strand}",
17+
"expected = #{string_list case.expected}",
18+
"assert.are.same expected, result"
19+
}
20+
table.concat [indent line, level for line in *lines], '\n'
21+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[2c44f7bf-ba20-43f7-a3bf-f2219c0c3f98]
13+
description = "Empty RNA sequence results in no proteins"
14+
15+
[96d3d44f-34a2-4db4-84cd-fff523e069be]
16+
description = "Methionine RNA sequence"
17+
18+
[1b4c56d8-d69f-44eb-be0e-7b17546143d9]
19+
description = "Phenylalanine RNA sequence 1"
20+
21+
[81b53646-bd57-4732-b2cb-6b1880e36d11]
22+
description = "Phenylalanine RNA sequence 2"
23+
24+
[42f69d4f-19d2-4d2c-a8b0-f0ae9ee1b6b4]
25+
description = "Leucine RNA sequence 1"
26+
27+
[ac5edadd-08ed-40a3-b2b9-d82bb50424c4]
28+
description = "Leucine RNA sequence 2"
29+
30+
[8bc36e22-f984-44c3-9f6b-ee5d4e73f120]
31+
description = "Serine RNA sequence 1"
32+
33+
[5c3fa5da-4268-44e5-9f4b-f016ccf90131]
34+
description = "Serine RNA sequence 2"
35+
36+
[00579891-b594-42b4-96dc-7ff8bf519606]
37+
description = "Serine RNA sequence 3"
38+
39+
[08c61c3b-fa34-4950-8c4a-133945570ef6]
40+
description = "Serine RNA sequence 4"
41+
42+
[54e1e7d8-63c0-456d-91d2-062c72f8eef5]
43+
description = "Tyrosine RNA sequence 1"
44+
45+
[47bcfba2-9d72-46ad-bbce-22f7666b7eb1]
46+
description = "Tyrosine RNA sequence 2"
47+
48+
[3a691829-fe72-43a7-8c8e-1bd083163f72]
49+
description = "Cysteine RNA sequence 1"
50+
51+
[1b6f8a26-ca2f-43b8-8262-3ee446021767]
52+
description = "Cysteine RNA sequence 2"
53+
54+
[1e91c1eb-02c0-48a0-9e35-168ad0cb5f39]
55+
description = "Tryptophan RNA sequence"
56+
57+
[e547af0b-aeab-49c7-9f13-801773a73557]
58+
description = "STOP codon RNA sequence 1"
59+
60+
[67640947-ff02-4f23-a2ef-816f8a2ba72e]
61+
description = "STOP codon RNA sequence 2"
62+
63+
[9c2ad527-ebc9-4ace-808b-2b6447cb54cb]
64+
description = "STOP codon RNA sequence 3"
65+
66+
[f4d9d8ee-00a8-47bf-a1e3-1641d4428e54]
67+
description = "Sequence of two protein codons translates into proteins"
68+
69+
[dd22eef3-b4f1-4ad6-bb0b-27093c090a9d]
70+
description = "Sequence of two different protein codons translates into proteins"
71+
72+
[d0f295df-fb70-425c-946c-ec2ec185388e]
73+
description = "Translate RNA strand into correct protein list"
74+
75+
[e30e8505-97ec-4e5f-a73e-5726a1faa1f4]
76+
description = "Translation stops if STOP codon at beginning of sequence"
77+
78+
[5358a20b-6f4c-4893-bce4-f929001710f3]
79+
description = "Translation stops if STOP codon at end of two-codon sequence"
80+
81+
[ba16703a-1a55-482f-bb07-b21eef5093a3]
82+
description = "Translation stops if STOP codon at end of three-codon sequence"
83+
84+
[4089bb5a-d5b4-4e71-b79e-b8d1f14a2911]
85+
description = "Translation stops if STOP codon in middle of three-codon sequence"
86+
87+
[2c2a2a60-401f-4a80-b977-e0715b23b93d]
88+
description = "Translation stops if STOP codon in middle of six-codon sequence"
89+
90+
[f6f92714-769f-4187-9524-e353e8a41a80]
91+
description = "Sequence of two non-STOP codons does not translate to a STOP codon"
92+
93+
[1e75ea2a-f907-4994-ae5c-118632a1cb0f]
94+
description = "Non-existing codon can't translate"
95+
include = false
96+
97+
[9eac93f3-627a-4c90-8653-6d0a0595bc6f]
98+
description = "Unknown amino acids, not part of a codon, can't translate"
99+
reimplements = "1e75ea2a-f907-4994-ae5c-118632a1cb0f"
100+
101+
[9d73899f-e68e-4291-b1e2-7bf87c00f024]
102+
description = "Incomplete RNA sequence can't translate"
103+
104+
[43945cf7-9968-402d-ab9f-b8a28750b050]
105+
description = "Incomplete RNA sequence can translate if valid until a STOP codon"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
proteins: (strand) ->
3+
error 'Implement me'
4+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import proteins from require 'protein_translation'
2+
3+
describe 'protein-translation', ->
4+
it 'Empty RNA sequence results in no proteins', ->
5+
result = proteins ''
6+
expected = {}
7+
assert.are.same expected, result
8+
9+
pending 'Methionine RNA sequence', ->
10+
result = proteins 'AUG'
11+
expected = {'Methionine'}
12+
assert.are.same expected, result
13+
14+
pending 'Phenylalanine RNA sequence 1', ->
15+
result = proteins 'UUU'
16+
expected = {'Phenylalanine'}
17+
assert.are.same expected, result
18+
19+
pending 'Phenylalanine RNA sequence 2', ->
20+
result = proteins 'UUC'
21+
expected = {'Phenylalanine'}
22+
assert.are.same expected, result
23+
24+
pending 'Leucine RNA sequence 1', ->
25+
result = proteins 'UUA'
26+
expected = {'Leucine'}
27+
assert.are.same expected, result
28+
29+
pending 'Leucine RNA sequence 2', ->
30+
result = proteins 'UUG'
31+
expected = {'Leucine'}
32+
assert.are.same expected, result
33+
34+
pending 'Serine RNA sequence 1', ->
35+
result = proteins 'UCU'
36+
expected = {'Serine'}
37+
assert.are.same expected, result
38+
39+
pending 'Serine RNA sequence 2', ->
40+
result = proteins 'UCC'
41+
expected = {'Serine'}
42+
assert.are.same expected, result
43+
44+
pending 'Serine RNA sequence 3', ->
45+
result = proteins 'UCA'
46+
expected = {'Serine'}
47+
assert.are.same expected, result
48+
49+
pending 'Serine RNA sequence 4', ->
50+
result = proteins 'UCG'
51+
expected = {'Serine'}
52+
assert.are.same expected, result
53+
54+
pending 'Tyrosine RNA sequence 1', ->
55+
result = proteins 'UAU'
56+
expected = {'Tyrosine'}
57+
assert.are.same expected, result
58+
59+
pending 'Tyrosine RNA sequence 2', ->
60+
result = proteins 'UAC'
61+
expected = {'Tyrosine'}
62+
assert.are.same expected, result
63+
64+
pending 'Cysteine RNA sequence 1', ->
65+
result = proteins 'UGU'
66+
expected = {'Cysteine'}
67+
assert.are.same expected, result
68+
69+
pending 'Cysteine RNA sequence 2', ->
70+
result = proteins 'UGC'
71+
expected = {'Cysteine'}
72+
assert.are.same expected, result
73+
74+
pending 'Tryptophan RNA sequence', ->
75+
result = proteins 'UGG'
76+
expected = {'Tryptophan'}
77+
assert.are.same expected, result
78+
79+
pending 'STOP codon RNA sequence 1', ->
80+
result = proteins 'UAA'
81+
expected = {}
82+
assert.are.same expected, result
83+
84+
pending 'STOP codon RNA sequence 2', ->
85+
result = proteins 'UAG'
86+
expected = {}
87+
assert.are.same expected, result
88+
89+
pending 'STOP codon RNA sequence 3', ->
90+
result = proteins 'UGA'
91+
expected = {}
92+
assert.are.same expected, result
93+
94+
pending 'Sequence of two protein codons translates into proteins', ->
95+
result = proteins 'UUUUUU'
96+
expected = {'Phenylalanine', 'Phenylalanine'}
97+
assert.are.same expected, result
98+
99+
pending 'Sequence of two different protein codons translates into proteins', ->
100+
result = proteins 'UUAUUG'
101+
expected = {'Leucine', 'Leucine'}
102+
assert.are.same expected, result
103+
104+
pending 'Translate RNA strand into correct protein list', ->
105+
result = proteins 'AUGUUUUGG'
106+
expected = {'Methionine', 'Phenylalanine', 'Tryptophan'}
107+
assert.are.same expected, result
108+
109+
pending 'Translation stops if STOP codon at beginning of sequence', ->
110+
result = proteins 'UAGUGG'
111+
expected = {}
112+
assert.are.same expected, result
113+
114+
pending 'Translation stops if STOP codon at end of two-codon sequence', ->
115+
result = proteins 'UGGUAG'
116+
expected = {'Tryptophan'}
117+
assert.are.same expected, result
118+
119+
pending 'Translation stops if STOP codon at end of three-codon sequence', ->
120+
result = proteins 'AUGUUUUAA'
121+
expected = {'Methionine', 'Phenylalanine'}
122+
assert.are.same expected, result
123+
124+
pending 'Translation stops if STOP codon in middle of three-codon sequence', ->
125+
result = proteins 'UGGUAGUGG'
126+
expected = {'Tryptophan'}
127+
assert.are.same expected, result
128+
129+
pending 'Translation stops if STOP codon in middle of six-codon sequence', ->
130+
result = proteins 'UGGUGUUAUUAAUGGUUU'
131+
expected = {'Tryptophan', 'Cysteine', 'Tyrosine'}
132+
assert.are.same expected, result
133+
134+
pending 'Sequence of two non-STOP codons does not translate to a STOP codon', ->
135+
result = proteins 'AUGAUG'
136+
expected = {'Methionine', 'Methionine'}
137+
assert.are.same expected, result
138+
139+
pending "Unknown amino acids, not part of a codon, can't translate", ->
140+
f = -> proteins 'XYZ'
141+
assert.has.errors f, 'Invalid codon'
142+
143+
pending "Incomplete RNA sequence can't translate", ->
144+
f = -> proteins 'AUGU'
145+
assert.has.errors f, 'Invalid codon'
146+
147+
pending 'Incomplete RNA sequence can translate if valid until a STOP codon', ->
148+
result = proteins 'UUCUUCUAAUGGU'
149+
expected = {'Phenylalanine', 'Phenylalanine'}
150+
assert.are.same expected, result

0 commit comments

Comments
 (0)