Skip to content

Commit ba01794

Browse files
authored
nucleotide-count (#16)
1 parent 3f91788 commit ba01794

File tree

9 files changed

+138
-0
lines changed

9 files changed

+138
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@
110110
"practices": [],
111111
"prerequisites": [],
112112
"difficulty": 2
113+
},
114+
{
115+
"slug": "nucleotide-count",
116+
"name": "Nucleotide Count",
117+
"uuid": "9a2d0b74-0cba-464d-a960-8f7469be50a1",
118+
"practices": [],
119+
"prerequisites": [],
120+
"difficulty": 2
113121
}
114122
]
115123
},
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
return {
2+
default = {
3+
ROOT = { '.' }
4+
}
5+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Instructions
2+
3+
Each of us inherits from our biological parents a set of chemical instructions known as DNA that influence how our bodies are constructed.
4+
All known life depends on DNA!
5+
6+
> Note: You do not need to understand anything about nucleotides or DNA to complete this exercise.
7+
8+
DNA is a long chain of other chemicals and the most important are the four nucleotides, adenine, cytosine, guanine and thymine.
9+
A single DNA chain can contain billions of these four nucleotides and the order in which they occur is important!
10+
We call the order of these nucleotides in a bit of DNA a "DNA sequence".
11+
12+
We represent a DNA sequence as an ordered collection of these four nucleotides and a common way to do that is with a string of characters such as "ATTACG" for a DNA sequence of 6 nucleotides.
13+
'A' for adenine, 'C' for cytosine, 'G' for guanine, and 'T' for thymine.
14+
15+
Given a string representing a DNA sequence, count how many of each nucleotide is present.
16+
If the string contains characters that aren't A, C, G, or T then it is invalid and you should signal an error.
17+
18+
For example:
19+
20+
```text
21+
"GATTACA" -> 'A': 3, 'C': 1, 'G': 1, 'T': 2
22+
"INVALID" -> error
23+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"glennj"
4+
],
5+
"files": {
6+
"solution": [
7+
"nucleotide_count.moon"
8+
],
9+
"test": [
10+
"nucleotide_count_spec.moon"
11+
],
12+
"example": [
13+
".meta/example.moon"
14+
]
15+
},
16+
"blurb": "Given a DNA string, compute how many times each nucleotide occurs in the string.",
17+
"source": "The Calculating DNA Nucleotides_problem at Rosalind",
18+
"source_url": "https://rosalind.info/problems/dna/"
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
return (strand) ->
2+
counts = A: 0, C: 0, G: 0, T: 0
3+
4+
for char in strand\gmatch(".")
5+
error 'Invalid nucleotide in strand' unless counts[char]
6+
counts[char] += 1
7+
8+
counts
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
module_name: 'nucleotide_count',
3+
4+
generate_test: (case, level) ->
5+
local lines
6+
if case.expected.error
7+
lines = {
8+
"f = -> nucleotide_count '#{case.input.strand}'",
9+
"assert.has.errors f, '#{case.expected.error}'"
10+
}
11+
else
12+
-- use "same", not "equal", to compare tables
13+
lines = {
14+
"expected = A: #{case.expected.A}, C: #{case.expected.C}, G: #{case.expected.G}, T: #{case.expected.T}"
15+
"result = nucleotide_count '#{case.input.strand}'",
16+
"assert.are.same expected, result"
17+
}
18+
19+
table.concat [indent line, level for line in *lines], '\n'
20+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[3e5c30a8-87e2-4845-a815-a49671ade970]
13+
description = "empty strand"
14+
15+
[a0ea42a6-06d9-4ac6-828c-7ccaccf98fec]
16+
description = "can count one nucleotide in single-character input"
17+
18+
[eca0d565-ed8c-43e7-9033-6cefbf5115b5]
19+
description = "strand with repeated nucleotide"
20+
21+
[40a45eac-c83f-4740-901a-20b22d15a39f]
22+
description = "strand with multiple nucleotides"
23+
24+
[b4c47851-ee9e-4b0a-be70-a86e343bd851]
25+
description = "strand with invalid nucleotides"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
counter = (strand) ->
2+
error 'Implement me'
3+
4+
return counter
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
nucleotide_count = require 'nucleotide_count'
2+
3+
describe 'nucleotide-count', ->
4+
it 'empty strand', ->
5+
expected = A: 0, C: 0, G: 0, T: 0
6+
result = nucleotide_count ''
7+
assert.are.same expected, result
8+
9+
pending 'can count one nucleotide in single-character input', ->
10+
expected = A: 0, C: 0, G: 1, T: 0
11+
result = nucleotide_count 'G'
12+
assert.are.same expected, result
13+
14+
pending 'strand with repeated nucleotide', ->
15+
expected = A: 0, C: 0, G: 7, T: 0
16+
result = nucleotide_count 'GGGGGGG'
17+
assert.are.same expected, result
18+
19+
pending 'strand with multiple nucleotides', ->
20+
expected = A: 20, C: 12, G: 17, T: 21
21+
result = nucleotide_count 'AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC'
22+
assert.are.same expected, result
23+
24+
pending 'strand with invalid nucleotides', ->
25+
f = -> nucleotide_count 'AGXXACT'
26+
assert.has.errors f, 'Invalid nucleotide in strand'

0 commit comments

Comments
 (0)