Skip to content

Commit ee2459a

Browse files
committed
small refactoring
1 parent cb7bf18 commit ee2459a

2 files changed

Lines changed: 11 additions & 18 deletions

File tree

‎src/rosalind/basics.clj‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
(ns rosalind.basics)
22

3-
(defn dna-counter-fn
4-
"This actually does the counting"
5-
[dna cnt]
6-
(let [l (first dna)
7-
r (rest dna)]
8-
(case l
9-
\A (def h (assoc cnt :A (+ 1 (:A cnt))))
10-
\G (def h (assoc cnt :G (+ 1 (:G cnt))))
11-
\C (def h (assoc cnt :C (+ 1 (:C cnt))))
12-
\T (def h (assoc cnt :T (+ 1 (:T cnt))))
13-
nil)
14-
(if (empty? r)
15-
h
16-
(recur r h))))
17-
18-
(defn dna-count
3+
(defn count-dna
194
"Counts DNA Neucleotides"
205
[dna]
21-
(let [h (dna-counter-fn dna {:A 0 :C 0 :T 0 :G 0})]
6+
(let [h (reduce (fn [c base]
7+
(case base
8+
\A (assoc c :A (+ 1 (:A c)))
9+
\G (assoc c :G (+ 1 (:G c)))
10+
\C (assoc c :C (+ 1 (:C c)))
11+
\T (assoc c :T (+ 1 (:T c)))
12+
nil))
13+
{:A 0 :C 0 :T 0 :G 0}
14+
dna)]
2215
[(:A h) (:C h) (:G h) (:T h)]))
2316

2417
(defn transcribe-dna

‎test/rosalind/basics_test.clj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(testing "Counting DNA Nucleotides"
77
(is (=
88
[20 12 17 21]
9-
(dna-count "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"))))
9+
(count-dna "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"))))
1010

1111
(testing "Transcribing DNA into RNA"
1212
(is (= "GAUGGAACUUGACUACGUAAAUU"

0 commit comments

Comments
 (0)