Last active
August 29, 2015 14:10
-
-
Save paulghaddad/b8565283189c207b003f to your computer and use it in GitHub Desktop.
Exercism: RNA Transcription
This file contains hidden or 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
# Rna Transcription | |
Write a program that, given a DNA strand, returns 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 thymidine (**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` | |
## Source | |
Rosalind [view source](http://rosalind.info/problems/rna) |
This file contains hidden or 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
module Complement | |
DNA_TO_RNA_MAP = { | |
'A' => 'U', | |
'C' => 'G', | |
'G' => 'C', | |
'T' => 'A' | |
} | |
RNA_TO_DNA_MAP = DNA_TO_RNA_MAP.invert | |
def self.of_dna(dna_strand) | |
dna_strand.chars.inject('') { |rna_strand, base| rna_strand << DNA_TO_RNA_MAP[base] } | |
end | |
def self.of_rna(rna_strand) | |
rna_strand.chars.inject('') { |dna_strand, base| dna_strand << RNA_TO_DNA_MAP[base] } | |
end | |
end |
This file contains hidden or 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
require 'minitest/autorun' | |
require_relative 'complement' | |
class ComplementTest < MiniTest::Unit::TestCase | |
def test_rna_complement_of_cytosine_is_guanine | |
assert_equal 'G', Complement.of_dna('C') | |
end | |
def test_rna_complement_of_guanine_is_cytosine | |
assert_equal 'C', Complement.of_dna('G') | |
end | |
def test_rna_complement_of_thymine_is_adenine | |
assert_equal 'A', Complement.of_dna('T') | |
end | |
def test_rna_complement_of_adenine_is_uracil | |
assert_equal 'U', Complement.of_dna('A') | |
end | |
def test_rna_complement | |
assert_equal 'UGCACCAGAAUU', Complement.of_dna('ACGTGGTCTTAA') | |
end | |
def test_dna_complement_of_cytosine_is_guanine | |
assert_equal 'G', Complement.of_rna('C') | |
end | |
def test_dna_complement_of_guanine_is_cytosine | |
assert_equal 'C', Complement.of_rna('G') | |
end | |
def test_dna_complement_of_uracil_is_adenine | |
assert_equal 'A', Complement.of_rna('U') | |
end | |
def test_dna_complement_of_adenine_is_thymine | |
assert_equal 'T', Complement.of_rna('A') | |
end | |
def test_dna_complement | |
assert_equal 'ACTTGGGCTGTAC', Complement.of_rna('UGAACCCGACAUG') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment