From 8a0b02049f614017dbab03b224256883649ac6dc Mon Sep 17 00:00:00 2001 From: Danylo Negrienko Date: Fri, 28 Jun 2024 13:11:21 -0400 Subject: [PATCH] rna-transcription --- .../rna-transcription/.exercism/config.json | 36 +++++++++ .../rna-transcription/.exercism/metadata.json | 1 + elixir/rna-transcription/.formatter.exs | 4 + elixir/rna-transcription/.gitignore | 24 ++++++ elixir/rna-transcription/HELP.md | 75 +++++++++++++++++++ elixir/rna-transcription/README.md | 70 +++++++++++++++++ .../lib/rna_transcription.ex | 17 +++++ elixir/rna-transcription/mix.exs | 28 +++++++ .../test/rna_transcription_test.exs | 28 +++++++ elixir/rna-transcription/test/test_helper.exs | 2 + 10 files changed, 285 insertions(+) create mode 100644 elixir/rna-transcription/.exercism/config.json create mode 100644 elixir/rna-transcription/.exercism/metadata.json create mode 100644 elixir/rna-transcription/.formatter.exs create mode 100644 elixir/rna-transcription/.gitignore create mode 100644 elixir/rna-transcription/HELP.md create mode 100644 elixir/rna-transcription/README.md create mode 100644 elixir/rna-transcription/lib/rna_transcription.ex create mode 100644 elixir/rna-transcription/mix.exs create mode 100644 elixir/rna-transcription/test/rna_transcription_test.exs create mode 100644 elixir/rna-transcription/test/test_helper.exs diff --git a/elixir/rna-transcription/.exercism/config.json b/elixir/rna-transcription/.exercism/config.json new file mode 100644 index 0000000..2f4ada2 --- /dev/null +++ b/elixir/rna-transcription/.exercism/config.json @@ -0,0 +1,36 @@ +{ + "authors": [ + "rubysolo" + ], + "contributors": [ + "angelikatyborska", + "Cohen-Carlisle", + "dalexj", + "devonestes", + "drueck", + "jinyeow", + "lpil", + "neenjaw", + "parkerl", + "pminten", + "sotojuan", + "Teapane", + "tjcelaya", + "veelenga", + "waiting-for-dev" + ], + "files": { + "solution": [ + "lib/rna_transcription.ex" + ], + "test": [ + "test/rna_transcription_test.exs" + ], + "example": [ + ".meta/example.ex" + ] + }, + "blurb": "Given a DNA strand, return its RNA Complement Transcription.", + "source": "Hyperphysics", + "source_url": "https://web.archive.org/web/20220408112140/http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html" +} diff --git a/elixir/rna-transcription/.exercism/metadata.json b/elixir/rna-transcription/.exercism/metadata.json new file mode 100644 index 0000000..8565442 --- /dev/null +++ b/elixir/rna-transcription/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"elixir","exercise":"rna-transcription","id":"63ab8e36c9144f84a7fdc34eb6d56856","url":"https://exercism.org/tracks/elixir/exercises/rna-transcription","handle":"negrienko","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/elixir/rna-transcription/.formatter.exs b/elixir/rna-transcription/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/elixir/rna-transcription/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/elixir/rna-transcription/.gitignore b/elixir/rna-transcription/.gitignore new file mode 100644 index 0000000..32ae836 --- /dev/null +++ b/elixir/rna-transcription/.gitignore @@ -0,0 +1,24 @@ +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +rna_transcription-*.tar + diff --git a/elixir/rna-transcription/HELP.md b/elixir/rna-transcription/HELP.md new file mode 100644 index 0000000..53f28a3 --- /dev/null +++ b/elixir/rna-transcription/HELP.md @@ -0,0 +1,75 @@ +# Help + +## Running the tests + +From the terminal, change to the base directory of the exercise then execute the tests with: + +```bash +$ mix test +``` + +This will execute the test file found in the `test` subfolder -- a file ending in `_test.exs` + +Documentation: + +* [`mix test` - Elixir's test execution tool](https://hexdocs.pm/mix/Mix.Tasks.Test.html) +* [`ExUnit` - Elixir's unit test library](https://hexdocs.pm/ex_unit/ExUnit.html) + +## Pending tests + +In test suites of practice exercises, all but the first test have been tagged to be skipped. + +Once you get a test passing, you can unskip the next one by commenting out the relevant `@tag :pending` with a `#` symbol. + +For example: + +```elixir +# @tag :pending +test "shouting" do + assert Bob.hey("WATCH OUT!") == "Whoa, chill out!" +end +``` + +If you wish to run all tests at once, you can include all skipped test by using the `--include` flag on the `mix test` command: + +```bash +$ mix test --include pending +``` + +Or, you can enable all the tests by commenting out the `ExUnit.configure` line in the file `test/test_helper.exs`. + +```elixir +# ExUnit.configure(exclude: :pending, trace: true) +``` + +## Useful `mix test` options + +* `test/.exs:LINENUM` - runs only a single test, the test from `.exs` whose definition is on line `LINENUM` +* `--failed` - runs only tests that failed the last time they ran +* `--max-failures` - the suite stops evaluating tests when this number of test failures +is reached +* `--seed 0` - disables randomization so the tests in a single file will always be ran +in the same order they were defined in + +## Submitting your solution + +You can submit your solution using the `exercism submit lib/rna_transcription.ex` 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 [Elixir track's documentation](https://exercism.org/docs/tracks/elixir) +- The [Elixir track's programming category on the forum](https://forum.exercism.org/c/programming/elixir) +- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +If you're stuck on something, it may help to look at some of the [available resources](https://exercism.org/docs/tracks/elixir/resources) out there where answers might be found. \ No newline at end of file diff --git a/elixir/rna-transcription/README.md b/elixir/rna-transcription/README.md new file mode 100644 index 0000000..b0e6b6e --- /dev/null +++ b/elixir/rna-transcription/README.md @@ -0,0 +1,70 @@ +# RNA Transcription + +Welcome to RNA Transcription on Exercism's Elixir Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Introduction + +You work for a bioengineering company that specializes in developing therapeutic solutions. + +Your team has just been given a new project to develop a targeted therapy for a rare type of cancer. + +~~~~exercism/note +It's all very complicated, but the basic idea is that sometimes people's bodies produce too much of a given protein. +That can cause all sorts of havoc. + +But if you can create a very specific molecule (called a micro-RNA), it can prevent the protein from being produced. + +This technique is called [RNA Interference][rnai]. + +[rnai]: https://admin.acceleratingscience.com/ask-a-scientist/what-is-rnai/ +~~~~ + +## Instructions + +Your task is determine the RNA complement of a given DNA sequence. + +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` + +~~~~exercism/note +If you want to look at how the inputs and outputs are structured, take a look at the examples in the test suite. +~~~~ + +## Source + +### Created by + +- @rubysolo + +### Contributed to by + +- @angelikatyborska +- @Cohen-Carlisle +- @dalexj +- @devonestes +- @drueck +- @jinyeow +- @lpil +- @neenjaw +- @parkerl +- @pminten +- @sotojuan +- @Teapane +- @tjcelaya +- @veelenga +- @waiting-for-dev + +### Based on + +Hyperphysics - https://web.archive.org/web/20220408112140/http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html \ No newline at end of file diff --git a/elixir/rna-transcription/lib/rna_transcription.ex b/elixir/rna-transcription/lib/rna_transcription.ex new file mode 100644 index 0000000..3ee2024 --- /dev/null +++ b/elixir/rna-transcription/lib/rna_transcription.ex @@ -0,0 +1,17 @@ +defmodule RnaTranscription do + @doc """ + Transcribes a character list representing DNA nucleotides to RNA + + ## Examples + + iex> RnaTranscription.to_rna(~c"ACTG") + ~c"UGAC" + """ + @spec to_rna([char]) :: [char] + def to_rna(?G), do: ?C + def to_rna(?C), do: ?G + def to_rna(?T), do: ?A + def to_rna(?A), do: ?U + def to_rna([char | rest]), do: [to_rna(char) | to_rna(rest)] + def to_rna([]), do: [] +end diff --git a/elixir/rna-transcription/mix.exs b/elixir/rna-transcription/mix.exs new file mode 100644 index 0000000..8a2487c --- /dev/null +++ b/elixir/rna-transcription/mix.exs @@ -0,0 +1,28 @@ +defmodule RnaTranscription.MixProject do + use Mix.Project + + def project do + [ + app: :rna_transcription, + version: "0.1.0", + # elixir: "~> 1.8", + start_permanent: Mix.env() == :prod, + deps: deps() + ] + end + + # Run "mix help compile.app" to learn about applications. + def application do + [ + extra_applications: [:logger] + ] + end + + # Run "mix help deps" to learn about dependencies. + defp deps do + [ + # {:dep_from_hexpm, "~> 0.3.0"}, + # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} + ] + end +end diff --git a/elixir/rna-transcription/test/rna_transcription_test.exs b/elixir/rna-transcription/test/rna_transcription_test.exs new file mode 100644 index 0000000..4a6c2be --- /dev/null +++ b/elixir/rna-transcription/test/rna_transcription_test.exs @@ -0,0 +1,28 @@ +defmodule RnaTranscriptionTest do + use ExUnit.Case + + # @tag :pending + test "empty RNA sequence" do + assert RnaTranscription.to_rna(~c"") == ~c"" + end + + test "transcribes guanine to cytosine" do + assert RnaTranscription.to_rna(~c"G") == ~c"C" + end + + test "transcribes cytosine to guanine" do + assert RnaTranscription.to_rna(~c"C") == ~c"G" + end + + test "transcribes thymidine to adenine" do + assert RnaTranscription.to_rna(~c"T") == ~c"A" + end + + test "transcribes adenine to uracil" do + assert RnaTranscription.to_rna(~c"A") == ~c"U" + end + + test "it transcribes all dna nucleotides to rna equivalents" do + assert RnaTranscription.to_rna(~c"ACGTGGTCTTAA") == ~c"UGCACCAGAAUU" + end +end diff --git a/elixir/rna-transcription/test/test_helper.exs b/elixir/rna-transcription/test/test_helper.exs new file mode 100644 index 0000000..35fc5bf --- /dev/null +++ b/elixir/rna-transcription/test/test_helper.exs @@ -0,0 +1,2 @@ +ExUnit.start() +ExUnit.configure(exclude: :pending, trace: true)