@genome-spy/core 0.64.0 → 0.65.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 (104) hide show
  1. package/dist/bundle/{index-CCJIjehY.js → AbortablePromiseCache-CcuMrnn7.js} +22 -91
  2. package/dist/bundle/browser-txUcLy2H.js +123 -0
  3. package/dist/bundle/index-BQpbYrv4.js +1712 -0
  4. package/dist/bundle/index-BhtHKLUo.js +73 -0
  5. package/dist/bundle/index-C0llXMqm.js +280 -0
  6. package/dist/bundle/index-CCe8rnZz.js +716 -0
  7. package/dist/bundle/index-CD7FLu9x.js +269 -0
  8. package/dist/bundle/{index-C08YCM2T.js → index-D-w7Mmt9.js} +246 -126
  9. package/dist/bundle/index-D74H8TTz.js +508 -0
  10. package/dist/bundle/index-DhcU-Gk-.js +1487 -0
  11. package/dist/bundle/index.es.js +4878 -4680
  12. package/dist/bundle/index.js +151 -167
  13. package/dist/bundle/inflate-DRgHi_KK.js +1050 -0
  14. package/dist/schema.json +9 -1
  15. package/dist/src/data/collector.d.ts +7 -2
  16. package/dist/src/data/collector.d.ts.map +1 -1
  17. package/dist/src/data/collector.js +13 -2
  18. package/dist/src/data/dataFlow.d.ts +20 -42
  19. package/dist/src/data/dataFlow.d.ts.map +1 -1
  20. package/dist/src/data/dataFlow.js +57 -80
  21. package/dist/src/data/dataFlow.test.js +35 -2
  22. package/dist/src/data/flowHandle.d.ts +15 -0
  23. package/dist/src/data/flowHandle.d.ts.map +1 -0
  24. package/dist/src/data/flowHandle.js +13 -0
  25. package/dist/src/data/flowInit.d.ts +85 -0
  26. package/dist/src/data/flowInit.d.ts.map +1 -0
  27. package/dist/src/data/flowInit.js +238 -0
  28. package/dist/src/data/flowInit.test.d.ts +2 -0
  29. package/dist/src/data/flowInit.test.d.ts.map +1 -0
  30. package/dist/src/data/flowInit.test.js +413 -0
  31. package/dist/src/data/flowOptimizer.d.ts +6 -4
  32. package/dist/src/data/flowOptimizer.d.ts.map +1 -1
  33. package/dist/src/data/flowOptimizer.js +29 -14
  34. package/dist/src/data/flowOptimizer.test.js +20 -15
  35. package/dist/src/data/sources/lazy/bamSource.js +1 -1
  36. package/dist/src/data/sources/lazy/bigBedSource.js +1 -1
  37. package/dist/src/data/sources/lazy/bigWigSource.js +1 -1
  38. package/dist/src/data/sources/lazy/gff3Source.d.ts +2 -6
  39. package/dist/src/data/sources/lazy/gff3Source.d.ts.map +1 -1
  40. package/dist/src/data/sources/lazy/gff3Source.js +4 -8
  41. package/dist/src/data/sources/lazy/indexedFastaSource.d.ts.map +1 -1
  42. package/dist/src/data/sources/lazy/indexedFastaSource.js +17 -17
  43. package/dist/src/data/sources/lazy/tabixSource.js +1 -1
  44. package/dist/src/genomeSpy.d.ts +1 -1
  45. package/dist/src/genomeSpy.d.ts.map +1 -1
  46. package/dist/src/genomeSpy.js +18 -61
  47. package/dist/src/marks/mark.d.ts +1 -0
  48. package/dist/src/marks/mark.d.ts.map +1 -1
  49. package/dist/src/marks/mark.js +22 -1
  50. package/dist/src/spec/sampleView.d.ts +3 -2
  51. package/dist/src/types/viewContext.d.ts +1 -1
  52. package/dist/src/view/axisResolution.d.ts +5 -0
  53. package/dist/src/view/axisResolution.d.ts.map +1 -1
  54. package/dist/src/view/axisResolution.js +16 -1
  55. package/dist/src/view/facetView.d.ts.map +1 -1
  56. package/dist/src/view/facetView.js +1 -0
  57. package/dist/src/view/flowBuilder.d.ts +2 -2
  58. package/dist/src/view/flowBuilder.d.ts.map +1 -1
  59. package/dist/src/view/flowBuilder.js +21 -4
  60. package/dist/src/view/gridView/gridView.d.ts.map +1 -1
  61. package/dist/src/view/gridView/gridView.js +13 -0
  62. package/dist/src/view/gridView/selectionRect.d.ts +8 -4
  63. package/dist/src/view/gridView/selectionRect.d.ts.map +1 -1
  64. package/dist/src/view/gridView/selectionRect.js +28 -3
  65. package/dist/src/view/gridView/selectionRect.test.d.ts +2 -0
  66. package/dist/src/view/gridView/selectionRect.test.d.ts.map +1 -0
  67. package/dist/src/view/gridView/selectionRect.test.js +87 -0
  68. package/dist/src/view/paramMediator.d.ts +2 -1
  69. package/dist/src/view/paramMediator.d.ts.map +1 -1
  70. package/dist/src/view/paramMediator.js +13 -1
  71. package/dist/src/view/paramMediator.test.js +22 -0
  72. package/dist/src/view/scaleResolution.d.ts +5 -0
  73. package/dist/src/view/scaleResolution.d.ts.map +1 -1
  74. package/dist/src/view/scaleResolution.js +10 -0
  75. package/dist/src/view/testUtils.d.ts.map +1 -1
  76. package/dist/src/view/testUtils.js +16 -4
  77. package/dist/src/view/unitView.d.ts.map +1 -1
  78. package/dist/src/view/unitView.js +58 -8
  79. package/dist/src/view/view.d.ts +17 -1
  80. package/dist/src/view/view.d.ts.map +1 -1
  81. package/dist/src/view/view.js +57 -1
  82. package/dist/src/view/viewDispose.test.d.ts +2 -0
  83. package/dist/src/view/viewDispose.test.d.ts.map +1 -0
  84. package/dist/src/view/viewDispose.test.js +110 -0
  85. package/dist/src/view/viewUtils.d.ts +4 -4
  86. package/dist/src/view/viewUtils.d.ts.map +1 -1
  87. package/dist/src/view/viewUtils.js +19 -15
  88. package/dist/src/view/viewUtils.test.d.ts +2 -0
  89. package/dist/src/view/viewUtils.test.d.ts.map +1 -0
  90. package/dist/src/view/viewUtils.test.js +87 -0
  91. package/package.json +10 -10
  92. package/dist/bundle/__vite-browser-external-C--ziKoh.js +0 -8
  93. package/dist/bundle/_commonjsHelpers-DjF3Plf2.js +0 -26
  94. package/dist/bundle/index-5ajWdKly.js +0 -1319
  95. package/dist/bundle/index-B03-Om4z.js +0 -274
  96. package/dist/bundle/index-BftNdA0O.js +0 -27
  97. package/dist/bundle/index-Bg7C4Xat.js +0 -2750
  98. package/dist/bundle/index-C3QR8Lv6.js +0 -2131
  99. package/dist/bundle/index-DTcHjAHp.js +0 -505
  100. package/dist/bundle/index-DnIkxb0L.js +0 -1025
  101. package/dist/bundle/index-Ww3TAo6_.js +0 -71
  102. package/dist/bundle/index-g8iXgW0W.js +0 -651
  103. package/dist/bundle/long-B-FASCSo.js +0 -2387
  104. package/dist/bundle/remoteFile-BuaqFGWk.js +0 -94
@@ -0,0 +1,1487 @@
1
+ import { L as D } from "./index-BhtHKLUo.js";
2
+ import { I as z, Z as G } from "./inflate-DRgHi_KK.js";
3
+ import { LocalFile as B, RemoteFile as T } from "./browser-txUcLy2H.js";
4
+ class N {
5
+ constructor(e, n, t, r) {
6
+ this.minv = e, this.maxv = n, this.bin = t, this._fetchedSize = r;
7
+ }
8
+ toUniqueString() {
9
+ return `${this.minv.toString()}..${this.maxv.toString()} (bin ${this.bin}, fetchedSize ${this.fetchedSize()})`;
10
+ }
11
+ toString() {
12
+ return this.toUniqueString();
13
+ }
14
+ compareTo(e) {
15
+ return this.minv.compareTo(e.minv) || this.maxv.compareTo(e.maxv) || this.bin - e.bin;
16
+ }
17
+ fetchedSize() {
18
+ return this._fetchedSize !== void 0 ? this._fetchedSize : this.maxv.blockPosition + 65536 - this.minv.blockPosition;
19
+ }
20
+ }
21
+ class H {
22
+ constructor({ filehandle: e, renameRefSeq: n = (t) => t }) {
23
+ this.filehandle = e, this.renameRefSeq = n;
24
+ }
25
+ }
26
+ const $ = 65536, te = $ * $;
27
+ function ne(c, e = 0) {
28
+ const n = c[e] | c[e + 1] << 8 | c[e + 2] << 16 | c[e + 3] << 24;
29
+ return ((c[e + 4] | c[e + 5] << 8 | c[e + 6] << 16 | c[e + 7] << 24) >>> 0) * te + (n >>> 0);
30
+ }
31
+ function re(c, e) {
32
+ return e.minv.blockPosition - c.maxv.blockPosition < 65e3 && e.maxv.blockPosition - c.minv.blockPosition < 5e6;
33
+ }
34
+ function se(c = {}) {
35
+ return "aborted" in c ? { signal: c } : c;
36
+ }
37
+ function j(c, e) {
38
+ const n = [];
39
+ let t;
40
+ if (c.length === 0)
41
+ return c;
42
+ c.sort((r, a) => {
43
+ const s = r.minv.blockPosition - a.minv.blockPosition;
44
+ return s === 0 ? r.minv.dataPosition - a.minv.dataPosition : s;
45
+ });
46
+ for (const r of c)
47
+ (!e || r.maxv.compareTo(e) > 0) && (t === void 0 ? (n.push(r), t = r) : re(t, r) ? r.maxv.compareTo(t.maxv) > 0 && (t.maxv = r.maxv) : (n.push(r), t = r));
48
+ return n;
49
+ }
50
+ function Q(c, e) {
51
+ return {
52
+ lineCount: ne(c, e)
53
+ };
54
+ }
55
+ function F(c, e) {
56
+ return c ? c.compareTo(e) > 0 ? e : c : e;
57
+ }
58
+ function ie(c, e = (n) => n) {
59
+ let n = 0, t = 0;
60
+ const r = [], a = {};
61
+ for (let s = 0; s < c.length; s += 1)
62
+ if (!c[s]) {
63
+ if (t < s) {
64
+ let o = "";
65
+ for (let i = t; i < s; i++)
66
+ o += String.fromCharCode(c[i]);
67
+ o = e(o), r[n] = o, a[o] = n;
68
+ }
69
+ t = s + 1, n += 1;
70
+ }
71
+ return { refNameToId: a, refIdToName: r };
72
+ }
73
+ function ae(c) {
74
+ let e = 0;
75
+ for (const r of c)
76
+ e += r.length;
77
+ const n = new Uint8Array(e);
78
+ let t = 0;
79
+ for (const r of c)
80
+ n.set(r, t), t += r.length;
81
+ return n;
82
+ }
83
+ async function oe(c) {
84
+ const e = [];
85
+ for await (const n of c)
86
+ for (const t of n)
87
+ e.push(t);
88
+ return e;
89
+ }
90
+ class W {
91
+ constructor(e, n) {
92
+ this.blockPosition = e, this.dataPosition = n;
93
+ }
94
+ toString() {
95
+ return `${this.blockPosition}:${this.dataPosition}`;
96
+ }
97
+ compareTo(e) {
98
+ return this.blockPosition - e.blockPosition || this.dataPosition - e.dataPosition;
99
+ }
100
+ }
101
+ function C(c, e = 0, n = !1) {
102
+ if (n)
103
+ throw new Error("big-endian virtual file offsets not implemented");
104
+ return new W(c[e + 7] * 1099511627776 + c[e + 6] * 4294967296 + c[e + 5] * 16777216 + c[e + 4] * 65536 + c[e + 3] * 256 + c[e + 2], c[e + 1] << 8 | c[e]);
105
+ }
106
+ const ce = 21578050;
107
+ function fe(c, e) {
108
+ return c - c % e;
109
+ }
110
+ function de(c, e) {
111
+ return c - c % e + e;
112
+ }
113
+ function he(c, e) {
114
+ return e -= 1, [
115
+ [0, 0],
116
+ [1 + (c >> 26), 1 + (e >> 26)],
117
+ [9 + (c >> 23), 9 + (e >> 23)],
118
+ [73 + (c >> 20), 73 + (e >> 20)],
119
+ [585 + (c >> 17), 585 + (e >> 17)],
120
+ [4681 + (c >> 14), 4681 + (e >> 14)]
121
+ ];
122
+ }
123
+ class E extends H {
124
+ async lineCount(e, n) {
125
+ var r, a;
126
+ return ((a = (r = (await this.parse(n)).indices(e)) == null ? void 0 : r.stats) == null ? void 0 : a.lineCount) || 0;
127
+ }
128
+ async _parse(e) {
129
+ const n = await this.filehandle.readFile(), t = new DataView(n.buffer);
130
+ if (t.getUint32(0, !0) !== ce)
131
+ throw new Error("Not a BAI file");
132
+ const r = t.getInt32(4, !0), s = ((1 << (5 + 1) * 3) - 1) / 7;
133
+ let o = 8, i;
134
+ const f = [];
135
+ for (let b = 0; b < r; b++) {
136
+ f.push(o);
137
+ const h = t.getInt32(o, !0);
138
+ o += 4;
139
+ for (let u = 0; u < h; u += 1) {
140
+ const l = t.getUint32(o, !0);
141
+ if (o += 4, l === s + 1)
142
+ o += 4, o += 32;
143
+ else {
144
+ if (l > s + 1)
145
+ throw new Error("bai index contains too many bins, please use CSI");
146
+ {
147
+ const m = t.getInt32(o, !0);
148
+ o += 4;
149
+ for (let y = 0; y < m; y++)
150
+ o += 8, o += 8;
151
+ }
152
+ }
153
+ }
154
+ const g = t.getInt32(o, !0);
155
+ o += 4;
156
+ const w = new Array(g);
157
+ for (let u = 0; u < g; u++) {
158
+ const l = C(n, o);
159
+ o += 8, i = F(i, l), w[u] = l;
160
+ }
161
+ }
162
+ const d = new D({
163
+ maxSize: 5
164
+ });
165
+ function x(b) {
166
+ let h = f[b];
167
+ if (h === void 0)
168
+ return;
169
+ const g = t.getInt32(h, !0);
170
+ let w;
171
+ h += 4;
172
+ const u = {};
173
+ for (let y = 0; y < g; y += 1) {
174
+ const _ = t.getUint32(h, !0);
175
+ if (h += 4, _ === s + 1)
176
+ h += 4, w = Q(n, h + 16), h += 32;
177
+ else {
178
+ if (_ > s + 1)
179
+ throw new Error("bai index contains too many bins, please use CSI");
180
+ {
181
+ const p = t.getInt32(h, !0);
182
+ h += 4;
183
+ const I = new Array(p);
184
+ for (let P = 0; P < p; P++) {
185
+ const S = C(n, h);
186
+ h += 8;
187
+ const k = C(n, h);
188
+ h += 8, i = F(i, S), I[P] = new N(S, k, _);
189
+ }
190
+ u[_] = I;
191
+ }
192
+ }
193
+ }
194
+ const l = t.getInt32(h, !0);
195
+ h += 4;
196
+ const m = new Array(l);
197
+ for (let y = 0; y < l; y++) {
198
+ const _ = C(n, h);
199
+ h += 8, i = F(i, _), m[y] = _;
200
+ }
201
+ return {
202
+ binIndex: u,
203
+ linearIndex: m,
204
+ stats: w
205
+ };
206
+ }
207
+ return {
208
+ bai: !0,
209
+ firstDataLine: i,
210
+ maxBlockSize: 65536,
211
+ indices: (b) => {
212
+ if (!d.has(b)) {
213
+ const h = x(b);
214
+ return h && d.set(b, h), h;
215
+ }
216
+ return d.get(b);
217
+ },
218
+ refCount: r
219
+ };
220
+ }
221
+ async indexCov(e, n, t, r) {
222
+ const s = n !== void 0, i = (await this.parse(r)).indices(e);
223
+ if (!i)
224
+ return [];
225
+ const { linearIndex: f = [], stats: d } = i;
226
+ if (f.length === 0)
227
+ return [];
228
+ const x = t === void 0 ? (f.length - 1) * 16384 : de(t, 16384), b = n === void 0 ? 0 : fe(n, 16384), h = s ? new Array((x - b) / 16384) : new Array(f.length - 1), g = f[f.length - 1].blockPosition;
229
+ if (x > (f.length - 1) * 16384)
230
+ throw new Error("query outside of range of linear index");
231
+ let w = f[b / 16384].blockPosition;
232
+ for (let u = b / 16384, l = 0; u < x / 16384; u++, l++)
233
+ h[l] = {
234
+ score: f[u + 1].blockPosition - w,
235
+ start: u * 16384,
236
+ end: u * 16384 + 16384
237
+ }, w = f[u + 1].blockPosition;
238
+ return h.map((u) => ({
239
+ ...u,
240
+ score: u.score * ((d == null ? void 0 : d.lineCount) || 0) / g
241
+ }));
242
+ }
243
+ async blocksForRange(e, n, t, r = {}) {
244
+ n < 0 && (n = 0);
245
+ const a = await this.parse(r);
246
+ if (!a)
247
+ return [];
248
+ const s = a.indices(e);
249
+ if (!s)
250
+ return [];
251
+ const o = he(n, t), i = [];
252
+ for (const [h, g] of o)
253
+ for (let w = h; w <= g; w++)
254
+ if (s.binIndex[w]) {
255
+ const u = s.binIndex[w];
256
+ for (const l of u)
257
+ i.push(new N(l.minv, l.maxv, w));
258
+ }
259
+ const f = s.linearIndex.length;
260
+ let d;
261
+ const x = Math.min(n >> 14, f - 1), b = Math.min(t >> 14, f - 1);
262
+ for (let h = x; h <= b; ++h) {
263
+ const g = s.linearIndex[h];
264
+ g && (!d || g.compareTo(d) < 0) && (d = g);
265
+ }
266
+ return j(i, d);
267
+ }
268
+ async parse(e = {}) {
269
+ return this.setupP || (this.setupP = this._parse(e).catch((n) => {
270
+ throw this.setupP = void 0, n;
271
+ })), this.setupP;
272
+ }
273
+ async hasRefSeq(e, n = {}) {
274
+ var r;
275
+ return !!((r = (await this.parse(n)).indices(e)) != null && r.binIndex);
276
+ }
277
+ }
278
+ function ue(c) {
279
+ let e = 0;
280
+ for (const n of c)
281
+ e += n.length;
282
+ return e;
283
+ }
284
+ function Y(c, e) {
285
+ const n = new Uint8Array(e ?? ue(c));
286
+ let t = 0;
287
+ for (const r of c)
288
+ n.set(r, t), t += r.length;
289
+ return n;
290
+ }
291
+ async function V(c) {
292
+ try {
293
+ let e, n = 0, t;
294
+ const r = [];
295
+ let a = 0;
296
+ do {
297
+ const s = c.subarray(n);
298
+ if (t = new z(void 0), { strm: e } = t, t.push(s, G), t.err)
299
+ throw new Error(t.msg);
300
+ n += e.next_in;
301
+ const o = t.result;
302
+ r.push(o), a += o.length;
303
+ } while (e.avail_in);
304
+ return Y(r, a);
305
+ } catch (e) {
306
+ throw /incorrect header check/.exec(`${e}`) ? new Error("problem decompressing block: incorrect gzip header check") : e;
307
+ }
308
+ }
309
+ async function le(c, e, n) {
310
+ try {
311
+ let t;
312
+ const { minv: r, maxv: a } = e;
313
+ let s = r.blockPosition, o = r.dataPosition;
314
+ const i = [], f = [], d = [];
315
+ let x = 0, b = !1, h = 0;
316
+ do {
317
+ const g = c.subarray(s - r.blockPosition), w = s.toString();
318
+ let u, l;
319
+ const m = n == null ? void 0 : n.get(w);
320
+ if (m)
321
+ u = m.buffer, l = m.nextIn, b = !0;
322
+ else {
323
+ const p = new z(void 0);
324
+ if ({ strm: t } = p, p.push(g, G), p.err)
325
+ throw new Error(p.msg);
326
+ u = p.result, l = t.next_in, b = !1, n == null || n.set(w, { buffer: u, nextIn: l });
327
+ }
328
+ i.push(u);
329
+ let y = u.length;
330
+ f.push(s), d.push(o), i.length === 1 && r.dataPosition && (i[0] = i[0].subarray(r.dataPosition), y = i[0].length);
331
+ const _ = s;
332
+ if (s += l, o += y, _ >= a.blockPosition) {
333
+ i[x] = i[x].subarray(0, a.blockPosition === r.blockPosition ? a.dataPosition - r.dataPosition + 1 : a.dataPosition + 1), h += i[x].length, f.push(s), d.push(o);
334
+ break;
335
+ }
336
+ h += y, x++;
337
+ } while (b ? s < c.length + r.blockPosition : (
338
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
339
+ t.avail_in
340
+ ));
341
+ return {
342
+ buffer: Y(i, h),
343
+ cpositions: f,
344
+ dpositions: d
345
+ };
346
+ } catch (t) {
347
+ throw /incorrect header check/.exec(`${t}`) ? new Error("problem decompressing block: incorrect gzip header check") : t;
348
+ }
349
+ }
350
+ let q = [
351
+ 0,
352
+ 1996959894,
353
+ 3993919788,
354
+ 2567524794,
355
+ 124634137,
356
+ 1886057615,
357
+ 3915621685,
358
+ 2657392035,
359
+ 249268274,
360
+ 2044508324,
361
+ 3772115230,
362
+ 2547177864,
363
+ 162941995,
364
+ 2125561021,
365
+ 3887607047,
366
+ 2428444049,
367
+ 498536548,
368
+ 1789927666,
369
+ 4089016648,
370
+ 2227061214,
371
+ 450548861,
372
+ 1843258603,
373
+ 4107580753,
374
+ 2211677639,
375
+ 325883990,
376
+ 1684777152,
377
+ 4251122042,
378
+ 2321926636,
379
+ 335633487,
380
+ 1661365465,
381
+ 4195302755,
382
+ 2366115317,
383
+ 997073096,
384
+ 1281953886,
385
+ 3579855332,
386
+ 2724688242,
387
+ 1006888145,
388
+ 1258607687,
389
+ 3524101629,
390
+ 2768942443,
391
+ 901097722,
392
+ 1119000684,
393
+ 3686517206,
394
+ 2898065728,
395
+ 853044451,
396
+ 1172266101,
397
+ 3705015759,
398
+ 2882616665,
399
+ 651767980,
400
+ 1373503546,
401
+ 3369554304,
402
+ 3218104598,
403
+ 565507253,
404
+ 1454621731,
405
+ 3485111705,
406
+ 3099436303,
407
+ 671266974,
408
+ 1594198024,
409
+ 3322730930,
410
+ 2970347812,
411
+ 795835527,
412
+ 1483230225,
413
+ 3244367275,
414
+ 3060149565,
415
+ 1994146192,
416
+ 31158534,
417
+ 2563907772,
418
+ 4023717930,
419
+ 1907459465,
420
+ 112637215,
421
+ 2680153253,
422
+ 3904427059,
423
+ 2013776290,
424
+ 251722036,
425
+ 2517215374,
426
+ 3775830040,
427
+ 2137656763,
428
+ 141376813,
429
+ 2439277719,
430
+ 3865271297,
431
+ 1802195444,
432
+ 476864866,
433
+ 2238001368,
434
+ 4066508878,
435
+ 1812370925,
436
+ 453092731,
437
+ 2181625025,
438
+ 4111451223,
439
+ 1706088902,
440
+ 314042704,
441
+ 2344532202,
442
+ 4240017532,
443
+ 1658658271,
444
+ 366619977,
445
+ 2362670323,
446
+ 4224994405,
447
+ 1303535960,
448
+ 984961486,
449
+ 2747007092,
450
+ 3569037538,
451
+ 1256170817,
452
+ 1037604311,
453
+ 2765210733,
454
+ 3554079995,
455
+ 1131014506,
456
+ 879679996,
457
+ 2909243462,
458
+ 3663771856,
459
+ 1141124467,
460
+ 855842277,
461
+ 2852801631,
462
+ 3708648649,
463
+ 1342533948,
464
+ 654459306,
465
+ 3188396048,
466
+ 3373015174,
467
+ 1466479909,
468
+ 544179635,
469
+ 3110523913,
470
+ 3462522015,
471
+ 1591671054,
472
+ 702138776,
473
+ 2966460450,
474
+ 3352799412,
475
+ 1504918807,
476
+ 783551873,
477
+ 3082640443,
478
+ 3233442989,
479
+ 3988292384,
480
+ 2596254646,
481
+ 62317068,
482
+ 1957810842,
483
+ 3939845945,
484
+ 2647816111,
485
+ 81470997,
486
+ 1943803523,
487
+ 3814918930,
488
+ 2489596804,
489
+ 225274430,
490
+ 2053790376,
491
+ 3826175755,
492
+ 2466906013,
493
+ 167816743,
494
+ 2097651377,
495
+ 4027552580,
496
+ 2265490386,
497
+ 503444072,
498
+ 1762050814,
499
+ 4150417245,
500
+ 2154129355,
501
+ 426522225,
502
+ 1852507879,
503
+ 4275313526,
504
+ 2312317920,
505
+ 282753626,
506
+ 1742555852,
507
+ 4189708143,
508
+ 2394877945,
509
+ 397917763,
510
+ 1622183637,
511
+ 3604390888,
512
+ 2714866558,
513
+ 953729732,
514
+ 1340076626,
515
+ 3518719985,
516
+ 2797360999,
517
+ 1068828381,
518
+ 1219638859,
519
+ 3624741850,
520
+ 2936675148,
521
+ 906185462,
522
+ 1090812512,
523
+ 3747672003,
524
+ 2825379669,
525
+ 829329135,
526
+ 1181335161,
527
+ 3412177804,
528
+ 3160834842,
529
+ 628085408,
530
+ 1382605366,
531
+ 3423369109,
532
+ 3138078467,
533
+ 570562233,
534
+ 1426400815,
535
+ 3317316542,
536
+ 2998733608,
537
+ 733239954,
538
+ 1555261956,
539
+ 3268935591,
540
+ 3050360625,
541
+ 752459403,
542
+ 1541320221,
543
+ 2607071920,
544
+ 3965973030,
545
+ 1969922972,
546
+ 40735498,
547
+ 2617837225,
548
+ 3943577151,
549
+ 1913087877,
550
+ 83908371,
551
+ 2512341634,
552
+ 3803740692,
553
+ 2075208622,
554
+ 213261112,
555
+ 2463272603,
556
+ 3855990285,
557
+ 2094854071,
558
+ 198958881,
559
+ 2262029012,
560
+ 4057260610,
561
+ 1759359992,
562
+ 534414190,
563
+ 2176718541,
564
+ 4139329115,
565
+ 1873836001,
566
+ 414664567,
567
+ 2282248934,
568
+ 4279200368,
569
+ 1711684554,
570
+ 285281116,
571
+ 2405801727,
572
+ 4167216745,
573
+ 1634467795,
574
+ 376229701,
575
+ 2685067896,
576
+ 3608007406,
577
+ 1308918612,
578
+ 956543938,
579
+ 2808555105,
580
+ 3495958263,
581
+ 1231636301,
582
+ 1047427035,
583
+ 2932959818,
584
+ 3654703836,
585
+ 1088359270,
586
+ 936918e3,
587
+ 2847714899,
588
+ 3736837829,
589
+ 1202900863,
590
+ 817233897,
591
+ 3183342108,
592
+ 3401237130,
593
+ 1404277552,
594
+ 615818150,
595
+ 3134207493,
596
+ 3453421203,
597
+ 1423857449,
598
+ 601450431,
599
+ 3009837614,
600
+ 3294710456,
601
+ 1567103746,
602
+ 711928724,
603
+ 3020668471,
604
+ 3272380065,
605
+ 1510334235,
606
+ 755167117
607
+ ];
608
+ typeof Int32Array < "u" && (q = new Int32Array(q));
609
+ const xe = (c, e) => {
610
+ let n = -1;
611
+ for (let t = 0; t < c.length; t++)
612
+ n = q[(n ^ c[t]) & 255] ^ n >>> 8;
613
+ return n ^ -1;
614
+ }, be = 21582659, ge = 38359875;
615
+ function we(c, e) {
616
+ return c * 2 ** e;
617
+ }
618
+ function O(c, e) {
619
+ return Math.floor(c / 2 ** e);
620
+ }
621
+ class U extends H {
622
+ constructor() {
623
+ super(...arguments), this.maxBinNumber = 0, this.depth = 0, this.minShift = 0;
624
+ }
625
+ async lineCount(e, n) {
626
+ var r, a;
627
+ return ((a = (r = (await this.parse(n)).indices(e)) == null ? void 0 : r.stats) == null ? void 0 : a.lineCount) || 0;
628
+ }
629
+ async indexCov() {
630
+ return [];
631
+ }
632
+ parseAuxData(e, n) {
633
+ const t = new DataView(e.buffer), r = t.getUint32(n, !0), a = r & 65536 ? "zero-based-half-open" : "1-based-closed", s = { 0: "generic", 1: "SAM", 2: "VCF" }[r & 15];
634
+ if (!s)
635
+ throw new Error(`invalid Tabix preset format flags ${r}`);
636
+ const o = {
637
+ ref: t.getInt32(n + 4, !0),
638
+ start: t.getInt32(n + 8, !0),
639
+ end: t.getInt32(n + 12, !0)
640
+ }, i = t.getInt32(n + 16, !0), f = i ? String.fromCharCode(i) : "", d = t.getInt32(n + 20, !0), x = t.getInt32(n + 24, !0);
641
+ return {
642
+ columnNumbers: o,
643
+ coordinateType: a,
644
+ metaValue: i,
645
+ metaChar: f,
646
+ skipLines: d,
647
+ format: s,
648
+ formatFlags: r,
649
+ ...ie(e.subarray(n + 28, n + 28 + x), this.renameRefSeq)
650
+ };
651
+ }
652
+ // fetch and parse the index
653
+ async _parse(e) {
654
+ const n = await this.filehandle.readFile(e), t = await V(n), r = new DataView(t.buffer);
655
+ let a;
656
+ const s = r.getUint32(0, !0);
657
+ if (s === be)
658
+ a = 1;
659
+ else if (s === ge)
660
+ a = 2;
661
+ else
662
+ throw new Error(`Not a CSI file ${s}`);
663
+ this.minShift = r.getInt32(4, !0), this.depth = r.getInt32(8, !0), this.maxBinNumber = ((1 << (this.depth + 1) * 3) - 1) / 7;
664
+ const o = this.maxBinNumber, i = r.getInt32(12, !0), f = i >= 30 ? this.parseAuxData(t, 16) : void 0, d = r.getInt32(16 + i, !0);
665
+ let x = 16 + i + 4, b;
666
+ const h = [];
667
+ for (let u = 0; u < d; u++) {
668
+ h.push(x);
669
+ const l = r.getInt32(x, !0);
670
+ x += 4;
671
+ for (let m = 0; m < l; m++) {
672
+ const y = r.getUint32(x, !0);
673
+ if (x += 4, y > this.maxBinNumber)
674
+ x += 44;
675
+ else {
676
+ x += 8;
677
+ const _ = r.getInt32(x, !0);
678
+ x += 4;
679
+ for (let p = 0; p < _; p += 1) {
680
+ const I = C(t, x);
681
+ x += 8, x += 8, b = F(b, I);
682
+ }
683
+ }
684
+ }
685
+ }
686
+ const g = new D({
687
+ maxSize: 5
688
+ });
689
+ function w(u) {
690
+ let l = h[u];
691
+ if (l === void 0)
692
+ return;
693
+ const m = r.getInt32(l, !0);
694
+ l += 4;
695
+ const y = {};
696
+ let _;
697
+ for (let p = 0; p < m; p++) {
698
+ const I = r.getUint32(l, !0);
699
+ if (l += 4, I > o)
700
+ _ = Q(t, l + 28), l += 44;
701
+ else {
702
+ b = F(b, C(t, l)), l += 8;
703
+ const P = r.getInt32(l, !0);
704
+ l += 4;
705
+ const S = new Array(P);
706
+ for (let k = 0; k < P; k += 1) {
707
+ const X = C(t, l);
708
+ l += 8;
709
+ const ee = C(t, l);
710
+ l += 8, S[k] = new N(X, ee, I);
711
+ }
712
+ y[I] = S;
713
+ }
714
+ }
715
+ return {
716
+ binIndex: y,
717
+ stats: _
718
+ };
719
+ }
720
+ return {
721
+ csiVersion: a,
722
+ firstDataLine: b,
723
+ indices: (u) => {
724
+ if (!g.has(u)) {
725
+ const l = w(u);
726
+ return l && g.set(u, l), l;
727
+ }
728
+ return g.get(u);
729
+ },
730
+ refCount: d,
731
+ csi: !0,
732
+ maxBlockSize: 65536,
733
+ ...f
734
+ };
735
+ }
736
+ async blocksForRange(e, n, t, r = {}) {
737
+ n < 0 && (n = 0);
738
+ const s = (await this.parse(r)).indices(e);
739
+ if (!s)
740
+ return [];
741
+ const o = this.reg2bins(n, t);
742
+ if (o.length === 0)
743
+ return [];
744
+ const i = [];
745
+ for (const [f, d] of o)
746
+ for (let x = f; x <= d; x++)
747
+ if (s.binIndex[x]) {
748
+ const b = s.binIndex[x];
749
+ for (const h of b)
750
+ i.push(h);
751
+ }
752
+ return j(i, new W(0, 0));
753
+ }
754
+ /**
755
+ * calculate the list of bins that may overlap with region [beg,end)
756
+ * (zero-based half-open)
757
+ */
758
+ reg2bins(e, n) {
759
+ e -= 1, e < 1 && (e = 1), n > 2 ** 50 && (n = 2 ** 34), n -= 1;
760
+ let t = 0, r = 0, a = this.minShift + this.depth * 3;
761
+ const s = [];
762
+ for (; t <= this.depth; a -= 3, r += we(1, t * 3), t += 1) {
763
+ const o = r + O(e, a), i = r + O(n, a);
764
+ if (i - o + s.length > this.maxBinNumber)
765
+ throw new Error(`query ${e}-${n} is too large for current binning scheme (shift ${this.minShift}, depth ${this.depth}), try a smaller query or a coarser index binning scheme`);
766
+ s.push([o, i]);
767
+ }
768
+ return s;
769
+ }
770
+ async parse(e = {}) {
771
+ return this.setupP || (this.setupP = this._parse(e).catch((n) => {
772
+ throw this.setupP = void 0, n;
773
+ })), this.setupP;
774
+ }
775
+ async hasRefSeq(e, n = {}) {
776
+ var r;
777
+ return !!((r = (await this.parse(n)).indices(e)) != null && r.binIndex);
778
+ }
779
+ }
780
+ class me {
781
+ read() {
782
+ throw new Error("never called");
783
+ }
784
+ stat() {
785
+ throw new Error("never called");
786
+ }
787
+ readFile() {
788
+ throw new Error("never called");
789
+ }
790
+ close() {
791
+ throw new Error("never called");
792
+ }
793
+ }
794
+ const A = {
795
+ // the read is paired in sequencing, no matter whether it is mapped in a pair
796
+ BAM_FPAIRED: 1,
797
+ // the read is mapped in a proper pair
798
+ BAM_FPROPER_PAIR: 2,
799
+ // the read itself is unmapped; conflictive with BAM_FPROPER_PAIR
800
+ BAM_FUNMAP: 4,
801
+ // the mate is unmapped
802
+ BAM_FMUNMAP: 8,
803
+ // the read is mapped to the reverse strand
804
+ BAM_FREVERSE: 16,
805
+ // the mate is mapped to the reverse strand
806
+ BAM_FMREVERSE: 32,
807
+ // this is read1
808
+ BAM_FREAD1: 64,
809
+ // this is read2
810
+ BAM_FREAD2: 128,
811
+ // not primary alignment
812
+ BAM_FSECONDARY: 256,
813
+ // QC failure
814
+ BAM_FQCFAIL: 512,
815
+ // optical or PCR duplicate
816
+ BAM_FDUP: 1024,
817
+ // supplementary alignment
818
+ BAM_FSUPPLEMENTARY: 2048
819
+ }, v = "=ACMGRSVTWYHKDBN".split(""), ye = [
820
+ 77,
821
+ 73,
822
+ 68,
823
+ 78,
824
+ 83,
825
+ 72,
826
+ 80,
827
+ 61,
828
+ 88,
829
+ 63,
830
+ 63,
831
+ 63,
832
+ 63,
833
+ 63,
834
+ 63,
835
+ 63
836
+ ], _e = 1, pe = 3, K = 4, Ae = 5, Ie = 1 << _e | 1 << K | 1 << Ae;
837
+ class R {
838
+ constructor(e) {
839
+ this.bytes = e.bytes, this.fileOffset = e.fileOffset, this._dataView = new DataView(this.bytes.byteArray.buffer);
840
+ }
841
+ get byteArray() {
842
+ return this.bytes.byteArray;
843
+ }
844
+ get flags() {
845
+ return (this._dataView.getInt32(this.bytes.start + 16, !0) & 4294901760) >> 16;
846
+ }
847
+ get ref_id() {
848
+ return this._dataView.getInt32(this.bytes.start + 4, !0);
849
+ }
850
+ get start() {
851
+ return this._dataView.getInt32(this.bytes.start + 8, !0);
852
+ }
853
+ get end() {
854
+ return this.start + this.length_on_ref;
855
+ }
856
+ get id() {
857
+ return this.fileOffset;
858
+ }
859
+ get mq() {
860
+ const e = (this.bin_mq_nl & 65280) >> 8;
861
+ return e === 255 ? void 0 : e;
862
+ }
863
+ get score() {
864
+ return this.mq;
865
+ }
866
+ get qual() {
867
+ if (this.isSegmentUnmapped())
868
+ return;
869
+ const e = this.b0 + this.read_name_length + this.num_cigar_bytes + this.num_seq_bytes;
870
+ return this.byteArray.subarray(e, e + this.seq_length);
871
+ }
872
+ get strand() {
873
+ return this.isReverseComplemented() ? -1 : 1;
874
+ }
875
+ get b0() {
876
+ return this.bytes.start + 36;
877
+ }
878
+ get name() {
879
+ let e = "";
880
+ for (let n = 0; n < this.read_name_length - 1; n++)
881
+ e += String.fromCharCode(this.byteArray[this.b0 + n]);
882
+ return e;
883
+ }
884
+ get tags() {
885
+ let e = this.b0 + this.read_name_length + this.num_cigar_bytes + this.num_seq_bytes + this.seq_length;
886
+ const n = this.bytes.end, t = {};
887
+ for (; e < n; ) {
888
+ const r = String.fromCharCode(this.byteArray[e]) + String.fromCharCode(this.byteArray[e + 1]), a = String.fromCharCode(this.byteArray[e + 2]);
889
+ switch (e += 3, a) {
890
+ case "A":
891
+ t[r] = String.fromCharCode(this.byteArray[e]), e += 1;
892
+ break;
893
+ case "i":
894
+ t[r] = this._dataView.getInt32(e, !0), e += 4;
895
+ break;
896
+ case "I":
897
+ t[r] = this._dataView.getUint32(e, !0), e += 4;
898
+ break;
899
+ case "c":
900
+ t[r] = this._dataView.getInt8(e), e += 1;
901
+ break;
902
+ case "C":
903
+ t[r] = this._dataView.getUint8(e), e += 1;
904
+ break;
905
+ case "s":
906
+ t[r] = this._dataView.getInt16(e, !0), e += 2;
907
+ break;
908
+ case "S":
909
+ t[r] = this._dataView.getUint16(e, !0), e += 2;
910
+ break;
911
+ case "f":
912
+ t[r] = this._dataView.getFloat32(e, !0), e += 4;
913
+ break;
914
+ case "Z":
915
+ case "H": {
916
+ const s = [];
917
+ for (; e <= n; ) {
918
+ const o = this.byteArray[e++];
919
+ if (o !== 0)
920
+ s.push(String.fromCharCode(o));
921
+ else
922
+ break;
923
+ }
924
+ t[r] = s.join("");
925
+ break;
926
+ }
927
+ case "B": {
928
+ const s = this.byteArray[e++], o = String.fromCharCode(s), i = this._dataView.getInt32(e, !0);
929
+ e += 4;
930
+ const f = this.byteArray.byteOffset + e;
931
+ if (o === "i") {
932
+ if (f % 4 === 0)
933
+ t[r] = new Int32Array(this.byteArray.buffer, f, i);
934
+ else {
935
+ const d = this.byteArray.slice(e, e + (i << 2));
936
+ t[r] = new Int32Array(d.buffer, d.byteOffset, i);
937
+ }
938
+ e += i << 2;
939
+ } else if (o === "I") {
940
+ if (f % 4 === 0)
941
+ t[r] = new Uint32Array(this.byteArray.buffer, f, i);
942
+ else {
943
+ const d = this.byteArray.slice(e, e + (i << 2));
944
+ t[r] = new Uint32Array(d.buffer, d.byteOffset, i);
945
+ }
946
+ e += i << 2;
947
+ } else if (o === "s") {
948
+ if (f % 2 === 0)
949
+ t[r] = new Int16Array(this.byteArray.buffer, f, i);
950
+ else {
951
+ const d = this.byteArray.slice(e, e + (i << 1));
952
+ t[r] = new Int16Array(d.buffer, d.byteOffset, i);
953
+ }
954
+ e += i << 1;
955
+ } else if (o === "S") {
956
+ if (f % 2 === 0)
957
+ t[r] = new Uint16Array(this.byteArray.buffer, f, i);
958
+ else {
959
+ const d = this.byteArray.slice(e, e + (i << 1));
960
+ t[r] = new Uint16Array(d.buffer, d.byteOffset, i);
961
+ }
962
+ e += i << 1;
963
+ } else if (o === "c")
964
+ t[r] = new Int8Array(this.byteArray.buffer, f, i), e += i;
965
+ else if (o === "C")
966
+ t[r] = new Uint8Array(this.byteArray.buffer, f, i), e += i;
967
+ else if (o === "f") {
968
+ if (f % 4 === 0)
969
+ t[r] = new Float32Array(this.byteArray.buffer, f, i);
970
+ else {
971
+ const d = this.byteArray.slice(e, e + (i << 2));
972
+ t[r] = new Float32Array(d.buffer, d.byteOffset, i);
973
+ }
974
+ e += i << 2;
975
+ }
976
+ break;
977
+ }
978
+ default:
979
+ console.error("Unknown BAM tag type", a);
980
+ break;
981
+ }
982
+ }
983
+ return t;
984
+ }
985
+ /**
986
+ * @returns {boolean} true if the read is paired, regardless of whether both
987
+ * segments are mapped
988
+ */
989
+ isPaired() {
990
+ return !!(this.flags & A.BAM_FPAIRED);
991
+ }
992
+ /** @returns {boolean} true if the read is paired, and both segments are mapped */
993
+ isProperlyPaired() {
994
+ return !!(this.flags & A.BAM_FPROPER_PAIR);
995
+ }
996
+ /** @returns {boolean} true if the read itself is unmapped; conflictive with isProperlyPaired */
997
+ isSegmentUnmapped() {
998
+ return !!(this.flags & A.BAM_FUNMAP);
999
+ }
1000
+ /** @returns {boolean} true if the read itself is unmapped; conflictive with isProperlyPaired */
1001
+ isMateUnmapped() {
1002
+ return !!(this.flags & A.BAM_FMUNMAP);
1003
+ }
1004
+ /** @returns {boolean} true if the read is mapped to the reverse strand */
1005
+ isReverseComplemented() {
1006
+ return !!(this.flags & A.BAM_FREVERSE);
1007
+ }
1008
+ /** @returns {boolean} true if the mate is mapped to the reverse strand */
1009
+ isMateReverseComplemented() {
1010
+ return !!(this.flags & A.BAM_FMREVERSE);
1011
+ }
1012
+ /** @returns {boolean} true if this is read number 1 in a pair */
1013
+ isRead1() {
1014
+ return !!(this.flags & A.BAM_FREAD1);
1015
+ }
1016
+ /** @returns {boolean} true if this is read number 2 in a pair */
1017
+ isRead2() {
1018
+ return !!(this.flags & A.BAM_FREAD2);
1019
+ }
1020
+ /** @returns {boolean} true if this is a secondary alignment */
1021
+ isSecondary() {
1022
+ return !!(this.flags & A.BAM_FSECONDARY);
1023
+ }
1024
+ /** @returns {boolean} true if this read has failed QC checks */
1025
+ isFailedQc() {
1026
+ return !!(this.flags & A.BAM_FQCFAIL);
1027
+ }
1028
+ /** @returns {boolean} true if the read is an optical or PCR duplicate */
1029
+ isDuplicate() {
1030
+ return !!(this.flags & A.BAM_FDUP);
1031
+ }
1032
+ /** @returns {boolean} true if this is a supplementary alignment */
1033
+ isSupplementary() {
1034
+ return !!(this.flags & A.BAM_FSUPPLEMENTARY);
1035
+ }
1036
+ get cigarAndLength() {
1037
+ if (this.isSegmentUnmapped())
1038
+ return {
1039
+ length_on_ref: 0,
1040
+ NUMERIC_CIGAR: new Uint32Array(0)
1041
+ };
1042
+ const e = this.num_cigar_ops;
1043
+ let n = this.b0 + this.read_name_length;
1044
+ const t = this._dataView.getInt32(n, !0), r = t >> 4;
1045
+ if ((t & 15) === K && r === this.seq_length) {
1046
+ n += 4;
1047
+ const s = this._dataView.getInt32(n, !0), o = s >> 4;
1048
+ return (s & 15) !== pe && console.warn("CG tag with no N tag"), {
1049
+ NUMERIC_CIGAR: this.tags.CG,
1050
+ length_on_ref: o
1051
+ };
1052
+ } else {
1053
+ const s = this.byteArray.byteOffset + n, o = s % 4 === 0 ? new Uint32Array(this.byteArray.buffer, s, e) : new Uint32Array(this.byteArray.slice(n, n + (e << 2)).buffer, 0, e);
1054
+ let i = 0;
1055
+ for (let f = 0; f < e; ++f) {
1056
+ const d = o[f];
1057
+ 1 << (d & 15) & Ie || (i += d >> 4);
1058
+ }
1059
+ return {
1060
+ NUMERIC_CIGAR: o,
1061
+ length_on_ref: i
1062
+ };
1063
+ }
1064
+ }
1065
+ get length_on_ref() {
1066
+ return this.cigarAndLength.length_on_ref;
1067
+ }
1068
+ get NUMERIC_CIGAR() {
1069
+ return this.cigarAndLength.NUMERIC_CIGAR;
1070
+ }
1071
+ get CIGAR() {
1072
+ const e = this.NUMERIC_CIGAR;
1073
+ let n = "";
1074
+ for (let t = 0, r = e.length; t < r; t++) {
1075
+ const a = e[t], s = a >> 4, o = ye[a & 15];
1076
+ n += s + String.fromCharCode(o);
1077
+ }
1078
+ return n;
1079
+ }
1080
+ get num_cigar_ops() {
1081
+ return this.flag_nc & 65535;
1082
+ }
1083
+ get num_cigar_bytes() {
1084
+ return this.num_cigar_ops << 2;
1085
+ }
1086
+ get read_name_length() {
1087
+ return this.bin_mq_nl & 255;
1088
+ }
1089
+ get num_seq_bytes() {
1090
+ return this.seq_length + 1 >> 1;
1091
+ }
1092
+ get NUMERIC_SEQ() {
1093
+ const e = this.b0 + this.read_name_length + this.num_cigar_bytes, n = this.byteArray.subarray(e, e + this.num_seq_bytes);
1094
+ return new Uint8Array(n.buffer, n.byteOffset, this.num_seq_bytes);
1095
+ }
1096
+ get seq() {
1097
+ const e = this.NUMERIC_SEQ, n = this.seq_length, t = new Array(n);
1098
+ let r = 0;
1099
+ const a = n >> 1;
1100
+ for (let s = 0; s < a; ++s) {
1101
+ const o = e[s];
1102
+ t[r++] = v[(o & 240) >> 4], t[r++] = v[o & 15];
1103
+ }
1104
+ if (r < n) {
1105
+ const s = e[a];
1106
+ t[r] = v[(s & 240) >> 4];
1107
+ }
1108
+ return t.join("");
1109
+ }
1110
+ // adapted from igv.js
1111
+ get pair_orientation() {
1112
+ if (!this.isSegmentUnmapped() && !this.isMateUnmapped() && this.ref_id === this.next_refid) {
1113
+ const e = this.isReverseComplemented() ? "R" : "F", n = this.isMateReverseComplemented() ? "R" : "F";
1114
+ let t = " ", r = " ";
1115
+ this.isRead1() ? (t = "1", r = "2") : this.isRead2() && (t = "2", r = "1");
1116
+ const a = [];
1117
+ return this.template_length > 0 ? (a[0] = e, a[1] = t, a[2] = n, a[3] = r) : (a[2] = e, a[3] = t, a[0] = n, a[1] = r), a.join("");
1118
+ }
1119
+ }
1120
+ get bin_mq_nl() {
1121
+ return this._dataView.getInt32(this.bytes.start + 12, !0);
1122
+ }
1123
+ get flag_nc() {
1124
+ return this._dataView.getInt32(this.bytes.start + 16, !0);
1125
+ }
1126
+ get seq_length() {
1127
+ return this._dataView.getInt32(this.bytes.start + 20, !0);
1128
+ }
1129
+ get next_refid() {
1130
+ return this._dataView.getInt32(this.bytes.start + 24, !0);
1131
+ }
1132
+ get next_pos() {
1133
+ return this._dataView.getInt32(this.bytes.start + 28, !0);
1134
+ }
1135
+ get template_length() {
1136
+ return this._dataView.getInt32(this.bytes.start + 32, !0);
1137
+ }
1138
+ seqAt(e) {
1139
+ if (e < this.seq_length) {
1140
+ const n = e >> 1, t = this.byteArray[this.b0 + this.read_name_length + this.num_cigar_bytes + n];
1141
+ return e % 2 === 0 ? v[(t & 240) >> 4] : v[t & 15];
1142
+ } else
1143
+ return;
1144
+ }
1145
+ toJSON() {
1146
+ const e = {};
1147
+ for (const n of Object.keys(this))
1148
+ n.startsWith("_") || n === "bytes" || (e[n] = this[n]);
1149
+ return e;
1150
+ }
1151
+ }
1152
+ function M(c, e) {
1153
+ const n = Object.getOwnPropertyDescriptor(c.prototype, e);
1154
+ if (!n)
1155
+ throw new Error("OH NO, NO PROPERTY DESCRIPTOR");
1156
+ const t = n.get;
1157
+ if (!t)
1158
+ throw new Error("OH NO, NOT A GETTER");
1159
+ Object.defineProperty(c.prototype, e, {
1160
+ get() {
1161
+ const r = t.call(this);
1162
+ return Object.defineProperty(this, e, { value: r }), r;
1163
+ }
1164
+ });
1165
+ }
1166
+ M(R, "tags");
1167
+ M(R, "cigarAndLength");
1168
+ M(R, "seq");
1169
+ M(R, "qual");
1170
+ M(R, "end");
1171
+ function Z(c) {
1172
+ const e = c.split(/\r?\n/), n = [];
1173
+ for (const t of e) {
1174
+ const [r, ...a] = t.split(/\t/);
1175
+ r && n.push({
1176
+ tag: r.slice(1),
1177
+ data: a.map((s) => {
1178
+ const o = s.indexOf(":"), i = s.slice(0, o), f = s.slice(o + 1);
1179
+ return { tag: i, value: f };
1180
+ })
1181
+ });
1182
+ }
1183
+ return n;
1184
+ }
1185
+ const J = 21840194, Ce = 65536;
1186
+ class Pe {
1187
+ constructor({ bamFilehandle: e, bamPath: n, bamUrl: t, baiPath: r, baiFilehandle: a, baiUrl: s, csiPath: o, csiFilehandle: i, csiUrl: f, htsget: d, renameRefSeqs: x = (b) => b }) {
1188
+ if (this.htsget = !1, this.cache = new D({
1189
+ maxSize: 1e3
1190
+ }), this.renameRefSeq = x, e)
1191
+ this.bam = e;
1192
+ else if (n)
1193
+ this.bam = new B(n);
1194
+ else if (t)
1195
+ this.bam = new T(t);
1196
+ else if (d)
1197
+ this.htsget = !0, this.bam = new me();
1198
+ else
1199
+ throw new Error("unable to initialize bam");
1200
+ if (i)
1201
+ this.index = new U({ filehandle: i });
1202
+ else if (o)
1203
+ this.index = new U({ filehandle: new B(o) });
1204
+ else if (f)
1205
+ this.index = new U({ filehandle: new T(f) });
1206
+ else if (a)
1207
+ this.index = new E({ filehandle: a });
1208
+ else if (r)
1209
+ this.index = new E({ filehandle: new B(r) });
1210
+ else if (s)
1211
+ this.index = new E({ filehandle: new T(s) });
1212
+ else if (n)
1213
+ this.index = new E({ filehandle: new B(`${n}.bai`) });
1214
+ else if (t)
1215
+ this.index = new E({ filehandle: new T(`${t}.bai`) });
1216
+ else if (d)
1217
+ this.htsget = !0;
1218
+ else
1219
+ throw new Error("unable to infer index format");
1220
+ }
1221
+ async getHeaderPre(e) {
1222
+ const n = se(e);
1223
+ if (!this.index)
1224
+ return;
1225
+ const t = await this.index.parse(n), r = t.firstDataLine === void 0 ? await this.bam.readFile() : (
1226
+ // the logic indexData.firstDataLine is a virtualOffset telling us
1227
+ // where the data is. It is in the middle of a virtualOffset
1228
+ // (provided by the bgzip block offset at blockPosition + the
1229
+ // virtualOffset dataPosition, so we add one extra blockLen to make
1230
+ // sure we consume the full header)
1231
+ await this.bam.read(t.firstDataLine.blockPosition + Ce, 0)
1232
+ ), a = await V(r), s = new DataView(a.buffer);
1233
+ if (s.getInt32(0, !0) !== J)
1234
+ throw new Error("Not a BAM file");
1235
+ const o = s.getInt32(4, !0), i = new TextDecoder("utf8");
1236
+ this.header = i.decode(a.subarray(8, 8 + o));
1237
+ const { chrToIndex: f, indexToChr: d } = this._parseRefSeqs(a, o + 8);
1238
+ return this.chrToIndex = f, this.indexToChr = d, Z(this.header);
1239
+ }
1240
+ getHeader(e) {
1241
+ return this.headerP || (this.headerP = this.getHeaderPre(e).catch((n) => {
1242
+ throw this.headerP = void 0, n;
1243
+ })), this.headerP;
1244
+ }
1245
+ async getHeaderText(e = {}) {
1246
+ return await this.getHeader(e), this.header;
1247
+ }
1248
+ _parseRefSeqs(e, n) {
1249
+ const t = new DataView(e.buffer), r = t.getInt32(n, !0);
1250
+ let a = n + 4;
1251
+ const s = {}, o = [], i = new TextDecoder("utf8");
1252
+ for (let f = 0; f < r; f += 1) {
1253
+ if (a + 8 > e.length)
1254
+ throw new Error(`Insufficient data for reference sequences: need more than ${e.length} bytes`);
1255
+ const d = t.getInt32(a, !0), x = this.renameRefSeq(i.decode(e.subarray(a + 4, a + 4 + d - 1))), b = t.getInt32(a + d + 4, !0);
1256
+ s[x] = f, o.push({ refName: x, length: b }), a = a + 8 + d;
1257
+ }
1258
+ return { chrToIndex: s, indexToChr: o };
1259
+ }
1260
+ async getRecordsForRange(e, n, t, r) {
1261
+ return oe(this.streamRecordsForRange(e, n, t, r));
1262
+ }
1263
+ async *streamRecordsForRange(e, n, t, r) {
1264
+ var o;
1265
+ await this.getHeader(r);
1266
+ const a = (o = this.chrToIndex) == null ? void 0 : o[e];
1267
+ if (a === void 0 || !this.index)
1268
+ return;
1269
+ const s = await this.index.blocksForRange(a, n - 1, t, r);
1270
+ yield* this._fetchChunkFeatures(s, a, n, t, r);
1271
+ }
1272
+ async *_fetchChunkFeatures(e, n, t, r, a = {}) {
1273
+ const { viewAsPairs: s } = a, o = [];
1274
+ let i = !1;
1275
+ for (const f of e) {
1276
+ const { data: d, cpositions: x, dpositions: b } = await this._readChunk({
1277
+ chunk: f,
1278
+ opts: a
1279
+ }), h = await this.readBamFeatures(d, x, b, f, n, t, r), g = [];
1280
+ for (const w of h)
1281
+ if (w.ref_id === n)
1282
+ if (w.start >= r) {
1283
+ i = !0;
1284
+ break;
1285
+ } else w.end >= t && g.push(w);
1286
+ if (o.push(g), yield g, i)
1287
+ break;
1288
+ }
1289
+ s && (yield this.fetchPairs(n, o, a));
1290
+ }
1291
+ async fetchPairs(e, n, t) {
1292
+ const { pairAcrossChr: r, maxInsertSize: a = 2e5 } = t, s = {}, o = {};
1293
+ for (const b of n) {
1294
+ const h = {};
1295
+ for (const g of b) {
1296
+ const w = g.name, u = g.id;
1297
+ h[w] || (h[w] = 0), h[w]++, o[u] = 1;
1298
+ }
1299
+ for (const [g, w] of Object.entries(h))
1300
+ w === 1 && (s[g] = !0);
1301
+ }
1302
+ const i = [];
1303
+ for (const b of n)
1304
+ for (const h of b) {
1305
+ const g = h.name, w = h.start, u = h.next_pos, l = h.next_refid;
1306
+ this.index && s[g] && (r || l === e && Math.abs(w - u) < a) && i.push(this.index.blocksForRange(l, u, u + 1, t));
1307
+ }
1308
+ const f = /* @__PURE__ */ new Map(), d = await Promise.all(i);
1309
+ for (const b of d.flat())
1310
+ f.has(b.toString()) || f.set(b.toString(), b);
1311
+ return (await Promise.all([...f.values()].map(async (b) => {
1312
+ const { data: h, cpositions: g, dpositions: w, chunk: u } = await this._readChunk({
1313
+ chunk: b,
1314
+ opts: t
1315
+ }), l = [];
1316
+ for (const m of await this.readBamFeatures(h, g, w, u))
1317
+ s[m.name] && !o[m.id] && l.push(m);
1318
+ return l;
1319
+ }))).flat();
1320
+ }
1321
+ async _readChunk({ chunk: e, opts: n }) {
1322
+ const t = await this.bam.read(e.fetchedSize(), e.minv.blockPosition, n), { buffer: r, cpositions: a, dpositions: s } = await le(t, e, this.cache);
1323
+ return { data: r, cpositions: a, dpositions: s, chunk: e };
1324
+ }
1325
+ async readBamFeatures(e, n, t, r, a, s, o) {
1326
+ let i = 0;
1327
+ const f = [];
1328
+ let d = 0;
1329
+ const x = new DataView(e.buffer), b = t.length > 0, h = n.length > 0, g = a !== void 0 && s !== void 0 && o !== void 0;
1330
+ for (; i + 4 < e.length; ) {
1331
+ const w = x.getInt32(i, !0), u = i + 4 + w - 1;
1332
+ if (b) {
1333
+ for (; i + r.minv.dataPosition >= t[d++]; )
1334
+ ;
1335
+ d--;
1336
+ }
1337
+ if (u < e.length) {
1338
+ if (g && i + 12 < e.length && !this._shouldIncludeFeature(x, i, a, o)) {
1339
+ i = u + 1;
1340
+ continue;
1341
+ }
1342
+ const l = new R({
1343
+ bytes: {
1344
+ byteArray: e,
1345
+ start: i,
1346
+ end: u
1347
+ },
1348
+ fileOffset: h ? n[d] * 256 + (i - t[d]) + r.minv.dataPosition + 1 : xe(e.subarray(i, u)) >>> 0
1349
+ });
1350
+ f.push(l);
1351
+ }
1352
+ i = u + 1;
1353
+ }
1354
+ return f;
1355
+ }
1356
+ _shouldIncludeFeature(e, n, t, r) {
1357
+ const a = e.getInt32(n + 4, !0), s = e.getInt32(n + 8, !0);
1358
+ return a === t && s < r;
1359
+ }
1360
+ async hasRefSeq(e) {
1361
+ var t, r;
1362
+ const n = (t = this.chrToIndex) == null ? void 0 : t[e];
1363
+ return n === void 0 ? !1 : (r = this.index) == null ? void 0 : r.hasRefSeq(n);
1364
+ }
1365
+ async lineCount(e) {
1366
+ var t;
1367
+ const n = (t = this.chrToIndex) == null ? void 0 : t[e];
1368
+ return n === void 0 || !this.index ? 0 : this.index.lineCount(n);
1369
+ }
1370
+ async indexCov(e, n, t) {
1371
+ var a;
1372
+ if (!this.index)
1373
+ return [];
1374
+ await this.index.parse();
1375
+ const r = (a = this.chrToIndex) == null ? void 0 : a[e];
1376
+ return r === void 0 ? [] : this.index.indexCov(r, n, t);
1377
+ }
1378
+ async blocksForRange(e, n, t, r) {
1379
+ var s;
1380
+ if (!this.index)
1381
+ return [];
1382
+ await this.index.parse();
1383
+ const a = (s = this.chrToIndex) == null ? void 0 : s[e];
1384
+ return a === void 0 ? [] : this.index.blocksForRange(a, n, t, r);
1385
+ }
1386
+ }
1387
+ async function L(c, e) {
1388
+ const n = await Promise.all(c.map(async (t) => {
1389
+ const { url: r, headers: a } = t;
1390
+ if (r.startsWith("data:")) {
1391
+ const s = await fetch(r);
1392
+ if (!s.ok)
1393
+ throw new Error("failed to decode base64");
1394
+ const o = await s.arrayBuffer();
1395
+ return new Uint8Array(o);
1396
+ } else {
1397
+ const { referer: s, ...o } = a, i = await fetch(r, {
1398
+ ...e,
1399
+ headers: { ...e == null ? void 0 : e.headers, ...o }
1400
+ });
1401
+ if (!i.ok)
1402
+ throw new Error(`HTTP ${i.status} fetching ${r}: ${await i.text()}`);
1403
+ return new Uint8Array(await i.arrayBuffer());
1404
+ }
1405
+ }));
1406
+ return ae(await Promise.all(n.map((t) => V(t))));
1407
+ }
1408
+ class Ee extends Pe {
1409
+ constructor(e) {
1410
+ super({ htsget: !0 }), this.baseUrl = e.baseUrl, this.trackId = e.trackId;
1411
+ }
1412
+ async *streamRecordsForRange(e, n, t, r) {
1413
+ var i;
1414
+ const s = `${`${this.baseUrl}/${this.trackId}`}?referenceName=${e}&start=${n}&end=${t}&format=BAM`, o = (i = this.chrToIndex) == null ? void 0 : i[e];
1415
+ if (o === void 0)
1416
+ yield [];
1417
+ else {
1418
+ const f = await fetch(s, { ...r });
1419
+ if (!f.ok)
1420
+ throw new Error(`HTTP ${f.status} fetching ${s}: ${await f.text()}`);
1421
+ const d = await f.json(), x = await L(d.htsget.urls.slice(1), r);
1422
+ yield* this._fetchChunkFeatures([
1423
+ // fake stuff to pretend to be a Chunk
1424
+ {
1425
+ buffer: x,
1426
+ _fetchedSize: void 0,
1427
+ bin: 0,
1428
+ compareTo() {
1429
+ return 0;
1430
+ },
1431
+ toUniqueString() {
1432
+ return `${e}_${n}_${t}`;
1433
+ },
1434
+ fetchedSize() {
1435
+ return 0;
1436
+ },
1437
+ minv: {
1438
+ dataPosition: 0,
1439
+ blockPosition: 0,
1440
+ compareTo: () => 0
1441
+ },
1442
+ maxv: {
1443
+ dataPosition: Number.MAX_SAFE_INTEGER,
1444
+ blockPosition: 0,
1445
+ compareTo: () => 0
1446
+ },
1447
+ toString() {
1448
+ return `${e}_${n}_${t}`;
1449
+ }
1450
+ }
1451
+ ], o, n, t, r);
1452
+ }
1453
+ }
1454
+ async _readChunk({ chunk: e }) {
1455
+ if (!e.buffer)
1456
+ throw new Error("expected chunk.buffer in htsget");
1457
+ return {
1458
+ data: e.buffer,
1459
+ cpositions: [],
1460
+ dpositions: [],
1461
+ chunk: e
1462
+ };
1463
+ }
1464
+ async getHeader(e = {}) {
1465
+ const n = `${this.baseUrl}/${this.trackId}?referenceName=na&class=header`, t = await fetch(n, e);
1466
+ if (!t.ok)
1467
+ throw new Error(`HTTP ${t.status} fetching ${n}: ${await t.text()}`);
1468
+ const r = await t.json(), a = await L(r.htsget.urls, e), s = new DataView(a.buffer);
1469
+ if (s.getInt32(0, !0) !== J)
1470
+ throw new Error("Not a BAM file");
1471
+ const o = s.getInt32(4, !0), f = new TextDecoder("utf8").decode(a.subarray(8, 8 + o)), d = Z(f), x = [], b = {}, h = d.filter((g) => g.tag === "SQ");
1472
+ for (const [g, w] of h.entries()) {
1473
+ let u = "", l = 0;
1474
+ for (const m of w.data)
1475
+ m.tag === "SN" ? u = m.value : m.tag === "LN" && (l = +m.value);
1476
+ b[u] = g, x[g] = { refName: u, length: l };
1477
+ }
1478
+ return this.chrToIndex = b, this.indexToChr = x, d;
1479
+ }
1480
+ }
1481
+ export {
1482
+ E as BAI,
1483
+ Pe as BamFile,
1484
+ R as BamRecord,
1485
+ U as CSI,
1486
+ Ee as HtsgetFile
1487
+ };