-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support CIGARs longer than 65535 operations
- Loading branch information
1 parent
843e30b
commit 1183ebd
Showing
11 changed files
with
339 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
(ns cljam.io.sam-bench | ||
(:require [libra.bench :refer [defbench are]] | ||
[libra.criterium :as c] | ||
[clojure.java.io :as cio] | ||
[cljam.test-common :as tcommon] | ||
[cljam.util :as util] | ||
[cljam.io.sam :as sam])) | ||
|
||
(defbench encode-alignment-short-bench | ||
(are [f] | ||
(util/with-temp-dir [d "encode-alignment-short-bench"] | ||
(with-open [r (sam/reader f) | ||
w (sam/writer (cio/file d "out.bam"))] | ||
(let [header (sam/read-header r) | ||
xs (vec (sam/read-alignments r))] | ||
(sam/write-header w header) | ||
(sam/write-refs w header) | ||
(doseq [x xs o (:options x)] o) | ||
(c/quick-bench | ||
(sam/write-alignments w xs header))))) | ||
tcommon/test-sam-file | ||
tcommon/medium-sam-file)) | ||
|
||
(defbench encode-alignment-long-bench | ||
(tcommon/prepare-cavia!) | ||
(are [f] | ||
(util/with-temp-dir [d "encode-alignment-long-bench"] | ||
(with-open [r (sam/reader f) | ||
w (sam/writer (cio/file d "out.bam"))] | ||
(let [header (sam/read-header r) | ||
xs (vec (take 2000000 (sam/read-alignments r)))] | ||
(sam/write-header w header) | ||
(sam/write-refs w header) | ||
(doseq [x xs o (:options x)] o) | ||
(c/quick-bench | ||
(sam/write-alignments w xs header))))) | ||
tcommon/large-bam-file)) | ||
|
||
(defbench decode-bam-alignment-short-bench | ||
(are [f decode-opts?] | ||
(c/quick-bench | ||
(with-open [r (sam/reader f)] | ||
(doseq [a (sam/read-alignments r) | ||
opts (when decode-opts? (:options a))] | ||
opts))) | ||
tcommon/test-bam-file false | ||
tcommon/test-bam-file true | ||
tcommon/medium-bam-file false | ||
tcommon/medium-bam-file true)) | ||
|
||
(defbench decode-bam-alignment-long-bench | ||
(tcommon/prepare-cavia!) | ||
(are [f] | ||
(c/quick-bench | ||
(with-open [r (sam/reader f)] | ||
(doseq [a (vec (take 10000000 (sam/read-alignments r))) | ||
opts (:options a)] | ||
opts))) | ||
tcommon/large-bam-file)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
(ns cljam.io.bam.decoder-test | ||
"Tests for cljam.io.bam.decoder." | ||
(:require [clojure.test :refer [deftest is are testing]] | ||
[cljam.io.protocols] | ||
[cljam.io.bam.decoder :as decoder] | ||
[cljam.test-common :as test-common])) | ||
|
||
(deftest B-I-type-cigar-str->cigar-str-test | ||
(is (= "1M2I4D8N16S32H64P128=65535X" | ||
(#'decoder/B-I-type-cigar-str->cigar-str | ||
"I,16,33,66,131,260,517,1030,2055,1048568")))) | ||
|
||
(deftest decode-alignment-test | ||
(let [rid-bin [0 0 0 0 1 0 0 0 2 0 73 18] | ||
flag-qname [0 0 2 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 81 0] | ||
seq-qual [17 -1 -1] | ||
no-opts (concat rid-bin | ||
[1 0] ;; n_cigar_op: 1 | ||
flag-qname | ||
[32 0 0 0] ;; cigar: 2M | ||
seq-qual) | ||
with-CG (concat rid-bin | ||
[2 0] ;; n_cigar_op: 2 | ||
flag-qname | ||
[36 0 0 0 ;; cigar: 2S | ||
35 0 0 0] ;; 2N | ||
seq-qual | ||
[67 71 66 73 ;; tag: CG, val_type: B-I | ||
1 0 0 0 ;; count | ||
32 0 0 0]) ;; cigar: 2M | ||
expected (test-common/to-sam-alignment | ||
{:qname "Q", :flag (int 0), | ||
:rname "ref", :pos (int 2), :end (int 3), | ||
:mapq (int 0), :cigar "2M", | ||
:rnext "*", :pnext (int 0), :tlen (int 0), | ||
:seq "AA", :qual "*", :options []})] | ||
|
||
(testing "two-arguments-decode-alignment-test" | ||
(are [?expected-aln ?byte] | ||
(= ?expected-aln | ||
(decoder/decode-alignment | ||
[{:name "ref", :len 0}] | ||
{:data (byte-array (map unchecked-byte ?byte))})) | ||
expected | ||
no-opts | ||
|
||
expected | ||
with-CG)) | ||
|
||
(testing "four-arguments-decode-alignment-test" | ||
(are [expected-aln byte start end] | ||
(= expected-aln | ||
(decoder/decode-alignment | ||
[{:name "ref", :len 0}] | ||
{:data (byte-array (map unchecked-byte byte))} start end)) | ||
expected | ||
no-opts ;; pos 2, ref-end 3 | ||
2 3 | ||
|
||
nil | ||
no-opts | ||
1 1 | ||
|
||
nil | ||
no-opts | ||
4 100 | ||
|
||
expected | ||
with-CG ;; pos 2, ref-end 3 | ||
2 2 | ||
|
||
nil | ||
with-CG | ||
1 1 | ||
|
||
nil | ||
with-CG | ||
4 (Math/pow 10 15))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.