Other Clojure solutions. ;; 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).
(ns rna-transcription)
(defn to-rna [dna]
(let [dna-to-rna (fn [n] (condp = n
\G \C
\C \G
\T \A
\A \U
(assert false (format "%s is not a valid nucleotide" n))))]
(apply str (map dna-to-rna dna))))
Other Elixir solutions. defmodule RnaTranscription do
@transcription %{
?G => ?C,
?C => ?G,
?T => ?A,
?A => ?U
}
@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,
fn c -> Map.fetch!(@transcription, c) end
)
end
end
Other Haskell solutions. module DNA (toRNA) where
import qualified Data.Map as M
translation :: M.Map Char Char
translation =
M.fromList
[ ('G', 'C'),
('C', 'G'),
('T', 'A'),
('A', 'U')
]
toRNA :: String -> Either Char String
toRNA =
mapM translate
where
translate dna = case M.lookup dna translation of
Just rna -> Right rna
Nothing -> Left dna
Other Roc solutions. module [toRna]
toRna : Str -> Str
toRna = \dna ->
dna
|> Str.toUtf8
|> List.map nucleoTideComplement
|> Str.fromUtf8
|> Result.withDefault ""
nucleoTideComplement = \n ->
when n is
'G' -> 'C'
'C' -> 'G'
'T' -> 'A'
'A' -> 'U'
_ -> n