Skip to content

Commit

Permalink
wip: Add tests for data series & tags decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
athos committed Feb 2, 2024
1 parent 32db818 commit 07248bf
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions test/cljam/io/cram/decode/data_series_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
(ns cljam.io.cram.decode.data-series-test
(:require [cljam.io.cram.decode.data-series :as ds]
[cljam.io.util.byte-buffer :as bb]
[clojure.test :refer [deftest is]]))

(deftest build-data-series-decoders-test
(let [encodings {:BA {:codec :external, :content-id 1}
:BF {:codec :external, :content-id 2}
:RL {:codec :huffman, :alphabet [151], :bit-len [0]}
:BB {:codec :byte-array-len
:len-encoding {:codec :external, :content-id 3}
:val-encoding {:codec :external, :content-id 4}}
:RN {:codec :byte-array-stop, :stop-byte 0, :external-id 5}}
blocks [{:content-id 1
:data (bb/make-lsb-byte-buffer (byte-array (.getBytes "ATGC")))}
{:content-id 2
:data (->> (byte-array [0x80 0xa1 0x80 0x63 0x80 0xa3 0x80 0x63])
bb/make-lsb-byte-buffer)}
{:content-id 3
:data (bb/make-lsb-byte-buffer (byte-array [3 5 4 3]))}
{:content-id 4
:data (bb/make-lsb-byte-buffer (.getBytes "CATCGAACAACTACT"))}
{:content-id 5
:data (->> "qname001\000qname002\000qname003\000qname004\000"
.getBytes
bb/make-lsb-byte-buffer)}]
{:keys [BA BF RL BB RN]}
(ds/build-data-series-decoders {:data-series encodings} blocks)]
(is (= (map int "ATGC") [(BA) (BA) (BA) (BA)]))
(is (= [0xa1 0x63 0xa3 0x63] [(BF) (BF) (BF) (BF)]))
(is (= [151 151 151 151] [(RL) (RL) (RL) (RL)]))
(is (= ["CAT" "CGAAC" "AACT" "ACT"]
(map #(String. ^bytes %) [(BB) (BB) (BB) (BB)])))
(is (= ["qname001" "qname002" "qname003" "qname004"]
(map #(String. ^bytes %) [(RN) (RN) (RN) (RN)])))))

(deftest build-tag-decoders-test
(let [encodings {:NM {:type \C
:encoding {:codec :byte-array-len
:len-encoding {:codec :huffman
:alphabet [1]
:bit-len [0]}
:val-encoding {:codec :external
:content-id 5131587}}}
:pa {:type \f
:encoding {:codec :byte-array-len
:len-encoding {:codec :huffman
:alphabet [4]
:bit-len [0]}
:val-encoding {:codec :external
:content-id 7364966}}}
:MC {:type \Z
:encoding {:codec :byte-array-stop
:stop-byte 9
:external-id 5063514}}}
blocks [{:content-id 5131587
:data (bb/make-lsb-byte-buffer (byte-array [0 1 2 0]))}
{:content-id 7364966
:data (doto (bb/allocate-lsb-byte-buffer 16)
(.putFloat 1.0)
(.putFloat 0.75)
(.putFloat 0.5)
(.putFloat 0.0)
(.flip))}
{:content-id 5063514
:data (->> (str "151M\000\011"
"20S131M\000\011"
"16S74M1D58M2S\000\011"
"151M\000\011")
.getBytes
bb/make-lsb-byte-buffer)}]
{:keys [NM pa MC]} (ds/build-tag-decoders {:tags encodings} blocks)]
(is (= [{:type "i" :value 0}
{:type "i" :value 1}
{:type "i" :value 2}
{:type "i" :value 0}]
[(NM) (NM) (NM) (NM)]))
(is (= [{:type "f" :value 1.0}
{:type "f" :value 0.75}
{:type "f" :value 0.5}
{:type "f" :value 0.0}]
[(pa) (pa) (pa) (pa)]))
(is (= [{:type "Z" :value "151M"}
{:type "Z" :value "20S131M"}
{:type "Z" :value "16S74M1D58M2S"}
{:type "Z" :value "151M"}]
[(MC) (MC) (MC) (MC)]))))

0 comments on commit 07248bf

Please sign in to comment.