diff options
Diffstat (limited to 'raku/nucleotide-count')
-rw-r--r-- | raku/nucleotide-count/NucleotideCount.rakumod | 6 | ||||
-rw-r--r-- | raku/nucleotide-count/README.md | 36 | ||||
-rw-r--r-- | raku/nucleotide-count/nucleotide-count.rakutest | 95 |
3 files changed, 137 insertions, 0 deletions
diff --git a/raku/nucleotide-count/NucleotideCount.rakumod b/raku/nucleotide-count/NucleotideCount.rakumod new file mode 100644 index 0000000..03bae38 --- /dev/null +++ b/raku/nucleotide-count/NucleotideCount.rakumod @@ -0,0 +1,6 @@ +unit module NucleotideCount; + +subset DNA of Str where * !~~ /<-[ACGT]>/; +sub nucleotide-count (DNA $strand) is export { + $strand.comb.Bag; +} diff --git a/raku/nucleotide-count/README.md b/raku/nucleotide-count/README.md new file mode 100644 index 0000000..7ac2b56 --- /dev/null +++ b/raku/nucleotide-count/README.md @@ -0,0 +1,36 @@ +# Nucleotide Count + +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: +- twigs are to birds nests as +- nucleotides are to DNA as +- legos are to lego houses as +- words are to sentences as... + +## Resources + +Remember to check out the Raku [documentation](https://docs.raku.org/) and +[resources](https://raku.org/resources/) pages for information, tips, and +examples if you get stuck. + +## Running the tests + +There is a test suite and module included with the exercise. +The test suite (a file with the extension `.rakutest`) will attempt to run routines +from the module (a file with the extension `.rakumod`). +Add/modify routines in the module so that the tests will pass! You can view the +test data by executing the command `raku --doc *.rakutest` (\* being the name of the +test suite), and run the test suite for the exercise by executing the command +`prove6 .` in the exercise directory. + +## Source + +The Calculating DNA Nucleotides_problem at Rosalind [http://rosalind.info/problems/dna/](http://rosalind.info/problems/dna/) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/raku/nucleotide-count/nucleotide-count.rakutest b/raku/nucleotide-count/nucleotide-count.rakutest new file mode 100644 index 0000000..51e405a --- /dev/null +++ b/raku/nucleotide-count/nucleotide-count.rakutest @@ -0,0 +1,95 @@ +#!/usr/bin/env raku +use Test; +use JSON::Fast; +use lib $?FILE.IO.dirname; +use NucleotideCount; +plan 5; + +my @test-cases = from-json($=pod.pop.contents).List; +for @test-cases -> %case { + given %case<expected> { + when .<error>.so { + throws-like + { nucleotide-count %case<input><strand> }, + Exception, + message => / + $( %case<expected><error> ) + || 'Constraint type check failed in binding to parameter' + /, + %case<description>; + } + + default { + cmp-ok nucleotide-count(%case<input><strand>), + '~~', %case<expected>.Bag, %case<description>; + } + } +} + +=head2 Test Cases +=begin code +[ + { + "description": "count all nucleotides in a strand: empty strand", + "expected": { + "A": 0, + "C": 0, + "G": 0, + "T": 0 + }, + "input": { + "strand": "" + }, + "property": "nucleotideCounts" + }, + { + "description": "count all nucleotides in a strand: can count one nucleotide in single-character input", + "expected": { + "A": 0, + "C": 0, + "G": 1, + "T": 0 + }, + "input": { + "strand": "G" + }, + "property": "nucleotideCounts" + }, + { + "description": "count all nucleotides in a strand: strand with repeated nucleotide", + "expected": { + "A": 0, + "C": 0, + "G": 7, + "T": 0 + }, + "input": { + "strand": "GGGGGGG" + }, + "property": "nucleotideCounts" + }, + { + "description": "count all nucleotides in a strand: strand with multiple nucleotides", + "expected": { + "A": 20, + "C": 12, + "G": 17, + "T": 21 + }, + "input": { + "strand": "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC" + }, + "property": "nucleotideCounts" + }, + { + "description": "count all nucleotides in a strand: strand with invalid nucleotides", + "expected": { + "error": "Invalid nucleotide in strand" + }, + "input": { + "strand": "AGXXACT" + }, + "property": "nucleotideCounts" + } +] +=end code |