Skip to content

Instantly share code, notes, and snippets.

@alexfaber2011
Created September 9, 2015 03:05
Show Gist options
  • Save alexfaber2011/5bc681c0a838c54fb3a1 to your computer and use it in GitHub Desktop.
Save alexfaber2011/5bc681c0a838c54fb3a1 to your computer and use it in GitHub Desktop.
Inverts DNA sequences in the form of strings
(ns sequence-inverter.core
(:gen-class))
(defn invert-char
[char]
(let [char-map {"A" "C"
"C" "A"
"G" "T"
"T" "G"}]
(get char-map char)))
(defn valid-sequence?
[sequence]
(every? #(contains? #{"A" "C" "G" "T"} %) sequence))
(defn invert-sequence
[sequence]
(let [string-sec (vec (map str (.toUpperCase sequence)))]
(if (valid-sequence? string-sec)
(->> string-sec
(map #(invert-char %))
clojure.string/join)
(str "Invalid Sequence"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment