Permalink
Browse files

Initial check-in

  • Loading branch information...
0 parents commit 11cd8ee79e5c5c948e304a18b46abc1f813ab845 @ray1729 committed Jul 13, 2010
Showing with 92 additions and 0 deletions.
  1. +31 −0 README
  2. +7 −0 examples/toy.sam
  3. +5 −0 project.clj
  4. +43 −0 src/bio/sam/core.clj
  5. +6 −0 test/bio/sam/core_test.clj
31 README
@@ -0,0 +1,31 @@
+# bio.sam
+
+Clojure interface to SAM-JDK. Just at proof of concept stage, provides function
+to read SAM/BAM files and return lazy-seq of SAMRecord objects.
+
+## Usage
+
+(use '[bio.sam.core :only (read-sam)])
+
+(def s (read-sam "examples/toy.sam"))
+
+(map (memfn getReadString) s)
+
+## Installation
+
+FIXME: write
+
+## See also
+
+http://picard.sourceforge.net/
+
+## License
+
+Copyright (C) 2010, Ray Miller <ray@1729.org.uk>.
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
+PUBLIC LICENSE, <http://www.eclipse.org/org/documents/epl-v10.php>.
+
+ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
+RECIPIENT’S ACCEPTANCE OF THIS AGREEMENT.
+
@@ -0,0 +1,7 @@
+@SQ SN:ref LN:45
+r001 163 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *
+r002 0 ref 9 30 1S2I6M1P1I4M2I * 0 0 AAAAGATAAGGATAAA *
+r003 0 ref 9 30 5H6M * 0 0 AGCTAA *
+r004 0 ref 16 30 6M14N1I5M * 0 0 ATAGCTCTCAGC *
+r003 16 ref 29 30 6H5M * 0 0 TAGGC *
+r001 83 ref 37 30 9M = 7 -39 CAGCGCCAT *
@@ -0,0 +1,5 @@
+(defproject bio.sam "1.0.0-SNAPSHOT"
+ :description "FIXME: write"
+ :dependencies [[org.clojure/clojure "1.2.0-master-SNAPSHOT"]
+ [org.clojure/clojure-contrib "1.2.0-SNAPSHOT"]]
+ :dev-dependencies [[swank-clojure "1.2.1"]])
@@ -0,0 +1,43 @@
+(ns bio.sam.core
+ (:use [clojure.contrib.io :only (file)])
+ (:import [net.sf.samtools SAMFileReader SAMRecordIterator]))
+
+(defn read-sam [filename]
+ "Read file in SAM/BAM format and return a lazy sequence of
+ SAMRecord objects. Close the file when the last record has
+ been read"
+ (let [sam-reader (SAMFileReader. (file filename))
+ read-record (fn this [#^SAMRecordIterator it]
+ (lazy-seq
+ (if (.hasNext it)
+ (cons (.next it) (this it))
+ (do (.close it) (.close sam-reader)))))]
+ (read-record (.iterator sam-reader))))
+
+(comment
+
+ (def s (read-sam "examples/toy.sam"))
+ ;;=> #'user/s
+
+ (first s)
+ ;;=> #<SAMRecord r001 2/2 17b aligned read.>
+
+ (.getCigarString (first s))
+ ;;=> "8M2I4M1D3M"
+
+ (map (memfn getCigarString) s)
+ ;;=> ("8M2I4M1D3M" "1S2I6M1P1I4M2I" "5H6M" "6M14N1I5M" "6H5M" "9M")
+
+ (.getReadLength (first s))
+ ;;=> 17
+
+ (map (memfn getReadLength) s)
+ ;;=> (17 16 6 12 5 9)
+
+ (map (memfn getReadString) s)
+ ;;=> ("TTAGATAAAGGATACTG" "AAAAGATAAGGATAAA" "AGCTAA" "ATAGCTCTCAGC" "TAGGC" "CAGCGCCAT")
+
+ ;; See <http://picard.sourceforge.net/javadoc/net/sf/samtools/SAMRecord.html>
+ ;; for other methods supported by SAMRecord
+
+ )
@@ -0,0 +1,6 @@
+(ns bio.sam.core-test
+ (:use [bio.sam.core] :reload-all)
+ (:use [clojure.test]))
+
+(deftest replace-me ;; FIXME: write
+ (is false))

0 comments on commit 11cd8ee

Please sign in to comment.