Skip to content

Instantly share code, notes, and snippets.

@boddhisattva
Last active October 24, 2018 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boddhisattva/bb5b584605c6b6f1870862c73e754cb9 to your computer and use it in GitHub Desktop.
Save boddhisattva/bb5b584605c6b6f1870862c73e754cb9 to your computer and use it in GitHub Desktop.
RNA Transcription Exercise - Elixir
defmodule RNATranscription do
@guanine "G"
@adenine "A"
@cystosine "C"
@uracil "U"
@thymine "T"
@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
rna_strand =
Enum.map(String.graphemes(to_string(dna)), fn dna_char ->
case dna_char do
@guanine -> @cystosine
@cystosine -> @guanine
@thymine -> @adenine
@adenine -> @uracil
_ -> "Error"
end
end)
rna_strand
|> to_string
|> to_charlist
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment