Given a single stranded DNA string, compute how many times each nucleotide occurs in the string.
The genetic language of every living thing on the planet is DNA. DNA is a large molecule that is built from an extremely long sequence of individual elements called nucleotides. 4 types exist in DNA and these differ only slightly and can be represented as the following symbols: 'A' for adenine, 'C' for cytosine, 'G' for guanine, and 'T' thymine.
Here is an analogy:
The Calculating DNA Nucleotides_problem at Rosalind http://rosalind.info/problems/dna/
This exercise has been tested on Julia versions >=1.0.
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
In [ ]:
# submit
function count_nucleotides(strand::AbstractString)
end
In [ ]:
using Test
# include("nucleotide-count.jl")
@testset "empty strand" begin
@test count_nucleotides("") == Dict('A' => 0, 'C' => 0, 'G' => 0, 'T' => 0)
end
@testset "strand with repeated nucleotide" begin
@test count_nucleotides("GGGGGGG") == Dict('A' => 0, 'C' => 0, 'G' => 7, 'T' => 0)
end
@testset "strand with multiple nucleotides" begin
@test count_nucleotides("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC") == Dict('A' => 20, 'C' => 12, 'G' => 17, 'T' => 21)
end
@testset "strand with invalid nucleotides" begin
@test_throws DomainError count_nucleotides("AGXXACT")
end
To submit your exercise, you need to save your solution in a file called nucleotide-count.jl
before using the CLI.
You can either create it manually or use the following functions, which will automatically write every notebook cell that starts with # submit
to the file nucleotide-count.jl
.
In [ ]:
# using Pkg; Pkg.add("Exercism")
# using Exercism
# Exercism.create_submission("nucleotide-count")