-
Notifications
You must be signed in to change notification settings - Fork 12
/
t_sam_util.clj
184 lines (157 loc) · 5.41 KB
/
t_sam_util.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
(ns cljam.util.t-sam-util
"Tests for cljam.util.sam-util."
(:require [midje.sweet :refer :all]
[cljam.t-common :refer :all]
[cljam.util :as util]
[cljam.util.sam-util :as sam-util]
[clojure.string :as cstr]))
(tabular
(fact "about char->compressed-base-high"
(sam-util/char->compressed-base-high ?base) => ?expected)
?base ?expected
\= (util/ubyte 0x0)
\a (util/ubyte 0x10)
\A (util/ubyte 0x10)
\c (util/ubyte 0x20)
\C (util/ubyte 0x20)
\g (util/ubyte 0x40)
\G (util/ubyte 0x40)
\t (util/ubyte 0x80)
\T (util/ubyte 0x80)
\n (util/ubyte 0xf0)
\N (util/ubyte 0xf0)
\. (util/ubyte 0xf0)
\m (util/ubyte 0x30)
\M (util/ubyte 0x30)
\r (util/ubyte 0x50)
\R (util/ubyte 0x50)
\s (util/ubyte 0x60)
\S (util/ubyte 0x60)
\v (util/ubyte 0x70)
\V (util/ubyte 0x70)
\w (util/ubyte 0x90)
\W (util/ubyte 0x90)
\y (util/ubyte 0xa0)
\Y (util/ubyte 0xa0)
\h (util/ubyte 0xb0)
\H (util/ubyte 0xb0)
\k (util/ubyte 0xc0)
\K (util/ubyte 0xc0)
\d (util/ubyte 0xd0)
\D (util/ubyte 0xd0)
\b (util/ubyte 0xe0)
\B (util/ubyte 0xe0))
(tabular
(fact "about compressed-base->char-low"
(sam-util/compressed-base->char-low ?base) => ?expected)
?base ?expected
(util/ubyte 0x0) \=
(util/ubyte 0x1) \A
(util/ubyte 0x2) \C
(util/ubyte 0x4) \G
(util/ubyte 0x8) \T
(util/ubyte 0xf) \N
(util/ubyte 0x3) \M
(util/ubyte 0x5) \R
(util/ubyte 0x6) \S
(util/ubyte 0x7) \V
(util/ubyte 0x9) \W
(util/ubyte 0xa) \Y
(util/ubyte 0xb) \H
(util/ubyte 0xc) \K
(util/ubyte 0xd) \D
(util/ubyte 0xe) \B)
(tabular
(fact "about compressed-base->char-high"
(sam-util/compressed-base->char-high ?base) => ?expected)
?base ?expected
(util/ubyte 0x0) \=
(util/ubyte 0x10) \A
(util/ubyte 0x20) \C
(util/ubyte 0x40) \G
(util/ubyte 0x80) \T
(util/ubyte 0xf0) \N
(util/ubyte 0x30) \M
(util/ubyte 0x50) \R
(util/ubyte 0x60) \S
(util/ubyte 0x70) \V
(util/ubyte 0x90) \W
(util/ubyte 0xa0) \Y
(util/ubyte 0xb0) \H
(util/ubyte 0xc0) \K
(util/ubyte 0xd0) \D
(util/ubyte 0xe0) \B)
(def nibble-table "=ACMGRSVTWYHKDBN")
(tabular
(fact
"about compressed-bases->str"
(let [ba (byte-array (mapv util/ubyte ?bases))]
(cstr/join (sam-util/compressed-bases->chars ?length ba ?offset)) => ?expected
(sam-util/compressed-bases->str ?length ba ?offset) => ?expected))
?length ?bases ?offset ?expected
1 [0x00] 0 "="
2 [0x00] 0 "=="
1 [0x10] 0 "A"
2 [0x12] 0 "AC"
4 [0x12 0x8F] 0 "ACTN"
1 [0x12 0x8F] 1 "T"
2 [0x12 0x8F] 1 "TN"
16 [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF] 0 nibble-table
14 [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF] 1 (subs nibble-table 2)
2 [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF] 7 "BN"
512 (range 256) 0 (->> (for [i nibble-table j nibble-table] [i j])
(apply concat)
cstr/join))
;; Reference functions
;; -------------------
(def refs '({:name "ref", :len 45} {:name "ref2", :len 40}))
(fact "about make-refs"
(sam-util/make-refs (:header test-sam)) => refs)
(tabular
(fact "about ref-id"
(sam-util/ref-id refs ?name) => ?expected)
?name ?expected
"ref" 0
"ref2" 1
"notfound" nil?)
(tabular
(fact "about ref-name"
(sam-util/ref-name refs ?id) => ?expected)
?id ?expected
0 "ref"
1 "ref2"
9 nil?)
(tabular
(fact "about ref-by-name"
(sam-util/ref-by-name refs ?name) => ?expected)
?name ?expected
"ref" {:name "ref", :len 45}
"ref2" {:name "ref2", :len 40}
"notfound" nil?)
(tabular
(facts "about flags"
(sam-util/decode-flags ?flag) => ?set
(sam-util/encode-flags ?set) => ?flag
(sam-util/primary? ?flag) => ?primary
(sam-util/primary? ?set) => ?primary)
?flag ?primary ?set
0 truthy #{}
1 truthy #{:multiple}
2 truthy #{:properly-aligned}
3 truthy #{:multiple :properly-aligned}
4 truthy #{:unmapped}
16 truthy #{:reversed}
83 truthy #{:multiple :properly-aligned :reversed :first}
163 truthy #{:multiple :properly-aligned :next-reversed :last}
99 truthy #{:multiple :properly-aligned :next-reversed :first}
147 truthy #{:multiple :properly-aligned :reversed :last}
121 truthy #{:multiple :next-unmapped :reversed :next-reversed :first}
181 truthy #{:multiple :unmapped :reversed :next-reversed :last}
77 truthy #{:multiple :unmapped :next-unmapped :first}
141 truthy #{:multiple :unmapped :next-unmapped :last}
256 falsey #{:secondary}
257 falsey #{:multiple :secondary}
2048 falsey #{:supplementary}
2049 falsey #{:multiple :supplementary}
2304 falsey #{:secondary :supplementary}
0x900 falsey #{:secondary :supplementary})