From 4d0b3654be965d01f5bd917c3c09766bb52db7ef Mon Sep 17 00:00:00 2001 From: James Walker Date: Fri, 17 Sep 2021 18:12:01 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20haskell:=20rna-transcription?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- haskell/rna-transcription/HELP.md | 88 +++++++++++++++++++ haskell/rna-transcription/README.md | 51 +++++++++++ .../examples/success-standard/package.yaml | 18 ++++ haskell/rna-transcription/package.yaml | 21 +++++ haskell/rna-transcription/src/DNA.hs | 12 +++ haskell/rna-transcription/stack.yaml | 1 + haskell/rna-transcription/test/Tests.hs | 61 +++++++++++++ 7 files changed, 252 insertions(+) create mode 100644 haskell/rna-transcription/HELP.md create mode 100644 haskell/rna-transcription/README.md create mode 100644 haskell/rna-transcription/examples/success-standard/package.yaml create mode 100644 haskell/rna-transcription/package.yaml create mode 100644 haskell/rna-transcription/src/DNA.hs create mode 100644 haskell/rna-transcription/stack.yaml create mode 100644 haskell/rna-transcription/test/Tests.hs diff --git a/haskell/rna-transcription/HELP.md b/haskell/rna-transcription/HELP.md new file mode 100644 index 0000000..37fd8ad --- /dev/null +++ b/haskell/rna-transcription/HELP.md @@ -0,0 +1,88 @@ +# Help + +## 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 +``` + +or + +``` +RedownloadInvalidResponse Request { +... +} + "/home/username/.stack/build-plan/lts-xx.yy.yaml" (Response {responseStatus = Status {statusCode = 404, statusMessage = "Not Found"}, +``` + +You are probably running an old stack version and need +to upgrade it. Try running: + +```bash +stack upgrade +``` + +Or see other options for upgrading at [Stack documentation](https://docs.haskellstack.org/en/stable/install_and_upgrade/#upgrade). + +#### 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 +``` + + +If you want to play with your solution in GHCi, just run the command: + +```bash +stack ghci +``` + +## Submitting your solution + +You can submit your solution using the `exercism submit src/DNA.hs` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Haskell track's documentation](https://exercism.org/docs/tracks/haskell) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +## Getting Started + +Please refer to the [installation](https://exercism.io/tracks/haskell/installation) +and [learning](https://exercism.io/tracks/haskell/learning) help pages. + +## 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! +{{ with .Spec.Credits }} \ No newline at end of file diff --git a/haskell/rna-transcription/README.md b/haskell/rna-transcription/README.md new file mode 100644 index 0000000..31cb230 --- /dev/null +++ b/haskell/rna-transcription/README.md @@ -0,0 +1,51 @@ +# Rna Transcription + +Welcome to Rna Transcription on Exercism's Haskell Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +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` + +Given invalid output, your program should return the first invalid character. + +## Source + +### Created by + +- @etrepum + +### Contributed to by + +- @b-mehta +- @eijynagai +- @iHiD +- @kytrinyx +- @MazeChaZer +- @petertseng +- @ppartarr +- @rbasso +- @rpottsoh +- @samjonester +- @sshine +- @tejasbubane + +### Based on + +Hyperphysics - http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html \ No newline at end of file diff --git a/haskell/rna-transcription/examples/success-standard/package.yaml b/haskell/rna-transcription/examples/success-standard/package.yaml new file mode 100644 index 0000000..5d7d110 --- /dev/null +++ b/haskell/rna-transcription/examples/success-standard/package.yaml @@ -0,0 +1,18 @@ +name: rna-transcription + +dependencies: + - base + +library: + exposed-modules: DNA + source-dirs: src + dependencies: + - containers + +tests: + test: + main: Tests.hs + source-dirs: test + dependencies: + - rna-transcription + - hspec diff --git a/haskell/rna-transcription/package.yaml b/haskell/rna-transcription/package.yaml new file mode 100644 index 0000000..d56ebb6 --- /dev/null +++ b/haskell/rna-transcription/package.yaml @@ -0,0 +1,21 @@ +name: rna-transcription +version: 1.3.0.10 + +dependencies: + - base + +library: + exposed-modules: DNA + source-dirs: src + ghc-options: -Wall + # dependencies: + # - foo # List here the packages you + # - bar # want to use in your solution. + +tests: + test: + main: Tests.hs + source-dirs: test + dependencies: + - rna-transcription + - hspec diff --git a/haskell/rna-transcription/src/DNA.hs b/haskell/rna-transcription/src/DNA.hs new file mode 100644 index 0000000..ed387bb --- /dev/null +++ b/haskell/rna-transcription/src/DNA.hs @@ -0,0 +1,12 @@ +module DNA (toRNA) where + +toRNA :: String -> Either Char String +toRNA xs = traverse fromDNA xs + +fromDNA :: Char -> Either Char Char +fromDNA c + | c == 'G' = Right 'C' + | c == 'C' = Right 'G' + | c == 'T' = Right 'A' + | c == 'A' = Right 'U' + | otherwise = Left c diff --git a/haskell/rna-transcription/stack.yaml b/haskell/rna-transcription/stack.yaml new file mode 100644 index 0000000..35c2e5b --- /dev/null +++ b/haskell/rna-transcription/stack.yaml @@ -0,0 +1 @@ +resolver: lts-16.21 diff --git a/haskell/rna-transcription/test/Tests.hs b/haskell/rna-transcription/test/Tests.hs new file mode 100644 index 0000000..0ad61a8 --- /dev/null +++ b/haskell/rna-transcription/test/Tests.hs @@ -0,0 +1,61 @@ +{-# LANGUAGE RecordWildCards #-} + +import Data.Foldable (for_) +import Test.Hspec (Spec, describe, it, shouldBe) +import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith) + +import DNA (toRNA) + +main :: IO () +main = hspecWith defaultConfig {configFastFail = True} specs + +specs :: Spec +specs = describe "toRNA" $ for_ cases test + where + test Case{..} = it description $ toRNA dna `shouldBe` expected + +data Case = Case { description :: String + , dna :: String + , expected :: Either Char String + } + +cases :: [Case] +cases = [ Case { description = "Empty RNA sequence" + , dna = "" + , expected = Right "" + } + , Case { description = "RNA complement of cytosine is guanine" + , dna = "C" + , expected = Right "G" + } + , Case { description = "RNA complement of guanine is cytosine" + , dna = "G" + , expected = Right "C" + } + , Case { description = "RNA complement of thymine is adenine" + , dna = "T" + , expected = Right "A" + } + , Case { description = "RNA complement of adenine is uracil" + , dna = "A" + , expected = Right "U" + } + , Case { description = "RNA complement" + , dna = "ACGTGGTCTTAA" + , expected = Right "UGCACCAGAAUU" + } + , Case { description = "correctly handles invalid input (RNA instead of DNA)" + , dna = "U" + , expected = Left 'U' + } + , Case { description = "correctly handles completely invalid DNA input" + , dna = "XXX" + , expected = Left 'X' + } + , Case { description = "correctly handles partially invalid DNA input" + , dna = "ACGTXXXCTTAA" + , expected = Left 'X' + } + ] + +-- b02fedbb302892cb17dfa608df335b530ae2bc92