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