Skip to content

Commit 7636a9f

Browse files
committed
Add protein-translation exercise
1 parent 4c4a76f commit 7636a9f

File tree

7 files changed

+353
-0
lines changed

7 files changed

+353
-0
lines changed

config.json

+8
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@
139139
"prerequisites": [],
140140
"difficulty": 2
141141
},
142+
{
143+
"slug": "protein-translation",
144+
"name": "Protein Translation",
145+
"uuid": "a93332b7-d630-4c58-b69f-3a01481774de",
146+
"practices": [],
147+
"prerequisites": [],
148+
"difficulty": 2
149+
},
142150
{
143151
"slug": "luhn",
144152
"name": "Luhn",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Instructions
2+
3+
Translate RNA sequences into proteins.
4+
5+
RNA can be broken into three nucleotide sequences called codons, and then translated to a polypeptide like so:
6+
7+
RNA: `"AUGUUUUCU"` => translates to
8+
9+
Codons: `"AUG", "UUU", "UCU"`
10+
=> which become a polypeptide with the following sequence =>
11+
12+
Protein: `"Methionine", "Phenylalanine", "Serine"`
13+
14+
There are 64 codons which in turn correspond to 20 amino acids; however, all of the codon sequences and resulting amino acids are not important in this exercise.
15+
If it works for one codon, the program should work for all of them.
16+
However, feel free to expand the list in the test suite to include them all.
17+
18+
There are also three terminating codons (also known as 'STOP' codons); if any of these codons are encountered (by the ribosome), all translation ends and the protein is terminated.
19+
20+
All subsequent codons after are ignored, like this:
21+
22+
RNA: `"AUGUUUUCUUAAAUG"` =>
23+
24+
Codons: `"AUG", "UUU", "UCU", "UAA", "AUG"` =>
25+
26+
Protein: `"Methionine", "Phenylalanine", "Serine"`
27+
28+
Note the stop codon `"UAA"` terminates the translation and the final methionine is not translated into the protein sequence.
29+
30+
Below are the codons and resulting Amino Acids needed for the exercise.
31+
32+
| Codon | Protein |
33+
| :----------------- | :------------ |
34+
| AUG | Methionine |
35+
| UUU, UUC | Phenylalanine |
36+
| UUA, UUG | Leucine |
37+
| UCU, UCC, UCA, UCG | Serine |
38+
| UAU, UAC | Tyrosine |
39+
| UGU, UGC | Cysteine |
40+
| UGG | Tryptophan |
41+
| UAA, UAG, UGA | STOP |
42+
43+
Learn more about [protein translation on Wikipedia][protein-translation].
44+
45+
[protein-translation]: https://en.wikipedia.org/wiki/Translation_(biology)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"authors": [
3+
"pfertyk"
4+
],
5+
"files": {
6+
"solution": [
7+
"protein_translation.gd"
8+
],
9+
"test": [
10+
"protein_translation_test.gd"
11+
],
12+
"example": [
13+
".meta/example.gd"
14+
]
15+
},
16+
"blurb": "Translate RNA sequences into proteins.",
17+
"source": "Tyler Long"
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const CODON_TO_PROTEINE = {
2+
'AUG': 'Methionine',
3+
'UUU': 'Phenylalanine',
4+
'UUC': '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+
21+
22+
func proteins(strand):
23+
var protein_list = []
24+
for i in range(0, len(strand), 3):
25+
var codon = strand.substr(i, 3)
26+
var proteine = CODON_TO_PROTEINE[codon]
27+
if proteine == 'STOP':
28+
break
29+
protein_list.append(proteine)
30+
return protein_list
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
[1e75ea2a-f907-4994-ae5c-118632a1cb0f]
91+
description = "Non-existing codon can't translate"
92+
93+
[9eac93f3-627a-4c90-8653-6d0a0595bc6f]
94+
description = "Unknown amino acids, not part of a codon, can't translate"
95+
96+
[9d73899f-e68e-4291-b1e2-7bf87c00f024]
97+
description = "Incomplete RNA sequence can't translate"
98+
99+
[43945cf7-9968-402d-ab9f-b8a28750b050]
100+
description = "Incomplete RNA sequence can translate if valid until a STOP codon"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
func proteins(strand):
2+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
func test_methionine_rna_sequence(solution_script):
2+
var value = "AUG"
3+
var expected = ["Methionine"]
4+
return [solution_script.proteins(value), expected]
5+
6+
7+
func test_phenylalanine_rna_sequence_1(solution_script):
8+
var value = "UUU"
9+
var expected = ["Phenylalanine"]
10+
return [solution_script.proteins(value), expected]
11+
12+
13+
func test_phenylalanine_rna_sequence_2(solution_script):
14+
var value = "UUC"
15+
var expected = ["Phenylalanine"]
16+
return [solution_script.proteins(value), expected]
17+
18+
19+
func test_leucine_rna_sequence_1(solution_script):
20+
var value = "UUA"
21+
var expected = ["Leucine"]
22+
return [solution_script.proteins(value), expected]
23+
24+
25+
func test_leucine_rna_sequence_2(solution_script):
26+
var value = "UUG"
27+
var expected = ["Leucine"]
28+
return [solution_script.proteins(value), expected]
29+
30+
31+
func test_serine_rna_sequence_1(solution_script):
32+
var value = "UCU"
33+
var expected = ["Serine"]
34+
return [solution_script.proteins(value), expected]
35+
36+
37+
func test_serine_rna_sequence_2(solution_script):
38+
var value = "UCC"
39+
var expected = ["Serine"]
40+
return [solution_script.proteins(value), expected]
41+
42+
43+
func test_serine_rna_sequence_3(solution_script):
44+
var value = "UCA"
45+
var expected = ["Serine"]
46+
return [solution_script.proteins(value), expected]
47+
48+
49+
func test_serine_rna_sequence_4(solution_script):
50+
var value = "UCG"
51+
var expected = ["Serine"]
52+
return [solution_script.proteins(value), expected]
53+
54+
55+
func test_tyrosine_rna_sequence_1(solution_script):
56+
var value = "UAU"
57+
var expected = ["Tyrosine"]
58+
return [solution_script.proteins(value), expected]
59+
60+
61+
func test_tyrosine_rna_sequence_2(solution_script):
62+
var value = "UAC"
63+
var expected = ["Tyrosine"]
64+
return [solution_script.proteins(value), expected]
65+
66+
67+
func test_cysteine_rna_sequence_1(solution_script):
68+
var value = "UGU"
69+
var expected = ["Cysteine"]
70+
return [solution_script.proteins(value), expected]
71+
72+
73+
func test_cysteine_rna_sequence_2(solution_script):
74+
var value = "UGC"
75+
var expected = ["Cysteine"]
76+
return [solution_script.proteins(value), expected]
77+
78+
79+
func test_tryptophan_rna_sequence(solution_script):
80+
var value = "UGG"
81+
var expected = ["Tryptophan"]
82+
return [solution_script.proteins(value), expected]
83+
84+
85+
func test_stop_codon_rna_sequence_1(solution_script):
86+
var value = "UAA"
87+
var expected = []
88+
return [solution_script.proteins(value), expected]
89+
90+
91+
func test_stop_codon_rna_sequence_2(solution_script):
92+
var value = "UAG"
93+
var expected = []
94+
return [solution_script.proteins(value), expected]
95+
96+
97+
func test_stop_codon_rna_sequence_3(solution_script):
98+
var value = "UGA"
99+
var expected = []
100+
return [solution_script.proteins(value), expected]
101+
102+
103+
func test_sequence_of_two_protein_codons_translates_into_proteins(solution_script):
104+
var value = "UUUUUU"
105+
var expected = ["Phenylalanine", "Phenylalanine"]
106+
return [solution_script.proteins(value), expected]
107+
108+
109+
func test_sequence_of_two_different_protein_codons_translates_into_proteins(solution_script):
110+
var value = "UUAUUG"
111+
var expected = ["Leucine", "Leucine"]
112+
return [solution_script.proteins(value), expected]
113+
114+
115+
func test_translate_rna_strand_into_correct_protein_list(solution_script):
116+
var value = "AUGUUUUGG"
117+
var expected = ["Methionine", "Phenylalanine", "Tryptophan"]
118+
return [solution_script.proteins(value), expected]
119+
120+
121+
func test_translation_stops_if_stop_codon_at_beginning_of_sequence(solution_script):
122+
var value = "UAGUGG"
123+
var expected = []
124+
return [solution_script.proteins(value), expected]
125+
126+
127+
func test_translation_stops_if_stop_codon_at_end_of_two_codon_sequence(solution_script):
128+
var value = "UGGUAG"
129+
var expected = ["Tryptophan"]
130+
return [solution_script.proteins(value), expected]
131+
132+
133+
func test_translation_stops_if_stop_codon_at_end_of_three_codon_sequence(solution_script):
134+
var value = "AUGUUUUAA"
135+
var expected = ["Methionine", "Phenylalanine"]
136+
return [solution_script.proteins(value), expected]
137+
138+
139+
func test_translation_stops_if_stop_codon_in_middle_of_three_codon_sequence(solution_script):
140+
var value = "UGGUAGUGG"
141+
var expected = ["Tryptophan"]
142+
return [solution_script.proteins(value), expected]
143+
144+
145+
func test_translation_stops_if_stop_codon_in_middle_of_six_codon_sequence(solution_script):
146+
var value = "UGGUGUUAUUAAUGGUUU"
147+
var expected = ["Tryptophan", "Cysteine", "Tyrosine"]
148+
return [solution_script.proteins(value), expected]
149+
150+

0 commit comments

Comments
 (0)