Commits

Steve Losh  committed c025fc9

Two more.

  • Participants
  • Parent commits 7f4e634

Comments (0)

Files changed (3)

   :dependencies [[org.clojure/clojure "1.4.0"]
                  [the/parsatron "0.0.3"]
                  [org.clojure/math.combinatorics "0.0.3"]
-                 ])
+                 [roul "0.2.0"]])

File src/rosalind/p007.clj

+(ns rosalind.p007
+  (:require [clojure.string :as s]))
+
+(def sample "0.23 0.31 0.75")
+
+(defn content-probs [gcc]
+  (let [gc (/ gcc 2)
+        at (/ (- 1 gcc) 2)]
+    {:g gc
+     :c gc
+     :a at
+     :t at}))
+
+(defn chance-of-twice [prob]
+  (* prob prob))
+
+(defn solve [s]
+  (let [gccs (map #(Float/parseFloat %)
+                  (s/split (s/trim s) #"\s+"))]
+  (println (s/join " "
+                   (for [gcc gccs]
+                     (reduce + (map chance-of-twice
+                                    (vals (content-probs gcc)))))))))
+
+(solve sample)
+
+(solve (slurp "/Users/sjl/Downloads/rosalind_prob.txt")) 

File src/rosalind/p008.clj

+(ns rosalind.p008
+  (:require [clojure.string :as s]))
+
+
+(def sample "AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA")
+
+(def acid
+  {"UUU" \F
+   "CUU" \L
+   "AUU" \I
+   "GUU" \V
+   "UUC" \F
+   "CUC" \L
+   "AUC" \I
+   "GUC" \V
+   "UUA" \L
+   "CUA" \L
+   "AUA" \I
+   "GUA" \V
+   "UUG" \L
+   "CUG" \L
+   "AUG" \M
+   "GUG" \V
+   "UCU" \S
+   "CCU" \P
+   "ACU" \T
+   "GCU" \A
+   "UCC" \S
+   "CCC" \P
+   "ACC" \T
+   "GCC" \A
+   "UCA" \S
+   "CCA" \P
+   "ACA" \T
+   "GCA" \A
+   "UCG" \S
+   "CCG" \P
+   "ACG" \T
+   "GCG" \A
+   "UAU" \Y
+   "CAU" \H
+   "AAU" \N
+   "GAU" \D
+   "UAC" \Y
+   "CAC" \H
+   "AAC" \N
+   "GAC" \D
+   "UAA" nil
+   "CAA" \Q
+   "AAA" \K
+   "GAA" \E
+   "UAG" nil
+   "CAG" \Q
+   "AAG" \K
+   "GAG" \E
+   "UGU" \C
+   "CGU" \R
+   "AGU" \S
+   "GGU" \G
+   "UGC" \C
+   "CGC" \R
+   "AGC" \S
+   "GGC" \G
+   "UGA" nil
+   "CGA" \R
+   "AGA" \R
+   "GGA" \G
+   "UGG" \W
+   "CGG" \R
+   "AGG" \R
+   "GGG" \G})
+
+
+(defn solve [s]
+  (println (->> s
+    s/trim
+    (partition 3)
+    (map s/join)
+    (map acid)
+    s/join)))
+
+(solve sample)
+
+(solve (slurp "/Users/sjl/Downloads/rosalind_prot.txt"))