7f4e6345e260

Do the first few problems.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 12 Nov 2012 12:36:49 -0500
parents
children c025fc91d497
branches/tags (none)
files .hgignore README.markdown project.clj src/rosalind/p001.clj src/rosalind/p002.clj src/rosalind/p003.clj src/rosalind/p004.clj src/rosalind/p005.clj src/rosalind/p006.clj

Changes

--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Mon Nov 12 12:36:49 2012 -0500
@@ -0,0 +1,11 @@
+syntax:glob
+target/
+lib/
+classes/
+checkouts/
+pom.xml
+*.jar
+*.class
+.lein-deps-sum
+.lein-failures
+.lein-plugins
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.markdown	Mon Nov 12 12:36:49 2012 -0500
@@ -0,0 +1,9 @@
+# Rosalind
+
+My Clojure solutions to [Rosalind][] problems.
+
+[Rosalind]: http://rosalind.info
+
+## License
+
+MIT/X11
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project.clj	Mon Nov 12 12:36:49 2012 -0500
@@ -0,0 +1,9 @@
+(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"]
+                 ])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/rosalind/p001.clj	Mon Nov 12 12:36:49 2012 -0500
@@ -0,0 +1,9 @@
+(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"))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/rosalind/p002.clj	Mon Nov 12 12:36:49 2012 -0500
@@ -0,0 +1,11 @@
+(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"))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/rosalind/p003.clj	Mon Nov 12 12:36:49 2012 -0500
@@ -0,0 +1,16 @@
+(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"))) 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/rosalind/p004.clj	Mon Nov 12 12:36:49 2012 -0500
@@ -0,0 +1,63 @@
+(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"))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/rosalind/p005.clj	Mon Nov 12 12:36:49 2012 -0500
@@ -0,0 +1,17 @@
+(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"))) 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/rosalind/p006.clj	Mon Nov 12 12:36:49 2012 -0500
@@ -0,0 +1,14 @@
+(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"))