Skip to content

Commit

Permalink
Add tests for cram reader
Browse files Browse the repository at this point in the history
  • Loading branch information
athos committed Mar 4, 2024
1 parent bdbeb4f commit 2c11a0a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
Binary file added test-resources/cram/medium.cram
Binary file not shown.
Binary file added test-resources/cram/test.cram
Binary file not shown.
40 changes: 40 additions & 0 deletions test/cljam/io/cram_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
(ns cljam.io.cram-test
(:require [cljam.io.cram :as cram]
[cljam.io.sam :as sam]
[cljam.test-common :as common :refer [deftest-remote
prepare-cavia!
with-before-after]]
[clojure.test :refer [deftest is]]))

(defn- fixup-bam-aln [aln]
(-> aln
(dissoc :end)
(update :cigar #(if (= % "") "*" %))
(update :options #(sort-by (comp name key first) %))))

(deftest reader-test
(with-open [bam-rdr (sam/reader common/test-bam-file)
cram-rdr (cram/reader common/test-cram-file
{:reference common/test-fa-file})
cram-rdr' (cram/reader cram-rdr)]
(is (= (sam/read-header bam-rdr)
(dissoc (cram/read-header cram-rdr) :HD)
(dissoc (cram/read-header cram-rdr') :HD)))
(is (= (sam/read-refs bam-rdr)
(cram/read-refs cram-rdr)
(cram/read-refs cram-rdr')))
(is (= (map fixup-bam-aln (sam/read-alignments bam-rdr))
(cram/read-alignments cram-rdr)
(cram/read-alignments cram-rdr')))))

(deftest-remote reader-with-multiple-containers-test
(with-before-after {:before (prepare-cavia!)}
(with-open [bam-rdr (sam/reader common/medium-bam-file)
cram-rdr (cram/reader common/medium-cram-file
{:reference common/hg19-twobit-file})]
(is (= (sam/read-header bam-rdr)
(dissoc (cram/read-header cram-rdr) :HD)))
(is (= (sam/read-refs bam-rdr)
(cram/read-refs cram-rdr)))
(is (= (map fixup-bam-aln (sam/read-alignments bam-rdr))
(cram/read-alignments cram-rdr))))))
8 changes: 7 additions & 1 deletion test/cljam/test_common.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
(expand-deftest (with-meta sym {:remote true}) args body))

(defprofile mycavia
{:resources [{:id "large.bam"
{:resources [{:id "hg19.2bit"
:url "https://test.chrov.is/data/refs/hg19.2bit"
:sha1 "95e5806aee9ecc092d30a482aaa008ef66cbc468"}
{:id "large.bam"
:url "https://test.chrov.is/data/GSM721144_H3K36me3.nodup.bam"
:sha1 "ad282c3779120057abc274ad8fad1910a4ad867b"}
{:id "large.bai"
Expand Down Expand Up @@ -162,6 +165,8 @@

;; ### CRAM file

(def test-cram-file "test-resources/cram/test.cram")
(def medium-cram-file "test-resources/cram/medium.cram")
(def medium-with-standard-tags-cram-file "test-resources/cram/medium_with_standard_tags.cram")

;; ### FASTA files
Expand All @@ -187,6 +192,7 @@
(def test-twobit-be-file "test-resources/twobit/be-test.2bit")
(def test-twobit-be-n-file "test-resources/twobit/be-test-n.2bit")
(def medium-twobit-file "test-resources/twobit/medium.2bit")
(def hg19-twobit-file (cavia/resource mycavia "hg19.2bit"))

;; ### FASTQ files

Expand Down

0 comments on commit 2c11a0a

Please sign in to comment.