Other Clojure solutions.
(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 Elm solutions.
module RNATranscription exposing (toRNA)
nucleotideComplement : Char -> Char
nucleotideComplement n =
case n of
'A' ->
'U'
'C' ->
'G'
'T' ->
'A'
'G' ->
'C'
_ ->
' '
toRNA : String -> Result Char String
toRNA dna =
Ok
(String.toList dna
|> List.map nucleotideComplement
|> String.fromList
)
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