-
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.
- Loading branch information
Showing
10 changed files
with
293 additions
and
57 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
Binary file not shown.
Binary file not shown.
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,35 @@ | ||
(ns cljam.algo.cram-indexer-test | ||
(:require [cljam.algo.cram-indexer :as indexer] | ||
[cljam.io.crai :as crai] | ||
[cljam.io.cram :as cram] | ||
[cljam.test-common :as common] | ||
[cljam.util :as util] | ||
[clojure.java.io :as io] | ||
[clojure.test :refer [deftest is]])) | ||
|
||
(defn- read-index-entries [f] | ||
(with-open [r (io/reader (util/compressor-input-stream f))] | ||
(doall (#'crai/read-index-entries r)))) | ||
|
||
(deftest create-index-test | ||
(let [f (io/file common/temp-dir "medium.cram.crai")] | ||
(common/with-before-after {:before (common/prepare-cache!) | ||
:after (common/clean-cache!)} | ||
(is (thrown-with-msg? Exception #"Cannot create CRAM index file .*" | ||
(indexer/create-index common/medium-cram-file f))) | ||
(indexer/create-index common/medium-cram-file f | ||
:skip-sort-order-check? true) | ||
(is (= (read-index-entries common/medium-crai-file) | ||
(read-index-entries f)))))) | ||
|
||
(deftest cram-without-alignments-test | ||
(common/with-before-after {:before (common/prepare-cache!) | ||
:after (common/clean-cache!)} | ||
(let [header {:HD {:SO "coordinate"} | ||
:SQ [{:SN "chr1", :LN 100}]} | ||
target (io/file common/temp-dir "no_aln.cram") | ||
target-crai (io/file common/temp-dir "no_aln.cram.crai")] | ||
(with-open [w (cram/writer target)] | ||
(cram/write-header w header) | ||
(cram/write-refs w header)) | ||
(is (common/not-throw? (indexer/create-index target target-crai)))))) |
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
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,70 @@ | ||
(ns cljam.io.cram.writer-test | ||
(:require [cljam.io.cram.encode.record :as record] | ||
[cljam.io.cram.writer :as writer] | ||
[clojure.test :refer [deftest is testing]])) | ||
|
||
(deftest container-index-entries-test | ||
(testing "no multiple reference slices" | ||
(is (= [{:ref-seq-id 0, :start 123, :span 456 | ||
:container-offset 100, :slice-offset 200, :size 1000} | ||
{:ref-seq-id 0, :start 987, :span 654 | ||
:container-offset 100, :slice-offset 1200, :size 900} | ||
{:ref-seq-id 1, :start 1234, :span 5678 | ||
:container-offset 100, :slice-offset 2100, :size 1100}] | ||
(#'writer/container-index-entries | ||
100 | ||
{:landmarks [200 1200 2100]} | ||
[{:header {:ref-seq-id 0, :start 123, :span 456} | ||
:size 1000} | ||
{:header {:ref-seq-id 0, :start 987, :span 654} | ||
:size 900} | ||
{:header {:ref-seq-id 1, :start 1234, :span 5678} | ||
:size 1100}] | ||
[[{::record/ref-index 0, :pos 123 ::record/end 273} | ||
{::record/ref-index 0, :pos 428 ::record/end 578}] | ||
[{::record/ref-index 0, :pos 987 ::record/end 1137} | ||
{::record/ref-index 0, :pos 1490 ::record/end 1640}] | ||
[{::record/ref-index 1, :pos 1234 ::record/end 1384} | ||
{::record/ref-index 1, :pos 6761 ::record/end 6911}]]))) | ||
(is (= [{:ref-seq-id -1, :start 0, :span 0 | ||
:container-offset 100, :slice-offset 200, :size 1000} | ||
{:ref-seq-id -1, :start 0, :span 0 | ||
:container-offset 100, :slice-offset 1200, :size 900}] | ||
(#'writer/container-index-entries | ||
100 | ||
{:landmarks [200 1200]} | ||
[{:header {:ref-seq-id -1, :start 0, :span 0} | ||
:size 1000} | ||
{:header {:ref-seq-id -1, :start 0, :span 0} | ||
:size 900}] | ||
[[{::record/ref-index -1, :pos 0 ::record/end 0} | ||
{::record/ref-index -1, :pos 0 ::record/end 0}] | ||
[{::record/ref-index -1, :pos 0 ::record/end 0} | ||
{::record/ref-index -1, :pos 0 ::record/end 0}]])))) | ||
(testing "some multiple reference slices" | ||
(is (= [{:ref-seq-id 0, :start 123, :span 456 | ||
:container-offset 100, :slice-offset 200, :size 1000} | ||
{:ref-seq-id 0, :start 987, :span 654 | ||
:container-offset 100, :slice-offset 1200, :size 900} | ||
{:ref-seq-id 1, :start 1234, :span 5678 | ||
:container-offset 100, :slice-offset 1200, :size 900} | ||
;; Both of :start/:span should be zero for unmapped slices in respect of | ||
;; the CRAM specification, but it's guaranteed by the CRAI writer, | ||
;; so it doesn't matter what values these keys actually take here | ||
{:ref-seq-id -1, :start 0, :span 1 | ||
:container-offset 100, :slice-offset 1200, :size 900}] | ||
(#'writer/container-index-entries | ||
100 | ||
{:landmarks [200 1200]} | ||
[{:header {:ref-seq-id 0, :start 123, :span 456} | ||
:size 1000} | ||
{:header {:ref-seq-id -2, :start 0, :span 0} | ||
:size 900}] | ||
[[{::record/ref-index 0, :pos 123 ::record/end 273} | ||
{::record/ref-index 0, :pos 428 ::record/end 578}] | ||
[{::record/ref-index 0, :pos 987 ::record/end 1138} | ||
{::record/ref-index 0, :pos 1490 ::record/end 1640} | ||
{::record/ref-index 1, :pos 1234 ::record/end 1384} | ||
{::record/ref-index 1, :pos 6761 ::record/end 6911} | ||
{::record/ref-index -1, :pos 0 ::record/end 0} | ||
{::record/ref-index -1, :pos 0 ::record/end 0}]]))))) |
Oops, something went wrong.