@genome-spy/app 0.57.0 → 0.58.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,9 +1,9 @@
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";
1
+ import { L as Y, u as P, a as Q } from "./long-BviWyoZx.js";
2
+ import { b as y } from "./index-BftNdA0O.js";
3
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
- class D {
4
+ import { R as L } from "./remoteFile-BuaqFGWk.js";
5
+ import { A as W, L as X } from "./index-CCJIjehY.js";
6
+ class O {
7
7
  constructor(e, t) {
8
8
  this.blockPosition = e, this.dataPosition = t;
9
9
  }
@@ -25,9 +25,9 @@ class D {
25
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
- 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]);
28
+ return new O(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]);
29
29
  }
30
- class $ {
30
+ class F {
31
31
  constructor(e, t, n, r) {
32
32
  this.minv = e, this.maxv = t, this.bin = n, this._fetchedSize = r;
33
33
  }
@@ -44,15 +44,10 @@ class $ {
44
44
  return this._fetchedSize !== void 0 ? this._fetchedSize : this.maxv.blockPosition + 65536 - this.minv.blockPosition;
45
45
  }
46
46
  }
47
- function W(o) {
47
+ function J(o) {
48
48
  return new Promise((e) => setTimeout(e, o));
49
49
  }
50
- function X(o) {
51
- if (o.greaterThan(Number.MAX_SAFE_INTEGER) || o.lessThan(Number.MIN_SAFE_INTEGER))
52
- throw new Error("integer overflow");
53
- return o.toNumber();
54
- }
55
- function J(o) {
50
+ function K(o) {
56
51
  if (o && o.aborted)
57
52
  if (typeof DOMException > "u") {
58
53
  const e = new Error("aborted");
@@ -60,13 +55,13 @@ function J(o) {
60
55
  } else
61
56
  throw new DOMException("aborted", "AbortError");
62
57
  }
63
- function K(o, e) {
58
+ function Z(o, e) {
64
59
  return e.minv.blockPosition - o.maxv.blockPosition < 65e3 && e.maxv.blockPosition - o.minv.blockPosition < 5e6;
65
60
  }
66
- function Z(o = {}) {
61
+ function ee(o = {}) {
67
62
  return "aborted" in o ? { signal: o } : o;
68
63
  }
69
- function U(o, e) {
64
+ function z(o, e) {
70
65
  const t = [];
71
66
  let n;
72
67
  if (o.length === 0)
@@ -76,16 +71,18 @@ function U(o, e) {
76
71
  return i === 0 ? r.minv.dataPosition - s.minv.dataPosition : i;
77
72
  });
78
73
  for (const r of o)
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));
74
+ (!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));
80
75
  return t;
81
76
  }
82
- function z(o, e) {
83
- return { lineCount: X(j.fromBytesLE(Array.prototype.slice.call(o, e, e + 8), !0)) };
77
+ function G(o, e) {
78
+ return {
79
+ lineCount: Y.fromBytesLE(Array.prototype.slice.call(o, e, e + 8), !0).toNumber()
80
+ };
84
81
  }
85
- function L(o, e) {
82
+ function S(o, e) {
86
83
  return o ? o.compareTo(e) > 0 ? e : o : e;
87
84
  }
88
- function ee(o, e = (t) => t) {
85
+ function te(o, e = (t) => t) {
89
86
  let t = 0, n = 0;
90
87
  const r = [], s = {};
91
88
  for (let i = 0; i < o.length; i += 1)
@@ -98,7 +95,7 @@ function ee(o, e = (t) => t) {
98
95
  }
99
96
  return { refNameToId: s, refIdToName: r };
100
97
  }
101
- class O {
98
+ class H {
102
99
  /**
103
100
  * @param {filehandle} filehandle
104
101
  * @param {function} [renameRefSeqs]
@@ -107,14 +104,14 @@ class O {
107
104
  this.filehandle = e, this.renameRefSeq = t;
108
105
  }
109
106
  }
110
- const te = 21578050;
111
- function ne(o, e) {
107
+ const ne = 21578050;
108
+ function re(o, e) {
112
109
  return o - o % e;
113
110
  }
114
- function re(o, e) {
111
+ function se(o, e) {
115
112
  return o - o % e + e;
116
113
  }
117
- function se(o, e) {
114
+ function ie(o, e) {
118
115
  return e -= 1, [
119
116
  [0, 0],
120
117
  [1 + (o >> 26), 1 + (e >> 26)],
@@ -124,7 +121,7 @@ function se(o, e) {
124
121
  [4681 + (o >> 14), 4681 + (e >> 14)]
125
122
  ];
126
123
  }
127
- class v extends O {
124
+ class v extends H {
128
125
  async lineCount(e, t) {
129
126
  var n, r;
130
127
  return ((r = (n = (await this.parse(t)).indices[e]) === null || n === void 0 ? void 0 : n.stats) === null || r === void 0 ? void 0 : r.lineCount) || 0;
@@ -132,74 +129,74 @@ class v extends O {
132
129
  // fetch and parse the index
133
130
  async _parse(e) {
134
131
  const t = await this.filehandle.readFile(e);
135
- if (t.readUInt32LE(0) !== te)
132
+ if (t.readUInt32LE(0) !== ne)
136
133
  throw new Error("Not a BAI file");
137
134
  const n = t.readInt32LE(4), s = ((1 << (5 + 1) * 3) - 1) / 7;
138
135
  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;
136
+ const a = new Array(n);
137
+ for (let d = 0; d < n; d++) {
138
+ const f = t.readInt32LE(i);
139
+ let h;
143
140
  i += 4;
144
- const h = {};
145
- for (let b = 0; b < l; b += 1) {
141
+ const l = {};
142
+ for (let b = 0; b < f; b += 1) {
146
143
  const u = t.readUInt32LE(i);
147
144
  if (i += 4, u === s + 1)
148
- i += 4, x = z(t, i + 16), i += 32;
145
+ i += 4, h = G(t, i + 16), i += 32;
149
146
  else {
150
147
  if (u > s + 1)
151
148
  throw new Error("bai index contains too many bins, please use CSI");
152
149
  {
153
150
  const g = t.readInt32LE(i);
154
151
  i += 4;
155
- const p = new Array(g);
156
- for (let w = 0; w < g; w++) {
157
- const y = E(t, i);
152
+ const w = new Array(g);
153
+ for (let _ = 0; _ < g; _++) {
154
+ const I = E(t, i);
158
155
  i += 8;
159
- const S = E(t, i);
160
- i += 8, c = L(c, y), p[w] = new $(y, S, u);
156
+ const M = E(t, i);
157
+ i += 8, c = S(c, I), w[_] = new F(I, M, u);
161
158
  }
162
- h[u] = p;
159
+ l[u] = w;
163
160
  }
164
161
  }
165
162
  }
166
- const f = t.readInt32LE(i);
163
+ const x = t.readInt32LE(i);
167
164
  i += 4;
168
- const m = new Array(f);
169
- for (let b = 0; b < f; b++) {
165
+ const m = new Array(x);
166
+ for (let b = 0; b < x; b++) {
170
167
  const u = E(t, i);
171
- i += 8, c = L(c, u), m[b] = u;
168
+ i += 8, c = S(c, u), m[b] = u;
172
169
  }
173
- d[a] = { binIndex: h, linearIndex: m, stats: x };
170
+ a[d] = { binIndex: l, linearIndex: m, stats: h };
174
171
  }
175
172
  return {
176
173
  bai: !0,
177
174
  firstDataLine: c,
178
175
  maxBlockSize: 65536,
179
- indices: d,
176
+ indices: a,
180
177
  refCount: n
181
178
  };
182
179
  }
183
180
  async indexCov(e, t, n, r = {}) {
184
- const i = t !== void 0, d = (await this.parse(r)).indices[e];
185
- if (!d)
181
+ const i = t !== void 0, a = (await this.parse(r)).indices[e];
182
+ if (!a)
186
183
  return [];
187
- const { linearIndex: a = [], stats: l } = d;
188
- if (a.length === 0)
184
+ const { linearIndex: d = [], stats: f } = a;
185
+ if (d.length === 0)
189
186
  return [];
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)
187
+ const h = n === void 0 ? (d.length - 1) * 16384 : se(n, 16384), l = t === void 0 ? 0 : re(t, 16384), x = i ? new Array((h - l) / 16384) : new Array(d.length - 1), m = d[d.length - 1].blockPosition;
188
+ if (h > (d.length - 1) * 16384)
192
189
  throw new Error("query outside of range of linear index");
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,
190
+ let b = d[l / 16384].blockPosition;
191
+ for (let u = l / 16384, g = 0; u < h / 16384; u++, g++)
192
+ x[g] = {
193
+ score: d[u + 1].blockPosition - b,
197
194
  start: u * 16384,
198
195
  end: u * 16384 + 16384
199
- }, b = a[u + 1].blockPosition;
200
- return f.map((u) => ({
196
+ }, b = d[u + 1].blockPosition;
197
+ return x.map((u) => ({
201
198
  ...u,
202
- score: u.score * ((l == null ? void 0 : l.lineCount) || 0) / m
199
+ score: u.score * ((f == null ? void 0 : f.lineCount) || 0) / m
203
200
  }));
204
201
  }
205
202
  async blocksForRange(e, t, n, r = {}) {
@@ -210,22 +207,22 @@ class v extends O {
210
207
  const i = s.indices[e];
211
208
  if (!i)
212
209
  return [];
213
- const c = se(t, n), d = [];
214
- for (const [f, m] of c)
215
- for (let b = f; b <= m; b++)
210
+ const c = ie(t, n), a = [];
211
+ for (const [x, m] of c)
212
+ for (let b = x; b <= m; b++)
216
213
  if (i.binIndex[b]) {
217
214
  const u = i.binIndex[b];
218
215
  for (const g of u)
219
- d.push(g);
216
+ a.push(new F(g.minv, g.maxv, b));
220
217
  }
221
- const a = i.linearIndex.length;
222
- let 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);
218
+ const d = i.linearIndex.length;
219
+ let f;
220
+ const h = Math.min(t >> 14, d - 1), l = Math.min(n >> 14, d - 1);
221
+ for (let x = h; x <= l; ++x) {
222
+ const m = i.linearIndex[x];
223
+ m && (!f || m.compareTo(f) < 0) && (f = m);
227
224
  }
228
- return U(d, l);
225
+ return z(a, f);
229
226
  }
230
227
  async parse(e = {}) {
231
228
  return this.setupP || (this.setupP = this._parse(e).catch((t) => {
@@ -237,7 +234,7 @@ class v extends O {
237
234
  return !!(!((n = (await this.parse(t)).indices[e]) === null || n === void 0) && n.binIndex);
238
235
  }
239
236
  }
240
- let T = [
237
+ let B = [
241
238
  0,
242
239
  1996959894,
243
240
  3993919788,
@@ -495,25 +492,25 @@ let T = [
495
492
  1510334235,
496
493
  755167117
497
494
  ];
498
- typeof Int32Array < "u" && (T = new Int32Array(T));
495
+ typeof Int32Array < "u" && (B = new Int32Array(B));
499
496
  const ae = (o, e) => {
500
497
  let t = e === 0 ? 0 : ~~e ^ -1;
501
498
  for (let n = 0; n < o.length; n++)
502
- t = T[(t ^ o[n]) & 255] ^ t >>> 8;
499
+ t = B[(t ^ o[n]) & 255] ^ t >>> 8;
503
500
  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;
501
+ }, N = (o, e) => y.Buffer.from(o, e);
502
+ function oe(o, e) {
503
+ const t = (n, r) => e(N(n), r) >>> 0;
504
+ return t.signed = (n, r) => e(N(n), r), t.unsigned = t, t.model = o, t;
508
505
  }
509
- const oe = ie("crc-32", ae), de = 21582659, ce = 38359875;
510
- function fe(o, e) {
506
+ const ce = oe("crc-32", ae), de = 21582659, fe = 38359875;
507
+ function he(o, e) {
511
508
  return o * 2 ** e;
512
509
  }
513
- function F(o, e) {
510
+ function q(o, e) {
514
511
  return Math.floor(o / 2 ** e);
515
512
  }
516
- class P extends O {
513
+ class T extends H {
517
514
  constructor() {
518
515
  super(...arguments), this.maxBinNumber = 0, this.depth = 0, this.minShift = 0;
519
516
  }
@@ -532,61 +529,61 @@ class P extends O {
532
529
  ref: e.readInt32LE(t + 4),
533
530
  start: e.readInt32LE(t + 8),
534
531
  end: e.readInt32LE(t + 12)
535
- }, c = e.readInt32LE(t + 16), d = c ? String.fromCharCode(c) : "", a = e.readInt32LE(t + 20), l = e.readInt32LE(t + 24);
532
+ }, c = e.readInt32LE(t + 16), a = c ? String.fromCharCode(c) : "", d = e.readInt32LE(t + 20), f = e.readInt32LE(t + 24);
536
533
  return {
537
534
  columnNumbers: i,
538
535
  coordinateType: r,
539
536
  metaValue: c,
540
- metaChar: d,
541
- skipLines: a,
537
+ metaChar: a,
538
+ skipLines: d,
542
539
  format: s,
543
540
  formatFlags: n,
544
- ...ee(e.subarray(t + 28, t + 28 + l), this.renameRefSeq)
541
+ ...te(e.subarray(t + 28, t + 28 + f), this.renameRefSeq)
545
542
  };
546
543
  }
547
544
  // fetch and parse the index
548
545
  async _parse(e) {
549
- const t = await this.filehandle.readFile(e), n = await R(t);
546
+ const t = await this.filehandle.readFile(e), n = await P(t);
550
547
  let r;
551
548
  if (n.readUInt32LE(0) === de)
552
549
  r = 1;
553
- else if (n.readUInt32LE(0) === ce)
550
+ else if (n.readUInt32LE(0) === fe)
554
551
  r = 2;
555
552
  else
556
553
  throw new Error("Not a CSI file");
557
554
  this.minShift = n.readInt32LE(4), this.depth = n.readInt32LE(8), this.maxBinNumber = ((1 << (this.depth + 1) * 3) - 1) / 7;
558
555
  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 = {};
556
+ let a = 16 + s + 4, d;
557
+ const f = new Array(c);
558
+ for (let h = 0; h < c; h++) {
559
+ const l = n.readInt32LE(a);
560
+ a += 4;
561
+ const x = {};
565
562
  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;
563
+ for (let b = 0; b < l; b++) {
564
+ const u = n.readUInt32LE(a);
565
+ if (a += 4, u > this.maxBinNumber)
566
+ m = G(n, a + 28), a += 44;
570
567
  else {
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);
568
+ d = S(d, E(n, a)), a += 8;
569
+ const g = n.readInt32LE(a);
570
+ a += 4;
571
+ const w = new Array(g);
572
+ for (let _ = 0; _ < g; _ += 1) {
573
+ const I = E(n, a);
574
+ a += 8;
575
+ const M = E(n, a);
576
+ a += 8, d = S(d, I), w[_] = new F(I, M, u);
580
577
  }
581
- f[u] = p;
578
+ x[u] = w;
582
579
  }
583
580
  }
584
- l[x] = { binIndex: f, stats: m };
581
+ f[h] = { binIndex: x, stats: m };
585
582
  }
586
583
  return {
587
584
  csiVersion: r,
588
- firstDataLine: a,
589
- indices: l,
585
+ firstDataLine: d,
586
+ indices: f,
590
587
  refCount: c,
591
588
  csi: !0,
592
589
  maxBlockSize: 65536,
@@ -595,21 +592,21 @@ class P extends O {
595
592
  }
596
593
  async blocksForRange(e, t, n, r = {}) {
597
594
  t < 0 && (t = 0);
598
- const s = await this.parse(r), i = s == null ? void 0 : s.indices[e];
595
+ const i = (await this.parse(r)).indices[e];
599
596
  if (!i)
600
597
  return [];
601
598
  const c = this.reg2bins(t, n);
602
599
  if (c.length === 0)
603
600
  return [];
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);
601
+ const a = [];
602
+ for (const [d, f] of c)
603
+ for (let h = d; h <= f; h++)
604
+ if (i.binIndex[h]) {
605
+ const l = i.binIndex[h];
606
+ for (const x of l)
607
+ a.push(x);
611
608
  }
612
- return U(d, new D(0, 0));
609
+ return z(a, new O(0, 0));
613
610
  }
614
611
  /**
615
612
  * calculate the list of bins that may overlap with region [beg,end)
@@ -619,11 +616,11 @@ class P extends O {
619
616
  e -= 1, e < 1 && (e = 1), t > 2 ** 50 && (t = 2 ** 34), t -= 1;
620
617
  let n = 0, r = 0, s = this.minShift + this.depth * 3;
621
618
  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)
619
+ for (; n <= this.depth; s -= 3, r += he(1, n * 3), n += 1) {
620
+ const c = r + q(e, s), a = r + q(t, s);
621
+ if (a - c + i.length > this.maxBinNumber)
625
622
  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`);
626
- i.push([c, d]);
623
+ i.push([c, a]);
627
624
  }
628
625
  return i;
629
626
  }
@@ -637,7 +634,7 @@ class P extends O {
637
634
  return !!(!((n = (await this.parse(t)).indices[e]) === null || n === void 0) && n.binIndex);
638
635
  }
639
636
  }
640
- const _ = {
637
+ const p = {
641
638
  // the read is paired in sequencing, no matter whether it is mapped in a pair
642
639
  BAM_FPAIRED: 1,
643
640
  // the read is mapped in a proper pair
@@ -662,319 +659,273 @@ const _ = {
662
659
  BAM_FDUP: 1024,
663
660
  // supplementary alignment
664
661
  BAM_FSUPPLEMENTARY: 2048
665
- }, B = "=ACMGRSVTWYHKDBN".split(""), A = "MIDNSHP=X???????".split("");
666
- class he {
662
+ }, D = "=ACMGRSVTWYHKDBN".split(""), A = "MIDNSHP=X???????".split("");
663
+ class R {
667
664
  constructor(e) {
668
- this.data = {}, this._tagList = [], this._allTagsParsed = !1;
669
- const { bytes: t, fileOffset: n } = e, { byteArray: r, start: s } = t;
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;
671
- }
672
- get(e) {
673
- return this[e] ? this.data[e] ? this.data[e] : (this.data[e] = this[e](), this.data[e]) : this._get(e.toLowerCase());
674
- }
675
- end() {
676
- return this.get("start") + this.get("length_on_ref");
677
- }
678
- seq_id() {
679
- return this._refID;
680
- }
681
- // same as get(), except requires lower-case arguments. used
682
- // internally to save lots of calls to field.toLowerCase()
683
- _get(e) {
684
- return e in this.data ? this.data[e] : (this.data[e] = this._parseTag(e), this.data[e]);
685
- }
686
- _tags() {
687
- this._parseAllTags();
688
- let e = ["seq"];
689
- this.isSegmentUnmapped() || e.push("start", "end", "strand", "score", "qual", "MQ", "CIGAR", "length_on_ref", "template_length"), this.isPaired() && e.push("next_segment_position", "pair_orientation"), e = e.concat(this._tagList || []);
690
- for (const n of Object.keys(this.data))
691
- !n.startsWith("_") && n !== "next_seq_id" && e.push(n);
692
- const t = {};
693
- return e.filter((n) => {
694
- if (n in this.data && this.data[n] === void 0 || n === "CG" || n === "cg")
695
- return !1;
696
- const r = n.toLowerCase(), s = t[r];
697
- return t[r] = !0, !s;
698
- });
665
+ this.bytes = e.bytes, this.fileOffset = e.fileOffset;
699
666
  }
700
- parent() {
667
+ get byteArray() {
668
+ return this.bytes.byteArray;
701
669
  }
702
- children() {
703
- return this.get("subfeatures");
670
+ get flags() {
671
+ return (this.byteArray.readInt32LE(this.bytes.start + 16) & 4294901760) >> 16;
704
672
  }
705
- id() {
706
- return this._id;
673
+ get ref_id() {
674
+ return this.byteArray.readInt32LE(this.bytes.start + 4);
707
675
  }
708
- // special parsers
709
- /**
710
- * Mapping quality score.
711
- */
712
- mq() {
713
- const e = (this.get("_bin_mq_nl") & 65280) >> 8;
714
- return e === 255 ? void 0 : e;
676
+ get start() {
677
+ return this.byteArray.readInt32LE(this.bytes.start + 8);
715
678
  }
716
- score() {
717
- return this.get("mq");
679
+ get end() {
680
+ return this.start + this.length_on_ref;
681
+ }
682
+ get id() {
683
+ return this.fileOffset;
684
+ }
685
+ get mq() {
686
+ const e = (this.bin_mq_nl & 65280) >> 8;
687
+ return e === 255 ? void 0 : e;
718
688
  }
719
- qual() {
720
- var e;
721
- return (e = this.qualRaw()) === null || e === void 0 ? void 0 : e.join(" ");
689
+ get score() {
690
+ return this.mq;
722
691
  }
723
- qualRaw() {
692
+ get qual() {
724
693
  if (this.isSegmentUnmapped())
725
694
  return;
726
- const { start: e, byteArray: t } = this.bytes, n = e + 36 + this.get("_l_read_name") + this.get("_n_cigar_op") * 4 + this.get("_seq_bytes"), r = this.get("seq_length");
727
- return t.subarray(n, n + r);
695
+ const e = this.b0 + this.read_name_length + this.num_cigar_ops * 4 + this.num_seq_bytes;
696
+ return this.byteArray.subarray(e, e + this.seq_length);
728
697
  }
729
- strand() {
698
+ get strand() {
730
699
  return this.isReverseComplemented() ? -1 : 1;
731
700
  }
732
- multi_segment_next_segment_strand() {
733
- if (!this.isMateUnmapped())
734
- return this.isMateReverseComplemented() ? -1 : 1;
735
- }
736
- name() {
737
- return this.get("_read_name");
738
- }
739
- _read_name() {
740
- const e = this.get("_l_read_name"), { byteArray: t, start: n } = this.bytes;
741
- return t.toString("ascii", n + 36, n + 36 + e - 1);
742
- }
743
- /**
744
- * Get the value of a tag, parsing the tags as far as necessary.
745
- * Only called if we have not already parsed that field.
746
- */
747
- _parseTag(e) {
748
- if (this._allTagsParsed)
749
- return;
750
- const { byteArray: t, start: n } = this.bytes;
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");
752
- const s = this.bytes.end;
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]);
758
- r += 3;
759
- let a;
760
- switch (d) {
761
- case "A": {
762
- a = String.fromCharCode(t[r]), r += 1;
763
- break;
764
- }
765
- case "i": {
766
- a = t.readInt32LE(r), r += 4;
767
- break;
768
- }
769
- case "I": {
770
- a = t.readUInt32LE(r), r += 4;
771
- break;
772
- }
773
- case "c": {
774
- a = t.readInt8(r), r += 1;
775
- break;
776
- }
777
- case "C": {
778
- a = t.readUInt8(r), r += 1;
779
- break;
780
- }
781
- case "s": {
782
- a = t.readInt16LE(r), r += 2;
783
- break;
784
- }
785
- case "S": {
786
- a = t.readUInt16LE(r), r += 2;
787
- break;
788
- }
789
- case "f": {
790
- a = t.readFloatLE(r), r += 4;
791
- break;
701
+ get b0() {
702
+ return this.bytes.start + 36;
703
+ }
704
+ get name() {
705
+ return this.byteArray.toString("ascii", this.b0, this.b0 + this.read_name_length - 1);
706
+ }
707
+ get tags() {
708
+ const { byteArray: e } = this.bytes;
709
+ let t = this.b0 + this.read_name_length + this.num_cigar_ops * 4 + this.num_seq_bytes + this.seq_length;
710
+ const n = this.bytes.end, r = {};
711
+ for (; t < n; ) {
712
+ const s = String.fromCharCode(e[t], e[t + 1]), i = String.fromCharCode(e[t + 2]);
713
+ if (t += 3, i === "A")
714
+ r[s] = String.fromCharCode(e[t]), t += 1;
715
+ else if (i === "i")
716
+ r[s] = e.readInt32LE(t), t += 4;
717
+ else if (i === "I")
718
+ r[s] = e.readUInt32LE(t), t += 4;
719
+ else if (i === "c")
720
+ r[s] = e.readInt8(t), t += 1;
721
+ else if (i === "C")
722
+ r[s] = e.readUInt8(t), t += 1;
723
+ else if (i === "s")
724
+ r[s] = e.readInt16LE(t), t += 2;
725
+ else if (i === "S")
726
+ r[s] = e.readUInt16LE(t), t += 2;
727
+ else if (i === "f")
728
+ r[s] = e.readFloatLE(t), t += 4;
729
+ else if (i === "Z" || i === "H") {
730
+ const c = [];
731
+ for (; t <= n; ) {
732
+ const a = e[t++];
733
+ if (a !== 0)
734
+ c.push(String.fromCharCode(a));
735
+ else
736
+ break;
792
737
  }
793
- case "Z":
794
- case "H": {
795
- for (a = ""; r <= s; ) {
796
- const l = t[r++];
797
- if (l === 0)
798
- break;
799
- a += String.fromCharCode(l);
738
+ r[s] = c.join("");
739
+ } else if (i === "B") {
740
+ const c = e[t++], a = String.fromCharCode(c), d = e.readInt32LE(t);
741
+ if (t += 4, a === "i")
742
+ if (s === "CG") {
743
+ const f = [];
744
+ for (let h = 0; h < d; h++) {
745
+ const l = e.readInt32LE(t), x = l >> 4, m = A[l & 15];
746
+ f.push(x + m), t += 4;
747
+ }
748
+ r[s] = f.join("");
749
+ } else {
750
+ const f = [];
751
+ for (let h = 0; h < d; h++)
752
+ f.push(e.readInt32LE(t)), t += 4;
753
+ r[s] = f;
800
754
  }
801
- break;
802
- }
803
- case "B": {
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;
811
- }
812
- else
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;
820
- }
821
- else
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;
839
- break;
755
+ else if (a === "I")
756
+ if (s === "CG") {
757
+ const f = [];
758
+ for (let h = 0; h < d; h++) {
759
+ const l = e.readUInt32LE(t), x = l >> 4, m = A[l & 15];
760
+ f.push(x + m), t += 4;
761
+ }
762
+ r[s] = f.join("");
763
+ } else {
764
+ const f = [];
765
+ for (let h = 0; h < d; h++)
766
+ f.push(e.readUInt32LE(t)), t += 4;
767
+ r[s] = f;
768
+ }
769
+ else if (a === "s") {
770
+ const f = [];
771
+ for (let h = 0; h < d; h++)
772
+ f.push(e.readInt16LE(t)), t += 2;
773
+ r[s] = f;
774
+ } else if (a === "S") {
775
+ const f = [];
776
+ for (let h = 0; h < d; h++)
777
+ f.push(e.readUInt16LE(t)), t += 2;
778
+ r[s] = f;
779
+ } else if (a === "c") {
780
+ const f = [];
781
+ for (let h = 0; h < d; h++)
782
+ f.push(e.readInt8(t)), t += 1;
783
+ r[s] = f;
784
+ } else if (a === "C") {
785
+ const f = [];
786
+ for (let h = 0; h < d; h++)
787
+ f.push(e.readUInt8(t)), t += 1;
788
+ r[s] = f;
789
+ } else if (a === "f") {
790
+ const f = [];
791
+ for (let h = 0; h < d; h++)
792
+ f.push(e.readFloatLE(t)), t += 4;
793
+ r[s] = f;
840
794
  }
841
- default:
842
- console.warn(`Unknown BAM tag type '${d}', tags may be incomplete`), a = void 0, r = s;
795
+ } else {
796
+ console.error("Unknown BAM tag type", i);
797
+ break;
843
798
  }
844
- if (this._tagOffset = r, this._tagList.push(c), i === e)
845
- return a;
846
- this.data[i] = a;
847
799
  }
848
- this._allTagsParsed = !0;
849
- }
850
- _parseAllTags() {
851
- this._parseTag("");
852
- }
853
- _parseCigar(e) {
854
- return (
855
- //@ts-ignore
856
- e.match(/\d+\D/g).map((t) => [/\D/.exec(t)[0].toUpperCase(), Number.parseInt(t, 10)])
857
- );
800
+ return r;
858
801
  }
859
802
  /**
860
803
  * @returns {boolean} true if the read is paired, regardless of whether both
861
804
  * segments are mapped
862
805
  */
863
806
  isPaired() {
864
- return !!(this.flags & _.BAM_FPAIRED);
807
+ return !!(this.flags & p.BAM_FPAIRED);
865
808
  }
866
809
  /** @returns {boolean} true if the read is paired, and both segments are mapped */
867
810
  isProperlyPaired() {
868
- return !!(this.flags & _.BAM_FPROPER_PAIR);
811
+ return !!(this.flags & p.BAM_FPROPER_PAIR);
869
812
  }
870
813
  /** @returns {boolean} true if the read itself is unmapped; conflictive with isProperlyPaired */
871
814
  isSegmentUnmapped() {
872
- return !!(this.flags & _.BAM_FUNMAP);
815
+ return !!(this.flags & p.BAM_FUNMAP);
873
816
  }
874
817
  /** @returns {boolean} true if the read itself is unmapped; conflictive with isProperlyPaired */
875
818
  isMateUnmapped() {
876
- return !!(this.flags & _.BAM_FMUNMAP);
819
+ return !!(this.flags & p.BAM_FMUNMAP);
877
820
  }
878
821
  /** @returns {boolean} true if the read is mapped to the reverse strand */
879
822
  isReverseComplemented() {
880
- return !!(this.flags & _.BAM_FREVERSE);
823
+ return !!(this.flags & p.BAM_FREVERSE);
881
824
  }
882
825
  /** @returns {boolean} true if the mate is mapped to the reverse strand */
883
826
  isMateReverseComplemented() {
884
- return !!(this.flags & _.BAM_FMREVERSE);
827
+ return !!(this.flags & p.BAM_FMREVERSE);
885
828
  }
886
829
  /** @returns {boolean} true if this is read number 1 in a pair */
887
830
  isRead1() {
888
- return !!(this.flags & _.BAM_FREAD1);
831
+ return !!(this.flags & p.BAM_FREAD1);
889
832
  }
890
833
  /** @returns {boolean} true if this is read number 2 in a pair */
891
834
  isRead2() {
892
- return !!(this.flags & _.BAM_FREAD2);
835
+ return !!(this.flags & p.BAM_FREAD2);
893
836
  }
894
837
  /** @returns {boolean} true if this is a secondary alignment */
895
838
  isSecondary() {
896
- return !!(this.flags & _.BAM_FSECONDARY);
839
+ return !!(this.flags & p.BAM_FSECONDARY);
897
840
  }
898
841
  /** @returns {boolean} true if this read has failed QC checks */
899
842
  isFailedQc() {
900
- return !!(this.flags & _.BAM_FQCFAIL);
843
+ return !!(this.flags & p.BAM_FQCFAIL);
901
844
  }
902
845
  /** @returns {boolean} true if the read is an optical or PCR duplicate */
903
846
  isDuplicate() {
904
- return !!(this.flags & _.BAM_FDUP);
847
+ return !!(this.flags & p.BAM_FDUP);
905
848
  }
906
849
  /** @returns {boolean} true if this is a supplementary alignment */
907
850
  isSupplementary() {
908
- return !!(this.flags & _.BAM_FSUPPLEMENTARY);
851
+ return !!(this.flags & p.BAM_FSUPPLEMENTARY);
909
852
  }
910
- cigar() {
853
+ get cigarAndLength() {
911
854
  if (this.isSegmentUnmapped())
912
- return;
913
- const { byteArray: e, start: t } = this.bytes, n = this.get("_n_cigar_op");
914
- let r = t + 36 + this.get("_l_read_name");
915
- const s = this.get("seq_length");
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;
855
+ return {
856
+ length_on_ref: 0,
857
+ CIGAR: ""
858
+ };
859
+ const e = this.num_cigar_ops;
860
+ let t = this.b0 + this.read_name_length;
861
+ const n = [];
862
+ let r = this.byteArray.readInt32LE(t), s = r >> 4, i = A[r & 15];
863
+ if (i === "S" && s === this.seq_length)
864
+ return t += 4, r = this.byteArray.readInt32LE(t), s = r >> 4, i = A[r & 15], i !== "N" && console.warn("CG tag with no N tag"), {
865
+ CIGAR: this.tags.CG,
866
+ length_on_ref: s
867
+ };
868
+ {
869
+ let c = 0;
870
+ for (let a = 0; a < e; ++a)
871
+ r = this.byteArray.readInt32LE(t), s = r >> 4, i = A[r & 15], n.push(s + i), i !== "H" && i !== "S" && i !== "I" && (c += s), t += 4;
872
+ return {
873
+ CIGAR: n.join(""),
874
+ length_on_ref: c
875
+ };
876
+ }
922
877
  }
923
- length_on_ref() {
924
- return this.data.length_on_ref ? this.data.length_on_ref : (this.get("cigar"), this.data.length_on_ref);
878
+ get length_on_ref() {
879
+ return this.cigarAndLength.length_on_ref;
925
880
  }
926
- _n_cigar_op() {
927
- return this.get("_flag_nc") & 65535;
881
+ get CIGAR() {
882
+ return this.cigarAndLength.CIGAR;
928
883
  }
929
- _l_read_name() {
930
- return this.get("_bin_mq_nl") & 255;
884
+ get num_cigar_ops() {
885
+ return this.flag_nc & 65535;
931
886
  }
932
- /**
933
- * number of bytes in the sequence field
934
- */
935
- _seq_bytes() {
936
- return this.get("seq_length") + 1 >> 1;
937
- }
938
- getReadBases() {
939
- return this.seq();
940
- }
941
- seq() {
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");
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++);
887
+ get read_name_length() {
888
+ return this.bin_mq_nl & 255;
889
+ }
890
+ get num_seq_bytes() {
891
+ return this.seq_length + 1 >> 1;
892
+ }
893
+ get seq() {
894
+ const { byteArray: e } = this.bytes, t = this.b0 + this.read_name_length + this.num_cigar_ops * 4, n = this.num_seq_bytes, r = this.seq_length, s = [];
895
+ let i = 0;
896
+ for (let c = 0; c < n; ++c) {
897
+ const a = e[t + c];
898
+ s.push(D[(a & 240) >> 4]), i++, i < r && (s.push(D[a & 15]), i++);
947
899
  }
948
- return i;
900
+ return s.join("");
949
901
  }
950
902
  // adapted from igv.js
951
- getPairOrientation() {
952
- if (!this.isSegmentUnmapped() && !this.isMateUnmapped() && this._refID === this._next_refid()) {
903
+ get pair_orientation() {
904
+ if (!this.isSegmentUnmapped() && !this.isMateUnmapped() && this.ref_id === this.next_refid) {
953
905
  const e = this.isReverseComplemented() ? "R" : "F", t = this.isMateReverseComplemented() ? "R" : "F";
954
906
  let n = " ", r = " ";
955
907
  this.isRead1() ? (n = "1", r = "2") : this.isRead2() && (n = "2", r = "1");
956
908
  const s = [];
957
- return this.template_length() > 0 ? (s[0] = e, s[1] = n, s[2] = t, s[3] = r) : (s[2] = e, s[3] = n, s[0] = t, s[1] = r), s.join("");
909
+ return this.template_length > 0 ? (s[0] = e, s[1] = n, s[2] = t, s[3] = r) : (s[2] = e, s[3] = n, s[0] = t, s[1] = r), s.join("");
958
910
  }
959
- return "";
960
911
  }
961
- _bin_mq_nl() {
962
- return this.bytes.byteArray.readInt32LE(this.bytes.start + 12);
912
+ get bin_mq_nl() {
913
+ return this.byteArray.readInt32LE(this.bytes.start + 12);
963
914
  }
964
- _flag_nc() {
965
- return this.bytes.byteArray.readInt32LE(this.bytes.start + 16);
915
+ get flag_nc() {
916
+ return this.byteArray.readInt32LE(this.bytes.start + 16);
966
917
  }
967
- seq_length() {
968
- return this.bytes.byteArray.readInt32LE(this.bytes.start + 20);
918
+ get seq_length() {
919
+ return this.byteArray.readInt32LE(this.bytes.start + 20);
969
920
  }
970
- _next_refid() {
971
- return this.bytes.byteArray.readInt32LE(this.bytes.start + 24);
921
+ get next_refid() {
922
+ return this.byteArray.readInt32LE(this.bytes.start + 24);
972
923
  }
973
- _next_pos() {
974
- return this.bytes.byteArray.readInt32LE(this.bytes.start + 28);
924
+ get next_pos() {
925
+ return this.byteArray.readInt32LE(this.bytes.start + 28);
975
926
  }
976
- template_length() {
977
- return this.bytes.byteArray.readInt32LE(this.bytes.start + 32);
927
+ get template_length() {
928
+ return this.byteArray.readInt32LE(this.bytes.start + 32);
978
929
  }
979
930
  toJSON() {
980
931
  const e = {};
@@ -983,21 +934,39 @@ class he {
983
934
  return e;
984
935
  }
985
936
  }
986
- function H(o) {
937
+ function k(o, e) {
938
+ const t = Object.getOwnPropertyDescriptor(o.prototype, e);
939
+ if (!t)
940
+ throw new Error("OH NO, NO PROPERTY DESCRIPTOR");
941
+ const n = t.get;
942
+ if (!n)
943
+ throw new Error("OH NO, NOT A GETTER");
944
+ Object.defineProperty(o.prototype, e, {
945
+ get() {
946
+ const r = n.call(this);
947
+ return Object.defineProperty(this, e, { value: r }), r;
948
+ }
949
+ });
950
+ }
951
+ k(R, "tags");
952
+ k(R, "cigarAndLength");
953
+ k(R, "seq");
954
+ k(R, "qual");
955
+ function j(o) {
987
956
  const e = o.split(/\r?\n/), t = [];
988
957
  for (const n of e) {
989
958
  const [r, ...s] = n.split(/\t/);
990
959
  r && t.push({
991
960
  tag: r.slice(1),
992
961
  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 };
962
+ const c = i.indexOf(":"), a = i.slice(0, c), d = i.slice(c + 1);
963
+ return { tag: a, value: d };
995
964
  })
996
965
  });
997
966
  }
998
967
  return t;
999
968
  }
1000
- const G = 21840194, q = 65536;
969
+ const V = 21840194, $ = 65536;
1001
970
  async function le(o) {
1002
971
  let e = [];
1003
972
  for await (const t of o)
@@ -1019,70 +988,70 @@ class xe {
1019
988
  }
1020
989
  }
1021
990
  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({
991
+ constructor({ bamFilehandle: e, bamPath: t, bamUrl: n, baiPath: r, baiFilehandle: s, baiUrl: i, csiPath: c, csiFilehandle: a, csiUrl: d, htsget: f, yieldThreadTime: h = 100, renameRefSeqs: l = (x) => x }) {
992
+ if (this.htsget = !1, this.featureCache = new W({
993
+ cache: new X({
1025
994
  maxSize: 50
1026
995
  }),
1027
- fill: async (f, m) => {
1028
- const { chunk: b, opts: u } = f, { data: g, cpositions: p, dpositions: w } = await this._readChunk({
996
+ fill: async (x, m) => {
997
+ const { chunk: b, opts: u } = x, { data: g, cpositions: w, dpositions: _ } = await this._readChunk({
1029
998
  chunk: b,
1030
999
  opts: { ...u, signal: m }
1031
1000
  });
1032
- return this.readBamFeatures(g, p, w, b);
1001
+ return this.readBamFeatures(g, w, _, b);
1033
1002
  }
1034
- }), this.renameRefSeq = h, e)
1003
+ }), this.renameRefSeq = l, e)
1035
1004
  this.bam = e;
1036
1005
  else if (t)
1037
1006
  this.bam = new C(t);
1038
1007
  else if (n)
1039
- this.bam = new k(n);
1040
- else if (l)
1008
+ this.bam = new L(n);
1009
+ else if (f)
1041
1010
  this.htsget = !0, this.bam = new xe();
1042
1011
  else
1043
1012
  throw new Error("unable to initialize bam");
1044
- if (d)
1045
- this.index = new P({ filehandle: d });
1013
+ if (a)
1014
+ this.index = new T({ filehandle: a });
1046
1015
  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) });
1016
+ this.index = new T({ filehandle: new C(c) });
1017
+ else if (d)
1018
+ this.index = new T({ filehandle: new L(d) });
1050
1019
  else if (s)
1051
1020
  this.index = new v({ filehandle: s });
1052
1021
  else if (r)
1053
1022
  this.index = new v({ filehandle: new C(r) });
1054
1023
  else if (i)
1055
- this.index = new v({ filehandle: new k(i) });
1024
+ this.index = new v({ filehandle: new L(i) });
1056
1025
  else if (t)
1057
1026
  this.index = new v({ filehandle: new C(`${t}.bai`) });
1058
1027
  else if (n)
1059
- this.index = new v({ filehandle: new k(`${n}.bai`) });
1060
- else if (l)
1028
+ this.index = new v({ filehandle: new L(`${n}.bai`) });
1029
+ else if (f)
1061
1030
  this.htsget = !0;
1062
1031
  else
1063
1032
  throw new Error("unable to infer index format");
1064
- this.yieldThreadTime = x;
1033
+ this.yieldThreadTime = h;
1065
1034
  }
1066
1035
  async getHeaderPre(e) {
1067
- const t = Z(e);
1036
+ const t = ee(e);
1068
1037
  if (!this.index)
1069
1038
  return;
1070
1039
  const n = await this.index.parse(t), r = n.firstDataLine ? n.firstDataLine.blockPosition + 65535 : void 0;
1071
1040
  let s;
1072
1041
  if (r) {
1073
- const l = r + q, x = await this.bam.read(I.Buffer.alloc(l), 0, l, 0, t);
1074
- if (!x.bytesRead)
1042
+ const f = r + $, h = await this.bam.read(y.Buffer.alloc(f), 0, f, 0, t);
1043
+ if (!h.bytesRead)
1075
1044
  throw new Error("Error reading header");
1076
- s = x.buffer.subarray(0, Math.min(x.bytesRead, r));
1045
+ s = h.buffer.subarray(0, Math.min(h.bytesRead, r));
1077
1046
  } else
1078
1047
  s = await this.bam.readFile(t);
1079
- const i = await R(s);
1080
- if (i.readInt32LE(0) !== G)
1048
+ const i = await P(s);
1049
+ if (i.readInt32LE(0) !== V)
1081
1050
  throw new Error("Not a BAM file");
1082
1051
  const c = i.readInt32LE(4);
1083
1052
  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);
1053
+ const { chrToIndex: a, indexToChr: d } = await this._readRefSeqs(c + 8, 65535, t);
1054
+ return this.chrToIndex = a, this.indexToChr = d, j(this.header);
1086
1055
  }
1087
1056
  getHeader(e) {
1088
1057
  return this.headerP || (this.headerP = this.getHeaderPre(e).catch((t) => {
@@ -1097,18 +1066,18 @@ class ue {
1097
1066
  async _readRefSeqs(e, t, n) {
1098
1067
  if (e > t)
1099
1068
  return this._readRefSeqs(e, t * 2, n);
1100
- const r = t + q, { bytesRead: s, buffer: i } = await this.bam.read(I.Buffer.alloc(r), 0, t, 0, n);
1069
+ const r = t + $, { bytesRead: s, buffer: i } = await this.bam.read(y.Buffer.alloc(r), 0, t, 0, n);
1101
1070
  if (!s)
1102
1071
  throw new Error("Error reading refseqs from header");
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)
1072
+ const c = await P(i.subarray(0, Math.min(s, t))), a = c.readInt32LE(e);
1073
+ let d = e + 4;
1074
+ const f = {}, h = [];
1075
+ for (let l = 0; l < a; l += 1) {
1076
+ const x = c.readInt32LE(d), m = this.renameRefSeq(c.toString("utf8", d + 4, d + 4 + x - 1)), b = c.readInt32LE(d + x + 4);
1077
+ if (f[m] = l, h.push({ refName: m, length: b }), d = d + 8 + x, d > c.length)
1109
1078
  return console.warn(`BAM header is very big. Re-fetching ${t} bytes.`), this._readRefSeqs(e, t * 2, n);
1110
1079
  }
1111
- return { chrToIndex: l, indexToChr: x };
1080
+ return { chrToIndex: f, indexToChr: h };
1112
1081
  }
1113
1082
  async getRecordsForRange(e, t, n, r) {
1114
1083
  return le(this.streamRecordsForRange(e, t, n, r));
@@ -1126,76 +1095,76 @@ class ue {
1126
1095
  }
1127
1096
  async *_fetchChunkFeatures(e, t, n, r, s = {}) {
1128
1097
  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;
1098
+ let a = !1;
1099
+ for (const d of e) {
1100
+ const f = await this.featureCache.get(d.toString(), { chunk: d, opts: s }, s.signal), h = [];
1101
+ for (const l of f)
1102
+ if (l.ref_id === t)
1103
+ if (l.start >= r) {
1104
+ a = !0;
1136
1105
  break;
1137
- } else h.get("end") >= n && x.push(h);
1138
- if (c.push(x), yield x, d)
1106
+ } else l.end >= n && h.push(l);
1107
+ if (c.push(h), yield h, a)
1139
1108
  break;
1140
1109
  }
1141
- J(s.signal), i && (yield this.fetchPairs(t, c, s));
1110
+ K(s.signal), i && (yield this.fetchPairs(t, c, s));
1142
1111
  }
1143
1112
  async fetchPairs(e, t, n) {
1144
1113
  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;
1114
+ t.map((l) => {
1115
+ const x = {};
1116
+ for (const m of l) {
1117
+ const b = m.name, u = m.id;
1118
+ x[b] || (x[b] = 0), x[b]++, c[u] = 1;
1150
1119
  }
1151
- for (const [m, b] of Object.entries(f))
1120
+ for (const [m, b] of Object.entries(x))
1152
1121
  b === 1 && (i[m] = !0);
1153
1122
  });
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));
1123
+ const a = [];
1124
+ t.map((l) => {
1125
+ for (const x of l) {
1126
+ const m = x.name, b = x.start, u = x.next_pos, g = x.next_refid;
1127
+ this.index && i[m] && (r || g === e && Math.abs(b - u) < s) && a.push(this.index.blocksForRange(g, u, u + 1, n));
1159
1128
  }
1160
1129
  });
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,
1130
+ const d = /* @__PURE__ */ new Map(), f = await Promise.all(a);
1131
+ for (const l of f.flat())
1132
+ d.has(l.toString()) || d.set(l.toString(), l);
1133
+ return (await Promise.all([...d.values()].map(async (l) => {
1134
+ const { data: x, cpositions: m, dpositions: b, chunk: u } = await this._readChunk({
1135
+ chunk: l,
1167
1136
  opts: n
1168
1137
  }), g = [];
1169
- for (const p of await this.readBamFeatures(f, m, b, u))
1170
- i[p.get("name")] && !c[p.id()] && g.push(p);
1138
+ for (const w of await this.readBamFeatures(x, m, b, u))
1139
+ i[w.name] && !c[w.id] && g.push(w);
1171
1140
  return g;
1172
1141
  }))).flat();
1173
1142
  }
1174
1143
  async _readRegion(e, t, n = {}) {
1175
- const { bytesRead: r, buffer: s } = await this.bam.read(I.Buffer.alloc(t), 0, t, e, n);
1144
+ const { bytesRead: r, buffer: s } = await this.bam.read(y.Buffer.alloc(t), 0, t, e, n);
1176
1145
  return s.subarray(0, Math.min(r, t));
1177
1146
  }
1178
1147
  async _readChunk({ chunk: e, opts: t }) {
1179
- const n = await this._readRegion(e.minv.blockPosition, e.fetchedSize(), t), { buffer: r, cpositions: s, dpositions: i } = await V(n, e);
1148
+ const n = await this._readRegion(e.minv.blockPosition, e.fetchedSize(), t), { buffer: r, cpositions: s, dpositions: i } = await Q(n, e);
1180
1149
  return { data: r, cpositions: s, dpositions: i, chunk: e };
1181
1150
  }
1182
1151
  async readBamFeatures(e, t, n, r) {
1183
1152
  let s = 0;
1184
1153
  const i = [];
1185
- let c = 0, d = +Date.now();
1154
+ let c = 0, a = +Date.now();
1186
1155
  for (; s + 4 < e.length; ) {
1187
- const a = e.readInt32LE(s), l = s + 4 + a - 1;
1156
+ const d = e.readInt32LE(s), f = s + 4 + d - 1;
1188
1157
  if (n) {
1189
1158
  for (; s + r.minv.dataPosition >= n[c++]; )
1190
1159
  ;
1191
1160
  c--;
1192
1161
  }
1193
- if (l < e.length) {
1194
- const x = new he({
1162
+ if (f < e.length) {
1163
+ const h = new R({
1195
1164
  bytes: {
1196
1165
  byteArray: e,
1197
1166
  start: s,
1198
- end: l
1167
+ end: f
1199
1168
  },
1200
1169
  // the below results in an automatically calculated file-offset based
1201
1170
  // ID if the info for that is available, otherwise crc32 of the
@@ -1219,12 +1188,13 @@ class ue {
1219
1188
  // realistically happen
1220
1189
  fileOffset: t.length > 0 ? t[c] * 256 + (s - n[c]) + r.minv.dataPosition + 1 : (
1221
1190
  // must be slice, not subarray for buffer polyfill on web
1222
- oe.signed(e.slice(s, l))
1191
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
1192
+ ce.signed(e.slice(s, f))
1223
1193
  )
1224
1194
  });
1225
- i.push(x), this.yieldThreadTime && +Date.now() - d > this.yieldThreadTime && (await W(1), d = +Date.now());
1195
+ i.push(h), this.yieldThreadTime && +Date.now() - a > this.yieldThreadTime && (await J(1), a = +Date.now());
1226
1196
  }
1227
- s = l + 1;
1197
+ s = f + 1;
1228
1198
  }
1229
1199
  return i;
1230
1200
  }
@@ -1255,41 +1225,41 @@ class ue {
1255
1225
  return i === void 0 ? [] : this.index.blocksForRange(i, t, n, r);
1256
1226
  }
1257
1227
  }
1258
- async function N(o, e) {
1228
+ async function U(o, e) {
1259
1229
  const t = await Promise.all(o.map(async (n) => {
1260
1230
  const { url: r, headers: s } = n;
1261
1231
  if (r.startsWith("data:"))
1262
- return I.Buffer.from(r.split(",")[1], "base64");
1232
+ return y.Buffer.from(r.split(",")[1], "base64");
1263
1233
  {
1264
- const { referer: i, ...c } = s, d = await fetch(r, {
1234
+ const { referer: i, ...c } = s, a = await fetch(r, {
1265
1235
  ...e,
1266
1236
  headers: { ...e == null ? void 0 : e.headers, ...c }
1267
1237
  });
1268
- if (!d.ok)
1269
- throw new Error(`HTTP ${d.status} fetching ${r}: ${await d.text()}`);
1270
- return I.Buffer.from(await d.arrayBuffer());
1238
+ if (!a.ok)
1239
+ throw new Error(`HTTP ${a.status} fetching ${r}: ${await a.text()}`);
1240
+ return y.Buffer.from(await a.arrayBuffer());
1271
1241
  }
1272
1242
  }));
1273
- return I.Buffer.concat(await Promise.all(t.map((n) => R(n))));
1243
+ return y.Buffer.concat(await Promise.all(t.map((n) => P(n))));
1274
1244
  }
1275
- class we extends ue {
1245
+ class _e extends ue {
1276
1246
  constructor(e) {
1277
1247
  super({ htsget: !0 }), this.baseUrl = e.baseUrl, this.trackId = e.trackId;
1278
1248
  }
1279
1249
  async *streamRecordsForRange(e, t, n, r) {
1280
1250
  var s;
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)
1251
+ const c = `${`${this.baseUrl}/${this.trackId}`}?referenceName=${e}&start=${t}&end=${n}&format=BAM`, a = (s = this.chrToIndex) === null || s === void 0 ? void 0 : s[e];
1252
+ if (a === void 0)
1283
1253
  yield [];
1284
1254
  else {
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);
1255
+ const d = await fetch(c, { ...r });
1256
+ if (!d.ok)
1257
+ throw new Error(`HTTP ${d.status} fetching ${c}: ${await d.text()}`);
1258
+ const f = await d.json(), h = await U(f.htsget.urls.slice(1), r);
1289
1259
  yield* this._fetchChunkFeatures([
1290
1260
  // fake stuff to pretend to be a Chunk
1291
1261
  {
1292
- buffer: x,
1262
+ buffer: h,
1293
1263
  _fetchedSize: void 0,
1294
1264
  bin: 0,
1295
1265
  compareTo() {
@@ -1315,7 +1285,7 @@ class we extends ue {
1315
1285
  return `${e}_${t}_${n}`;
1316
1286
  }
1317
1287
  }
1318
- ], d, t, n, r);
1288
+ ], a, t, n, r);
1319
1289
  }
1320
1290
  }
1321
1291
  async _readChunk({ chunk: e }) {
@@ -1327,23 +1297,23 @@ class we extends ue {
1327
1297
  const t = `${this.baseUrl}/${this.trackId}?referenceName=na&class=header`, n = await fetch(t, e);
1328
1298
  if (!n.ok)
1329
1299
  throw new Error(`HTTP ${n.status} fetching ${t}: ${await n.text()}`);
1330
- const r = await n.json(), s = await N(r.htsget.urls, e);
1331
- if (s.readInt32LE(0) !== G)
1300
+ const r = await n.json(), s = await U(r.htsget.urls, e);
1301
+ if (s.readInt32LE(0) !== V)
1332
1302
  throw new Error("Not a BAM file");
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()) {
1303
+ const i = s.readInt32LE(4), c = s.toString("utf8", 8, 8 + i), a = j(c), d = [], f = {}, h = a.filter((l) => l.tag === "SQ");
1304
+ for (const [l, x] of h.entries()) {
1335
1305
  let m = "", b = 0;
1336
- for (const u of f.data)
1306
+ for (const u of x.data)
1337
1307
  u.tag === "SN" ? m = u.value : u.tag === "LN" && (b = +u.value);
1338
- l[m] = h, a[h] = { refName: m, length: b };
1308
+ f[m] = l, d[l] = { refName: m, length: b };
1339
1309
  }
1340
- return this.chrToIndex = l, this.indexToChr = a, d;
1310
+ return this.chrToIndex = f, this.indexToChr = d, a;
1341
1311
  }
1342
1312
  }
1343
1313
  export {
1344
1314
  v as BAI,
1345
1315
  ue as BamFile,
1346
- he as BamRecord,
1347
- P as CSI,
1348
- we as HtsgetFile
1316
+ R as BamRecord,
1317
+ T as CSI,
1318
+ _e as HtsgetFile
1349
1319
  };