From 2c71be5e5740cdebe856d0838a0028af80ddb2dc Mon Sep 17 00:00:00 2001 From: niyarin Date: Fri, 10 Apr 2020 16:42:16 +0900 Subject: [PATCH] Fix wrong usage of util->bin. --- src/cljam/io/bam_index/writer.clj | 4 ++-- src/cljam/io/sam/util.clj | 2 +- src/cljam/io/util/bin.clj | 4 ++-- test/cljam/io/util/bin_test.clj | 40 +++++++++++++++++++++++++++---- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/cljam/io/bam_index/writer.clj b/src/cljam/io/bam_index/writer.clj index 6b2c639b..b1239c1b 100644 --- a/src/cljam/io/bam_index/writer.clj +++ b/src/cljam/io/bam_index/writer.clj @@ -73,8 +73,8 @@ (defn- update-bin-index [bin-index ^BAMPointerBlock aln] - (let [bin (util-bin/reg->bin (.pos aln) (inc (.end aln)) - linear-index-shift linear-index-depth) + (let [bin (util-bin/reg->bin + (.pos aln) (.end aln) linear-index-shift linear-index-depth) beg (.pointer-beg aln) end (.pointer-end aln)] (assoc bin-index bin diff --git a/src/cljam/io/sam/util.clj b/src/cljam/io/sam/util.clj index 52879339..533b08a9 100644 --- a/src/cljam/io/sam/util.clj +++ b/src/cljam/io/sam/util.clj @@ -46,6 +46,6 @@ (defn compute-bin "Returns indexing bin based on alignment start and end." [aln] - (let [beg (dec (:pos aln)) + (let [beg (:pos aln) end (get-end aln)] (util-bin/reg->bin beg end linear-index-shift linear-index-depth))) diff --git a/src/cljam/io/util/bin.clj b/src/cljam/io/util/bin.clj index cbc4b66d..a76d4b0f 100644 --- a/src/cljam/io/util/bin.clj +++ b/src/cljam/io/util/bin.clj @@ -71,8 +71,8 @@ "Calculates bin given an alignment covering [beg, end]" ^long [^long beg ^long end ^long min-shift ^long depth] (let [max-pos (max-pos min-shift depth) - beg (Math/min max-pos (Math/max 0 (dec beg))) - end (Math/min max-pos (Math/max 0 (dec end)))] + beg (dec (Math/min max-pos (Math/max 1 beg))) + end (dec (Math/min max-pos (Math/max 1 end)))] (loop [level depth] (if-not (neg? level) (let [beg-bins (leading-bins-at-level beg level min-shift depth)] diff --git a/test/cljam/io/util/bin_test.clj b/test/cljam/io/util/bin_test.clj index 5f1c2077..ce53e699 100644 --- a/test/cljam/io/util/bin_test.clj +++ b/test/cljam/io/util/bin_test.clj @@ -59,8 +59,38 @@ 5 37448)) (deftest reg->bin-test - (is (= (util-bin/reg->bin 1 1 14 6) 37449)) - (is (= (util-bin/reg->bin 1 1 14 7) 299593)) - (is (= (util-bin/reg->bin 1 32769 15 6) 4681)) - (is (= (util-bin/reg->bin 1 2 0 2) 1)) - (is (= (util-bin/reg->bin 240877561 240877568 14 6) 52150))) + (testing "BAI-compatible" + (are [?start ?end ?bin] + (= ?bin (util-bin/reg->bin ?start ?end 14 5)) + 0 0 4681 + 0 1 4681 + 1 1 4681 + 1 16384 4681 + 16384 16384 4681 + 16384 16385 585 + 16385 16385 4682 + 131072 131072 4688 + 131072 131073 73 + 8388608 8388609 1 + 67108864 67108865 0 + 536870912 536870912 37448 + 536870912 536870913 37448)) + (testing "1-by-1" + (are [?start ?end ?bin] + (= ?bin (util-bin/reg->bin ?start ?end 0 2)) + 0 1 9 + 1 1 9 + 2 2 10 + 1 2 1 + 1 8 1 + 1 9 0 + 8 9 0 + 9 9 17 + 63 64 8 + 64 64 72 + 64 64 72)) + (testing "various min-shfits and depths" + (is (= (util-bin/reg->bin 1 1 14 6) 37449)) + (is (= (util-bin/reg->bin 1 1 14 7) 299593)) + (is (= (util-bin/reg->bin 1 32769 15 6) 4681)) + (is (= (util-bin/reg->bin 240877561 240877568 14 6) 52150))))