Skip to content

Commit dc64988

Browse files
committed
evolution
1 parent 932cff7 commit dc64988

File tree

10 files changed

+124
-119
lines changed

10 files changed

+124
-119
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
rosalind
2-
========
2+
=======
3+

doc/intro.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Introduction to rosalind
2+
3+
TODO: write [great documentation](http://jacobian.org/writing/great-documentation/what-to-write/)

project.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(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"
44
:license {:name "Eclipse Public License"
55
: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)

src/rosalind/core.clj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
(ns rosalind.core)
1+
(ns rosalind.core
2+
(:gen-class))
23

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"))

src/rosalind/dna.clj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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)

src/rosalind/fasta.clj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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))))

src/rosalind/gc.clj

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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"))

src/rosalind/revc.clj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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)

src/rosalind/worksheet1.clj

Lines changed: 0 additions & 110 deletions
This file was deleted.

test/rosalind/fasta_test.clj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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)))))

0 commit comments

Comments
 (0)