Commits

Steve Losh committed 7f4e634

Do the first few problems.

Comments (0)

Files changed (9)

+syntax:glob
+target/
+lib/
+classes/
+checkouts/
+pom.xml
+*.jar
+*.class
+.lein-deps-sum
+.lein-failures
+.lein-plugins
+# Rosalind
+
+My Clojure solutions to [Rosalind][] problems.
+
+[Rosalind]: http://rosalind.info
+
+## License
+
+MIT/X11
+(defproject rosalind "0.1.0-SNAPSHOT"
+  :description "FIXME: write description"
+  :url "http://example.com/FIXME"
+  :license {:name "Eclipse Public License"
+            :url "http://www.eclipse.org/legal/epl-v10.html"}
+  :dependencies [[org.clojure/clojure "1.4.0"]
+                 [the/parsatron "0.0.3"]
+                 [org.clojure/math.combinatorics "0.0.3"]
+                 ])

src/rosalind/p001.clj

+(ns rosalind.p001
+  (:require [clojure.string :refer [join]]))
+
+(defn solve [s]
+  (println (join " " (map (frequencies s) "ACGT"))))
+
+(solve "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC")
+
+(solve (slurp "/Users/sjl/Downloads/rosalind_dna.txt"))

src/rosalind/p002.clj

+(ns rosalind.p002
+  (:refer-clojure :exclude [replace])
+  (:require [clojure.string :refer [replace]]))
+
+
+(defn solve [s]
+  (replace s "T" "U"))
+
+(solve "GATGGAACTTGACTACGTAAATT")
+
+(solve (slurp "/Users/sjl/Downloads/rosalind_rna.txt"))

src/rosalind/p003.clj

+(ns rosalind.p003
+  (:require [clojure.string :refer [join]]))
+
+(def nucleotide-complement
+  {\A \T
+   \C \G
+   \T \A
+   \G \C})
+
+
+(defn solve [s]
+  (join "" (map nucleotide-complement (reverse s))))
+
+(solve "AAAACCCGGT")
+
+(print (solve (slurp "/Users/sjl/Downloads/rosalind_revc.txt"))) 

src/rosalind/p004.clj

+(ns rosalind.p004
+  (:refer-clojure :exclude [char])
+  (:require [the.parsatron :refer [defparser many1 always run string digit char
+                                   eof let->> token between]]))
+
+(defparser number []
+  (let->> [ds (many1 (digit))]
+    (always (apply str ds))))
+
+(defparser dna-line []
+  (let->> [nts (many1 (token #{\G \T \C \A}))
+           _ (char \newline)]
+    (always (apply str nts))))
+
+(defparser dna []
+  (let->> [ntls (many1 (dna-line))]
+    (always (apply str ntls))))
+
+(defparser header []
+  (between (string ">Rosalind_") (char \newline)
+           (number)))
+
+(defparser chunk []
+  (let->> [id (header)
+           content (dna)]
+    (always [id content])))
+
+(defparser file []
+  (let->> [chunks (many1 (chunk))
+           _ (eof)
+           ]
+    (always chunks)))
+
+(defn parse [s]
+  (run (file) s))
+
+(def sample
+">Rosalind_6404
+CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC
+TCCCACTAATAATTCTGAGG
+>Rosalind_5959
+CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT
+ATATCCATTTGTCAGCAGACACGC
+>Rosalind_0808
+CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC
+TGGGAACCTGCGGGCAGTAGGTGGAAT
+"
+)
+
+(defn gc-content [dna]
+  (float (/ (count (filter #{\G \C} dna))
+            (count dna))))
+
+(defn solve [s]
+  (let [[id gcc] (last (sort-by second
+                                 (map (juxt first (comp gc-content second))
+                                      (parse s))))]
+    (println (str "Rosalind_" id))
+    (println (str (* 100 gcc) "%"))))
+
+(solve sample)
+
+(solve (slurp "/Users/sjl/Downloads/rosalind_gc.txt"))

src/rosalind/p005.clj

+(ns rosalind.p005
+  (:require [clojure.string :refer [split-lines trim]]))
+
+(defn hamming [s t]
+  (count (filter identity (map not= s t))))
+
+(def sample
+"GAGCCTACTAACGGGAT
+CATCGTAATGACGGCCT")
+
+(defn solve [s]
+  (println (apply hamming
+                  (-> s trim split-lines))))
+
+(solve sample)
+
+(print (solve (slurp "/Users/sjl/Downloads/rosalind_hamm.txt"))) 

src/rosalind/p006.clj

+(ns rosalind.p006
+  (:require [clojure.math.combinatorics :refer [permutations]]
+            [clojure.string :refer [join trim]]))
+
+(def sample "3")
+
+(defn solve [s]
+  (let [ps (permutations (range 1 (inc (Long/parseLong (trim s)))))]
+    (println (count ps))
+    (dorun (map #(println (join " " %)) ps))))
+
+(solve sample)
+
+(solve (slurp "/Users/sjl/Downloads/rosalind_perm.txt")) 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.