Repository: exercism/clojure
Pull request #191 (2017-10-21 10:14:07)

add protein-translation exercise

haus: @querenker it looks like there is a merge conflict with config.json that needs to be resolved before it will be mergeable. There are a couple of ways to resolve the conflict:

1. Try the 'Resolve conflicts' button in the PR screen (https://help.github.com/articles/resolving-a-merge-conflict-on-github/ seems like a good resource)
2. Try resolving the conflict on the command line (https://help.github.com/articles/resolving-a-merge-conflict-using-the-command-line/ seems like a good resource)

If you have questions or need a hand resolving the conflict let me know.
querenker: Thanks for your review. The missing README is now added.

Patch:
diff --git a/config.json b/config.json
index 72a6683..71f7317 100644
--- a/config.json
+++ b/config.json
@@ -527,9 +527,20 @@
       "core": false,
       "difficulty": 1,
       "slug": "diamond",
-      "topics": null, 
+      "topics": null,
       "unlocked_by": null,
       "uuid": "f3971f71-08c9-4e36-a69e-5bd7fe070b07"
+    },
+    {
+      "core": false,
+      "difficulty": 1,
+      "slug": "protein-translation",
+      "unlocked_by": null,
+      "topics": [
+        "strings",
+        "pattern matching"
+      ],
+      "uuid": "c4b7120c-a7c5-4a39-a08e-8d4fb9861a27"
     }
   ],
   "foregone": [],
diff --git a/exercises/protein-translation/README.md b/exercises/protein-translation/README.md
new file mode 100644
index 0000000..0b1c9ef
--- /dev/null
+++ b/exercises/protein-translation/README.md
@@ -0,0 +1,40 @@
+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", "UAG", "AUG"` =>
+
+Protein: `"Methionine", "Phenylalanine", "Serine"`
+
+Note the stop codon 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](http://en.wikipedia.org/wiki/Translation_(biology))
diff --git a/exercises/protein-translation/project.clj b/exercises/protein-translation/project.clj
new file mode 100644
index 0000000..839dd95
--- /dev/null
+++ b/exercises/protein-translation/project.clj
@@ -0,0 +1,4 @@
+(defproject protein-translation "0.1.0-SNAPSHOT"
+  :description "protein translation exercise."
+  :url "https://github.com/exercism/xclojure/tree/master/exercises/protein-translation"
+  :dependencies [[org.clojure/clojure "1.8.0"]])
diff --git a/exercises/protein-translation/src/example.clj b/exercises/protein-translation/src/example.clj
new file mode 100644
index 0000000..215bd96
--- /dev/null
+++ b/exercises/protein-translation/src/example.clj
@@ -0,0 +1,19 @@
+(ns protein-translation)
+
+(defn translate-codon [codon]
+  (case codon
+    "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"))
+
+(defn translate-rna [rna]
+  (->> rna
+       (partition 3)
+       (map (partial apply str))
+       (map translate-codon)
+       (take-while #(not= "STOP" %))))


Test patch:
diff --git a/exercises/protein-translation/test/protein_translation_test.clj b/exercises/protein-translation/test/protein_translation_test.clj
new file mode 100644
index 0000000..05981ed
--- /dev/null
+++ b/exercises/protein-translation/test/protein_translation_test.clj
@@ -0,0 +1,36 @@
+(ns protein-translation-test
+  (:require [clojure.test :refer [deftest is are]]
+            protein-translation))
+
+(deftest AUG-translates-to-Methionine
+  (is (= "Methionine" (protein-translation/translate-codon "AUG"))))
+
+(deftest UGG-translates-to-Tryptophan
+  (is (= "Tryptophan" (protein-translation/translate-codon "UGG"))))
+
+(deftest identifies-Phenylalanine-codons
+  (are [codon] (= "Phenylalanine" (protein-translation/translate-codon codon)) "UUU" "UUC"))
+
+(deftest identifies-Leucine-codons
+  (are [codon] (= "Leucine" (protein-translation/translate-codon codon)) "UUA" "UUG"))
+
+(deftest identiefies-Serine-codons
+  (are [codon] (= "Serine" (protein-translation/translate-codon codon)) "UCU" "UCC" "UCA" "UCG"))
+
+(deftest identiefies-Tyrosine-codons
+  (are [codon] (= "Tyrosine" (protein-translation/translate-codon codon)) "UAU" "UAC"))
+
+(deftest identifies-Cysteine-codons
+  (are [codon] (= "Cysteine" (protein-translation/translate-codon codon)) "UGU" "UGC"))
+
+(deftest identifies-stop-codons
+  (are [codon] (= "STOP" (protein-translation/translate-codon codon)) "UAA" "UAG" "UGA"))
+
+(deftest translates-rna-strand-into-correct-protein
+  (is (= ["Methionine" "Phenylalanine" "Tryptophan"] (protein-translation/translate-rna "AUGUUUUGG"))))
+
+(deftest stops-translation-if-stop-codon-present
+  (is (= ["Methionine" "Phenylalanine"] (protein-translation/translate-rna "AUGUUUUAA"))))
+
+(deftest stops-translation-of-longer-strand
+  (is (= ["Tryptophan" "Cysteine" "Tyrosine"] (protein-translation/translate-rna "UGGUGUUAUUAAUGGUUU"))))