Skip to content

Commit

Permalink
Fix wrong usage of util->bin.
Browse files Browse the repository at this point in the history
  • Loading branch information
niyarin committed Apr 10, 2020
1 parent 985fed3 commit 2c71be5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/cljam/io/bam_index/writer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/cljam/io/sam/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
4 changes: 2 additions & 2 deletions src/cljam/io/util/bin.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
40 changes: 35 additions & 5 deletions test/cljam/io/util/bin_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

0 comments on commit 2c71be5

Please sign in to comment.