Last active
February 1, 2023 23:35
-
-
Save KevinDaSilvaS/fe6057b96313a6e9edc110d0ee9aa07c to your computer and use it in GitHub Desktop.
DNA -> RNA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule RnaTranscription do | |
def to_rna(dna) do | |
to_string(dna) | |
|> String.split("", trim: true) | |
|> Enum.map(fn "G" -> "C" | |
"C" -> "G" | |
"T" -> "A" | |
"A" -> "U" | |
end) | |
|> Enum.join("") | |
|> to_charlist() | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
toRna [] = "" | |
toRna ('G':xs) = 'C':toRna xs | |
toRna ('C':xs) = 'G':toRna xs | |
toRna ('T':xs) = 'A':toRna xs | |
toRna ('A':xs) = 'U':toRna xs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sequenceencoder(x) | |
if x == "G" | |
"C" | |
elseif x == "C" | |
"G" | |
elseif x == "T" | |
"A" | |
elseif x == "A" | |
"U" | |
end | |
end | |
function torna(dna) | |
splitedSequence = collect(eachsplit(dna, "")) | |
if first(splitedSequence) == "" | |
return "" | |
end | |
encodedseq = map(sequenceencoder, splitedSequence) | |
join(encodedseq) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const toRna = dna => { | |
const encoder = { | |
"G": "C", | |
"C": "G", | |
"T": "A", | |
"A": "U" | |
} | |
return dna.split("") | |
.map(x => encoder[x]) | |
.reduce((acc, x) => `${acc}${x}`, "") | |
} | |
console.log(toRna("") == "") | |
console.log(toRna("A") == "U") | |
console.log(toRna("ACGTGGTCTTAA") == "UGCACCAGAAUU") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn to_rna(dna string) string { | |
runes := dna.runes() | |
return runes.map(fn (x rune) string { | |
return match x { | |
`G` { "C" } | |
`C` { "G" } | |
`T` { "A" } | |
`A` { "U" } | |
else { "" } | |
} | |
}).join("") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function torna(dna) | |
encoder = Dict( | |
"G"=>"C", | |
"C"=>"G", | |
"T"=>"A", | |
"A"=>"U" | |
) | |
splitedSequence = collect(eachsplit(dna, "")) | |
encodedseq = map(x -> get(encoder, "$x", ""), splitedSequence) | |
join(encodedseq) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assert RnaTranscription.to_rna('') == '' | |
assert RnaTranscription.to_rna('G') == 'C' | |
assert RnaTranscription.to_rna('C') == 'G' | |
assert RnaTranscription.to_rna('T') == 'A' | |
assert RnaTranscription.to_rna('A') == 'U' | |
assert RnaTranscription.to_rna('ACGTGGTCTTAA') == 'UGCACCAGAAUU' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment