Skip to content

Commit

Permalink
Add protein translation
Browse files Browse the repository at this point in the history
  • Loading branch information
BNAndras committed Feb 14, 2024
1 parent c914932 commit e75e97c
Show file tree
Hide file tree
Showing 7 changed files with 388 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,14 @@
"result"
],
"difficulty": 8
},
{
"slug": "protein-translation",
"name": "protein-translation",
"uuid": "c405e318-7101-4b4a-88b4-4099bbd2cd19",
"practices": [],
"prerequisites": [],
"difficulty": 5
}
]
},
Expand Down
45 changes: 45 additions & 0 deletions exercises/practice/protein-translation/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Instructions

Translate RNA sequences into proteins.

RNA can be broken into three nucleotide sequences called codons, and then translated to a polypeptide like so:

RNA: `"AUGUUUUCU"` => translates to

Codons: `"AUG", "UUU", "UCU"`
=> which become a polypeptide with the following sequence =>

Protein: `"Methionine", "Phenylalanine", "Serine"`

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.
If it works for one codon, the program should work for all of them.
However, feel free to expand the list in the test suite to include them all.

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.

All subsequent codons after are ignored, like this:

RNA: `"AUGUUUUCUUAAAUG"` =>

Codons: `"AUG", "UUU", "UCU", "UAA", "AUG"` =>

Protein: `"Methionine", "Phenylalanine", "Serine"`

Note the stop codon `"UAA"` terminates the translation and the final methionine is not translated into the protein sequence.

Below are the codons and resulting Amino Acids needed for the exercise.

| Codon | Protein |
| :----------------- | :------------ |
| AUG | Methionine |
| UUU, UUC | Phenylalanine |
| UUA, UUG | Leucine |
| UCU, UCC, UCA, UCG | Serine |
| UAU, UAC | Tyrosine |
| UGU, UGC | Cysteine |
| UGG | Tryptophan |
| UAA, UAG, UGA | STOP |

Learn more about [protein translation on Wikipedia][protein-translation].

[protein-translation]: https://en.wikipedia.org/wiki/Translation_(biology)
18 changes: 18 additions & 0 deletions exercises/practice/protein-translation/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"authors": [
"BNAndras"
],
"files": {
"solution": [
"src/ProteinTranslation.elm"
],
"test": [
"tests/Tests.elm"
],
"example": [
".meta/src/ProteinTranslation.example.elm"
]
},
"blurb": "Translate RNA sequences into proteins.",
"source": "Tyler Long"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
module ProteinTranslation exposing (proteins)

import List
import String


proteins : String -> Result String (List String)
proteins strand =
case splitIntoCodons strand of
[ "" ] ->
Ok []

codons ->
case processCodons [] codons of
Ok results ->
Ok (List.reverse results)

Err err ->
Err err


splitIntoCodons : String -> List String
splitIntoCodons strand =
if String.length strand > 3 then
String.left 3 strand :: splitIntoCodons (String.dropLeft 3 strand)

else
[ strand ]


processCodons : List String -> List String -> Result String (List String)
processCodons acc codons =
case codons of
[] ->
Ok acc

codon :: rest ->
case codonToProtein codon of
Ok "STOP" ->
Ok acc

Ok protein ->
processCodons (protein :: acc) rest

Err err ->
Err err


codonToProtein : String -> Result String String
codonToProtein codon =
case codon of
"AUG" ->
Ok "Methionine"

"UUU" ->
Ok "Phenylalanine"

"UUC" ->
Ok "Phenylalanine"

"UUA" ->
Ok "Leucine"

"UUG" ->
Ok "Leucine"

"UCU" ->
Ok "Serine"

"UCC" ->
Ok "Serine"

"UCA" ->
Ok "Serine"

"UCG" ->
Ok "Serine"

"UAU" ->
Ok "Tyrosine"

"UAC" ->
Ok "Tyrosine"

"UGU" ->
Ok "Cysteine"

"UGC" ->
Ok "Cysteine"

"UGG" ->
Ok "Tryptophan"

"UAA" ->
Ok "STOP"

"UAG" ->
Ok "STOP"

"UGA" ->
Ok "STOP"

_ ->
Err "Invalid codon"
29 changes: 29 additions & 0 deletions exercises/practice/protein-translation/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/core": "1.0.5",
"elm/json": "1.1.3",
"elm/parser": "1.1.0",
"elm/random": "1.0.0",
"elm/regex": "1.0.0",
"elm/time": "1.0.0"
},
"indirect": {}
},
"test-dependencies": {
"direct": {
"elm-explorations/test": "2.1.0",
"rtfeldman/elm-iso8601-date-strings": "1.1.4"
},
"indirect": {
"elm/bytes": "1.0.8",
"elm/html": "1.0.0",
"elm/virtual-dom": "1.0.3"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module ProteinTranslation exposing (proteins)


proteins : String -> Result String List todo
proteins strand =
Debug.todo "Please implement proteins"
Loading

0 comments on commit e75e97c

Please sign in to comment.