diff --git a/config.json b/config.json index 3b53b152d..88521b17c 100644 --- a/config.json +++ b/config.json @@ -86,6 +86,15 @@ "topics": [ ] }, + { + "uuid": "13154065-a5dc-4824-92ed-b2fae41c4dd6", + "slug": "protein-translation", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + ] + }, { "uuid": "197a543c-d9c7-41c3-814c-4b1ece3db568", "slug": "grains", @@ -782,7 +791,7 @@ "uuid": "d5997b60-e54c-4caa-beae-8614f0da3fb3", "slug": "trinary", "deprecated": true - } + } ], "foregone": [ diff --git a/exercises/protein-translation/README.md b/exercises/protein-translation/README.md new file mode 100644 index 000000000..bdda6f5e1 --- /dev/null +++ b/exercises/protein-translation/README.md @@ -0,0 +1,79 @@ +# Rna Transcription + +Given a DNA strand, return its RNA complement (per RNA transcription). + +Both DNA and RNA strands are a sequence of nucleotides. + +The four nucleotides found in DNA are adenine (**A**), cytosine (**C**), +guanine (**G**) and thymine (**T**). + +The four nucleotides found in RNA are adenine (**A**), cytosine (**C**), +guanine (**G**) and uracil (**U**). + +Given a DNA strand, its transcribed RNA strand is formed by replacing +each nucleotide with its complement: + +* `G` -> `C` +* `C` -> `G` +* `T` -> `A` +* `A` -> `U` + + +## Getting Started + +For installation and learning resources, refer to the +[exercism help page](http://exercism.io/languages/haskell). + +## Running the tests + +To run the test suite, execute the following command: + +```bash +stack test +``` + +#### If you get an error message like this... + +``` +No .cabal file found in directory +``` + +You are probably running an old stack version and need +to upgrade it. + +#### Otherwise, if you get an error message like this... + +``` +No compiler found, expected minor version match with... +Try running "stack setup" to install the correct GHC... +``` + +Just do as it says and it will download and install +the correct compiler version: + +```bash +stack setup +``` + +## Running *GHCi* + +If you want to play with your solution in GHCi, just run the command: + +```bash +stack ghci +``` + +## Feedback, Issues, Pull Requests + +The [exercism/haskell](https://github.com/exercism/haskell) repository on +GitHub is the home for all of the Haskell exercises. + +If you have feedback about an exercise, or want to help implementing a new +one, head over there and create an issue. We'll do our best to help you! + +## Source + +Rosalind [http://rosalind.info/problems/rna](http://rosalind.info/problems/rna) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/protein-translation/examples/success-standard/package.yaml b/exercises/protein-translation/examples/success-standard/package.yaml new file mode 100644 index 000000000..7d4a074b0 --- /dev/null +++ b/exercises/protein-translation/examples/success-standard/package.yaml @@ -0,0 +1,18 @@ +name: protein-translation + +dependencies: + - base + +library: + exposed-modules: ProteinTranslation + source-dirs: src + dependencies: + - split + +tests: + test: + main: Tests.hs + source-dirs: test + dependencies: + - protein-translation + - hspec diff --git a/exercises/protein-translation/examples/success-standard/src/ProteinTranslation.hs b/exercises/protein-translation/examples/success-standard/src/ProteinTranslation.hs new file mode 100644 index 000000000..e35af8e3a --- /dev/null +++ b/exercises/protein-translation/examples/success-standard/src/ProteinTranslation.hs @@ -0,0 +1,26 @@ +module ProteinTranslation (toProtein) where + +import Data.List.Split (chunksOf) + +toProtein :: String -> [String] +toProtein strand = takeWhile ("STOP" /=) $ map codonToProtein $ chunksOf 3 strand + +codonToProtein :: String -> String +codonToProtein "AUG" = "Methionine" +codonToProtein "UUU" = "Phenylalanine" +codonToProtein "UUC" = "Phenylalanine" +codonToProtein "UUA" = "Leucine" +codonToProtein "UUG" = "Leucine" +codonToProtein "UCU" = "Serine" +codonToProtein "UCC" = "Serine" +codonToProtein "UCA" = "Serine" +codonToProtein "UCG" = "Serine" +codonToProtein "UAU" = "Tyrosine" +codonToProtein "UAC" = "Tyrosine" +codonToProtein "UGU" = "Cysteine" +codonToProtein "UGC" = "Cysteine" +codonToProtein "UGG" = "Tryptophan" +codonToProtein "UAA" = "STOP" +codonToProtein "UAG" = "STOP" +codonToProtein "UGA" = "STOP" +codonToProtein _ = error "Invalid codon." diff --git a/exercises/protein-translation/package.yaml b/exercises/protein-translation/package.yaml new file mode 100644 index 000000000..e2918876f --- /dev/null +++ b/exercises/protein-translation/package.yaml @@ -0,0 +1,20 @@ +name: protein-translation +version: 1.0.0.0 + +dependencies: + - base + +library: + exposed-modules: ProteinTranslation + source-dirs: src + dependencies: + # - foo # List here the packages you + # - bar # want to use in your solution. + +tests: + test: + main: Tests.hs + source-dirs: test + dependencies: + - protein-translation + - hspec diff --git a/exercises/protein-translation/src/ProteinTranslation.hs b/exercises/protein-translation/src/ProteinTranslation.hs new file mode 100644 index 000000000..60c88f883 --- /dev/null +++ b/exercises/protein-translation/src/ProteinTranslation.hs @@ -0,0 +1,4 @@ +module ProteinTranslation (toProtein) where + +toProtein :: String -> [String] +toProtein strand = error "You need to implement this function" diff --git a/exercises/protein-translation/stack.yaml b/exercises/protein-translation/stack.yaml new file mode 100644 index 000000000..51403bc8b --- /dev/null +++ b/exercises/protein-translation/stack.yaml @@ -0,0 +1 @@ +resolver: lts-8.12 diff --git a/exercises/protein-translation/test/Tests.hs b/exercises/protein-translation/test/Tests.hs new file mode 100644 index 000000000..49e266fea --- /dev/null +++ b/exercises/protein-translation/test/Tests.hs @@ -0,0 +1,95 @@ +{-# LANGUAGE RecordWildCards #-} + +import Data.Foldable (for_) +import Test.Hspec (Spec, describe, it, shouldBe) +import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith) + +import ProteinTranslation (toProtein) + +main :: IO () +main = hspecWith defaultConfig {configFastFail = True} specs + +specs :: Spec +specs = describe "toProtein" $ for_ cases test + where + test Case{..} = it description $ toProtein strand `shouldBe` expected + +data Case = Case { description :: String + , strand :: String + , expected :: [String] + } + +cases :: [Case] +cases = [ Case { description = "identifies methionine codon" + , strand = "AUG" + , expected = ["Methionine"] + } + , Case { description = "identifies phenylalanine codon (UUU)" + , strand = "UUU" + , expected = ["Phenylalanine"] + } + , Case { description = "identifies phenylalanine codon (UUC)" + , strand = "UUC" + , expected = ["Phenylalanine"] + } + , Case { description = "identifies leucine codon (UUA)" + , strand = "UUA" + , expected = ["Leucine"] + } + , Case { description = "identifies leucine codon (UUG)" + , strand = "UUG" + , expected = ["Leucine"] + } + , Case { description = "identifies leucine codon (UUG)" + , strand = "UUG" + , expected = ["Leucine"] + } + , Case { description = "identifies serine codon (UCU)" + , strand = "UCU" + , expected = ["Serine"] + } + , Case { description = "identifies serine codon (UCC)" + , strand = "UCC" + , expected = ["Serine"] + } + , Case { description = "identifies serine codon (UCA)" + , strand = "UCA" + , expected = ["Serine"] + } + , Case { description = "identifies serine codon (UCG)" + , strand = "UCG" + , expected = ["Serine"] + } + , Case { description = "identifies tyrosine codon (UAU)" + , strand = "UAU" + , expected = ["Tyrosine"] + } + , Case { description = "identifies tyrosine codon (UAC)" + , strand = "UAC" + , expected = ["Tyrosine"] + } + , Case { description = "identifies cysteine codon (UGU)" + , strand = "UGU" + , expected = ["Cysteine"] + } + , Case { description = "identifies cysteine codon (UGC)" + , strand = "UGC" + , expected = ["Cysteine"] + } + , Case { description = "identifies tryptophan codon" + , strand = "UGG" + , expected = ["Tryptophan"] + } + , Case { description = "translate RNA strand into correct protein" + , strand = "AUGUUUUGG" + , expected = ["Methionine", "Phenylalanine", "Tryptophan"] + } + , Case { description = "stops translation if the STOP codon is present" + , strand = "AUGUUUUAA" + , expected = ["Methionine", "Phenylalanine"] + } + , Case { description = "stops translation of longest strand" + , strand = "UGGUGUUAUUAAUGGUUU" + , expected = ["Tryptophan", "Cysteine", "Tyrosine"] + } + ]