@gmod/cram 6.0.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/dist/craiIndex.js +2 -2
  2. package/dist/craiIndex.js.map +1 -1
  3. package/dist/cram-bundle.js +1 -1
  4. package/dist/cramFile/file.d.ts +2 -2
  5. package/dist/cramFile/file.js +9 -13
  6. package/dist/cramFile/file.js.map +1 -1
  7. package/dist/htscodecs/index.d.ts +1 -5
  8. package/dist/htscodecs/index.js +11 -72
  9. package/dist/htscodecs/index.js.map +1 -1
  10. package/dist/htscodecs-wasm.d.ts +7 -0
  11. package/dist/htscodecs-wasm.js +183 -0
  12. package/dist/htscodecs-wasm.js.map +1 -0
  13. package/dist/unzip.d.ts +1 -1
  14. package/dist/unzip.js +3 -3
  15. package/dist/unzip.js.map +1 -1
  16. package/dist/wasm/htscodecs.d.ts +5 -0
  17. package/dist/wasm/htscodecs.js +0 -0
  18. package/dist/wasm/htscodecs.js.map +1 -0
  19. package/esm/craiIndex.js +2 -2
  20. package/esm/craiIndex.js.map +1 -1
  21. package/esm/cramFile/file.d.ts +2 -2
  22. package/esm/cramFile/file.js +7 -11
  23. package/esm/cramFile/file.js.map +1 -1
  24. package/esm/htscodecs/index.d.ts +1 -5
  25. package/esm/htscodecs/index.js +3 -31
  26. package/esm/htscodecs/index.js.map +1 -1
  27. package/esm/htscodecs-wasm.d.ts +7 -0
  28. package/esm/htscodecs-wasm.js +171 -0
  29. package/esm/htscodecs-wasm.js.map +1 -0
  30. package/esm/unzip.d.ts +1 -1
  31. package/esm/unzip.js +3 -3
  32. package/esm/unzip.js.map +1 -1
  33. package/esm/wasm/htscodecs.d.ts +5 -0
  34. package/esm/wasm/htscodecs.js +0 -0
  35. package/esm/wasm/htscodecs.js.map +1 -0
  36. package/package.json +9 -9
  37. package/src/craiIndex.ts +4 -2
  38. package/src/cramFile/file.ts +7 -11
  39. package/src/htscodecs/index.ts +12 -38
  40. package/src/htscodecs-wasm.ts +210 -0
  41. package/src/unzip.ts +3 -3
  42. package/src/wasm/htscodecs.d.ts +58 -0
  43. package/src/wasm/htscodecs.js +0 -0
  44. package/dist/htscodecs/arith_gen.d.ts +0 -16
  45. package/dist/htscodecs/arith_gen.js +0 -323
  46. package/dist/htscodecs/arith_gen.js.map +0 -1
  47. package/dist/htscodecs/arith_sh.d.ts +0 -9
  48. package/dist/htscodecs/arith_sh.js +0 -134
  49. package/dist/htscodecs/arith_sh.js.map +0 -1
  50. package/dist/htscodecs/byte_model.d.ts +0 -6
  51. package/dist/htscodecs/byte_model.js +0 -121
  52. package/dist/htscodecs/byte_model.js.map +0 -1
  53. package/dist/htscodecs/fqzcomp.d.ts +0 -1
  54. package/dist/htscodecs/fqzcomp.js +0 -346
  55. package/dist/htscodecs/fqzcomp.js.map +0 -1
  56. package/dist/htscodecs/iostream.d.ts +0 -16
  57. package/dist/htscodecs/iostream.js +0 -148
  58. package/dist/htscodecs/iostream.js.map +0 -1
  59. package/dist/htscodecs/rans.d.ts +0 -1
  60. package/dist/htscodecs/rans.js +0 -224
  61. package/dist/htscodecs/rans.js.map +0 -1
  62. package/dist/htscodecs/rans4x16.d.ts +0 -1
  63. package/dist/htscodecs/rans4x16.js +0 -445
  64. package/dist/htscodecs/rans4x16.js.map +0 -1
  65. package/dist/htscodecs/tok3.d.ts +0 -1
  66. package/dist/htscodecs/tok3.js +0 -206
  67. package/dist/htscodecs/tok3.js.map +0 -1
  68. package/dist/rans/constants.d.ts +0 -4
  69. package/dist/rans/constants.js +0 -10
  70. package/dist/rans/constants.js.map +0 -1
  71. package/dist/rans/d04.d.ts +0 -1
  72. package/dist/rans/d04.js +0 -100
  73. package/dist/rans/d04.js.map +0 -1
  74. package/dist/rans/d14.d.ts +0 -1
  75. package/dist/rans/d14.js +0 -96
  76. package/dist/rans/d14.js.map +0 -1
  77. package/dist/rans/decoding.d.ts +0 -27
  78. package/dist/rans/decoding.js +0 -119
  79. package/dist/rans/decoding.js.map +0 -1
  80. package/dist/rans/frequencies.d.ts +0 -2
  81. package/dist/rans/frequencies.js +0 -112
  82. package/dist/rans/frequencies.js.map +0 -1
  83. package/dist/rans/index.d.ts +0 -1
  84. package/dist/rans/index.js +0 -198
  85. package/dist/rans/index.js.map +0 -1
  86. package/dist/seek-bzip/bitreader.d.ts +0 -27
  87. package/dist/seek-bzip/bitreader.js +0 -101
  88. package/dist/seek-bzip/bitreader.js.map +0 -1
  89. package/dist/seek-bzip/crc32.d.ts +0 -26
  90. package/dist/seek-bzip/crc32.js +0 -115
  91. package/dist/seek-bzip/crc32.js.map +0 -1
  92. package/dist/seek-bzip/index.d.ts +0 -9
  93. package/dist/seek-bzip/index.js +0 -585
  94. package/dist/seek-bzip/index.js.map +0 -1
  95. package/dist/seek-bzip/stream.d.ts +0 -8
  96. package/dist/seek-bzip/stream.js +0 -37
  97. package/dist/seek-bzip/stream.js.map +0 -1
  98. package/dist/seek-bzip/toHex.d.ts +0 -1
  99. package/dist/seek-bzip/toHex.js +0 -36
  100. package/dist/seek-bzip/toHex.js.map +0 -1
  101. package/esm/htscodecs/arith_gen.d.ts +0 -16
  102. package/esm/htscodecs/arith_gen.js +0 -317
  103. package/esm/htscodecs/arith_gen.js.map +0 -1
  104. package/esm/htscodecs/arith_sh.d.ts +0 -9
  105. package/esm/htscodecs/arith_sh.js +0 -131
  106. package/esm/htscodecs/arith_sh.js.map +0 -1
  107. package/esm/htscodecs/byte_model.d.ts +0 -6
  108. package/esm/htscodecs/byte_model.js +0 -118
  109. package/esm/htscodecs/byte_model.js.map +0 -1
  110. package/esm/htscodecs/fqzcomp.d.ts +0 -1
  111. package/esm/htscodecs/fqzcomp.js +0 -340
  112. package/esm/htscodecs/fqzcomp.js.map +0 -1
  113. package/esm/htscodecs/iostream.d.ts +0 -16
  114. package/esm/htscodecs/iostream.js +0 -145
  115. package/esm/htscodecs/iostream.js.map +0 -1
  116. package/esm/htscodecs/rans.d.ts +0 -1
  117. package/esm/htscodecs/rans.js +0 -218
  118. package/esm/htscodecs/rans.js.map +0 -1
  119. package/esm/htscodecs/rans4x16.d.ts +0 -1
  120. package/esm/htscodecs/rans4x16.js +0 -439
  121. package/esm/htscodecs/rans4x16.js.map +0 -1
  122. package/esm/htscodecs/tok3.d.ts +0 -1
  123. package/esm/htscodecs/tok3.js +0 -167
  124. package/esm/htscodecs/tok3.js.map +0 -1
  125. package/esm/rans/constants.d.ts +0 -4
  126. package/esm/rans/constants.js +0 -5
  127. package/esm/rans/constants.js.map +0 -1
  128. package/esm/rans/d04.d.ts +0 -1
  129. package/esm/rans/d04.js +0 -94
  130. package/esm/rans/d04.js.map +0 -1
  131. package/esm/rans/d14.d.ts +0 -1
  132. package/esm/rans/d14.js +0 -93
  133. package/esm/rans/d14.js.map +0 -1
  134. package/esm/rans/decoding.d.ts +0 -27
  135. package/esm/rans/decoding.js +0 -117
  136. package/esm/rans/decoding.js.map +0 -1
  137. package/esm/rans/frequencies.d.ts +0 -2
  138. package/esm/rans/frequencies.js +0 -105
  139. package/esm/rans/frequencies.js.map +0 -1
  140. package/esm/rans/index.d.ts +0 -1
  141. package/esm/rans/index.js +0 -192
  142. package/esm/rans/index.js.map +0 -1
  143. package/esm/seek-bzip/bitreader.d.ts +0 -27
  144. package/esm/seek-bzip/bitreader.js +0 -98
  145. package/esm/seek-bzip/bitreader.js.map +0 -1
  146. package/esm/seek-bzip/crc32.d.ts +0 -26
  147. package/esm/seek-bzip/crc32.js +0 -112
  148. package/esm/seek-bzip/crc32.js.map +0 -1
  149. package/esm/seek-bzip/index.d.ts +0 -9
  150. package/esm/seek-bzip/index.js +0 -579
  151. package/esm/seek-bzip/index.js.map +0 -1
  152. package/esm/seek-bzip/stream.d.ts +0 -8
  153. package/esm/seek-bzip/stream.js +0 -34
  154. package/esm/seek-bzip/stream.js.map +0 -1
  155. package/esm/seek-bzip/toHex.d.ts +0 -1
  156. package/esm/seek-bzip/toHex.js +0 -33
  157. package/esm/seek-bzip/toHex.js.map +0 -1
  158. package/src/htscodecs/arith_gen.ts +0 -371
  159. package/src/htscodecs/arith_sh.ts +0 -146
  160. package/src/htscodecs/byte_model.ts +0 -136
  161. package/src/htscodecs/fqzcomp.ts +0 -394
  162. package/src/htscodecs/iostream.ts +0 -159
  163. package/src/htscodecs/rans.ts +0 -250
  164. package/src/htscodecs/rans4x16.ts +0 -521
  165. package/src/htscodecs/tok3.ts +0 -197
  166. package/src/rans/README.md +0 -1
  167. package/src/rans/constants.ts +0 -5
  168. package/src/rans/d04.ts +0 -112
  169. package/src/rans/d14.ts +0 -106
  170. package/src/rans/decoding.ts +0 -138
  171. package/src/rans/frequencies.ts +0 -115
  172. package/src/rans/index.ts +0 -245
  173. package/src/seek-bzip/README.md +0 -6
  174. package/src/seek-bzip/bitreader.ts +0 -113
  175. package/src/seek-bzip/crc32.ts +0 -121
  176. package/src/seek-bzip/index.ts +0 -615
  177. package/src/seek-bzip/stream.ts +0 -33
  178. package/src/seek-bzip/toHex.ts +0 -33
@@ -1,394 +0,0 @@
1
- /* eslint-disable no-var */
2
- // @ts-nocheck
3
-
4
- /*
5
- * Copyright (c) 2019 Genome Research Ltd.
6
- * Author(s): James Bonfield
7
- *
8
- * Redistribution and use in source and binary forms, with or without
9
- * modification, are permitted provided that the following conditions are met:
10
- *
11
- * 1. Redistributions of source code must retain the above copyright notice,
12
- * this list of conditions and the following disclaimer.
13
- *
14
- * 2. Redistributions in binary form must reproduce the above
15
- * copyright notice, this list of conditions and the following
16
- * disclaimer in the documentation and/or other materials provided
17
- * with the distribution.
18
- *
19
- * 3. Neither the names Genome Research Ltd and Wellcome Trust Sanger
20
- * Institute nor the names of its contributors may be used to endorse
21
- * or promote products derived from this software without specific
22
- * prior written permission.
23
- *
24
- * THIS SOFTWARE IS PROVIDED BY GENOME RESEARCH LTD AND CONTRIBUTORS "AS
25
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENOME RESEARCH
28
- * LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
- */
36
-
37
- import RangeCoder from './arith_sh.ts'
38
- import ByteModel from './byte_model.ts'
39
- import IOStream from './iostream.ts'
40
-
41
- // ----------------------------------------------------------------------
42
- // Main arithmetic entry function: decodes a compressed src and
43
- // returns the uncompressed buffer.
44
-
45
- function read_array(src, tab, size) {
46
- let j = 0 // array value
47
- let z = 0 // array index: tab[j]
48
- let last = -1
49
-
50
- // Remove first level of run-length encoding
51
- const R = new Array(1024) // runs
52
- while (z < size) {
53
- const run = src.ReadByte()
54
- R[j++] = run
55
- z += run
56
-
57
- if (run == last) {
58
- let copy = src.ReadByte()
59
- z += run * copy
60
- while (copy--) {
61
- R[j++] = run
62
- }
63
- }
64
- last = run
65
- }
66
-
67
- // Now expand runs in R to tab, noting 255 is max run
68
- let i = 0
69
- j = 0
70
- z = 0
71
- while (z < size) {
72
- let run_len = 0
73
- do {
74
- var part = R[j++]
75
- run_len += part
76
- } while (part == 255)
77
-
78
- while (run_len--) {
79
- tab[z++] = i
80
- }
81
- i++
82
- }
83
- }
84
-
85
- const QMAX = 256
86
-
87
- const FLAG_DEDUP = 2
88
- const FLAG_FLEN = 4
89
- const FLAG_SEL = 8 // whether selector is used in context
90
- const FLAG_QMAP = 16
91
- const FLAG_PTAB = 32
92
- const FLAG_DTAB = 64
93
- const FLAG_QTAB = 128
94
-
95
- const GFLAG_MULTI_PARAM = 1
96
- const GFLAG_HAVE_STAB = 2
97
- const GFLAG_DO_REV = 4
98
-
99
- // Compute a new context from our current state and qual q
100
- function fqz_update_ctx(params, state, q) {
101
- let last = params.context
102
- state.qctx = (state.qctx << params.qshift) + params.qtab[q] // >>> 0
103
- last += (state.qctx & ((1 << params.qbits) - 1)) << params.qloc // >>> 0
104
-
105
- if (params.do_pos) {
106
- last += params.ptab[Math.min(state.p, 1023)] << params.ploc
107
- }
108
-
109
- if (params.do_delta) {
110
- last += params.dtab[Math.min(state.delta, 255)] << params.dloc
111
- // Is it better to use q here or qtab[q]?
112
- // If qtab[q] we can map eg [a-z0-9A-Z]->0 ,->1 and have
113
- // delta being a token number count into comma separated lists?
114
- state.delta += state.prevq != q ? 1 : 0
115
- state.prevq = q
116
- }
117
-
118
- if (params.do_sel) {
119
- last += state.s << params.sloc
120
- }
121
-
122
- state.p--
123
-
124
- return last & 0xffff
125
- }
126
-
127
- function decode_fqz_single_param(src) {
128
- const p = {} // params
129
-
130
- // Load FQZ parameters
131
- p.context = src.ReadUint16()
132
- p.pflags = src.ReadByte()
133
-
134
- p.do_dedup = p.pflags & FLAG_DEDUP
135
- p.fixed_len = p.pflags & FLAG_FLEN
136
- p.do_sel = p.pflags & FLAG_SEL
137
- p.do_qmap = p.pflags & FLAG_QMAP
138
- p.do_pos = p.pflags & FLAG_PTAB
139
- p.do_delta = p.pflags & FLAG_DTAB
140
- p.do_qtab = p.pflags & FLAG_QTAB
141
-
142
- p.max_sym = src.ReadByte()
143
-
144
- let x = src.ReadByte()
145
- p.qbits = x >> 4
146
- p.qshift = x & 15
147
- x = src.ReadByte()
148
- p.qloc = x >> 4
149
- p.sloc = x & 15
150
- x = src.ReadByte()
151
- p.ploc = x >> 4
152
- p.dloc = x & 15
153
-
154
- // Qual map, eg to "unbin" Illumina qualities
155
- p.qmap = new Array(256)
156
- if (p.pflags & FLAG_QMAP) {
157
- for (var i = 0; i < p.max_sym; i++) {
158
- p.qmap[i] = src.ReadByte()
159
- }
160
- } else {
161
- // Useful optimisation to speed up main loop
162
- for (var i = 0; i < 256; i++) {
163
- p.qmap[i] = i
164
- } // NOP
165
- }
166
-
167
- // Read tables
168
- p.qtab = new Array(1024)
169
- if (p.qbits > 0 && p.pflags & FLAG_QTAB) {
170
- read_array(src, p.qtab, 256)
171
- } else {
172
- // Useful optimisation to speed up main loop
173
- for (var i = 0; i < 256; i++) {
174
- p.qtab[i] = i
175
- } // NOP
176
- }
177
-
178
- p.ptab = new Array(1024)
179
- if (p.pflags & FLAG_PTAB) {
180
- read_array(src, p.ptab, 1024)
181
- }
182
-
183
- p.dtab = new Array(256)
184
- if (p.pflags & FLAG_DTAB) {
185
- read_array(src, p.dtab, 256)
186
- }
187
-
188
- return p
189
- }
190
-
191
- function decode_fqz_params(src) {
192
- const gparams = {
193
- max_sym: 0,
194
- }
195
-
196
- // Check fqz format version
197
- const vers = src.ReadByte()
198
- if (vers != 5) {
199
- console.error('Invalid FQZComp version number')
200
- return
201
- }
202
-
203
- const gflags = src.ReadByte()
204
- const nparam = gflags & GFLAG_MULTI_PARAM ? src.ReadByte() : 1
205
- let max_sel = gflags.nparam > 1 ? gflags.nparam - 1 : 0 // Note max_sel, not num_sel
206
-
207
- const stab = new Array(256)
208
- if (gflags & GFLAG_HAVE_STAB) {
209
- max_sel = src.ReadByte()
210
- read_array(src, stab, 256)
211
- } else {
212
- for (var i = 0; i < nparam; i++) {
213
- stab[i] = i
214
- }
215
- for (; i < 256; i++) {
216
- stab[i] = nparam - 1
217
- }
218
- }
219
- gparams.do_rev = gflags & GFLAG_DO_REV
220
- gparams.stab = stab
221
- gparams.max_sel = max_sel
222
-
223
- gparams.params = new Array(gparams.nparam)
224
- for (let p = 0; p < nparam; p++) {
225
- gparams.params[p] = decode_fqz_single_param(src)
226
- if (gparams.max_sym < gparams.params[p].max_sym) {
227
- gparams.max_sym = gparams.params[p].max_sym
228
- }
229
- }
230
-
231
- return gparams
232
- }
233
-
234
- function fqz_create_models(gparams) {
235
- const model = {}
236
-
237
- model.qual = new Array(1 << 16)
238
- for (var i = 0; i < 1 << 16; i++) {
239
- model.qual[i] = new ByteModel(gparams.max_sym + 1)
240
- } // +1 as max value not num. values
241
-
242
- model.len = new Array(4)
243
- for (var i = 0; i < 4; i++) {
244
- model.len[i] = new ByteModel(256)
245
- }
246
-
247
- model.rev = new ByteModel(2)
248
- model.dup = new ByteModel(2)
249
-
250
- if (gparams.max_sel > 0) {
251
- model.sel = new ByteModel(gparams.max_sel + 1)
252
- } // +1 as max value not num. values
253
-
254
- return model
255
- }
256
-
257
- // Initialise a new record, updating state.
258
- // Returns 1 if dup, otherwise 0
259
- function decode_fqz_new_record(src, rc, gparams, model, state, rev) {
260
- // Parameter selector
261
- state.s = gparams.max_sel > 0 ? model.sel.ModelDecode(src, rc) : 0
262
- state.x = gparams.stab[state.s]
263
-
264
- const params = gparams.params[state.x]
265
-
266
- // Reset contexts at the start of each new record
267
- if (params.fixed_len >= 0) {
268
- // Not fixed or fixed but first record
269
- var len = model.len[0].ModelDecode(src, rc)
270
- len |= model.len[1].ModelDecode(src, rc) << 8
271
- len |= model.len[2].ModelDecode(src, rc) << 16
272
- len |= model.len[3].ModelDecode(src, rc) << 24
273
- if (params.fixed_len > 0) {
274
- params.fixed_len = -len
275
- }
276
- } else {
277
- len = -params.fixed_len
278
- }
279
- state.len = len
280
-
281
- if (gparams.do_rev) {
282
- rev[state.rec] = model.rev.ModelDecode(src, rc)
283
- }
284
-
285
- state.is_dup = 0
286
- if (params.pflags & FLAG_DEDUP) {
287
- if (model.dup.ModelDecode(src, rc)) {
288
- state.is_dup = 1
289
- }
290
- }
291
-
292
- state.p = len // number of remaining bytes in this record
293
- state.delta = 0
294
- state.qctx = 0
295
- state.prevq = 0
296
- state.rec++
297
- }
298
-
299
- function decode_fqz(src: IOStream, q_lens: number) {
300
- // Decode parameter block
301
- const n_out = src.ReadUint7()
302
- const gparams = decode_fqz_params(src)
303
- if (!gparams) {
304
- return
305
- }
306
- var params = gparams.params
307
- const rev = new Array(q_lens.length)
308
-
309
- // Create initial models
310
- const model = fqz_create_models(gparams)
311
-
312
- // Create our entropy encoder and output buffers
313
- const rc = new RangeCoder(src)
314
- rc.RangeStartDecode(src)
315
- const output = new Uint8Array(n_out)
316
-
317
- // Internal FQZ state
318
- const state = {
319
- qctx: 0, // Qual-only sub-context
320
- prevq: 0, // Previous quality value
321
- delta: 0, // Running delta (q vs prevq)
322
- p: 0, // Number of bases left in current record
323
- s: 0, // Current parameter selector value (0 if unused)
324
- x: 0, // "stab" tabulated copy of s
325
- len: 0, // Length of current string
326
- is_dup: 0, // This string is a duplicate of last
327
- rec: 0, // Record number
328
- }
329
-
330
- // The main decode loop itself
331
- let i = 0 // position in output buffer
332
- while (i < n_out) {
333
- if (state.p == 0) {
334
- decode_fqz_new_record(src, rc, gparams, model, state, rev)
335
- if (state.is_dup > 0) {
336
- if (model.dup.ModelDecode(src, rc)) {
337
- // Duplicate of last line
338
- for (let x = 0; x < len; x++) {
339
- output[i + x] = output[i + x - state.len]
340
- }
341
- i += state.len
342
- state.p = 0
343
- continue
344
- }
345
- }
346
- q_lens.push(state.len)
347
-
348
- var params = gparams.params[state.x]
349
- var last = params.context
350
- }
351
-
352
- // Decode the current quality (possibly mapped via qmap)
353
- const Q = model.qual[last].ModelDecode(src, rc)
354
-
355
- // if (params.do_qmap)
356
- // output[i++] = params.qmap[Q];
357
- // else
358
- // output[i++] = Q
359
- output[i++] = params.qmap[Q] // optimised version of above
360
- last = fqz_update_ctx(params, state, Q)
361
- }
362
-
363
- if (gparams.do_rev) {
364
- reverse_qualities(output, n_out, rev, q_lens)
365
- }
366
-
367
- return output
368
- }
369
-
370
- function reverse_qualities(qual, qual_len, rev, len) {
371
- let rec = 0
372
- let i = 0
373
- while (i < qual_len) {
374
- if (rev[rec]) {
375
- let j = 0
376
- let k = len[rec] - 1
377
- while (j < k) {
378
- const tmp = qual[i + j]
379
- qual[i + j] = qual[i + k]
380
- qual[i + k] = tmp
381
- j++
382
- k--
383
- }
384
- }
385
-
386
- i += len[rec++]
387
- }
388
- }
389
-
390
- export function decode(src: Uint8Array, q_lens) {
391
- const stream = new IOStream(src)
392
-
393
- return decode_fqz(stream, q_lens)
394
- }
@@ -1,159 +0,0 @@
1
- // @ts-nocheck
2
-
3
- /*
4
- * Copyright (c) 2019 Genome Research Ltd.
5
- * Author(s): James Bonfield
6
- *
7
- * Redistribution and use in source and binary forms, with or without
8
- * modification, are permitted provided that the following conditions are met:
9
- *
10
- * 1. Redistributions of source code must retain the above copyright notice,
11
- * this list of conditions and the following disclaimer.
12
- *
13
- * 2. Redistributions in binary form must reproduce the above
14
- * copyright notice, this list of conditions and the following
15
- * disclaimer in the documentation and/or other materials provided
16
- * with the distribution.
17
- *
18
- * 3. Neither the names Genome Research Ltd and Wellcome Trust Sanger
19
- * Institute nor the names of its contributors may be used to endorse
20
- * or promote products derived from this software without specific
21
- * prior written permission.
22
- *
23
- * THIS SOFTWARE IS PROVIDED BY GENOME RESEARCH LTD AND CONTRIBUTORS "AS
24
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENOME RESEARCH
27
- * LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- */
35
-
36
- // Turn a buffer into a fake stream with get / put commands.
37
- // This enables up to closely match the published pseudocode.
38
- export default class IOStream {
39
- buf: Uint8Array
40
- length: number
41
- pos: number
42
- dataView: DataView
43
-
44
- constructor(buf: Uint8Array, start_pos = 0, size = 0) {
45
- if (size !== 0) {
46
- this.buf = new Uint8Array(size)
47
- this.length = size
48
- } else {
49
- this.buf = buf
50
- this.length = buf.length
51
- }
52
- this.dataView = new DataView(this.buf.buffer)
53
- this.pos = start_pos
54
- }
55
-
56
- // ----------
57
- // Reading
58
- EOF() {
59
- return this.pos >= this.length
60
- }
61
-
62
- ReadData(len: number) {
63
- const A = this.buf.slice(this.pos, this.pos + len)
64
- this.pos += len
65
- return A
66
- }
67
-
68
- ReadByte() {
69
- const b = this.buf[this.pos]!
70
- this.pos++
71
- return b
72
- }
73
-
74
- ReadChar() {
75
- const b = this.buf[this.pos]!
76
- this.pos++
77
- return String.fromCharCode(b)
78
- }
79
-
80
- ReadUint16() {
81
- let i = this.ReadByte()
82
- i |= this.ReadByte() << 8
83
- return i
84
- }
85
-
86
- ReadUint32() {
87
- const i = this.dataView.getInt32(this.pos, true)
88
- this.pos += 4
89
- return i
90
- }
91
-
92
- // nul terminated string
93
- ReadString() {
94
- let s = ''
95
- let b: number
96
- do {
97
- b = this.buf[this.pos++]!
98
- if (b) {
99
- s += String.fromCharCode(b)
100
- }
101
- } while (b)
102
- return s
103
- }
104
-
105
- ReadUint7() {
106
- // Variable sized unsigned integers
107
- let i = 0
108
- let c: number
109
- do {
110
- c = this.ReadByte()
111
- i = (i << 7) | (c & 0x7f)
112
- } while (c & 0x80)
113
-
114
- return i
115
- }
116
-
117
- ReadITF8() {
118
- let i = this.buf[this.pos]!
119
- this.pos++
120
-
121
- // process.stderr.write("i="+i+"\n");
122
-
123
- if (i >= 0xf0) {
124
- // 1111xxxx => +4 bytes
125
- i = (i & 0x0f) << 28
126
- i +=
127
- (this.buf[this.pos + 0]! << 20) +
128
- (this.buf[this.pos + 1]! << 12) +
129
- (this.buf[this.pos + 2]! << 4) +
130
- (this.buf[this.pos + 3]! >> 4)
131
- this.pos += 4
132
- // process.stderr.write(" 4i="+i+"\n");
133
- } else if (i >= 0xe0) {
134
- // 1110xxxx => +3 bytes
135
- i = (i & 0x0f) << 24
136
- i +=
137
- (this.buf[this.pos + 0]! << 16) +
138
- (this.buf[this.pos + 1]! << 8) +
139
- (this.buf[this.pos + 2]! << 0)
140
- this.pos += 3
141
- // process.stderr.write(" 3i="+i+"\n");
142
- } else if (i >= 0xc0) {
143
- // 110xxxxx => +2 bytes
144
- i = (i & 0x1f) << 16
145
- i += (this.buf[this.pos + 0]! << 8) + (this.buf[this.pos + 1]! << 0)
146
- this.pos += 2
147
- // process.stderr.write(" 2i="+i+"\n");
148
- } else if (i >= 0x80) {
149
- // 10xxxxxx => +1 bytes
150
- i = (i & 0x3f) << 8
151
- i += this.buf[this.pos]!
152
- this.pos++
153
- } else {
154
- // 0xxxxxxx => +0 bytes
155
- }
156
-
157
- return i
158
- }
159
- }