@genome-spy/app 0.58.0 → 0.58.1

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,7 +1,7 @@
1
1
  import { A as J, L as K } from "./index-CCJIjehY.js";
2
2
  import { b as Q } from "./index-BftNdA0O.js";
3
- import { L as B } from "./__vite-browser-external-C--ziKoh.js";
4
- import { R as A } from "./remoteFile-BuaqFGWk.js";
3
+ import { L as R } from "./__vite-browser-external-C--ziKoh.js";
4
+ import { R as F } from "./remoteFile-BuaqFGWk.js";
5
5
  import { u as $, L as H, a as Z } from "./long-BviWyoZx.js";
6
6
  function j(o) {
7
7
  if (o.greaterThan(Number.MAX_SAFE_INTEGER) || o.lessThan(Number.MIN_SAFE_INTEGER))
@@ -10,7 +10,7 @@ function j(o) {
10
10
  }
11
11
  class ee extends Error {
12
12
  }
13
- function L(o) {
13
+ function _(o) {
14
14
  if (o && o.aborted) {
15
15
  if (typeof DOMException < "u")
16
16
  throw new DOMException("aborted", "AbortError");
@@ -26,9 +26,9 @@ function te(o, e) {
26
26
  function X(o, e) {
27
27
  const t = [];
28
28
  let n = null;
29
- return o.length === 0 ? o : (o.sort(function(i, a) {
30
- const r = i.minv.blockPosition - a.minv.blockPosition;
31
- return r !== 0 ? r : i.minv.dataPosition - a.minv.dataPosition;
29
+ return o.length === 0 ? o : (o.sort(function(i, s) {
30
+ const a = i.minv.blockPosition - s.minv.blockPosition;
31
+ return a !== 0 ? a : i.minv.dataPosition - s.minv.dataPosition;
32
32
  }), o.forEach((i) => {
33
33
  (!e || i.maxv.compareTo(e) > 0) && (n === null ? (t.push(i), n = i) : te(n, i) ? i.maxv.compareTo(n.maxv) > 0 && (n.maxv = i.maxv) : (t.push(i), n = i));
34
34
  }), t);
@@ -98,73 +98,73 @@ function ie(o, e) {
98
98
  [4681 + (o >> 14), 4681 + (e >> 14)]
99
99
  ];
100
100
  }
101
- class k extends W {
101
+ class y extends W {
102
102
  async lineCount(e, t = {}) {
103
103
  const n = await this.parse(t), i = n.refNameToId[e];
104
104
  if (i === void 0 || !n.indices[i])
105
105
  return -1;
106
- const { stats: r } = n.indices[i];
107
- return r ? r.lineCount : -1;
106
+ const { stats: a } = n.indices[i];
107
+ return a ? a.lineCount : -1;
108
108
  }
109
109
  // fetch and parse the index
110
110
  async _parse(e = {}) {
111
111
  const t = await this.filehandle.readFile(e), n = await $(t);
112
- if (L(e.signal), n.readUInt32LE(0) !== ne)
112
+ if (_(e.signal), n.readUInt32LE(0) !== ne)
113
113
  throw new Error("Not a TBI file");
114
- const i = n.readInt32LE(4), a = n.readInt32LE(8), r = a & 65536 ? "zero-based-half-open" : "1-based-closed", d = {
114
+ const i = n.readInt32LE(4), s = n.readInt32LE(8), a = s & 65536 ? "zero-based-half-open" : "1-based-closed", f = {
115
115
  0: "generic",
116
116
  1: "SAM",
117
117
  2: "VCF"
118
- }[a & 15];
119
- if (!d)
120
- throw new Error(`invalid Tabix preset format flags ${a}`);
121
- const l = {
118
+ }[s & 15];
119
+ if (!f)
120
+ throw new Error(`invalid Tabix preset format flags ${s}`);
121
+ const d = {
122
122
  ref: n.readInt32LE(12),
123
123
  start: n.readInt32LE(16),
124
124
  end: n.readInt32LE(20)
125
- }, u = n.readInt32LE(24), c = 5, f = ((1 << (c + 1) * 3) - 1) / 7, I = 2 ** (14 + c * 3), w = u ? String.fromCharCode(u) : null, m = n.readInt32LE(28), b = n.readInt32LE(32), { refNameToId: p, refIdToName: x } = this._parseNameBytes(n.slice(36, 36 + b));
126
- let h = 36 + b, g;
125
+ }, u = n.readInt32LE(24), h = 5, c = ((1 << (h + 1) * 3) - 1) / 7, b = 2 ** (14 + h * 3), I = u ? String.fromCharCode(u) : null, m = n.readInt32LE(28), w = n.readInt32LE(32), { refNameToId: x, refIdToName: p } = this._parseNameBytes(n.slice(36, 36 + w));
126
+ let l = 36 + w, g;
127
127
  return {
128
128
  indices: new Array(i).fill(0).map(() => {
129
- const y = n.readInt32LE(h);
130
- h += 4;
131
- const S = {};
132
- let E;
133
- for (let v = 0; v < y; v += 1) {
134
- const _ = n.readUInt32LE(h);
135
- if (h += 4, _ > f + 1)
129
+ const E = n.readInt32LE(l);
130
+ l += 4;
131
+ const v = {};
132
+ let N;
133
+ for (let C = 0; C < E; C += 1) {
134
+ const A = n.readUInt32LE(l);
135
+ if (l += 4, A > c + 1)
136
136
  throw new Error("tabix index contains too many bins, please use a CSI index");
137
- if (_ === f + 1) {
138
- const N = n.readInt32LE(h);
139
- h += 4, N === 2 && (E = this.parsePseudoBin(n, h)), h += 16 * N;
137
+ if (A === c + 1) {
138
+ const k = n.readInt32LE(l);
139
+ l += 4, k === 2 && (N = this.parsePseudoBin(n, l)), l += 16 * k;
140
140
  } else {
141
- const N = n.readInt32LE(h);
142
- h += 4;
143
- const O = new Array(N);
144
- for (let F = 0; F < N; F += 1) {
145
- const q = T(n, h), Y = T(n, h + 8);
146
- h += 16, g = this._findFirstData(g, q), O[F] = new D(q, Y, _);
141
+ const k = n.readInt32LE(l);
142
+ l += 4;
143
+ const O = new Array(k);
144
+ for (let M = 0; M < k; M += 1) {
145
+ const q = T(n, l), Y = T(n, l + 8);
146
+ l += 16, g = this._findFirstData(g, q), O[M] = new D(q, Y, A);
147
147
  }
148
- S[_] = O;
148
+ v[A] = O;
149
149
  }
150
150
  }
151
- const P = n.readInt32LE(h);
152
- h += 4;
153
- const R = new Array(P);
154
- for (let v = 0; v < P; v += 1)
155
- R[v] = T(n, h), h += 8, g = this._findFirstData(g, R[v]);
156
- return { binIndex: S, linearIndex: R, stats: E };
151
+ const B = n.readInt32LE(l);
152
+ l += 4;
153
+ const L = new Array(B);
154
+ for (let C = 0; C < B; C += 1)
155
+ L[C] = T(n, l), l += 8, g = this._findFirstData(g, L[C]);
156
+ return { binIndex: v, linearIndex: L, stats: N };
157
157
  }),
158
- metaChar: w,
159
- maxBinNumber: f,
160
- maxRefLength: I,
158
+ metaChar: I,
159
+ maxBinNumber: c,
160
+ maxRefLength: b,
161
161
  skipLines: m,
162
162
  firstDataLine: g,
163
- columnNumbers: l,
164
- coordinateType: r,
165
- format: d,
166
- refIdToName: x,
167
- refNameToId: p,
163
+ columnNumbers: d,
164
+ coordinateType: a,
165
+ format: f,
166
+ refIdToName: p,
167
+ refNameToId: x,
168
168
  maxBlockSize: 65536
169
169
  };
170
170
  }
@@ -173,40 +173,40 @@ class k extends W {
173
173
  }
174
174
  _parseNameBytes(e) {
175
175
  let t = 0, n = 0;
176
- const i = [], a = {};
177
- for (let r = 0; r < e.length; r += 1)
178
- if (!e[r]) {
179
- if (n < r) {
180
- let s = e.toString("utf8", n, r);
181
- s = this.renameRefSeq(s), i[t] = s, a[s] = t;
176
+ const i = [], s = {};
177
+ for (let a = 0; a < e.length; a += 1)
178
+ if (!e[a]) {
179
+ if (n < a) {
180
+ let r = e.toString("utf8", n, a);
181
+ r = this.renameRefSeq(r), i[t] = r, s[r] = t;
182
182
  }
183
- n = r + 1, t += 1;
183
+ n = a + 1, t += 1;
184
184
  }
185
- return { refNameToId: a, refIdToName: i };
185
+ return { refNameToId: s, refIdToName: i };
186
186
  }
187
187
  async blocksForRange(e, t, n, i = {}) {
188
188
  t < 0 && (t = 0);
189
- const a = await this.parse(i), r = a.refNameToId[e];
190
- if (r === void 0)
189
+ const s = await this.parse(i), a = s.refNameToId[e];
190
+ if (a === void 0)
191
191
  return [];
192
- const s = a.indices[r];
193
- if (!s)
192
+ const r = s.indices[a];
193
+ if (!r)
194
194
  return [];
195
- (s.linearIndex.length ? s.linearIndex[t >> U >= s.linearIndex.length ? s.linearIndex.length - 1 : t >> U] : new V(0, 0)) || console.warn("querying outside of possible tabix range");
196
- const l = ie(t, n), u = [];
197
- for (const [m, b] of l)
198
- for (let p = m; p <= b; p++)
199
- if (s.binIndex[p])
200
- for (const x of s.binIndex[p])
201
- u.push(new D(x.minv, x.maxv, p));
202
- const c = s.linearIndex.length;
203
- let f = null;
204
- const I = Math.min(t >> 14, c - 1), w = Math.min(n >> 14, c - 1);
205
- for (let m = I; m <= w; ++m) {
206
- const b = s.linearIndex[m];
207
- b && (!f || b.compareTo(f) < 0) && (f = b);
195
+ (r.linearIndex.length ? r.linearIndex[t >> U >= r.linearIndex.length ? r.linearIndex.length - 1 : t >> U] : new V(0, 0)) || console.warn("querying outside of possible tabix range");
196
+ const d = ie(t, n), u = [];
197
+ for (const [m, w] of d)
198
+ for (let x = m; x <= w; x++)
199
+ if (r.binIndex[x])
200
+ for (const p of r.binIndex[x])
201
+ u.push(new D(p.minv, p.maxv, x));
202
+ const h = r.linearIndex.length;
203
+ let c = null;
204
+ const b = Math.min(t >> 14, h - 1), I = Math.min(n >> 14, h - 1);
205
+ for (let m = b; m <= I; ++m) {
206
+ const w = r.linearIndex[m];
207
+ w && (!c || w.compareTo(c) < 0) && (c = w);
208
208
  }
209
- return X(u, f);
209
+ return X(u, c);
210
210
  }
211
211
  }
212
212
  const re = 21582659, se = 38359875;
@@ -216,7 +216,7 @@ function ae(o, e) {
216
216
  function G(o, e) {
217
217
  return Math.floor(o / 2 ** e);
218
218
  }
219
- class M extends W {
219
+ class z extends W {
220
220
  constructor(e) {
221
221
  super(e), this.maxBinNumber = 0, this.depth = 0, this.minShift = 0;
222
222
  }
@@ -224,43 +224,43 @@ class M extends W {
224
224
  const n = await this.parse(t), i = n.refNameToId[e];
225
225
  if (i === void 0 || !n.indices[i])
226
226
  return -1;
227
- const { stats: r } = n.indices[i];
228
- return r ? r.lineCount : -1;
227
+ const { stats: a } = n.indices[i];
228
+ return a ? a.lineCount : -1;
229
229
  }
230
230
  indexCov() {
231
231
  throw new Error("CSI indexes do not support indexcov");
232
232
  }
233
233
  parseAuxData(e, t) {
234
- const n = e.readInt32LE(t), i = n & 65536 ? "zero-based-half-open" : "1-based-closed", a = { 0: "generic", 1: "SAM", 2: "VCF" }[n & 15];
235
- if (!a)
234
+ const n = e.readInt32LE(t), i = n & 65536 ? "zero-based-half-open" : "1-based-closed", s = { 0: "generic", 1: "SAM", 2: "VCF" }[n & 15];
235
+ if (!s)
236
236
  throw new Error(`invalid Tabix preset format flags ${n}`);
237
- const r = {
237
+ const a = {
238
238
  ref: e.readInt32LE(t + 4),
239
239
  start: e.readInt32LE(t + 8),
240
240
  end: e.readInt32LE(t + 12)
241
- }, s = e.readInt32LE(t + 16), d = s ? String.fromCharCode(s) : null, l = e.readInt32LE(t + 20), u = e.readInt32LE(t + 24), { refIdToName: c, refNameToId: f } = this._parseNameBytes(e.slice(t + 28, t + 28 + u));
241
+ }, r = e.readInt32LE(t + 16), f = r ? String.fromCharCode(r) : null, d = e.readInt32LE(t + 20), u = e.readInt32LE(t + 24), { refIdToName: h, refNameToId: c } = this._parseNameBytes(e.slice(t + 28, t + 28 + u));
242
242
  return {
243
- refIdToName: c,
244
- refNameToId: f,
245
- skipLines: l,
246
- metaChar: d,
247
- columnNumbers: r,
248
- format: a,
243
+ refIdToName: h,
244
+ refNameToId: c,
245
+ skipLines: d,
246
+ metaChar: f,
247
+ columnNumbers: a,
248
+ format: s,
249
249
  coordinateType: i
250
250
  };
251
251
  }
252
252
  _parseNameBytes(e) {
253
253
  let t = 0, n = 0;
254
- const i = [], a = {};
255
- for (let r = 0; r < e.length; r += 1)
256
- if (!e[r]) {
257
- if (n < r) {
258
- let s = e.toString("utf8", n, r);
259
- s = this.renameRefSeq(s), i[t] = s, a[s] = t;
254
+ const i = [], s = {};
255
+ for (let a = 0; a < e.length; a += 1)
256
+ if (!e[a]) {
257
+ if (n < a) {
258
+ let r = e.toString("utf8", n, a);
259
+ r = this.renameRefSeq(r), i[t] = r, s[r] = t;
260
260
  }
261
- n = r + 1, t += 1;
261
+ n = a + 1, t += 1;
262
262
  }
263
- return { refNameToId: a, refIdToName: i };
263
+ return { refNameToId: s, refIdToName: i };
264
264
  }
265
265
  // fetch and parse the index
266
266
  async _parse(e = {}) {
@@ -273,45 +273,45 @@ class M extends W {
273
273
  else
274
274
  throw new Error("Not a CSI file");
275
275
  this.minShift = t.readInt32LE(4), this.depth = t.readInt32LE(8), this.maxBinNumber = ((1 << (this.depth + 1) * 3) - 1) / 7;
276
- const i = 2 ** (this.minShift + this.depth * 3), a = t.readInt32LE(12), r = a && a >= 30 ? this.parseAuxData(t, 16) : {
276
+ const i = 2 ** (this.minShift + this.depth * 3), s = t.readInt32LE(12), a = s && s >= 30 ? this.parseAuxData(t, 16) : {
277
277
  refIdToName: [],
278
278
  refNameToId: {},
279
279
  metaChar: null,
280
280
  columnNumbers: { ref: 0, start: 1, end: 2 },
281
281
  coordinateType: "zero-based-half-open",
282
282
  format: "generic"
283
- }, s = t.readInt32LE(16 + a);
284
- let d, l = 16 + a + 4;
285
- const u = new Array(s).fill(0).map(() => {
286
- const c = t.readInt32LE(l);
287
- l += 4;
288
- const f = {};
289
- let I;
290
- for (let w = 0; w < c; w += 1) {
291
- const m = t.readUInt32LE(l);
283
+ }, r = t.readInt32LE(16 + s);
284
+ let f, d = 16 + s + 4;
285
+ const u = new Array(r).fill(0).map(() => {
286
+ const h = t.readInt32LE(d);
287
+ d += 4;
288
+ const c = {};
289
+ let b;
290
+ for (let I = 0; I < h; I += 1) {
291
+ const m = t.readUInt32LE(d);
292
292
  if (m > this.maxBinNumber)
293
- I = this.parsePseudoBin(t, l + 4), l += 48;
293
+ b = this.parsePseudoBin(t, d + 4), d += 48;
294
294
  else {
295
- const b = T(t, l + 4);
296
- d = this._findFirstData(d, b);
297
- const p = t.readInt32LE(l + 12);
298
- l += 16;
299
- const x = new Array(p);
300
- for (let h = 0; h < p; h += 1) {
301
- const g = T(t, l), C = T(t, l + 8);
302
- l += 16, x[h] = new D(g, C, m);
295
+ const w = T(t, d + 4);
296
+ f = this._findFirstData(f, w);
297
+ const x = t.readInt32LE(d + 12);
298
+ d += 16;
299
+ const p = new Array(x);
300
+ for (let l = 0; l < x; l += 1) {
301
+ const g = T(t, d), P = T(t, d + 8);
302
+ d += 16, p[l] = new D(g, P, m);
303
303
  }
304
- f[m] = x;
304
+ c[m] = p;
305
305
  }
306
306
  }
307
- return { binIndex: f, stats: I };
307
+ return { binIndex: c, stats: b };
308
308
  });
309
309
  return {
310
- ...r,
310
+ ...a,
311
311
  csi: !0,
312
- refCount: s,
312
+ refCount: r,
313
313
  maxBlockSize: 65536,
314
- firstDataLine: d,
314
+ firstDataLine: f,
315
315
  csiVersion: n,
316
316
  indices: u,
317
317
  depth: this.depth,
@@ -324,40 +324,40 @@ class M extends W {
324
324
  }
325
325
  async blocksForRange(e, t, n, i = {}) {
326
326
  t < 0 && (t = 0);
327
- const a = await this.parse(i), r = a.refNameToId[e];
328
- if (r === void 0)
327
+ const s = await this.parse(i), a = s.refNameToId[e];
328
+ if (a === void 0)
329
329
  return [];
330
- const s = a.indices[r];
331
- if (!s)
330
+ const r = s.indices[a];
331
+ if (!r)
332
332
  return [];
333
- const d = this.reg2bins(t, n), l = [];
334
- for (const [u, c] of d)
335
- for (let f = u; f <= c; f++)
336
- if (s.binIndex[f])
337
- for (const I of s.binIndex[f])
338
- l.push(new D(I.minv, I.maxv, f));
339
- return X(l, new V(0, 0));
333
+ const f = this.reg2bins(t, n), d = [];
334
+ for (const [u, h] of f)
335
+ for (let c = u; c <= h; c++)
336
+ if (r.binIndex[c])
337
+ for (const b of r.binIndex[c])
338
+ d.push(new D(b.minv, b.maxv, c));
339
+ return X(d, new V(0, 0));
340
340
  }
341
341
  /**
342
342
  * calculate the list of bins that may overlap with region [beg,end) (zero-based half-open)
343
343
  */
344
344
  reg2bins(e, t) {
345
345
  e -= 1, e < 1 && (e = 1), t > 2 ** 50 && (t = 2 ** 34), t -= 1;
346
- let n = 0, i = 0, a = this.minShift + this.depth * 3;
347
- const r = [];
348
- for (; n <= this.depth; a -= 3, i += ae(1, n * 3), n += 1) {
349
- const s = i + G(e, a), d = i + G(t, a);
350
- if (d - s + r.length > this.maxBinNumber)
346
+ let n = 0, i = 0, s = this.minShift + this.depth * 3;
347
+ const a = [];
348
+ for (; n <= this.depth; s -= 3, i += ae(1, n * 3), n += 1) {
349
+ const r = i + G(e, s), f = i + G(t, s);
350
+ if (f - r + a.length > this.maxBinNumber)
351
351
  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`);
352
- r.push([s, d]);
352
+ a.push([r, f]);
353
353
  }
354
- return r;
354
+ return a;
355
355
  }
356
356
  }
357
- const z = typeof TextDecoder < "u" ? new TextDecoder("utf8") : void 0;
358
357
  function oe(o) {
359
- return new Promise((e) => setTimeout(e, o));
358
+ return /^[\u0000-\u007F]*$/.test(o);
360
359
  }
360
+ const S = typeof TextDecoder < "u" ? new TextDecoder("utf8") : void 0;
361
361
  class ue {
362
362
  /**
363
363
  * @param {object} args
@@ -374,65 +374,68 @@ class ue {
374
374
  *
375
375
  * @param {filehandle} [args.csiFilehandle]
376
376
  *
377
- * @param {number} [args.yieldTime] yield to main thread after N milliseconds
378
- * if reading features is taking a long time to avoid hanging main thread
377
+ * @param {url} [args.url]
378
+ *
379
+ * @param {csiUrl} [args.csiUrl]
380
+ *
381
+ * @param {tbiUrl} [args.tbiUrl]
379
382
  *
380
383
  * @param {function} [args.renameRefSeqs] optional function with sig `string
381
384
  * => string` to transform reference sequence names for the purpose of
382
385
  * indexing and querying. note that the data that is returned is not altered,
383
386
  * just the names of the reference sequences that are used for querying.
384
387
  */
385
- constructor({ path: e, filehandle: t, url: n, tbiPath: i, tbiUrl: a, tbiFilehandle: r, csiPath: s, csiUrl: d, csiFilehandle: l, yieldTime: u = 500, renameRefSeqs: c = (I) => I, chunkCacheSize: f = 5 * 2 ** 20 }) {
388
+ constructor({ path: e, filehandle: t, url: n, tbiPath: i, tbiUrl: s, tbiFilehandle: a, csiPath: r, csiUrl: f, csiFilehandle: d, renameRefSeqs: u = (c) => c, chunkCacheSize: h = 5 * 2 ** 20 }) {
386
389
  if (t)
387
390
  this.filehandle = t;
388
391
  else if (e)
389
- this.filehandle = new B(e);
392
+ this.filehandle = new R(e);
390
393
  else if (n)
391
- this.filehandle = new A(n);
394
+ this.filehandle = new F(n);
392
395
  else
393
396
  throw new TypeError("must provide either filehandle or path");
394
- if (r)
395
- this.index = new k({
396
- filehandle: r,
397
- renameRefSeqs: c
397
+ if (a)
398
+ this.index = new y({
399
+ filehandle: a,
400
+ renameRefSeqs: u
398
401
  });
399
- else if (l)
400
- this.index = new M({
401
- filehandle: l,
402
- renameRefSeqs: c
402
+ else if (d)
403
+ this.index = new z({
404
+ filehandle: d,
405
+ renameRefSeqs: u
403
406
  });
404
407
  else if (i)
405
- this.index = new k({
406
- filehandle: new B(i),
407
- renameRefSeqs: c
408
+ this.index = new y({
409
+ filehandle: new R(i),
410
+ renameRefSeqs: u
408
411
  });
409
- else if (s)
410
- this.index = new M({
411
- filehandle: new B(s),
412
- renameRefSeqs: c
412
+ else if (r)
413
+ this.index = new z({
414
+ filehandle: new R(r),
415
+ renameRefSeqs: u
413
416
  });
414
417
  else if (e)
415
- this.index = new k({
416
- filehandle: new B(`${e}.tbi`),
417
- renameRefSeqs: c
418
+ this.index = new y({
419
+ filehandle: new R(`${e}.tbi`),
420
+ renameRefSeqs: u
418
421
  });
419
- else if (d)
420
- this.index = new M({
421
- filehandle: new A(d)
422
+ else if (f)
423
+ this.index = new z({
424
+ filehandle: new F(f)
422
425
  });
423
- else if (a)
424
- this.index = new k({
425
- filehandle: new A(a)
426
+ else if (s)
427
+ this.index = new y({
428
+ filehandle: new F(s)
426
429
  });
427
430
  else if (n)
428
- this.index = new k({
429
- filehandle: new A(`${n}.tbi`)
431
+ this.index = new y({
432
+ filehandle: new F(`${n}.tbi`)
430
433
  });
431
434
  else
432
435
  throw new TypeError("must provide one of tbiFilehandle, tbiPath, csiFilehandle, csiPath, tbiUrl, csiUrl");
433
- this.renameRefSeq = c, this.yieldTime = u, this.chunkCache = new J({
434
- cache: new K({ maxSize: Math.floor(f / 65536) }),
435
- fill: (I, w) => this.readChunk(I, { signal: w })
436
+ this.renameRefSeq = u, this.chunkCache = new J({
437
+ cache: new K({ maxSize: Math.floor(h / 65536) }),
438
+ fill: (c, b) => this.readChunk(c, { signal: b })
436
439
  });
437
440
  }
438
441
  /**
@@ -449,54 +452,62 @@ class ue {
449
452
  * rejected on error
450
453
  */
451
454
  async getLines(e, t, n, i) {
452
- var a;
453
- let r, s = {}, d;
454
- typeof i == "function" ? d = i : (s = i, d = i.lineCallback, r = i.signal);
455
- const l = await this.index.getMetadata(s);
456
- L(r);
457
- const u = t ?? 0, c = n ?? l.maxRefLength;
458
- if (!(u <= c))
455
+ var s, a;
456
+ let r, f = {}, d;
457
+ typeof i == "function" ? d = i : (f = i, d = i.lineCallback, r = i.signal);
458
+ const u = await this.index.getMetadata(f);
459
+ _(r);
460
+ const h = t ?? 0, c = n ?? u.maxRefLength;
461
+ if (!(h <= c))
459
462
  throw new TypeError("invalid start and end coordinates. start must be less than or equal to end");
460
- if (u === c)
463
+ if (h === c)
461
464
  return;
462
- const f = await this.index.blocksForRange(e, u, c, s);
463
- L(r);
464
- let I = Date.now();
465
- for (const w of f) {
466
- let m;
467
- const { buffer: b, cpositions: p, dpositions: x } = await this.chunkCache.get(w.toString(), w, r);
468
- L(r);
469
- let h = 0, g = 0;
470
- for (; h < b.length; ) {
471
- const C = b.indexOf(`
472
- `, h);
473
- if (C === -1)
474
- break;
475
- const y = b.slice(h, C), S = (a = z == null ? void 0 : z.decode(y)) !== null && a !== void 0 ? a : y.toString();
465
+ const b = await this.index.blocksForRange(e, h, c, f);
466
+ _(r);
467
+ for (const I of b) {
468
+ const { buffer: m, cpositions: w, dpositions: x } = await this.chunkCache.get(I.toString(), I, r);
469
+ _(r);
470
+ let p = 0, l = 0;
471
+ const g = (s = S == null ? void 0 : S.decode(m)) !== null && s !== void 0 ? s : m.toString(), P = m.length < 5e8 && oe(g);
472
+ for (; p < g.length; ) {
473
+ let E, v;
474
+ if (P) {
475
+ if (v = g.indexOf(`
476
+ `, p), v === -1)
477
+ break;
478
+ E = g.slice(p, v);
479
+ } else {
480
+ if (v = m.indexOf(`
481
+ `, p), v === -1)
482
+ break;
483
+ const L = m.slice(p, v);
484
+ E = (a = S == null ? void 0 : S.decode(L)) !== null && a !== void 0 ? a : L.toString();
485
+ }
476
486
  if (x) {
477
- for (; h + w.minv.dataPosition >= x[g++]; )
487
+ for (; p + I.minv.dataPosition >= x[l++]; )
478
488
  ;
479
- g--;
489
+ l--;
480
490
  }
481
- const { startCoordinate: E, overlaps: P } = this.checkLine(l, e, u, c, S);
482
- if (m !== void 0 && E !== void 0 && m > E)
483
- throw new Error(`Lines not sorted by start coordinate (${m} > ${E}), this file is not usable with Tabix.`);
484
- if (m = E, P)
491
+ const { startCoordinate: N, overlaps: B } = this.checkLine(u, e, h, c, E);
492
+ if (B)
485
493
  d(
486
- S.trim(),
487
- // cpositions[pos] refers to actual file offset of a bgzip block boundaries
494
+ E,
495
+ // cpositions[pos] refers to actual file offset of a bgzip block
496
+ // boundaries
488
497
  //
489
- // we multiply by (1 <<8) in order to make sure each block has a "unique"
490
- // address space so that data in that block could never overlap
498
+ // we multiply by (1 <<8) in order to make sure each block has a
499
+ // "unique" address space so that data in that block could never
500
+ // overlap
491
501
  //
492
- // then the blockStart-dpositions is an uncompressed file offset from
493
- // that bgzip block boundary, and since the cpositions are multiplied by
494
- // (1 << 8) these uncompressed offsets get a unique space
495
- p[g] * 256 + (h - x[g]) + w.minv.dataPosition + 1
502
+ // then the blockStart-dpositions is an uncompressed file offset
503
+ // from that bgzip block boundary, and since the cpositions are
504
+ // multiplied by (1 << 8) these uncompressed offsets get a unique
505
+ // space
506
+ w[l] * 256 + (p - x[l]) + I.minv.dataPosition + 1
496
507
  );
497
- else if (E !== void 0 && E >= c)
508
+ else if (N !== void 0 && N >= c)
498
509
  return;
499
- this.yieldTime && I - Date.now() > this.yieldTime && (I = Date.now(), L(r), await oe(1)), h = C + 1;
510
+ p = v + 1;
500
511
  }
501
512
  }
502
513
  }
@@ -509,16 +520,16 @@ class ue {
509
520
  */
510
521
  async getHeaderBuffer(e = {}) {
511
522
  const { firstDataLine: t, metaChar: n, maxBlockSize: i } = await this.getMetadata(e);
512
- L(e.signal);
513
- const a = ((t == null ? void 0 : t.blockPosition) || 0) + i, r = await this._readRegion(0, a, e), s = await $(r);
523
+ _(e.signal);
524
+ const s = ((t == null ? void 0 : t.blockPosition) || 0) + i, a = await this._readRegion(0, s, e), r = await $(a);
514
525
  if (n) {
515
- let d = -1;
516
- const l = 10, u = n.charCodeAt(0);
517
- for (let c = 0; c < s.length && !(c === d + 1 && s[c] !== u); c += 1)
518
- s[c] === l && (d = c);
519
- return s.slice(0, d + 1);
526
+ let f = -1;
527
+ const d = 10, u = n.charCodeAt(0);
528
+ for (let h = 0; h < r.length && !(h === f + 1 && r[h] !== u); h += 1)
529
+ r[h] === d && (f = h);
530
+ return r.subarray(0, f + 1);
520
531
  }
521
- return s;
532
+ return r;
522
533
  }
523
534
  /**
524
535
  * get a string containing the "header" region of the file, is the portion up
@@ -551,47 +562,61 @@ class ue {
551
562
  * @returns {object} like `{startCoordinate, overlaps}`. overlaps is boolean,
552
563
  * true if line is a data line that overlaps the given region
553
564
  */
554
- checkLine(e, t, n, i, a) {
555
- const { columnNumbers: r, metaChar: s, coordinateType: d, format: l } = e;
556
- if (s && a.startsWith(s))
565
+ checkLine(e, t, n, i, s) {
566
+ const { columnNumbers: a, metaChar: r, coordinateType: f, format: d } = e;
567
+ if (r && s.startsWith(r))
557
568
  return { overlaps: !1 };
558
- let { ref: u, start: c, end: f } = r;
559
- u || (u = 0), c || (c = 0), f || (f = 0), l === "VCF" && (f = 8);
560
- const I = Math.max(u, c, f);
561
- let w = 1, m = 0, b = "", p = -1 / 0;
562
- for (let x = 0; x < a.length + 1; x += 1)
563
- if (a[x] === " " || x === a.length) {
564
- if (w === u) {
565
- if (this.renameRefSeq(a.slice(m, x)) !== t)
566
- return { overlaps: !1 };
567
- } else if (w === c) {
568
- if (p = parseInt(a.slice(m, x), 10), d === "1-based-closed" && (p -= 1), p >= i)
569
- return { startCoordinate: p, overlaps: !1 };
570
- if ((f === 0 || f === c) && p + 1 <= n)
571
- return { startCoordinate: p, overlaps: !1 };
572
- } else if (l === "VCF" && w === 4)
573
- b = a.slice(m, x);
574
- else if (w === f && (l === "VCF" ? this._getVcfEnd(p, b, a.slice(m, x)) : parseInt(a.slice(m, x), 10)) <= n)
575
- return { overlaps: !1 };
576
- if (m = x + 1, w += 1, w > I)
569
+ let { ref: u, start: h, end: c } = a;
570
+ u || (u = 0), h || (h = 0), c || (c = 0), d === "VCF" && (c = 8);
571
+ const b = Math.max(u, h, c);
572
+ let I = 1, m = 0, w = "", x = -1 / 0;
573
+ const p = s.length;
574
+ for (let l = 0; l < p + 1; l++)
575
+ if (s[l] === " " || l === p) {
576
+ if (I === u) {
577
+ if (this.renameRefSeq(s.slice(m, l)) !== t)
578
+ return {
579
+ overlaps: !1
580
+ };
581
+ } else if (I === h) {
582
+ if (x = parseInt(s.slice(m, l), 10), f === "1-based-closed" && (x -= 1), x >= i)
583
+ return {
584
+ startCoordinate: x,
585
+ overlaps: !1
586
+ };
587
+ if ((c === 0 || c === h) && x + 1 <= n)
588
+ return {
589
+ startCoordinate: x,
590
+ overlaps: !1
591
+ };
592
+ } else if (d === "VCF" && I === 4)
593
+ w = s.slice(m, l);
594
+ else if (I === c && (d === "VCF" ? this._getVcfEnd(x, w, s.slice(m, l)) : Number.parseInt(s.slice(m, l), 10)) <= n)
595
+ return {
596
+ overlaps: !1
597
+ };
598
+ if (m = l + 1, I += 1, I > b)
577
599
  break;
578
600
  }
579
- return { startCoordinate: p, overlaps: !0 };
601
+ return {
602
+ startCoordinate: x,
603
+ overlaps: !0
604
+ };
580
605
  }
581
606
  _getVcfEnd(e, t, n) {
582
607
  let i = e + t.length;
583
- const a = n.includes("SVTYPE=TRA");
584
- if (n[0] !== "." && !a) {
585
- let r = ";";
586
- for (let s = 0; s < n.length; s += 1) {
587
- if (r === ";" && n.slice(s, s + 4) === "END=") {
588
- let d = n.indexOf(";", s);
589
- d === -1 && (d = n.length), i = parseInt(n.slice(s + 4, d), 10);
608
+ const s = n.includes("SVTYPE=TRA");
609
+ if (n[0] !== "." && !s) {
610
+ let a = ";";
611
+ for (let r = 0; r < n.length; r += 1) {
612
+ if (a === ";" && n.slice(r, r + 4) === "END=") {
613
+ let f = n.indexOf(";", r);
614
+ f === -1 && (f = n.length), i = parseInt(n.slice(r + 4, f), 10);
590
615
  break;
591
616
  }
592
- r = n[s];
617
+ a = n[r];
593
618
  }
594
- } else if (a)
619
+ } else if (s)
595
620
  return e + 1;
596
621
  return i;
597
622
  }
@@ -607,8 +632,8 @@ class ue {
607
632
  return this.index.lineCount(e, t);
608
633
  }
609
634
  async _readRegion(e, t, n = {}) {
610
- const i = Q.Buffer.alloc(t), { bytesRead: a, buffer: r } = await this.filehandle.read(i, 0, t, e, n);
611
- return r.slice(0, a);
635
+ const i = Q.Buffer.alloc(t), { bytesRead: s, buffer: a } = await this.filehandle.read(i, 0, t, e, n);
636
+ return a.subarray(0, s);
612
637
  }
613
638
  /**
614
639
  * read and uncompress the data in a chunk (composed of one or more
@@ -620,7 +645,7 @@ class ue {
620
645
  }
621
646
  }
622
647
  export {
623
- M as CSI,
624
- k as TBI,
648
+ z as CSI,
649
+ y as TBI,
625
650
  ue as TabixIndexedFile
626
651
  };