@genome-spy/app 0.56.1 → 0.57.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.
@@ -1,8 +1,8 @@
1
- import { L as V, u as k, a as Q } from "./long-BXK3UEks.js";
2
- import { b as I } from "./index-B6haPltu.js";
3
- import { L as A } from "./__vite-browser-external-C--ziKoh.js";
4
- import { R } from "./remoteFile-DuIsnepi.js";
5
- import { _ as Y, L as W } from "./index-BhtH2nrr.js";
1
+ import { L as j, u as R, a as V } from "./long-DM5IWGqg.js";
2
+ import { b as I } from "./index-DluFz_0j.js";
3
+ import { L as C } from "./__vite-browser-external-C--ziKoh.js";
4
+ import { R as k } from "./remoteFile-DwSeXAZ0.js";
5
+ import { A as Q, L as Y } from "./index-C159nEYc.js";
6
6
  class D {
7
7
  constructor(e, t) {
8
8
  this.blockPosition = e, this.dataPosition = t;
@@ -22,7 +22,7 @@ class D {
22
22
  return t;
23
23
  }
24
24
  }
25
- function x(o, e = 0, t = !1) {
25
+ function E(o, e = 0, t = !1) {
26
26
  if (t)
27
27
  throw new Error("big-endian virtual file offsets not implemented");
28
28
  return new D(o[e + 7] * 1099511627776 + o[e + 6] * 4294967296 + o[e + 5] * 16777216 + o[e + 4] * 65536 + o[e + 3] * 256 + o[e + 2], o[e + 1] << 8 | o[e]);
@@ -44,15 +44,15 @@ class $ {
44
44
  return this._fetchedSize !== void 0 ? this._fetchedSize : this.maxv.blockPosition + 65536 - this.minv.blockPosition;
45
45
  }
46
46
  }
47
- function X(o) {
47
+ function W(o) {
48
48
  return new Promise((e) => setTimeout(e, o));
49
49
  }
50
- function J(o) {
50
+ function X(o) {
51
51
  if (o.greaterThan(Number.MAX_SAFE_INTEGER) || o.lessThan(Number.MIN_SAFE_INTEGER))
52
52
  throw new Error("integer overflow");
53
53
  return o.toNumber();
54
54
  }
55
- function K(o) {
55
+ function J(o) {
56
56
  if (o && o.aborted)
57
57
  if (typeof DOMException > "u") {
58
58
  const e = new Error("aborted");
@@ -60,10 +60,10 @@ function K(o) {
60
60
  } else
61
61
  throw new DOMException("aborted", "AbortError");
62
62
  }
63
- function Z(o, e) {
63
+ function K(o, e) {
64
64
  return e.minv.blockPosition - o.maxv.blockPosition < 65e3 && e.maxv.blockPosition - o.minv.blockPosition < 5e6;
65
65
  }
66
- function ee(o = {}) {
66
+ function Z(o = {}) {
67
67
  return "aborted" in o ? { signal: o } : o;
68
68
  }
69
69
  function U(o, e) {
@@ -72,29 +72,29 @@ function U(o, e) {
72
72
  if (o.length === 0)
73
73
  return o;
74
74
  o.sort((r, s) => {
75
- const a = r.minv.blockPosition - s.minv.blockPosition;
76
- return a === 0 ? r.minv.dataPosition - s.minv.dataPosition : a;
75
+ const i = r.minv.blockPosition - s.minv.blockPosition;
76
+ return i === 0 ? r.minv.dataPosition - s.minv.dataPosition : i;
77
77
  });
78
78
  for (const r of o)
79
- (!e || r.maxv.compareTo(e) > 0) && (n === void 0 ? (t.push(r), n = r) : Z(n, r) ? r.maxv.compareTo(n.maxv) > 0 && (n.maxv = r.maxv) : (t.push(r), n = r));
79
+ (!e || r.maxv.compareTo(e) > 0) && (n === void 0 ? (t.push(r), n = r) : K(n, r) ? r.maxv.compareTo(n.maxv) > 0 && (n.maxv = r.maxv) : (t.push(r), n = r));
80
80
  return t;
81
81
  }
82
82
  function z(o, e) {
83
- return { lineCount: J(V.fromBytesLE(Array.prototype.slice.call(o, e, e + 8), !0)) };
83
+ return { lineCount: X(j.fromBytesLE(Array.prototype.slice.call(o, e, e + 8), !0)) };
84
84
  }
85
85
  function L(o, e) {
86
86
  return o ? o.compareTo(e) > 0 ? e : o : e;
87
87
  }
88
- function te(o, e = (t) => t) {
88
+ function ee(o, e = (t) => t) {
89
89
  let t = 0, n = 0;
90
90
  const r = [], s = {};
91
- for (let a = 0; a < o.length; a += 1)
92
- if (!o[a]) {
93
- if (n < a) {
94
- let h = o.toString("utf8", n, a);
95
- h = e(h), r[t] = h, s[h] = t;
91
+ for (let i = 0; i < o.length; i += 1)
92
+ if (!o[i]) {
93
+ if (n < i) {
94
+ let c = o.toString("utf8", n, i);
95
+ c = e(c), r[t] = c, s[c] = t;
96
96
  }
97
- n = a + 1, t += 1;
97
+ n = i + 1, t += 1;
98
98
  }
99
99
  return { refNameToId: s, refIdToName: r };
100
100
  }
@@ -107,14 +107,14 @@ class O {
107
107
  this.filehandle = e, this.renameRefSeq = t;
108
108
  }
109
109
  }
110
- const ne = 21578050;
111
- function re(o, e) {
110
+ const te = 21578050;
111
+ function ne(o, e) {
112
112
  return o - o % e;
113
113
  }
114
- function se(o, e) {
114
+ function re(o, e) {
115
115
  return o - o % e + e;
116
116
  }
117
- function ie(o, e) {
117
+ function se(o, e) {
118
118
  return e -= 1, [
119
119
  [0, 0],
120
120
  [1 + (o >> 26), 1 + (e >> 26)],
@@ -132,74 +132,74 @@ class v extends O {
132
132
  // fetch and parse the index
133
133
  async _parse(e) {
134
134
  const t = await this.filehandle.readFile(e);
135
- if (t.readUInt32LE(0) !== ne)
135
+ if (t.readUInt32LE(0) !== te)
136
136
  throw new Error("Not a BAI file");
137
137
  const n = t.readInt32LE(4), s = ((1 << (5 + 1) * 3) - 1) / 7;
138
- let a = 8, h;
139
- const c = new Array(n);
140
- for (let i = 0; i < n; i++) {
141
- const l = t.readInt32LE(a);
142
- let u;
143
- a += 4;
144
- const f = {};
145
- for (let g = 0; g < l; g += 1) {
146
- const m = t.readUInt32LE(a);
147
- if (a += 4, m === s + 1)
148
- a += 4, u = z(t, a + 16), a += 32;
138
+ let i = 8, c;
139
+ const d = new Array(n);
140
+ for (let a = 0; a < n; a++) {
141
+ const l = t.readInt32LE(i);
142
+ let x;
143
+ i += 4;
144
+ const h = {};
145
+ for (let b = 0; b < l; b += 1) {
146
+ const u = t.readUInt32LE(i);
147
+ if (i += 4, u === s + 1)
148
+ i += 4, x = z(t, i + 16), i += 32;
149
149
  else {
150
- if (m > s + 1)
150
+ if (u > s + 1)
151
151
  throw new Error("bai index contains too many bins, please use CSI");
152
152
  {
153
- const p = t.readInt32LE(a);
154
- a += 4;
155
- const w = new Array(p);
156
- for (let E = 0; E < p; E++) {
157
- const y = x(t, a);
158
- a += 8;
159
- const S = x(t, a);
160
- a += 8, h = L(h, y), w[E] = new $(y, S, m);
153
+ const g = t.readInt32LE(i);
154
+ i += 4;
155
+ const p = new Array(g);
156
+ for (let w = 0; w < g; w++) {
157
+ const y = E(t, i);
158
+ i += 8;
159
+ const S = E(t, i);
160
+ i += 8, c = L(c, y), p[w] = new $(y, S, u);
161
161
  }
162
- f[m] = w;
162
+ h[u] = p;
163
163
  }
164
164
  }
165
165
  }
166
- const d = t.readInt32LE(a);
167
- a += 4;
168
- const _ = new Array(d);
169
- for (let g = 0; g < d; g++) {
170
- const m = x(t, a);
171
- a += 8, h = L(h, m), _[g] = m;
166
+ const f = t.readInt32LE(i);
167
+ i += 4;
168
+ const m = new Array(f);
169
+ for (let b = 0; b < f; b++) {
170
+ const u = E(t, i);
171
+ i += 8, c = L(c, u), m[b] = u;
172
172
  }
173
- c[i] = { binIndex: f, linearIndex: _, stats: u };
173
+ d[a] = { binIndex: h, linearIndex: m, stats: x };
174
174
  }
175
175
  return {
176
176
  bai: !0,
177
- firstDataLine: h,
177
+ firstDataLine: c,
178
178
  maxBlockSize: 65536,
179
- indices: c,
179
+ indices: d,
180
180
  refCount: n
181
181
  };
182
182
  }
183
183
  async indexCov(e, t, n, r = {}) {
184
- const a = t !== void 0, c = (await this.parse(r)).indices[e];
185
- if (!c)
184
+ const i = t !== void 0, d = (await this.parse(r)).indices[e];
185
+ if (!d)
186
186
  return [];
187
- const { linearIndex: i = [], stats: l } = c;
188
- if (i.length === 0)
187
+ const { linearIndex: a = [], stats: l } = d;
188
+ if (a.length === 0)
189
189
  return [];
190
- const u = n === void 0 ? (i.length - 1) * 16384 : se(n, 16384), f = t === void 0 ? 0 : re(t, 16384), d = a ? new Array((u - f) / 16384) : new Array(i.length - 1), _ = i[i.length - 1].blockPosition;
191
- if (u > (i.length - 1) * 16384)
190
+ const x = n === void 0 ? (a.length - 1) * 16384 : re(n, 16384), h = t === void 0 ? 0 : ne(t, 16384), f = i ? new Array((x - h) / 16384) : new Array(a.length - 1), m = a[a.length - 1].blockPosition;
191
+ if (x > (a.length - 1) * 16384)
192
192
  throw new Error("query outside of range of linear index");
193
- let g = i[f / 16384].blockPosition;
194
- for (let m = f / 16384, p = 0; m < u / 16384; m++, p++)
195
- d[p] = {
196
- score: i[m + 1].blockPosition - g,
197
- start: m * 16384,
198
- end: m * 16384 + 16384
199
- }, g = i[m + 1].blockPosition;
200
- return d.map((m) => ({
201
- ...m,
202
- score: m.score * ((l == null ? void 0 : l.lineCount) || 0) / _
193
+ let b = a[h / 16384].blockPosition;
194
+ for (let u = h / 16384, g = 0; u < x / 16384; u++, g++)
195
+ f[g] = {
196
+ score: a[u + 1].blockPosition - b,
197
+ start: u * 16384,
198
+ end: u * 16384 + 16384
199
+ }, b = a[u + 1].blockPosition;
200
+ return f.map((u) => ({
201
+ ...u,
202
+ score: u.score * ((l == null ? void 0 : l.lineCount) || 0) / m
203
203
  }));
204
204
  }
205
205
  async blocksForRange(e, t, n, r = {}) {
@@ -207,25 +207,25 @@ class v extends O {
207
207
  const s = await this.parse(r);
208
208
  if (!s)
209
209
  return [];
210
- const a = s.indices[e];
211
- if (!a)
210
+ const i = s.indices[e];
211
+ if (!i)
212
212
  return [];
213
- const h = ie(t, n), c = [];
214
- for (const [d, _] of h)
215
- for (let g = d; g <= _; g++)
216
- if (a.binIndex[g]) {
217
- const m = a.binIndex[g];
218
- for (const p of m)
219
- c.push(p);
213
+ const c = se(t, n), d = [];
214
+ for (const [f, m] of c)
215
+ for (let b = f; b <= m; b++)
216
+ if (i.binIndex[b]) {
217
+ const u = i.binIndex[b];
218
+ for (const g of u)
219
+ d.push(g);
220
220
  }
221
- const i = a.linearIndex.length;
221
+ const a = i.linearIndex.length;
222
222
  let l;
223
- const u = Math.min(t >> 14, i - 1), f = Math.min(n >> 14, i - 1);
224
- for (let d = u; d <= f; ++d) {
225
- const _ = a.linearIndex[d];
226
- _ && (!l || _.compareTo(l) < 0) && (l = _);
223
+ const x = Math.min(t >> 14, a - 1), h = Math.min(n >> 14, a - 1);
224
+ for (let f = x; f <= h; ++f) {
225
+ const m = i.linearIndex[f];
226
+ m && (!l || m.compareTo(l) < 0) && (l = m);
227
227
  }
228
- return U(c, l);
228
+ return U(d, l);
229
229
  }
230
230
  async parse(e = {}) {
231
231
  return this.setupP || (this.setupP = this._parse(e).catch((t) => {
@@ -237,10 +237,7 @@ class v extends O {
237
237
  return !!(!((n = (await this.parse(t)).indices[e]) === null || n === void 0) && n.binIndex);
238
238
  }
239
239
  }
240
- function ae(o) {
241
- return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
242
- }
243
- const oe = new Int32Array([
240
+ let T = [
244
241
  0,
245
242
  1996959894,
246
243
  3993919788,
@@ -497,42 +494,23 @@ const oe = new Int32Array([
497
494
  3272380065,
498
495
  1510334235,
499
496
  755167117
500
- ]);
501
- function H(o) {
502
- if (Buffer.isBuffer(o))
503
- return o;
504
- if (typeof o == "number")
505
- return Buffer.alloc(o);
506
- if (typeof o == "string")
507
- return Buffer.from(o);
508
- throw new Error("input must be buffer, number, or string, received " + typeof o);
509
- }
510
- function ce(o) {
511
- const e = H(4);
512
- return e.writeInt32BE(o, 0), e;
513
- }
514
- function T(o, e) {
515
- o = H(o), Buffer.isBuffer(e) && (e = e.readUInt32BE(0));
516
- let t = ~~e ^ -1;
517
- for (var n = 0; n < o.length; n++)
518
- t = oe[(t ^ o[n]) & 255] ^ t >>> 8;
497
+ ];
498
+ typeof Int32Array < "u" && (T = new Int32Array(T));
499
+ const ae = (o, e) => {
500
+ let t = e === 0 ? 0 : ~~e ^ -1;
501
+ for (let n = 0; n < o.length; n++)
502
+ t = T[(t ^ o[n]) & 255] ^ t >>> 8;
519
503
  return t ^ -1;
504
+ }, M = (o, e) => I.Buffer.from(o, e);
505
+ function ie(o, e) {
506
+ const t = (n, r) => e(M(n), r) >>> 0;
507
+ return t.signed = (n, r) => e(M(n), r), t.unsigned = t, t.model = o, t;
520
508
  }
521
- function M() {
522
- return ce(T.apply(null, arguments));
523
- }
524
- M.signed = function() {
525
- return T.apply(null, arguments);
526
- };
527
- M.unsigned = function() {
528
- return T.apply(null, arguments) >>> 0;
529
- };
530
- var he = M;
531
- const de = /* @__PURE__ */ ae(he), fe = 21582659, le = 38359875;
532
- function ue(o, e) {
509
+ const oe = ie("crc-32", ae), de = 21582659, ce = 38359875;
510
+ function fe(o, e) {
533
511
  return o * 2 ** e;
534
512
  }
535
- function B(o, e) {
513
+ function F(o, e) {
536
514
  return Math.floor(o / 2 ** e);
537
515
  }
538
516
  class P extends O {
@@ -550,88 +528,88 @@ class P extends O {
550
528
  const n = e.readInt32LE(t), r = n & 65536 ? "zero-based-half-open" : "1-based-closed", s = { 0: "generic", 1: "SAM", 2: "VCF" }[n & 15];
551
529
  if (!s)
552
530
  throw new Error(`invalid Tabix preset format flags ${n}`);
553
- const a = {
531
+ const i = {
554
532
  ref: e.readInt32LE(t + 4),
555
533
  start: e.readInt32LE(t + 8),
556
534
  end: e.readInt32LE(t + 12)
557
- }, h = e.readInt32LE(t + 16), c = h ? String.fromCharCode(h) : "", i = e.readInt32LE(t + 20), l = e.readInt32LE(t + 24);
535
+ }, c = e.readInt32LE(t + 16), d = c ? String.fromCharCode(c) : "", a = e.readInt32LE(t + 20), l = e.readInt32LE(t + 24);
558
536
  return {
559
- columnNumbers: a,
537
+ columnNumbers: i,
560
538
  coordinateType: r,
561
- metaValue: h,
562
- metaChar: c,
563
- skipLines: i,
539
+ metaValue: c,
540
+ metaChar: d,
541
+ skipLines: a,
564
542
  format: s,
565
543
  formatFlags: n,
566
- ...te(e.subarray(t + 28, t + 28 + l), this.renameRefSeq)
544
+ ...ee(e.subarray(t + 28, t + 28 + l), this.renameRefSeq)
567
545
  };
568
546
  }
569
547
  // fetch and parse the index
570
548
  async _parse(e) {
571
- const t = await this.filehandle.readFile(e), n = await k(t);
549
+ const t = await this.filehandle.readFile(e), n = await R(t);
572
550
  let r;
573
- if (n.readUInt32LE(0) === fe)
551
+ if (n.readUInt32LE(0) === de)
574
552
  r = 1;
575
- else if (n.readUInt32LE(0) === le)
553
+ else if (n.readUInt32LE(0) === ce)
576
554
  r = 2;
577
555
  else
578
556
  throw new Error("Not a CSI file");
579
557
  this.minShift = n.readInt32LE(4), this.depth = n.readInt32LE(8), this.maxBinNumber = ((1 << (this.depth + 1) * 3) - 1) / 7;
580
- const s = n.readInt32LE(12), a = s >= 30 ? this.parseAuxData(n, 16) : void 0, h = n.readInt32LE(16 + s);
581
- let c = 16 + s + 4, i;
582
- const l = new Array(h);
583
- for (let u = 0; u < h; u++) {
584
- const f = n.readInt32LE(c);
585
- c += 4;
586
- const d = {};
587
- let _;
588
- for (let g = 0; g < f; g++) {
589
- const m = n.readUInt32LE(c);
590
- if (c += 4, m > this.maxBinNumber)
591
- _ = z(n, c + 28), c += 44;
558
+ const s = n.readInt32LE(12), i = s >= 30 ? this.parseAuxData(n, 16) : void 0, c = n.readInt32LE(16 + s);
559
+ let d = 16 + s + 4, a;
560
+ const l = new Array(c);
561
+ for (let x = 0; x < c; x++) {
562
+ const h = n.readInt32LE(d);
563
+ d += 4;
564
+ const f = {};
565
+ let m;
566
+ for (let b = 0; b < h; b++) {
567
+ const u = n.readUInt32LE(d);
568
+ if (d += 4, u > this.maxBinNumber)
569
+ m = z(n, d + 28), d += 44;
592
570
  else {
593
- i = L(i, x(n, c)), c += 8;
594
- const p = n.readInt32LE(c);
595
- c += 4;
596
- const w = new Array(p);
597
- for (let E = 0; E < p; E += 1) {
598
- const y = x(n, c);
599
- c += 8;
600
- const S = x(n, c);
601
- c += 8, i = L(i, y), w[E] = new $(y, S, m);
571
+ a = L(a, E(n, d)), d += 8;
572
+ const g = n.readInt32LE(d);
573
+ d += 4;
574
+ const p = new Array(g);
575
+ for (let w = 0; w < g; w += 1) {
576
+ const y = E(n, d);
577
+ d += 8;
578
+ const S = E(n, d);
579
+ d += 8, a = L(a, y), p[w] = new $(y, S, u);
602
580
  }
603
- d[m] = w;
581
+ f[u] = p;
604
582
  }
605
583
  }
606
- l[u] = { binIndex: d, stats: _ };
584
+ l[x] = { binIndex: f, stats: m };
607
585
  }
608
586
  return {
609
587
  csiVersion: r,
610
- firstDataLine: i,
588
+ firstDataLine: a,
611
589
  indices: l,
612
- refCount: h,
590
+ refCount: c,
613
591
  csi: !0,
614
592
  maxBlockSize: 65536,
615
- ...a
593
+ ...i
616
594
  };
617
595
  }
618
596
  async blocksForRange(e, t, n, r = {}) {
619
597
  t < 0 && (t = 0);
620
- const s = await this.parse(r), a = s == null ? void 0 : s.indices[e];
621
- if (!a)
598
+ const s = await this.parse(r), i = s == null ? void 0 : s.indices[e];
599
+ if (!i)
622
600
  return [];
623
- const h = this.reg2bins(t, n);
624
- if (h.length === 0)
601
+ const c = this.reg2bins(t, n);
602
+ if (c.length === 0)
625
603
  return [];
626
- const c = [];
627
- for (const [i, l] of h)
628
- for (let u = i; u <= l; u++)
629
- if (a.binIndex[u]) {
630
- const f = a.binIndex[u];
631
- for (const d of f)
632
- c.push(d);
604
+ const d = [];
605
+ for (const [a, l] of c)
606
+ for (let x = a; x <= l; x++)
607
+ if (i.binIndex[x]) {
608
+ const h = i.binIndex[x];
609
+ for (const f of h)
610
+ d.push(f);
633
611
  }
634
- return U(c, new D(0, 0));
612
+ return U(d, new D(0, 0));
635
613
  }
636
614
  /**
637
615
  * calculate the list of bins that may overlap with region [beg,end)
@@ -640,14 +618,14 @@ class P extends O {
640
618
  reg2bins(e, t) {
641
619
  e -= 1, e < 1 && (e = 1), t > 2 ** 50 && (t = 2 ** 34), t -= 1;
642
620
  let n = 0, r = 0, s = this.minShift + this.depth * 3;
643
- const a = [];
644
- for (; n <= this.depth; s -= 3, r += ue(1, n * 3), n += 1) {
645
- const h = r + B(e, s), c = r + B(t, s);
646
- if (c - h + a.length > this.maxBinNumber)
621
+ const i = [];
622
+ for (; n <= this.depth; s -= 3, r += fe(1, n * 3), n += 1) {
623
+ const c = r + F(e, s), d = r + F(t, s);
624
+ if (d - c + i.length > this.maxBinNumber)
647
625
  throw new 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`);
648
- a.push([h, c]);
626
+ i.push([c, d]);
649
627
  }
650
- return a;
628
+ return i;
651
629
  }
652
630
  async parse(e = {}) {
653
631
  return this.setupP || (this.setupP = this._parse(e).catch((t) => {
@@ -659,7 +637,7 @@ class P extends O {
659
637
  return !!(!((n = (await this.parse(t)).indices[e]) === null || n === void 0) && n.binIndex);
660
638
  }
661
639
  }
662
- const b = {
640
+ const _ = {
663
641
  // the read is paired in sequencing, no matter whether it is mapped in a pair
664
642
  BAM_FPAIRED: 1,
665
643
  // the read is mapped in a proper pair
@@ -684,12 +662,12 @@ const b = {
684
662
  BAM_FDUP: 1024,
685
663
  // supplementary alignment
686
664
  BAM_FSUPPLEMENTARY: 2048
687
- }, F = "=ACMGRSVTWYHKDBN".split(""), C = "MIDNSHP=X???????".split("");
688
- class me {
665
+ }, B = "=ACMGRSVTWYHKDBN".split(""), A = "MIDNSHP=X???????".split("");
666
+ class he {
689
667
  constructor(e) {
690
668
  this.data = {}, this._tagList = [], this._allTagsParsed = !1;
691
669
  const { bytes: t, fileOffset: n } = e, { byteArray: r, start: s } = t;
692
- this.data = {}, this.bytes = t, this._id = n, this._refID = r.readInt32LE(s + 4), this.data.start = r.readInt32LE(s + 8), this.flags = (r.readInt32LE(s + 16) & 4294901760) >> 16;
670
+ this.data = { start: r.readInt32LE(s + 8) }, this.bytes = t, this._id = n, this._refID = r.readInt32LE(s + 4), this.flags = (r.readInt32LE(s + 16) & 4294901760) >> 16;
693
671
  }
694
672
  get(e) {
695
673
  return this[e] ? this.data[e] ? this.data[e] : (this.data[e] = this[e](), this.data[e]) : this._get(e.toLowerCase());
@@ -772,100 +750,100 @@ class me {
772
750
  const { byteArray: t, start: n } = this.bytes;
773
751
  let r = this._tagOffset || n + 36 + this.get("_l_read_name") + this.get("_n_cigar_op") * 4 + this.get("_seq_bytes") + this.get("seq_length");
774
752
  const s = this.bytes.end;
775
- let a;
776
- for (; r < s && a !== e; ) {
777
- const h = String.fromCharCode(t[r], t[r + 1]);
778
- a = h.toLowerCase();
779
- const c = String.fromCharCode(t[r + 2]);
753
+ let i;
754
+ for (; r < s && i !== e; ) {
755
+ const c = String.fromCharCode(t[r], t[r + 1]);
756
+ i = c.toLowerCase();
757
+ const d = String.fromCharCode(t[r + 2]);
780
758
  r += 3;
781
- let i;
782
- switch (c) {
759
+ let a;
760
+ switch (d) {
783
761
  case "A": {
784
- i = String.fromCharCode(t[r]), r += 1;
762
+ a = String.fromCharCode(t[r]), r += 1;
785
763
  break;
786
764
  }
787
765
  case "i": {
788
- i = t.readInt32LE(r), r += 4;
766
+ a = t.readInt32LE(r), r += 4;
789
767
  break;
790
768
  }
791
769
  case "I": {
792
- i = t.readUInt32LE(r), r += 4;
770
+ a = t.readUInt32LE(r), r += 4;
793
771
  break;
794
772
  }
795
773
  case "c": {
796
- i = t.readInt8(r), r += 1;
774
+ a = t.readInt8(r), r += 1;
797
775
  break;
798
776
  }
799
777
  case "C": {
800
- i = t.readUInt8(r), r += 1;
778
+ a = t.readUInt8(r), r += 1;
801
779
  break;
802
780
  }
803
781
  case "s": {
804
- i = t.readInt16LE(r), r += 2;
782
+ a = t.readInt16LE(r), r += 2;
805
783
  break;
806
784
  }
807
785
  case "S": {
808
- i = t.readUInt16LE(r), r += 2;
786
+ a = t.readUInt16LE(r), r += 2;
809
787
  break;
810
788
  }
811
789
  case "f": {
812
- i = t.readFloatLE(r), r += 4;
790
+ a = t.readFloatLE(r), r += 4;
813
791
  break;
814
792
  }
815
793
  case "Z":
816
794
  case "H": {
817
- for (i = ""; r <= s; ) {
795
+ for (a = ""; r <= s; ) {
818
796
  const l = t[r++];
819
797
  if (l === 0)
820
798
  break;
821
- i += String.fromCharCode(l);
799
+ a += String.fromCharCode(l);
822
800
  }
823
801
  break;
824
802
  }
825
803
  case "B": {
826
- i = "";
827
- const l = t[r++], u = String.fromCharCode(l), f = t.readInt32LE(r);
828
- if (r += 4, u === "i")
829
- if (h === "CG")
830
- for (let d = 0; d < f; d++) {
831
- const _ = t.readInt32LE(r), g = _ >> 4, m = C[_ & 15];
832
- i += g + m, r += 4;
804
+ a = "";
805
+ const l = t[r++], x = String.fromCharCode(l), h = t.readInt32LE(r);
806
+ if (r += 4, x === "i")
807
+ if (c === "CG")
808
+ for (let f = 0; f < h; f++) {
809
+ const m = t.readInt32LE(r), b = m >> 4, u = A[m & 15];
810
+ a += b + u, r += 4;
833
811
  }
834
812
  else
835
- for (let d = 0; d < f; d++)
836
- i += t.readInt32LE(r), d + 1 < f && (i += ","), r += 4;
837
- if (u === "I")
838
- if (h === "CG")
839
- for (let d = 0; d < f; d++) {
840
- const _ = t.readUInt32LE(r), g = _ >> 4, m = C[_ & 15];
841
- i += g + m, r += 4;
813
+ for (let f = 0; f < h; f++)
814
+ a += t.readInt32LE(r), f + 1 < h && (a += ","), r += 4;
815
+ if (x === "I")
816
+ if (c === "CG")
817
+ for (let f = 0; f < h; f++) {
818
+ const m = t.readUInt32LE(r), b = m >> 4, u = A[m & 15];
819
+ a += b + u, r += 4;
842
820
  }
843
821
  else
844
- for (let d = 0; d < f; d++)
845
- i += t.readUInt32LE(r), d + 1 < f && (i += ","), r += 4;
846
- if (u === "s")
847
- for (let d = 0; d < f; d++)
848
- i += t.readInt16LE(r), d + 1 < f && (i += ","), r += 2;
849
- if (u === "S")
850
- for (let d = 0; d < f; d++)
851
- i += t.readUInt16LE(r), d + 1 < f && (i += ","), r += 2;
852
- if (u === "c")
853
- for (let d = 0; d < f; d++)
854
- i += t.readInt8(r), d + 1 < f && (i += ","), r += 1;
855
- if (u === "C")
856
- for (let d = 0; d < f; d++)
857
- i += t.readUInt8(r), d + 1 < f && (i += ","), r += 1;
858
- if (u === "f")
859
- for (let d = 0; d < f; d++)
860
- i += t.readFloatLE(r), d + 1 < f && (i += ","), r += 4;
822
+ for (let f = 0; f < h; f++)
823
+ a += t.readUInt32LE(r), f + 1 < h && (a += ","), r += 4;
824
+ if (x === "s")
825
+ for (let f = 0; f < h; f++)
826
+ a += t.readInt16LE(r), f + 1 < h && (a += ","), r += 2;
827
+ if (x === "S")
828
+ for (let f = 0; f < h; f++)
829
+ a += t.readUInt16LE(r), f + 1 < h && (a += ","), r += 2;
830
+ if (x === "c")
831
+ for (let f = 0; f < h; f++)
832
+ a += t.readInt8(r), f + 1 < h && (a += ","), r += 1;
833
+ if (x === "C")
834
+ for (let f = 0; f < h; f++)
835
+ a += t.readUInt8(r), f + 1 < h && (a += ","), r += 1;
836
+ if (x === "f")
837
+ for (let f = 0; f < h; f++)
838
+ a += t.readFloatLE(r), f + 1 < h && (a += ","), r += 4;
861
839
  break;
862
840
  }
863
841
  default:
864
- console.warn(`Unknown BAM tag type '${c}', tags may be incomplete`), i = void 0, r = s;
842
+ console.warn(`Unknown BAM tag type '${d}', tags may be incomplete`), a = void 0, r = s;
865
843
  }
866
- if (this._tagOffset = r, this._tagList.push(h), a === e)
867
- return i;
868
- this.data[a] = i;
844
+ if (this._tagOffset = r, this._tagList.push(c), i === e)
845
+ return a;
846
+ this.data[i] = a;
869
847
  }
870
848
  this._allTagsParsed = !0;
871
849
  }
@@ -875,58 +853,59 @@ class me {
875
853
  _parseCigar(e) {
876
854
  return (
877
855
  //@ts-ignore
878
- e.match(/\d+\D/g).map((t) => [t.match(/\D/)[0].toUpperCase(), Number.parseInt(t, 10)])
856
+ e.match(/\d+\D/g).map((t) => [/\D/.exec(t)[0].toUpperCase(), Number.parseInt(t, 10)])
879
857
  );
880
858
  }
881
859
  /**
882
- * @returns {boolean} true if the read is paired, regardless of whether both segments are mapped
860
+ * @returns {boolean} true if the read is paired, regardless of whether both
861
+ * segments are mapped
883
862
  */
884
863
  isPaired() {
885
- return !!(this.flags & b.BAM_FPAIRED);
864
+ return !!(this.flags & _.BAM_FPAIRED);
886
865
  }
887
866
  /** @returns {boolean} true if the read is paired, and both segments are mapped */
888
867
  isProperlyPaired() {
889
- return !!(this.flags & b.BAM_FPROPER_PAIR);
868
+ return !!(this.flags & _.BAM_FPROPER_PAIR);
890
869
  }
891
870
  /** @returns {boolean} true if the read itself is unmapped; conflictive with isProperlyPaired */
892
871
  isSegmentUnmapped() {
893
- return !!(this.flags & b.BAM_FUNMAP);
872
+ return !!(this.flags & _.BAM_FUNMAP);
894
873
  }
895
874
  /** @returns {boolean} true if the read itself is unmapped; conflictive with isProperlyPaired */
896
875
  isMateUnmapped() {
897
- return !!(this.flags & b.BAM_FMUNMAP);
876
+ return !!(this.flags & _.BAM_FMUNMAP);
898
877
  }
899
878
  /** @returns {boolean} true if the read is mapped to the reverse strand */
900
879
  isReverseComplemented() {
901
- return !!(this.flags & b.BAM_FREVERSE);
880
+ return !!(this.flags & _.BAM_FREVERSE);
902
881
  }
903
882
  /** @returns {boolean} true if the mate is mapped to the reverse strand */
904
883
  isMateReverseComplemented() {
905
- return !!(this.flags & b.BAM_FMREVERSE);
884
+ return !!(this.flags & _.BAM_FMREVERSE);
906
885
  }
907
886
  /** @returns {boolean} true if this is read number 1 in a pair */
908
887
  isRead1() {
909
- return !!(this.flags & b.BAM_FREAD1);
888
+ return !!(this.flags & _.BAM_FREAD1);
910
889
  }
911
890
  /** @returns {boolean} true if this is read number 2 in a pair */
912
891
  isRead2() {
913
- return !!(this.flags & b.BAM_FREAD2);
892
+ return !!(this.flags & _.BAM_FREAD2);
914
893
  }
915
894
  /** @returns {boolean} true if this is a secondary alignment */
916
895
  isSecondary() {
917
- return !!(this.flags & b.BAM_FSECONDARY);
896
+ return !!(this.flags & _.BAM_FSECONDARY);
918
897
  }
919
898
  /** @returns {boolean} true if this read has failed QC checks */
920
899
  isFailedQc() {
921
- return !!(this.flags & b.BAM_FQCFAIL);
900
+ return !!(this.flags & _.BAM_FQCFAIL);
922
901
  }
923
902
  /** @returns {boolean} true if the read is an optical or PCR duplicate */
924
903
  isDuplicate() {
925
- return !!(this.flags & b.BAM_FDUP);
904
+ return !!(this.flags & _.BAM_FDUP);
926
905
  }
927
906
  /** @returns {boolean} true if this is a supplementary alignment */
928
907
  isSupplementary() {
929
- return !!(this.flags & b.BAM_FSUPPLEMENTARY);
908
+ return !!(this.flags & _.BAM_FSUPPLEMENTARY);
930
909
  }
931
910
  cigar() {
932
911
  if (this.isSegmentUnmapped())
@@ -934,12 +913,12 @@ class me {
934
913
  const { byteArray: e, start: t } = this.bytes, n = this.get("_n_cigar_op");
935
914
  let r = t + 36 + this.get("_l_read_name");
936
915
  const s = this.get("seq_length");
937
- let a = "", h = 0, c = e.readInt32LE(r), i = c >> 4, l = C[c & 15];
938
- if (l === "S" && i === s)
939
- return r += 4, c = e.readInt32LE(r), i = c >> 4, l = C[c & 15], l !== "N" && console.warn("CG tag with no N tag"), this.data.length_on_ref = i, this.get("CG");
940
- for (let u = 0; u < n; ++u)
941
- c = e.readInt32LE(r), i = c >> 4, l = C[c & 15], a += i + l, l !== "H" && l !== "S" && l !== "I" && (h += i), r += 4;
942
- return this.data.length_on_ref = h, a;
916
+ let i = "", c = 0, d = e.readInt32LE(r), a = d >> 4, l = A[d & 15];
917
+ if (l === "S" && a === s)
918
+ return r += 4, d = e.readInt32LE(r), a = d >> 4, l = A[d & 15], l !== "N" && console.warn("CG tag with no N tag"), this.data.length_on_ref = a, this.get("CG");
919
+ for (let x = 0; x < n; ++x)
920
+ d = e.readInt32LE(r), a = d >> 4, l = A[d & 15], i += a + l, l !== "H" && l !== "S" && l !== "I" && (c += a), r += 4;
921
+ return this.data.length_on_ref = c, i;
943
922
  }
944
923
  length_on_ref() {
945
924
  return this.data.length_on_ref ? this.data.length_on_ref : (this.get("cigar"), this.data.length_on_ref);
@@ -961,12 +940,12 @@ class me {
961
940
  }
962
941
  seq() {
963
942
  const { byteArray: e, start: t } = this.bytes, n = t + 36 + this.get("_l_read_name") + this.get("_n_cigar_op") * 4, r = this.get("_seq_bytes"), s = this.get("seq_length");
964
- let a = "", h = 0;
965
- for (let c = 0; c < r; ++c) {
966
- const i = e[n + c];
967
- a += F[(i & 240) >> 4], h++, h < s && (a += F[i & 15], h++);
943
+ let i = "", c = 0;
944
+ for (let d = 0; d < r; ++d) {
945
+ const a = e[n + d];
946
+ i += B[(a & 240) >> 4], c++, c < s && (i += B[a & 15], c++);
968
947
  }
969
- return a;
948
+ return i;
970
949
  }
971
950
  // adapted from igv.js
972
951
  getPairOrientation() {
@@ -1004,28 +983,28 @@ class me {
1004
983
  return e;
1005
984
  }
1006
985
  }
1007
- function G(o) {
986
+ function H(o) {
1008
987
  const e = o.split(/\r?\n/), t = [];
1009
988
  for (const n of e) {
1010
989
  const [r, ...s] = n.split(/\t/);
1011
990
  r && t.push({
1012
991
  tag: r.slice(1),
1013
- data: s.map((a) => {
1014
- const h = a.indexOf(":"), c = a.slice(0, h), i = a.slice(h + 1);
1015
- return { tag: c, value: i };
992
+ data: s.map((i) => {
993
+ const c = i.indexOf(":"), d = i.slice(0, c), a = i.slice(c + 1);
994
+ return { tag: d, value: a };
1016
995
  })
1017
996
  });
1018
997
  }
1019
998
  return t;
1020
999
  }
1021
- const j = 21840194, q = 65536;
1022
- async function ge(o) {
1000
+ const G = 21840194, q = 65536;
1001
+ async function le(o) {
1023
1002
  let e = [];
1024
1003
  for await (const t of o)
1025
1004
  e = e.concat(t);
1026
1005
  return e;
1027
1006
  }
1028
- class _e {
1007
+ class xe {
1029
1008
  read() {
1030
1009
  throw new Error("never called");
1031
1010
  }
@@ -1039,71 +1018,71 @@ class _e {
1039
1018
  throw new Error("never called");
1040
1019
  }
1041
1020
  }
1042
- class pe {
1043
- constructor({ bamFilehandle: e, bamPath: t, bamUrl: n, baiPath: r, baiFilehandle: s, baiUrl: a, csiPath: h, csiFilehandle: c, csiUrl: i, htsget: l, yieldThreadTime: u = 100, renameRefSeqs: f = (d) => d }) {
1044
- if (this.htsget = !1, this.featureCache = new Y({
1045
- cache: new W({
1021
+ class ue {
1022
+ constructor({ bamFilehandle: e, bamPath: t, bamUrl: n, baiPath: r, baiFilehandle: s, baiUrl: i, csiPath: c, csiFilehandle: d, csiUrl: a, htsget: l, yieldThreadTime: x = 100, renameRefSeqs: h = (f) => f }) {
1023
+ if (this.htsget = !1, this.featureCache = new Q({
1024
+ cache: new Y({
1046
1025
  maxSize: 50
1047
1026
  }),
1048
- fill: async (d, _) => {
1049
- const { chunk: g, opts: m } = d, { data: p, cpositions: w, dpositions: E } = await this._readChunk({
1050
- chunk: g,
1051
- opts: { ...m, signal: _ }
1027
+ fill: async (f, m) => {
1028
+ const { chunk: b, opts: u } = f, { data: g, cpositions: p, dpositions: w } = await this._readChunk({
1029
+ chunk: b,
1030
+ opts: { ...u, signal: m }
1052
1031
  });
1053
- return this.readBamFeatures(p, w, E, g);
1032
+ return this.readBamFeatures(g, p, w, b);
1054
1033
  }
1055
- }), this.renameRefSeq = f, e)
1034
+ }), this.renameRefSeq = h, e)
1056
1035
  this.bam = e;
1057
1036
  else if (t)
1058
- this.bam = new A(t);
1037
+ this.bam = new C(t);
1059
1038
  else if (n)
1060
- this.bam = new R(n);
1039
+ this.bam = new k(n);
1061
1040
  else if (l)
1062
- this.htsget = !0, this.bam = new _e();
1041
+ this.htsget = !0, this.bam = new xe();
1063
1042
  else
1064
1043
  throw new Error("unable to initialize bam");
1065
- if (c)
1066
- this.index = new P({ filehandle: c });
1067
- else if (h)
1068
- this.index = new P({ filehandle: new A(h) });
1069
- else if (i)
1070
- this.index = new P({ filehandle: new R(i) });
1044
+ if (d)
1045
+ this.index = new P({ filehandle: d });
1046
+ else if (c)
1047
+ this.index = new P({ filehandle: new C(c) });
1048
+ else if (a)
1049
+ this.index = new P({ filehandle: new k(a) });
1071
1050
  else if (s)
1072
1051
  this.index = new v({ filehandle: s });
1073
1052
  else if (r)
1074
- this.index = new v({ filehandle: new A(r) });
1075
- else if (a)
1076
- this.index = new v({ filehandle: new R(a) });
1053
+ this.index = new v({ filehandle: new C(r) });
1054
+ else if (i)
1055
+ this.index = new v({ filehandle: new k(i) });
1077
1056
  else if (t)
1078
- this.index = new v({ filehandle: new A(`${t}.bai`) });
1057
+ this.index = new v({ filehandle: new C(`${t}.bai`) });
1079
1058
  else if (n)
1080
- this.index = new v({ filehandle: new R(`${n}.bai`) });
1059
+ this.index = new v({ filehandle: new k(`${n}.bai`) });
1081
1060
  else if (l)
1082
1061
  this.htsget = !0;
1083
1062
  else
1084
1063
  throw new Error("unable to infer index format");
1085
- this.yieldThreadTime = u;
1064
+ this.yieldThreadTime = x;
1086
1065
  }
1087
1066
  async getHeaderPre(e) {
1088
- const t = ee(e);
1067
+ const t = Z(e);
1089
1068
  if (!this.index)
1090
1069
  return;
1091
1070
  const n = await this.index.parse(t), r = n.firstDataLine ? n.firstDataLine.blockPosition + 65535 : void 0;
1092
1071
  let s;
1093
1072
  if (r) {
1094
- const l = r + q, u = await this.bam.read(I.Buffer.alloc(l), 0, l, 0, t);
1095
- if (!u.bytesRead)
1073
+ const l = r + q, x = await this.bam.read(I.Buffer.alloc(l), 0, l, 0, t);
1074
+ if (!x.bytesRead)
1096
1075
  throw new Error("Error reading header");
1097
- s = u.buffer.subarray(0, Math.min(u.bytesRead, r));
1076
+ s = x.buffer.subarray(0, Math.min(x.bytesRead, r));
1098
1077
  } else
1099
1078
  s = await this.bam.readFile(t);
1100
- const a = await k(s);
1101
- if (a.readInt32LE(0) !== j)
1079
+ const i = await R(s);
1080
+ if (i.readInt32LE(0) !== G)
1102
1081
  throw new Error("Not a BAM file");
1103
- const h = a.readInt32LE(4);
1104
- this.header = a.toString("utf8", 8, 8 + h);
1105
- const { chrToIndex: c, indexToChr: i } = await this._readRefSeqs(h + 8, 65535, t);
1106
- return this.chrToIndex = c, this.indexToChr = i, G(this.header);
1082
+ const c = i.readInt32LE(4);
1083
+ this.header = i.toString("utf8", 8, 8 + c);
1084
+ const { chrToIndex: d, indexToChr: a } = await this._readRefSeqs(c + 8, 65535, t);
1085
+ return this.chrToIndex = d, this.indexToChr = a, H(this.header);
1107
1086
  }
1108
1087
  getHeader(e) {
1109
1088
  return this.headerP || (this.headerP = this.getHeaderPre(e).catch((t) => {
@@ -1118,78 +1097,78 @@ class pe {
1118
1097
  async _readRefSeqs(e, t, n) {
1119
1098
  if (e > t)
1120
1099
  return this._readRefSeqs(e, t * 2, n);
1121
- const r = t + q, { bytesRead: s, buffer: a } = await this.bam.read(I.Buffer.alloc(r), 0, t, 0, n);
1100
+ const r = t + q, { bytesRead: s, buffer: i } = await this.bam.read(I.Buffer.alloc(r), 0, t, 0, n);
1122
1101
  if (!s)
1123
1102
  throw new Error("Error reading refseqs from header");
1124
- const h = await k(a.subarray(0, Math.min(s, t))), c = h.readInt32LE(e);
1125
- let i = e + 4;
1126
- const l = {}, u = [];
1127
- for (let f = 0; f < c; f += 1) {
1128
- const d = h.readInt32LE(i), _ = this.renameRefSeq(h.toString("utf8", i + 4, i + 4 + d - 1)), g = h.readInt32LE(i + d + 4);
1129
- if (l[_] = f, u.push({ refName: _, length: g }), i = i + 8 + d, i > h.length)
1103
+ const c = await R(i.subarray(0, Math.min(s, t))), d = c.readInt32LE(e);
1104
+ let a = e + 4;
1105
+ const l = {}, x = [];
1106
+ for (let h = 0; h < d; h += 1) {
1107
+ const f = c.readInt32LE(a), m = this.renameRefSeq(c.toString("utf8", a + 4, a + 4 + f - 1)), b = c.readInt32LE(a + f + 4);
1108
+ if (l[m] = h, x.push({ refName: m, length: b }), a = a + 8 + f, a > c.length)
1130
1109
  return console.warn(`BAM header is very big. Re-fetching ${t} bytes.`), this._readRefSeqs(e, t * 2, n);
1131
1110
  }
1132
- return { chrToIndex: l, indexToChr: u };
1111
+ return { chrToIndex: l, indexToChr: x };
1133
1112
  }
1134
1113
  async getRecordsForRange(e, t, n, r) {
1135
- return ge(this.streamRecordsForRange(e, t, n, r));
1114
+ return le(this.streamRecordsForRange(e, t, n, r));
1136
1115
  }
1137
1116
  async *streamRecordsForRange(e, t, n, r) {
1138
1117
  var s;
1139
1118
  await this.getHeader(r);
1140
- const a = (s = this.chrToIndex) === null || s === void 0 ? void 0 : s[e];
1141
- if (a === void 0 || !this.index)
1119
+ const i = (s = this.chrToIndex) === null || s === void 0 ? void 0 : s[e];
1120
+ if (i === void 0 || !this.index)
1142
1121
  yield [];
1143
1122
  else {
1144
- const h = await this.index.blocksForRange(a, t - 1, n, r);
1145
- yield* this._fetchChunkFeatures(h, a, t, n, r);
1123
+ const c = await this.index.blocksForRange(i, t - 1, n, r);
1124
+ yield* this._fetchChunkFeatures(c, i, t, n, r);
1146
1125
  }
1147
1126
  }
1148
1127
  async *_fetchChunkFeatures(e, t, n, r, s = {}) {
1149
- const { viewAsPairs: a } = s, h = [];
1150
- let c = !1;
1151
- for (const i of e) {
1152
- const l = await this.featureCache.get(i.toString(), { chunk: i, opts: s }, s.signal), u = [];
1153
- for (const f of l)
1154
- if (f.seq_id() === t)
1155
- if (f.get("start") >= r) {
1156
- c = !0;
1128
+ const { viewAsPairs: i } = s, c = [];
1129
+ let d = !1;
1130
+ for (const a of e) {
1131
+ const l = await this.featureCache.get(a.toString(), { chunk: a, opts: s }, s.signal), x = [];
1132
+ for (const h of l)
1133
+ if (h.seq_id() === t)
1134
+ if (h.get("start") >= r) {
1135
+ d = !0;
1157
1136
  break;
1158
- } else f.get("end") >= n && u.push(f);
1159
- if (h.push(u), yield u, c)
1137
+ } else h.get("end") >= n && x.push(h);
1138
+ if (c.push(x), yield x, d)
1160
1139
  break;
1161
1140
  }
1162
- K(s.signal), a && (yield this.fetchPairs(t, h, s));
1141
+ J(s.signal), i && (yield this.fetchPairs(t, c, s));
1163
1142
  }
1164
1143
  async fetchPairs(e, t, n) {
1165
- const { pairAcrossChr: r, maxInsertSize: s = 2e5 } = n, a = {}, h = {};
1166
- t.map((f) => {
1167
- const d = {};
1168
- for (const _ of f) {
1169
- const g = _.name(), m = _.id();
1170
- d[g] || (d[g] = 0), d[g]++, h[m] = 1;
1144
+ const { pairAcrossChr: r, maxInsertSize: s = 2e5 } = n, i = {}, c = {};
1145
+ t.map((h) => {
1146
+ const f = {};
1147
+ for (const m of h) {
1148
+ const b = m.name(), u = m.id();
1149
+ f[b] || (f[b] = 0), f[b]++, c[u] = 1;
1171
1150
  }
1172
- for (const [_, g] of Object.entries(d))
1173
- g === 1 && (a[_] = !0);
1151
+ for (const [m, b] of Object.entries(f))
1152
+ b === 1 && (i[m] = !0);
1174
1153
  });
1175
- const c = [];
1176
- t.map((f) => {
1177
- for (const d of f) {
1178
- const _ = d.name(), g = d.get("start"), m = d._next_pos(), p = d._next_refid();
1179
- this.index && a[_] && (r || p === e && Math.abs(g - m) < s) && c.push(this.index.blocksForRange(p, m, m + 1, n));
1154
+ const d = [];
1155
+ t.map((h) => {
1156
+ for (const f of h) {
1157
+ const m = f.name(), b = f.get("start"), u = f._next_pos(), g = f._next_refid();
1158
+ this.index && i[m] && (r || g === e && Math.abs(b - u) < s) && d.push(this.index.blocksForRange(g, u, u + 1, n));
1180
1159
  }
1181
1160
  });
1182
- const i = /* @__PURE__ */ new Map(), l = await Promise.all(c);
1183
- for (const f of l.flat())
1184
- i.has(f.toString()) || i.set(f.toString(), f);
1185
- return (await Promise.all([...i.values()].map(async (f) => {
1186
- const { data: d, cpositions: _, dpositions: g, chunk: m } = await this._readChunk({
1187
- chunk: f,
1161
+ const a = /* @__PURE__ */ new Map(), l = await Promise.all(d);
1162
+ for (const h of l.flat())
1163
+ a.has(h.toString()) || a.set(h.toString(), h);
1164
+ return (await Promise.all([...a.values()].map(async (h) => {
1165
+ const { data: f, cpositions: m, dpositions: b, chunk: u } = await this._readChunk({
1166
+ chunk: h,
1188
1167
  opts: n
1189
- }), p = [];
1190
- for (const w of await this.readBamFeatures(d, _, g, m))
1191
- a[w.get("name")] && !h[w.id()] && p.push(w);
1192
- return p;
1168
+ }), g = [];
1169
+ for (const p of await this.readBamFeatures(f, m, b, u))
1170
+ i[p.get("name")] && !c[p.id()] && g.push(p);
1171
+ return g;
1193
1172
  }))).flat();
1194
1173
  }
1195
1174
  async _readRegion(e, t, n = {}) {
@@ -1197,22 +1176,22 @@ class pe {
1197
1176
  return s.subarray(0, Math.min(r, t));
1198
1177
  }
1199
1178
  async _readChunk({ chunk: e, opts: t }) {
1200
- const n = await this._readRegion(e.minv.blockPosition, e.fetchedSize(), t), { buffer: r, cpositions: s, dpositions: a } = await Q(n, e);
1201
- return { data: r, cpositions: s, dpositions: a, chunk: e };
1179
+ const n = await this._readRegion(e.minv.blockPosition, e.fetchedSize(), t), { buffer: r, cpositions: s, dpositions: i } = await V(n, e);
1180
+ return { data: r, cpositions: s, dpositions: i, chunk: e };
1202
1181
  }
1203
1182
  async readBamFeatures(e, t, n, r) {
1204
1183
  let s = 0;
1205
- const a = [];
1206
- let h = 0, c = +Date.now();
1184
+ const i = [];
1185
+ let c = 0, d = +Date.now();
1207
1186
  for (; s + 4 < e.length; ) {
1208
- const i = e.readInt32LE(s), l = s + 4 + i - 1;
1187
+ const a = e.readInt32LE(s), l = s + 4 + a - 1;
1209
1188
  if (n) {
1210
- for (; s + r.minv.dataPosition >= n[h++]; )
1189
+ for (; s + r.minv.dataPosition >= n[c++]; )
1211
1190
  ;
1212
- h--;
1191
+ c--;
1213
1192
  }
1214
1193
  if (l < e.length) {
1215
- const u = new me({
1194
+ const x = new he({
1216
1195
  bytes: {
1217
1196
  byteArray: e,
1218
1197
  start: s,
@@ -1238,16 +1217,16 @@ class pe {
1238
1217
  //
1239
1218
  // the +1 is just to avoid any possible uniqueId 0 but this does not
1240
1219
  // realistically happen
1241
- fileOffset: t.length > 0 ? t[h] * 256 + (s - n[h]) + r.minv.dataPosition + 1 : (
1220
+ fileOffset: t.length > 0 ? t[c] * 256 + (s - n[c]) + r.minv.dataPosition + 1 : (
1242
1221
  // must be slice, not subarray for buffer polyfill on web
1243
- de.signed(e.slice(s, l))
1222
+ oe.signed(e.slice(s, l))
1244
1223
  )
1245
1224
  });
1246
- a.push(u), this.yieldThreadTime && +Date.now() - c > this.yieldThreadTime && (await X(1), c = +Date.now());
1225
+ i.push(x), this.yieldThreadTime && +Date.now() - d > this.yieldThreadTime && (await W(1), d = +Date.now());
1247
1226
  }
1248
1227
  s = l + 1;
1249
1228
  }
1250
- return a;
1229
+ return i;
1251
1230
  }
1252
1231
  async hasRefSeq(e) {
1253
1232
  var t, n;
@@ -1272,8 +1251,8 @@ class pe {
1272
1251
  if (!this.index)
1273
1252
  return [];
1274
1253
  await this.index.parse();
1275
- const a = (s = this.chrToIndex) === null || s === void 0 ? void 0 : s[e];
1276
- return a === void 0 ? [] : this.index.blocksForRange(a, t, n, r);
1254
+ const i = (s = this.chrToIndex) === null || s === void 0 ? void 0 : s[e];
1255
+ return i === void 0 ? [] : this.index.blocksForRange(i, t, n, r);
1277
1256
  }
1278
1257
  }
1279
1258
  async function N(o, e) {
@@ -1282,35 +1261,35 @@ async function N(o, e) {
1282
1261
  if (r.startsWith("data:"))
1283
1262
  return I.Buffer.from(r.split(",")[1], "base64");
1284
1263
  {
1285
- const { referer: a, ...h } = s, c = await fetch(r, {
1264
+ const { referer: i, ...c } = s, d = await fetch(r, {
1286
1265
  ...e,
1287
- headers: { ...e == null ? void 0 : e.headers, ...h }
1266
+ headers: { ...e == null ? void 0 : e.headers, ...c }
1288
1267
  });
1289
- if (!c.ok)
1290
- throw new Error(`HTTP ${c.status} fetching ${r}: ${await c.text()}`);
1291
- return I.Buffer.from(await c.arrayBuffer());
1268
+ if (!d.ok)
1269
+ throw new Error(`HTTP ${d.status} fetching ${r}: ${await d.text()}`);
1270
+ return I.Buffer.from(await d.arrayBuffer());
1292
1271
  }
1293
1272
  }));
1294
- return I.Buffer.concat(await Promise.all(t.map((n) => k(n))));
1273
+ return I.Buffer.concat(await Promise.all(t.map((n) => R(n))));
1295
1274
  }
1296
- class ye extends pe {
1275
+ class we extends ue {
1297
1276
  constructor(e) {
1298
1277
  super({ htsget: !0 }), this.baseUrl = e.baseUrl, this.trackId = e.trackId;
1299
1278
  }
1300
1279
  async *streamRecordsForRange(e, t, n, r) {
1301
1280
  var s;
1302
- const h = `${`${this.baseUrl}/${this.trackId}`}?referenceName=${e}&start=${t}&end=${n}&format=BAM`, c = (s = this.chrToIndex) === null || s === void 0 ? void 0 : s[e];
1303
- if (c === void 0)
1281
+ const c = `${`${this.baseUrl}/${this.trackId}`}?referenceName=${e}&start=${t}&end=${n}&format=BAM`, d = (s = this.chrToIndex) === null || s === void 0 ? void 0 : s[e];
1282
+ if (d === void 0)
1304
1283
  yield [];
1305
1284
  else {
1306
- const i = await fetch(h, { ...r });
1307
- if (!i.ok)
1308
- throw new Error(`HTTP ${i.status} fetching ${h}: ${await i.text()}`);
1309
- const l = await i.json(), u = await N(l.htsget.urls.slice(1), r);
1285
+ const a = await fetch(c, { ...r });
1286
+ if (!a.ok)
1287
+ throw new Error(`HTTP ${a.status} fetching ${c}: ${await a.text()}`);
1288
+ const l = await a.json(), x = await N(l.htsget.urls.slice(1), r);
1310
1289
  yield* this._fetchChunkFeatures([
1311
1290
  // fake stuff to pretend to be a Chunk
1312
1291
  {
1313
- buffer: u,
1292
+ buffer: x,
1314
1293
  _fetchedSize: void 0,
1315
1294
  bin: 0,
1316
1295
  compareTo() {
@@ -1336,7 +1315,7 @@ class ye extends pe {
1336
1315
  return `${e}_${t}_${n}`;
1337
1316
  }
1338
1317
  }
1339
- ], c, t, n, r);
1318
+ ], d, t, n, r);
1340
1319
  }
1341
1320
  }
1342
1321
  async _readChunk({ chunk: e }) {
@@ -1349,22 +1328,22 @@ class ye extends pe {
1349
1328
  if (!n.ok)
1350
1329
  throw new Error(`HTTP ${n.status} fetching ${t}: ${await n.text()}`);
1351
1330
  const r = await n.json(), s = await N(r.htsget.urls, e);
1352
- if (s.readInt32LE(0) !== j)
1331
+ if (s.readInt32LE(0) !== G)
1353
1332
  throw new Error("Not a BAM file");
1354
- const a = s.readInt32LE(4), h = s.toString("utf8", 8, 8 + a), c = G(h), i = [], l = {}, u = c.filter((f) => f.tag === "SQ");
1355
- for (const [f, d] of u.entries()) {
1356
- let _ = "", g = 0;
1357
- for (const m of d.data)
1358
- m.tag === "SN" ? _ = m.value : m.tag === "LN" && (g = +m.value);
1359
- l[_] = f, i[f] = { refName: _, length: g };
1333
+ const i = s.readInt32LE(4), c = s.toString("utf8", 8, 8 + i), d = H(c), a = [], l = {}, x = d.filter((h) => h.tag === "SQ");
1334
+ for (const [h, f] of x.entries()) {
1335
+ let m = "", b = 0;
1336
+ for (const u of f.data)
1337
+ u.tag === "SN" ? m = u.value : u.tag === "LN" && (b = +u.value);
1338
+ l[m] = h, a[h] = { refName: m, length: b };
1360
1339
  }
1361
- return this.chrToIndex = l, this.indexToChr = i, c;
1340
+ return this.chrToIndex = l, this.indexToChr = a, d;
1362
1341
  }
1363
1342
  }
1364
1343
  export {
1365
1344
  v as BAI,
1366
- pe as BamFile,
1367
- me as BamRecord,
1345
+ ue as BamFile,
1346
+ he as BamRecord,
1368
1347
  P as CSI,
1369
- ye as HtsgetFile
1348
+ we as HtsgetFile
1370
1349
  };