Skip to content

Commit 37fca5f

Browse files
authored
Add protein-translation (#746)
* Add protein-translation * Update example.jl
1 parent af7e017 commit 37fca5f

File tree

7 files changed

+347
-0
lines changed

7 files changed

+347
-0
lines changed

config.json

+8
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,14 @@
468468
"strings"
469469
]
470470
},
471+
{
472+
"slug": "protein-translation",
473+
"name": "Protein Translation",
474+
"uuid": "ef95ea34-cc9e-48aa-b2f9-6226134a3644",
475+
"practices": [],
476+
"prerequisites": [],
477+
"difficulty": 2
478+
},
471479
{
472480
"slug": "isbn-verifier",
473481
"name": "ISBN Verifier",
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+
"BNAndras"
4+
],
5+
"files": {
6+
"solution": [
7+
"protein-translation.jl"
8+
],
9+
"test": [
10+
"runtests.jl"
11+
],
12+
"example": [
13+
".meta/example.jl"
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,39 @@
1+
function proteins(strand)
2+
codons = chunked(strand)
3+
results = []
4+
for codon in codons
5+
if !haskey(codon_to_protein, codon)
6+
throw(DomainError(codon, "Invalid codon"))
7+
end
8+
9+
protein = codon_to_protein[codon]
10+
protein == "STOP" && return results
11+
12+
push!(results, protein)
13+
end
14+
results
15+
end
16+
17+
function chunked(strand)
18+
[strand[i:min(i + 3 - 1, end)] for i in 1:3:length(strand)]
19+
end
20+
21+
codon_to_protein = Dict(
22+
"AUG" => "Methionine",
23+
"UUU" => "Phenylalanine",
24+
"UUC" => "Phenylalanine",
25+
"UUA" => "Leucine",
26+
"UUG" => "Leucine",
27+
"UCU" => "Serine",
28+
"UCC" => "Serine",
29+
"UCA" => "Serine",
30+
"UCG" => "Serine",
31+
"UAU" => "Tyrosine",
32+
"UAC" => "Tyrosine",
33+
"UGU" => "Cysteine",
34+
"UGC" => "Cysteine",
35+
"UGG" => "Tryptophan",
36+
"UAA" => "STOP",
37+
"UAG" => "STOP",
38+
"UGA" => "STOP"
39+
)
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"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function proteins(strand)
2+
3+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
using Test
2+
3+
include("protein-translation.jl")
4+
5+
@testset verbose = true "tests" begin
6+
@testset "Empty RNA sequence results in no proteins" begin
7+
@test proteins("") == []
8+
end
9+
10+
@testset "Methionine RNA sequence" begin
11+
@test proteins("AUG") == ["Methionine"]
12+
end
13+
14+
@testset "Phenylalanine RNA sequence 1" begin
15+
@test proteins("UUU") == ["Phenylalanine"]
16+
end
17+
18+
@testset "Phenylalanine RNA sequence 2" begin
19+
@test proteins("UUC") == ["Phenylalanine"]
20+
end
21+
22+
@testset "Leucine RNA sequence 1" begin
23+
@test proteins("UUA") == ["Leucine"]
24+
end
25+
26+
@testset "Leucine RNA sequence 2" begin
27+
@test proteins("UUG") == ["Leucine"]
28+
end
29+
30+
@testset "Serine RNA sequence 1" begin
31+
@test proteins("UCU") == ["Serine"]
32+
end
33+
34+
@testset "Serine RNA sequence 2" begin
35+
@test proteins("UCC") == ["Serine"]
36+
end
37+
38+
@testset "Serine RNA sequence 3" begin
39+
@test proteins("UCA") == ["Serine"]
40+
end
41+
42+
@testset "Serine RNA sequence 4" begin
43+
@test proteins("UCG") == ["Serine"]
44+
end
45+
46+
@testset "Tyrosine RNA sequence 1" begin
47+
@test proteins("UAU") == ["Tyrosine"]
48+
end
49+
50+
@testset "Tyrosine RNA sequence 2" begin
51+
@test proteins("UAC") == ["Tyrosine"]
52+
end
53+
54+
@testset "Cysteine RNA sequence 1" begin
55+
@test proteins("UGU") == ["Cysteine"]
56+
end
57+
58+
@testset "Cysteine RNA sequence 2" begin
59+
@test proteins("UGC") == ["Cysteine"]
60+
end
61+
62+
@testset "Tryptophan RNA sequence" begin
63+
@test proteins("UGG") == ["Tryptophan"]
64+
end
65+
66+
@testset "STOP codon RNA sequence 1" begin
67+
@test proteins("UAA") == []
68+
end
69+
70+
@testset "STOP codon RNA sequence 2" begin
71+
@test proteins("UAG") == []
72+
end
73+
74+
@testset "STOP codon RNA sequence 3" begin
75+
@test proteins("UGA") == []
76+
end
77+
78+
@testset "Sequence of two protein codons translates into proteins" begin
79+
@test proteins("UUUUUU") == ["Phenylalanine", "Phenylalanine"]
80+
end
81+
82+
@testset "Sequence of two different protein codons translates into proteins" begin
83+
@test proteins("UUAUUG") == ["Leucine", "Leucine"]
84+
end
85+
86+
@testset "Translate RNA strand into correct protein list" begin
87+
@test proteins("AUGUUUUGG") == ["Methionine", "Phenylalanine", "Tryptophan"]
88+
end
89+
90+
@testset "Translation stops if STOP codon at beginning of sequence" begin
91+
@test proteins("UAGUGG") == []
92+
end
93+
94+
@testset "Translation stops if STOP codon at end of two-codon sequence" begin
95+
@test proteins("UGGUAG") == ["Tryptophan"]
96+
end
97+
98+
@testset "Translation stops if STOP codon at end of three-codon sequence" begin
99+
@test proteins("AUGUUUUAA") == ["Methionine", "Phenylalanine"]
100+
end
101+
102+
@testset "Translation stops if STOP codon in middle of three-codon sequence" begin
103+
@test proteins("UGGUAGUGG") == ["Tryptophan"]
104+
end
105+
106+
@testset "Translation stops if STOP codon in middle of six-codon sequence" begin
107+
@test proteins("UGGUGUUAUUAAUGGUUU") == ["Tryptophan", "Cysteine", "Tyrosine"]
108+
end
109+
110+
@testset "Sequence of two non-STOP codons does not translate to a STOP codon" begin
111+
@test proteins("AUGAUG") == ["Methionine", "Methionine"]
112+
end
113+
114+
@testset "Non-existing codon can't translate" begin
115+
@test_throws DomainError proteins("AAA")
116+
end
117+
118+
@testset "Unknown amino acids, not part of a codon, can't translate" begin
119+
@test_throws DomainError proteins("XYZ")
120+
end
121+
122+
@testset "Incomplete RNA sequence can't translate" begin
123+
@test_throws DomainError proteins("AUGU")
124+
end
125+
126+
@testset "Incomplete RNA sequence can translate if valid until a STOP codon" begin
127+
@test proteins("UUCUUCUAAUGGU") == ["Phenylalanine", "Phenylalanine"]
128+
end
129+
end

0 commit comments

Comments
 (0)