File tree Expand file tree Collapse file tree 10 files changed +124
-119
lines changed Expand file tree Collapse file tree 10 files changed +124
-119
lines changed Original file line number Diff line number Diff line change 1
1
rosalind
2
- ========
2
+ =======
3
+
Original file line number Diff line number Diff line change
1
+ # Introduction to rosalind
2
+
3
+ TODO: write [ great documentation] ( http://jacobian.org/writing/great-documentation/what-to-write/ )
Original file line number Diff line number Diff line change 1
1
(defproject rosalind " 0.1.0-SNAPSHOT"
2
- :description " FIXME: write description "
3
- :url " http://example .com/FIXME "
2
+ :description " Project Rosalind problems in Clojure "
3
+ :url " http://github .com/tmoerman/rosalind "
4
4
:license {:name " Eclipse Public License"
5
5
:url " http://www.eclipse.org/legal/epl-v10.html" }
6
- :dependencies [[org.clojure/clojure " 1.5.1" ]])
6
+ :dependencies [[org.clojure/clojure " 1.5.1" ]]
7
+ :main rosalind.core )
Original file line number Diff line number Diff line change 1
- (ns rosalind.core )
1
+ (ns rosalind.core
2
+ (:gen-class ))
2
3
3
- (defn foo
4
- " I don't do a whole lot."
5
- [x]
6
- (println x " Hello, World!" ))
4
+ (defn -main [& args]
5
+ (prn " Project Rosalind in Clojure" ))
Original file line number Diff line number Diff line change
1
+ (ns rosalind.dna
2
+ (:use clojure.java.io)
3
+ (:use [clojure.string :only (trim )]))
4
+
5
+ ; ;
6
+ ; ; http://rosalind.info/problems/dna/
7
+ ; ;
8
+
9
+ (def dna-data (trim (slurp (resource " rosalind_dna.txt" ))))
10
+
11
+ (defn freqs [collection] (vals (sort (frequencies collection))))
12
+
13
+ (freqs dna-data)
Original file line number Diff line number Diff line change
1
+ (ns rosalind.fasta
2
+ (:use [clojure.string :only (join trim)]))
3
+
4
+ ; ;
5
+ ; ; fasta related functions
6
+ ; ;
7
+
8
+ (defn is-fasta-header-line [line] (.startsWith line " >" ))
9
+
10
+ (def is-fasta-seq-line (complement is-fasta-header-line))
11
+
12
+ (defn join-trimmed [strings] (join (map trim strings)))
13
+
14
+ (defn parse-fasta
15
+ " parses a fasta file to a seq of maps {:header \" header\" :seq \" AAACTGCCA\" }"
16
+ [lines]
17
+ (let [step (fn [c]
18
+ (when-let [s (seq c)]
19
+ (let [fasta-header-line (.substring (first s) 1 )
20
+ [fasta-seq-lines fasta-rest] (split-with is-fasta-seq-line (rest s))]
21
+ (cons {:header fasta-header-line
22
+ :seq (join-trimmed fasta-seq-lines)}
23
+ (parse-fasta fasta-rest)))))]
24
+ (lazy-seq (step lines))))
Original file line number Diff line number Diff line change
1
+ (ns rosalind.gc
2
+ (:use clojure.java.io)
3
+ (:use rosalind.fasta))
4
+
5
+ ; ;
6
+ ; ; http://rosalind.info/problems/gc/
7
+ ; ;
8
+
9
+ (defn nucleotide-count [dna-string & nucleotides]
10
+ (let [freqs (frequencies dna-string)]
11
+ (reduce + (map freqs nucleotides))))
12
+
13
+ (defn nucleotide-ratio [dna-string & nucleotides]
14
+ (/ (apply nucleotide-count dna-string nucleotides) (count dna-string)))
15
+
16
+ (defn gc-ratio [dna-string] (nucleotide-ratio dna-string \C \G))
17
+
18
+ (defn gc-pct [dna-string] (float (* 100 (gc-ratio dna-string))))
19
+
20
+ (defn assoc-gc-val [f fasta-map]
21
+ (assoc fasta-map :gc (f (:seq fasta-map))))
22
+
23
+ (defn assoc-gc-vals [f fasta-maps]
24
+ (map (partial assoc-gc-val f) fasta-maps))
25
+
26
+ (defn max-gc [fasta-maps-with-gc]
27
+ (apply max-key :gc fasta-maps-with-gc))
28
+
29
+ (defn gc-result [file]
30
+ (with-open [rdr (reader (resource file))]
31
+ (max-gc (assoc-gc-vals gc-pct (parse-fasta (line-seq rdr))))))
32
+
33
+ (defn pretty-gc [fasta-map]
34
+ (format " %s\n %s" (:header fasta-map) (:gc fasta-map)))
35
+
36
+ (pretty-gc (gc-result " rosalind_gc.txt" ))
Original file line number Diff line number Diff line change
1
+ (ns rosalind.revc
2
+ (:use clojure.java.io)
3
+ (:use [clojure.string :only (trim join)]))
4
+
5
+ ; ;
6
+ ; ; http://rosalind.info/problems/revc/
7
+ ; ;
8
+
9
+ (def revc-data (trim (slurp (resource " rosalind_revc.txt" ))))
10
+
11
+ (def dna-complement
12
+ {\A \T
13
+ \C \G
14
+ \G \C
15
+ \T \A})
16
+
17
+ (defn reverse-complement [dna-string] (join (map dna-complement (reverse dna-string))))
18
+
19
+ (reverse-complement revc-data)
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ (ns rosalind.fasta-test
2
+ (:require [clojure.test :refer :all ])
3
+ (:require [rosalind.fasta :refer :all ]))
4
+
5
+ (def test-data
6
+ '(" >Rosalind_6404"
7
+ " CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC"
8
+ " TCCCACTAATAATTCTGAGG"
9
+ " >Rosalind_5959"
10
+ " CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT"
11
+ " ATATCCATTTGTCAGCAGACACGC"
12
+ " >Rosalind_0808"
13
+ " CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC"
14
+ " TGGGAACCTGCGGGCAGTAGGTGGAAT" ))
15
+
16
+ (deftest test-parse-fasta
17
+ (testing " yields a lazy seq"
18
+ (is ()))
19
+ (is (not (realized? (parse-fasta test-data)))))
You can’t perform that action at this time.
0 commit comments