Created
June 29, 2014 09:53
-
-
Save trikitrok/e70d659c53990a7ead20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns dna) | |
(def dna-nucleotides #{\A, \T, \C, \G}) | |
(def nucleotides (conj dna-nucleotides \U)) | |
(defn nucleotide-counts [strand] | |
(let | |
[counted-nucleotides | |
(zipmap dna-nucleotides (repeat (count dna-nucleotides) 0)) | |
count | |
(fn [counted-nucleotides nucleotide] | |
(assoc | |
counted-nucleotides | |
nucleotide | |
(+ (get counted-nucleotides nucleotide) 1)))] | |
(reduce count counted-nucleotides strand))) | |
(defn count [nucleotide strand] | |
(if (contains? nucleotides nucleotide) | |
(get (nucleotide-counts strand) nucleotide 0) | |
(throw (Exception. "invalid nucleotide")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment