forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exercise: rna-transcription (JuliaLang#19)
* Init exercise: rna-transcription * Add exercise: rna-transcription * Modified formatting and error in config for rna-transcription exercise
- Loading branch information
1 parent
34ba97c
commit 1b0fd4a
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# 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 | ||
function to_rna(dna::AbstractString) | ||
typeof(match(r"^[GCTA]+$", dna)) == Void && error("Invalid RNA strand") | ||
# Define character associations | ||
a_nucleotides = Dict('G'=>'C', 'C'=>'G', 'T'=>'A', 'A'=>'U') | ||
# Replace characters using dictionary | ||
map((x)->a_nucleotides[x], dna) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function to_rna(dna::AbstractString) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Base.Test | ||
|
||
include("rna-transcription.jl") | ||
|
||
@testset "basic transformations" begin | ||
@testset "rna complement of cytosine is guanine" begin | ||
@test to_rna("C") == "G" | ||
end | ||
|
||
@testset "rna complement of guanine is cytosine" begin | ||
@test to_rna("G") == "C" | ||
end | ||
|
||
@testset "rna complement of thymine is adenine" begin | ||
@test to_rna("T") == "A" | ||
end | ||
|
||
@testset "rna complement of adenine is uracil" begin | ||
@test to_rna("A") == "U" | ||
end | ||
end | ||
|
||
@testset "rna complement" begin | ||
@test to_rna("ACGTGGTCTTAA") == "UGCACCAGAAUU" | ||
end | ||
|
||
@testset "error handling" begin | ||
@testset "dna correctly handles invalid input" begin | ||
@test_throws ErrorException to_rna("U") | ||
end | ||
|
||
@testset "dna correctly handles completely invalid input" begin | ||
@test_throws ErrorException to_rna("XXX") | ||
end | ||
|
||
@testset "dna correctly handles partially invalid input" begin | ||
@test_throws ErrorException to_rna("ACGTXXXCTTAA") | ||
end | ||
end | ||
|