Permalink
Browse files

small refactoring

  • Loading branch information...
serialhex committed Apr 3, 2013
1 parent cb7bf18 commit ee2459a66fe5e680002bb212ab6c874a66735bfd
Showing with 11 additions and 18 deletions.
  1. +10 −17 src/rosalind/basics.clj
  2. +1 −1 test/rosalind/basics_test.clj
@@ -1,24 +1,17 @@
(ns rosalind.basics)
(defn dna-counter-fn
"This actually does the counting"
[dna cnt]
(let [l (first dna)
r (rest dna)]
(case l
\A (def h (assoc cnt :A (+ 1 (:A cnt))))
\G (def h (assoc cnt :G (+ 1 (:G cnt))))
\C (def h (assoc cnt :C (+ 1 (:C cnt))))
\T (def h (assoc cnt :T (+ 1 (:T cnt))))
nil)
(if (empty? r)
h
(recur r h))))
(defn dna-count
(defn count-dna
"Counts DNA Neucleotides"
[dna]
(let [h (dna-counter-fn dna {:A 0 :C 0 :T 0 :G 0})]
(let [h (reduce (fn [c base]
(case base
\A (assoc c :A (+ 1 (:A c)))
\G (assoc c :G (+ 1 (:G c)))
\C (assoc c :C (+ 1 (:C c)))
\T (assoc c :T (+ 1 (:T c)))
nil))
{:A 0 :C 0 :T 0 :G 0}
dna)]
[(:A h) (:C h) (:G h) (:T h)]))
(defn transcribe-dna
@@ -6,7 +6,7 @@
(testing "Counting DNA Nucleotides"
(is (=
[20 12 17 21]
(dna-count "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"))))
(count-dna "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"))))
(testing "Transcribing DNA into RNA"
(is (= "GAUGGAACUUGACUACGUAAAUU"

0 comments on commit ee2459a

Please sign in to comment.