Skip to content

Commit

Permalink
Add a function to clone bam reader.
Browse files Browse the repository at this point in the history
  • Loading branch information
alumi committed Apr 5, 2017
1 parent 2b915b9 commit 1949fec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/cljam/bam.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
[f & option]
(bam-core/reader f option))

(defn ^BAMReader clone-reader
"Clones bam reader sharing persistent objects."
[r]
(bam-core/clone-reader r))

(defn ^BAMWriter writer
"Returns BAM file writer of f."
[f]
Expand Down
10 changes: 9 additions & 1 deletion src/cljam/bam/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@
(let [{:keys [header refs]} (reader/load-headers data-rdr)
index-delay (delay (bam-index f :ignore ignore-index))]
(BAMReader. (.getAbsolutePath (file f))
header refs rdr data-rdr index-delay))))
header refs rdr data-rdr index-delay (.getFilePointer rdr)))))

(defn ^BAMReader clone-reader
"Clones bam reader sharing persistent objects."
[^BAMReader rdr]
(let [bgzf-rdr (BGZFInputStream. (file (.f rdr)))
data-rdr (DataInputStream. bgzf-rdr)]
(.seek bgzf-rdr (.start-pos rdr))
(BAMReader. (.f rdr) (.header rdr) (.refs rdr) bgzf-rdr data-rdr (.index-delay rdr) (.start-pos rdr))))

(extend-type BAMReader
cljam.io/ISAMReader
Expand Down
2 changes: 1 addition & 1 deletion src/cljam/bam/reader.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
;; BAMReader
;; ---------

(deftype BAMReader [f header refs reader data-reader index-delay]
(deftype BAMReader [f header refs reader data-reader index-delay start-pos]
Closeable
(close [this]
(.close ^Closeable (.reader this))))
Expand Down

0 comments on commit 1949fec

Please sign in to comment.