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