From dc5e05a03a7d3d467160ba9cc93486b24f24ecc1 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Thu, 16 Jul 2020 20:35:10 -0300 Subject: [PATCH] DNA -> RNA transformation --- elixir/rna-transcription/README.md | 61 +++++++++++++++++++ .../lib/rna_transcription.ex | 24 ++++++++ elixir/rna-transcription/mix.exs | 28 +++++++++ .../test/rna_transcription_test.exs | 28 +++++++++ elixir/rna-transcription/test/test_helper.exs | 2 + 5 files changed, 143 insertions(+) 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/README.md b/elixir/rna-transcription/README.md new file mode 100644 index 0000000..05c0c4a --- /dev/null +++ b/elixir/rna-transcription/README.md @@ -0,0 +1,61 @@ +# 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` + +## Running tests + +Execute the tests with: + +```bash +$ mix test +``` + +### Pending tests + +In the test suites, all but the first test have been 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 +``` + +Or, you can enable all the tests by commenting out the +`ExUnit.configure` line in the test suite. + +```elixir +# ExUnit.configure exclude: :pending, trace: true +``` + +If you're stuck on something, it may help to look at some of +the [available resources](https://exercism.io/tracks/elixir/resources) +out there where answers might be found. + +## Source + +Hyperphysics [http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html](http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/elixir/rna-transcription/lib/rna_transcription.ex b/elixir/rna-transcription/lib/rna_transcription.ex new file mode 100644 index 0000000..531cd83 --- /dev/null +++ b/elixir/rna-transcription/lib/rna_transcription.ex @@ -0,0 +1,24 @@ +defmodule RnaTranscription do + @doc """ + Transcribes a character list representing DNA nucleotides to RNA + + ## Examples + + iex> RnaTranscription.to_rna('ACTG') + 'UGAC' + """ + @spec to_rna([char]) :: [char] + def to_rna(dna) do + Enum.map(dna, &(dna_to_rna(&1))) + end + + @spec dna_to_rna(char) :: char + def dna_to_rna(strand) do + case strand do + ?A -> ?U + ?C -> ?G + ?T -> ?A + ?G -> ?C + end + end +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..b39a23c --- /dev/null +++ b/elixir/rna-transcription/test/rna_transcription_test.exs @@ -0,0 +1,28 @@ +defmodule RnaTranscriptionTest do + use ExUnit.Case + + # @tag :pending + test "transcribes guanine to cytosine" do + assert RnaTranscription.to_rna('G') == 'C' + end + + # @tag :pending + test "transcribes cytosine to guanine" do + assert RnaTranscription.to_rna('C') == 'G' + end + + # @tag :pending + test "transcribes thymidine to adenine" do + assert RnaTranscription.to_rna('T') == 'A' + end + + # @tag :pending + test "transcribes adenine to uracil" do + assert RnaTranscription.to_rna('A') == 'U' + end + + # @tag :pending + test "it transcribes all dna nucleotides to rna equivalents" do + assert RnaTranscription.to_rna('ACGTGGTCTTAA') == '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)