src/nucleotide_count.clj

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(ns nucleotide-count)


(def empty-map {\A 0 \T 0 \C 0 \G 0})

(defn nucleotide-counts [sequence]
  "Count occurrences of nucleotides in sequence"
  (merge
    empty-map
    (into
      {}
      (for [[k v] (group-by identity sequence)]
        [k (count v)]))))

(defn count [nucleotide sequence]
  {:pre [(some #{nucleotide} "ACGT")]}
  "Count occurrences of nucleotide in sequence"
  ((nucleotide-counts sequence) nucleotide))

Comments

Lein gives a warning about replacing count in the namespace. Feel a bit uncomfortable about this as I'm also using core count further up.

helenst commented 26 March 2016 at 10:16 UTC

You're not logged in right now. Please login via GitHub to comment