Skip to content

Instantly share code, notes, and snippets.

@erasmas
Last active December 21, 2015 07:48
Show Gist options
  • Save erasmas/6273272 to your computer and use it in GitHub Desktop.
Save erasmas/6273272 to your computer and use it in GitHub Desktop.
(use 'clojure.java.io)
(defn read-lines [file]
(with-open [rdr (reader file)]
(doall (line-seq rdr))))
(defn dna-reverse-complement [dna]
"Takes a DNA string and returns it's reverse complement"
(apply str (map (fn [x]
(cond
(= x \A) \T
(= x \T) \A
(= x \G) \C
(= x \C) \G
:else x))
(reverse dna))))
(defn dna-reverse-complement2 [s]
(let [reversed-dna (reverse s)
pairs {\T \A, \A \T, \G \C, \C \G}]
(apply str (map pairs reversed-dna))))
(defn hamming-distance [s t]
(reduce + (map #(if (= % %2) 0 1) s t)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment