Created
June 14, 2010 13:12
-
-
Save timyates/437658 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 user) | |
(defn- reverse-base [base] | |
(let [mapping { :A \T :T \A :G \C :C \G } | |
key (keyword (.toString base))] | |
(key mapping))) | |
(defn reverse-complement [sequence] | |
(let [rev-seq (reverse (.toUpperCase sequence))] | |
(map reverse-base rev-seq))) | |
(println "Reverse complement gives" (reverse-complement "TGAC")) |
Thanks for that link. Does help to clear it up at least a little bit for me. Trouble is that the core 'complement' cannot be easily accessed then (apart from prepending "clojure.core/"). Would be nice if we could say:
(println bio/complement(bio/reverse-str "TGACC"))
i.e. adding "bio" in front.
@wmacgyver: This is the code that we're trying to get going:
(ns bio)
(defn reverse-str
"Reverse a string"
[s]
(apply str (reverse s))
)
(defn complement
"Complement a base"
[base]
(let [mapping { :A \T :T \A :G \C :C \G }
key (keyword (.toString base))]
(key mapping)))
)
(println bio/complement (bio/reverse-str "TGACC"))
Output should be: "GGTCA"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You might be able to use something like the following to exclude 'complement' from the namespace:
http://stackoverflow.com/questions/2832582/how-to-rename-an-operation-in-clojure/2834069#2834069
(That example excludes + but the principle should be the same)
To be honest though, I'm not sure... Namespaces are the one major thing in clojure which don't currently fit in my brain (which comes from C, Java and Groovy which all seem to follow the same or similar forms) :-(