diff --git a/test/cljam/io/cram/decode/data_series_test.clj b/test/cljam/io/cram/decode/data_series_test.clj new file mode 100644 index 00000000..f2960366 --- /dev/null +++ b/test/cljam/io/cram/decode/data_series_test.clj @@ -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)]))))