@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,613 +0,0 @@
1
- import { _ as Y, L as J } from "./index-BhtH2nrr.js";
2
- import { b as K } from "./index-B6haPltu.js";
3
- import { L as P } from "./__vite-browser-external-C--ziKoh.js";
4
- import { u as F, L as G, a as Q } from "./long-BXK3UEks.js";
5
- function H(a) {
6
- if (a.greaterThan(Number.MAX_SAFE_INTEGER) || a.lessThan(Number.MIN_SAFE_INTEGER))
7
- throw new Error("integer overflow");
8
- return a.toNumber();
9
- }
10
- class Z extends Error {
11
- }
12
- function L(a) {
13
- if (a && a.aborted) {
14
- if (typeof DOMException < "u")
15
- throw new DOMException("aborted", "AbortError");
16
- {
17
- const e = new Z("aborted");
18
- throw e.code = "ERR_ABORTED", e;
19
- }
20
- }
21
- }
22
- function ee(a, e) {
23
- return e.minv.blockPosition - a.maxv.blockPosition < 65e3 && e.maxv.blockPosition - a.minv.blockPosition < 5e6;
24
- }
25
- function j(a, e) {
26
- const t = [];
27
- let n = null;
28
- return a.length === 0 ? a : (a.sort(function(i, r) {
29
- const s = i.minv.blockPosition - r.minv.blockPosition;
30
- return s !== 0 ? s : i.minv.dataPosition - r.minv.dataPosition;
31
- }), a.forEach((i) => {
32
- (!e || i.maxv.compareTo(e) > 0) && (n === null ? (t.push(i), n = i) : ee(n, i) ? i.maxv.compareTo(n.maxv) > 0 && (n.maxv = i.maxv) : (t.push(i), n = i));
33
- }), t);
34
- }
35
- class M {
36
- constructor(e, t) {
37
- this.blockPosition = e, this.dataPosition = t;
38
- }
39
- toString() {
40
- return `${this.blockPosition}:${this.dataPosition}`;
41
- }
42
- compareTo(e) {
43
- return this.blockPosition - e.blockPosition || this.dataPosition - e.dataPosition;
44
- }
45
- static min(...e) {
46
- let t, n = 0;
47
- for (; !t; n += 1)
48
- t = e[n];
49
- for (; n < e.length; n += 1)
50
- t.compareTo(e[n]) > 0 && (t = e[n]);
51
- return t;
52
- }
53
- }
54
- function T(a, e = 0, t = !1) {
55
- if (t)
56
- throw new Error("big-endian virtual file offsets not implemented");
57
- return new M(a[e + 7] * 1099511627776 + a[e + 6] * 4294967296 + a[e + 5] * 16777216 + a[e + 4] * 65536 + a[e + 3] * 256 + a[e + 2], a[e + 1] << 8 | a[e]);
58
- }
59
- class B {
60
- constructor(e, t, n, i = void 0) {
61
- this.minv = e, this.maxv = t, this.bin = n, this._fetchedSize = i;
62
- }
63
- toUniqueString() {
64
- return `${this.minv}..${this.maxv} (bin ${this.bin}, fetchedSize ${this.fetchedSize()})`;
65
- }
66
- toString() {
67
- return this.toUniqueString();
68
- }
69
- compareTo(e) {
70
- return this.minv.compareTo(e.minv) || this.maxv.compareTo(e.maxv) || this.bin - e.bin;
71
- }
72
- fetchedSize() {
73
- return this._fetchedSize !== void 0 ? this._fetchedSize : this.maxv.blockPosition + 65536 - this.minv.blockPosition;
74
- }
75
- }
76
- class X {
77
- constructor({ filehandle: e, renameRefSeqs: t = (n) => n }) {
78
- this.filehandle = e, this.renameRefSeq = t;
79
- }
80
- async getMetadata(e = {}) {
81
- const { indices: t, ...n } = await this.parse(e);
82
- return n;
83
- }
84
- _findFirstData(e, t) {
85
- return e ? e.compareTo(t) > 0 ? t : e : t;
86
- }
87
- async parse(e = {}) {
88
- return this.parseP || (this.parseP = this._parse(e).catch((t) => {
89
- throw this.parseP = void 0, t;
90
- })), this.parseP;
91
- }
92
- async hasRefSeq(e, t = {}) {
93
- var n;
94
- return !!(!((n = (await this.parse(t)).indices[e]) === null || n === void 0) && n.binIndex);
95
- }
96
- }
97
- const te = 21578324, q = 14;
98
- function ne(a, e) {
99
- return a += 1, e -= 1, [
100
- [0, 0],
101
- [1 + (a >> 26), 1 + (e >> 26)],
102
- [9 + (a >> 23), 9 + (e >> 23)],
103
- [73 + (a >> 20), 73 + (e >> 20)],
104
- [585 + (a >> 17), 585 + (e >> 17)],
105
- [4681 + (a >> 14), 4681 + (e >> 14)]
106
- ];
107
- }
108
- class z extends X {
109
- async lineCount(e, t = {}) {
110
- const n = await this.parse(t);
111
- if (!n)
112
- return -1;
113
- const i = n.refNameToId[e];
114
- if (!n.indices[i])
115
- return -1;
116
- const { stats: s } = n.indices[i];
117
- return s ? s.lineCount : -1;
118
- }
119
- // fetch and parse the index
120
- async _parse(e = {}) {
121
- const t = await this.filehandle.readFile(e), n = await F(t);
122
- if (L(e.signal), n.readUInt32LE(0) !== te)
123
- throw new Error("Not a TBI file");
124
- const i = n.readInt32LE(4), r = n.readInt32LE(8), s = r & 65536 ? "zero-based-half-open" : "1-based-closed", f = {
125
- 0: "generic",
126
- 1: "SAM",
127
- 2: "VCF"
128
- }[r & 15];
129
- if (!f)
130
- throw new Error(`invalid Tabix preset format flags ${r}`);
131
- const c = {
132
- ref: n.readInt32LE(12),
133
- start: n.readInt32LE(16),
134
- end: n.readInt32LE(20)
135
- }, m = n.readInt32LE(24), l = 5, d = ((1 << (l + 1) * 3) - 1) / 7, b = 2 ** (14 + l * 3), w = m ? String.fromCharCode(m) : null, u = n.readInt32LE(28), I = n.readInt32LE(32), { refNameToId: x, refIdToName: p } = this._parseNameBytes(n.slice(36, 36 + I));
136
- let h = 36 + I, g;
137
- return {
138
- indices: new Array(i).fill(0).map(() => {
139
- const N = n.readInt32LE(h);
140
- h += 4;
141
- const S = {};
142
- let E;
143
- for (let v = 0; v < N; v += 1) {
144
- const _ = n.readUInt32LE(h);
145
- if (h += 4, _ > d + 1)
146
- throw new Error("tabix index contains too many bins, please use a CSI index");
147
- if (_ === d + 1) {
148
- const k = n.readInt32LE(h);
149
- h += 4, k === 2 && (E = this.parsePseudoBin(n, h)), h += 16 * k;
150
- } else {
151
- const k = n.readInt32LE(h);
152
- h += 4;
153
- const $ = new Array(k);
154
- for (let D = 0; D < k; D += 1) {
155
- const V = T(n, h), W = T(n, h + 8);
156
- h += 16, g = this._findFirstData(g, V), $[D] = new B(V, W, _);
157
- }
158
- S[_] = $;
159
- }
160
- }
161
- const y = n.readInt32LE(h);
162
- h += 4;
163
- const A = new Array(y);
164
- for (let v = 0; v < y; v += 1)
165
- A[v] = T(n, h), h += 8, g = this._findFirstData(g, A[v]);
166
- return { binIndex: S, linearIndex: A, stats: E };
167
- }),
168
- metaChar: w,
169
- maxBinNumber: d,
170
- maxRefLength: b,
171
- skipLines: u,
172
- firstDataLine: g,
173
- columnNumbers: c,
174
- coordinateType: s,
175
- format: f,
176
- refIdToName: p,
177
- refNameToId: x,
178
- maxBlockSize: 65536
179
- };
180
- }
181
- parsePseudoBin(e, t) {
182
- return { lineCount: H(G.fromBytesLE(e.slice(t + 16, t + 24), !0)) };
183
- }
184
- _parseNameBytes(e) {
185
- let t = 0, n = 0;
186
- const i = [], r = {};
187
- for (let s = 0; s < e.length; s += 1)
188
- if (!e[s]) {
189
- if (n < s) {
190
- let o = e.toString("utf8", n, s);
191
- o = this.renameRefSeq(o), i[t] = o, r[o] = t;
192
- }
193
- n = s + 1, t += 1;
194
- }
195
- return { refNameToId: r, refIdToName: i };
196
- }
197
- async blocksForRange(e, t, n, i = {}) {
198
- t < 0 && (t = 0);
199
- const r = await this.parse(i);
200
- if (!r)
201
- return [];
202
- const s = r.refNameToId[e], o = r.indices[s];
203
- if (!o)
204
- return [];
205
- (o.linearIndex.length ? o.linearIndex[t >> q >= o.linearIndex.length ? o.linearIndex.length - 1 : t >> q] : new M(0, 0)) || console.warn("querying outside of possible tabix range");
206
- const c = ne(t, n), m = [];
207
- for (const [u, I] of c)
208
- for (let x = u; x <= I; x++)
209
- if (o.binIndex[x])
210
- for (const p of o.binIndex[x])
211
- m.push(new B(p.minv, p.maxv, x));
212
- const l = o.linearIndex.length;
213
- let d = null;
214
- const b = Math.min(t >> 14, l - 1), w = Math.min(n >> 14, l - 1);
215
- for (let u = b; u <= w; ++u) {
216
- const I = o.linearIndex[u];
217
- I && (!d || I.compareTo(d) < 0) && (d = I);
218
- }
219
- return j(m, d);
220
- }
221
- }
222
- const ie = 21582659, re = 38359875;
223
- function oe(a, e) {
224
- return a * 2 ** e;
225
- }
226
- function O(a, e) {
227
- return Math.floor(a / 2 ** e);
228
- }
229
- class U extends X {
230
- constructor(e) {
231
- super(e), this.maxBinNumber = 0, this.depth = 0, this.minShift = 0;
232
- }
233
- async lineCount(e, t = {}) {
234
- const n = await this.parse(t);
235
- if (!n)
236
- return -1;
237
- const i = n.refNameToId[e];
238
- if (!n.indices[i])
239
- return -1;
240
- const { stats: s } = n.indices[i];
241
- return s ? s.lineCount : -1;
242
- }
243
- indexCov() {
244
- throw new Error("CSI indexes do not support indexcov");
245
- }
246
- parseAuxData(e, t) {
247
- const n = e.readInt32LE(t), i = n & 65536 ? "zero-based-half-open" : "1-based-closed", r = { 0: "generic", 1: "SAM", 2: "VCF" }[n & 15];
248
- if (!r)
249
- throw new Error(`invalid Tabix preset format flags ${n}`);
250
- const s = {
251
- ref: e.readInt32LE(t + 4),
252
- start: e.readInt32LE(t + 8),
253
- end: e.readInt32LE(t + 12)
254
- }, o = e.readInt32LE(t + 16), f = o ? String.fromCharCode(o) : null, c = e.readInt32LE(t + 20), m = e.readInt32LE(t + 24), { refIdToName: l, refNameToId: d } = this._parseNameBytes(e.slice(t + 28, t + 28 + m));
255
- return {
256
- refIdToName: l,
257
- refNameToId: d,
258
- skipLines: c,
259
- metaChar: f,
260
- columnNumbers: s,
261
- format: r,
262
- coordinateType: i
263
- };
264
- }
265
- _parseNameBytes(e) {
266
- let t = 0, n = 0;
267
- const i = [], r = {};
268
- for (let s = 0; s < e.length; s += 1)
269
- if (!e[s]) {
270
- if (n < s) {
271
- let o = e.toString("utf8", n, s);
272
- o = this.renameRefSeq(o), i[t] = o, r[o] = t;
273
- }
274
- n = s + 1, t += 1;
275
- }
276
- return { refNameToId: r, refIdToName: i };
277
- }
278
- // fetch and parse the index
279
- async _parse(e = {}) {
280
- const t = await F(await this.filehandle.readFile(e));
281
- let n;
282
- if (t.readUInt32LE(0) === ie)
283
- n = 1;
284
- else if (t.readUInt32LE(0) === re)
285
- n = 2;
286
- else
287
- throw new Error("Not a CSI file");
288
- this.minShift = t.readInt32LE(4), this.depth = t.readInt32LE(8), this.maxBinNumber = ((1 << (this.depth + 1) * 3) - 1) / 7;
289
- const i = 2 ** (this.minShift + this.depth * 3), r = t.readInt32LE(12), s = r && r >= 30 ? this.parseAuxData(t, 16) : {
290
- refIdToName: [],
291
- refNameToId: {},
292
- metaChar: null,
293
- columnNumbers: { ref: 0, start: 1, end: 2 },
294
- coordinateType: "zero-based-half-open",
295
- format: "generic"
296
- }, o = t.readInt32LE(16 + r);
297
- let f, c = 16 + r + 4;
298
- const m = new Array(o).fill(0).map(() => {
299
- const l = t.readInt32LE(c);
300
- c += 4;
301
- const d = {};
302
- let b;
303
- for (let w = 0; w < l; w += 1) {
304
- const u = t.readUInt32LE(c);
305
- if (u > this.maxBinNumber)
306
- b = this.parsePseudoBin(t, c + 4), c += 48;
307
- else {
308
- const I = T(t, c + 4);
309
- f = this._findFirstData(f, I);
310
- const x = t.readInt32LE(c + 12);
311
- c += 16;
312
- const p = new Array(x);
313
- for (let h = 0; h < x; h += 1) {
314
- const g = T(t, c), C = T(t, c + 8);
315
- c += 16, p[h] = new B(g, C, u);
316
- }
317
- d[u] = p;
318
- }
319
- }
320
- return { binIndex: d, stats: b };
321
- });
322
- return {
323
- ...s,
324
- csi: !0,
325
- refCount: o,
326
- maxBlockSize: 65536,
327
- firstDataLine: f,
328
- csiVersion: n,
329
- indices: m,
330
- depth: this.depth,
331
- maxBinNumber: this.maxBinNumber,
332
- maxRefLength: i
333
- };
334
- }
335
- parsePseudoBin(e, t) {
336
- return { lineCount: H(G.fromBytesLE(e.slice(t + 28, t + 36), !0)) };
337
- }
338
- async blocksForRange(e, t, n, i = {}) {
339
- t < 0 && (t = 0);
340
- const r = await this.parse(i);
341
- if (!r)
342
- return [];
343
- const s = r.refNameToId[e], o = r.indices[s];
344
- if (!o)
345
- return [];
346
- const f = this.reg2bins(t, n), c = [];
347
- for (const [m, l] of f)
348
- for (let d = m; d <= l; d++)
349
- if (o.binIndex[d])
350
- for (const b of o.binIndex[d])
351
- c.push(new B(b.minv, b.maxv, d));
352
- return j(c, new M(0, 0));
353
- }
354
- /**
355
- * calculate the list of bins that may overlap with region [beg,end) (zero-based half-open)
356
- */
357
- reg2bins(e, t) {
358
- e -= 1, e < 1 && (e = 1), t > 2 ** 50 && (t = 2 ** 34), t -= 1;
359
- let n = 0, i = 0, r = this.minShift + this.depth * 3;
360
- const s = [];
361
- for (; n <= this.depth; r -= 3, i += oe(1, n * 3), n += 1) {
362
- const o = i + O(e, r), f = i + O(t, r);
363
- if (f - o + s.length > this.maxBinNumber)
364
- 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`);
365
- s.push([o, f]);
366
- }
367
- return s;
368
- }
369
- }
370
- const R = typeof TextDecoder < "u" ? new TextDecoder("utf8") : void 0;
371
- function se(a) {
372
- return new Promise((e) => setTimeout(e, a));
373
- }
374
- class fe {
375
- /**
376
- * @param {object} args
377
- * @param {string} [args.path]
378
- * @param {filehandle} [args.filehandle]
379
- * @param {string} [args.tbiPath]
380
- * @param {filehandle} [args.tbiFilehandle]
381
- * @param {string} [args.csiPath]
382
- * @param {filehandle} [args.csiFilehandle]
383
- * @param {number} [args.yieldTime] yield to main thread after N milliseconds if reading features is taking a long time to avoid hanging main thread
384
- * @param {function} [args.renameRefSeqs] optional function with sig `string => string` to transform
385
- * reference sequence names for the purpose of indexing and querying. note that the data that is returned is
386
- * not altered, just the names of the reference sequences that are used for querying.
387
- */
388
- constructor({ path: e, filehandle: t, tbiPath: n, tbiFilehandle: i, csiPath: r, csiFilehandle: s, yieldTime: o = 500, chunkSizeLimit: f = 5e7, renameRefSeqs: c = (l) => l, chunkCacheSize: m = 5 * 2 ** 20 }) {
389
- if (t)
390
- this.filehandle = t;
391
- else if (e)
392
- this.filehandle = new P(e);
393
- else
394
- throw new TypeError("must provide either filehandle or path");
395
- if (i)
396
- this.index = new z({
397
- filehandle: i,
398
- renameRefSeqs: c
399
- });
400
- else if (s)
401
- this.index = new U({
402
- filehandle: s,
403
- renameRefSeqs: c
404
- });
405
- else if (n)
406
- this.index = new z({
407
- filehandle: new P(n),
408
- renameRefSeqs: c
409
- });
410
- else if (r)
411
- this.index = new U({
412
- filehandle: new P(r),
413
- renameRefSeqs: c
414
- });
415
- else if (e)
416
- this.index = new z({
417
- filehandle: new P(`${e}.tbi`),
418
- renameRefSeqs: c
419
- });
420
- else
421
- throw new TypeError("must provide one of tbiFilehandle, tbiPath, csiFilehandle, or csiPath");
422
- this.chunkSizeLimit = f, this.renameRefSeq = c, this.yieldTime = o, this.chunkCache = new Y({
423
- cache: new J({ maxSize: Math.floor(m / 65536) }),
424
- fill: (l, d) => this.readChunk(l, { signal: d })
425
- });
426
- }
427
- /**
428
- * @param refName name of the reference sequence
429
- * @param start start of the region (in 0-based half-open coordinates)
430
- * @param end end of the region (in 0-based half-open coordinates)
431
- * @param opts callback called for each line in the region. can also pass a object param containing obj.lineCallback, obj.signal, etc
432
- * @returns promise that is resolved when the whole read is finished, rejected on error
433
- */
434
- async getLines(e, t, n, i) {
435
- var r;
436
- let s, o = {}, f;
437
- if (i === void 0)
438
- throw new TypeError("line callback must be provided");
439
- if (typeof i == "function" ? f = i : (o = i, f = i.lineCallback, s = i.signal), e === void 0)
440
- throw new TypeError("must provide a reference sequence name");
441
- if (!f)
442
- throw new TypeError("line callback must be provided");
443
- const c = await this.index.getMetadata(o);
444
- L(s);
445
- const m = t ?? 0, l = n ?? c.maxRefLength;
446
- if (!(m <= l))
447
- throw new TypeError("invalid start and end coordinates. start must be less than or equal to end");
448
- if (m === l)
449
- return;
450
- const d = await this.index.blocksForRange(e, m, l, o);
451
- L(s);
452
- for (const w of d) {
453
- const u = w.fetchedSize();
454
- if (u > this.chunkSizeLimit)
455
- throw new Error(`Too much data. Chunk size ${u.toLocaleString()} bytes exceeds chunkSizeLimit of ${this.chunkSizeLimit.toLocaleString()}.`);
456
- }
457
- let b = Date.now();
458
- for (const w of d) {
459
- let u;
460
- const { buffer: I, cpositions: x, dpositions: p } = await this.chunkCache.get(w.toString(), w, s);
461
- L(s);
462
- let h = 0, g = 0;
463
- for (; h < I.length; ) {
464
- const C = I.indexOf(`
465
- `, h);
466
- if (C === -1)
467
- break;
468
- const N = I.slice(h, C), S = (r = R == null ? void 0 : R.decode(N)) !== null && r !== void 0 ? r : N.toString();
469
- if (p) {
470
- for (; h + w.minv.dataPosition >= p[g++]; )
471
- ;
472
- g--;
473
- }
474
- const { startCoordinate: E, overlaps: y } = this.checkLine(c, e, m, l, S);
475
- if (u !== void 0 && E !== void 0 && u > E)
476
- throw new Error(`Lines not sorted by start coordinate (${u} > ${E}), this file is not usable with Tabix.`);
477
- if (u = E, y)
478
- f(
479
- S.trim(),
480
- // cpositions[pos] refers to actual file offset of a bgzip block boundaries
481
- //
482
- // we multiply by (1 <<8) in order to make sure each block has a "unique"
483
- // address space so that data in that block could never overlap
484
- //
485
- // then the blockStart-dpositions is an uncompressed file offset from
486
- // that bgzip block boundary, and since the cpositions are multiplied by
487
- // (1 << 8) these uncompressed offsets get a unique space
488
- x[g] * 256 + (h - p[g]) + w.minv.dataPosition + 1
489
- );
490
- else if (E !== void 0 && E >= l)
491
- return;
492
- this.yieldTime && b - Date.now() > this.yieldTime && (b = Date.now(), L(s), await se(1)), h = C + 1;
493
- }
494
- }
495
- }
496
- async getMetadata(e = {}) {
497
- return this.index.getMetadata(e);
498
- }
499
- /**
500
- * get a buffer containing the "header" region of
501
- * the file, which are the bytes up to the first
502
- * non-meta line
503
- */
504
- async getHeaderBuffer(e = {}) {
505
- const { firstDataLine: t, metaChar: n, maxBlockSize: i } = await this.getMetadata(e);
506
- L(e.signal);
507
- const r = ((t == null ? void 0 : t.blockPosition) || 0) + i, s = await this._readRegion(0, r, e), o = await F(s);
508
- if (n) {
509
- let f = -1;
510
- const c = 10, m = n.charCodeAt(0);
511
- for (let l = 0; l < o.length && !(l === f + 1 && o[l] !== m); l += 1)
512
- o[l] === c && (f = l);
513
- return o.slice(0, f + 1);
514
- }
515
- return o;
516
- }
517
- /**
518
- * get a string containing the "header" region of the
519
- * file, is the portion up to the first non-meta line
520
- *
521
- * @returns {Promise} for a string
522
- */
523
- async getHeader(e = {}) {
524
- return (await this.getHeaderBuffer(e)).toString("utf8");
525
- }
526
- /**
527
- * get an array of reference sequence names, in the order in which
528
- * they occur in the file. reference sequence renaming is not applied
529
- * to these names.
530
- */
531
- async getReferenceSequenceNames(e = {}) {
532
- return (await this.getMetadata(e)).refIdToName;
533
- }
534
- /**
535
- * @param {object} metadata metadata object from the parsed index,
536
- * containing columnNumbers, metaChar, and format
537
- * @param {string} regionRefName
538
- * @param {number} regionStart region start coordinate (0-based-half-open)
539
- * @param {number} regionEnd region end coordinate (0-based-half-open)
540
- * @param {array[string]} line
541
- * @returns {object} like `{startCoordinate, overlaps}`. overlaps is boolean,
542
- * true if line is a data line that overlaps the given region
543
- */
544
- checkLine(e, t, n, i, r) {
545
- const { columnNumbers: s, metaChar: o, coordinateType: f, format: c } = e;
546
- if (o && r.startsWith(o))
547
- return { overlaps: !1 };
548
- let { ref: m, start: l, end: d } = s;
549
- m || (m = 0), l || (l = 0), d || (d = 0), c === "VCF" && (d = 8);
550
- const b = Math.max(m, l, d);
551
- let w = 1, u = 0, I = "", x = -1 / 0;
552
- for (let p = 0; p < r.length + 1; p += 1)
553
- if (r[p] === " " || p === r.length) {
554
- if (w === m) {
555
- if (this.renameRefSeq(r.slice(u, p)) !== t)
556
- return { overlaps: !1 };
557
- } else if (w === l) {
558
- if (x = parseInt(r.slice(u, p), 10), f === "1-based-closed" && (x -= 1), x >= i)
559
- return { startCoordinate: x, overlaps: !1 };
560
- if ((d === 0 || d === l) && x + 1 <= n)
561
- return { startCoordinate: x, overlaps: !1 };
562
- } else if (c === "VCF" && w === 4)
563
- I = r.slice(u, p);
564
- else if (w === d && (c === "VCF" ? this._getVcfEnd(x, I, r.slice(u, p)) : parseInt(r.slice(u, p), 10)) <= n)
565
- return { overlaps: !1 };
566
- if (u = p + 1, w += 1, w > b)
567
- break;
568
- }
569
- return { startCoordinate: x, overlaps: !0 };
570
- }
571
- _getVcfEnd(e, t, n) {
572
- let i = e + t.length;
573
- const r = n.includes("SVTYPE=TRA");
574
- if (n[0] !== "." && !r) {
575
- let s = ";";
576
- for (let o = 0; o < n.length; o += 1) {
577
- if (s === ";" && n.slice(o, o + 4) === "END=") {
578
- let f = n.indexOf(";", o);
579
- f === -1 && (f = n.length), i = parseInt(n.slice(o + 4, f), 10);
580
- break;
581
- }
582
- s = n[o];
583
- }
584
- } else if (r)
585
- return e + 1;
586
- return i;
587
- }
588
- /**
589
- * return the approximate number of data lines in the given reference sequence
590
- * @param refSeq reference sequence name
591
- * @returns number of data lines present on that reference sequence
592
- */
593
- async lineCount(e, t = {}) {
594
- return this.index.lineCount(e, t);
595
- }
596
- async _readRegion(e, t, n = {}) {
597
- const i = K.Buffer.alloc(t), { bytesRead: r, buffer: s } = await this.filehandle.read(i, 0, t, e, n);
598
- return s.slice(0, r);
599
- }
600
- /**
601
- * read and uncompress the data in a chunk (composed of one or more
602
- * contiguous bgzip blocks) of the file
603
- */
604
- async readChunk(e, t = {}) {
605
- const n = await this._readRegion(e.minv.blockPosition, e.fetchedSize(), t);
606
- return Q(n, e);
607
- }
608
- }
609
- export {
610
- U as CSI,
611
- z as TBI,
612
- fe as TabixIndexedFile
613
- };
@@ -1,90 +0,0 @@
1
- import { b as d } from "./index-B6haPltu.js";
2
- class b {
3
- async getBufferFromResponse(e) {
4
- const t = await e.arrayBuffer();
5
- return d.Buffer.from(t);
6
- }
7
- constructor(e, t = {}) {
8
- this.baseOverrides = {}, this.url = e;
9
- const r = t.fetch || globalThis.fetch.bind(globalThis);
10
- if (!r)
11
- throw new TypeError("no fetch function supplied, and none found in global environment");
12
- t.overrides && (this.baseOverrides = t.overrides), this.fetchImplementation = r;
13
- }
14
- async fetch(e, t) {
15
- let r;
16
- try {
17
- r = await this.fetchImplementation(e, t);
18
- } catch (s) {
19
- if (`${s}`.includes("Failed to fetch"))
20
- console.warn(`generic-filehandle: refetching ${e} to attempt to work around chrome CORS header caching bug`), r = await this.fetchImplementation(e, {
21
- ...t,
22
- cache: "reload"
23
- });
24
- else
25
- throw s;
26
- }
27
- return r;
28
- }
29
- async read(e, t = 0, r, s = 0, h = {}) {
30
- const { headers: n = {}, signal: c, overrides: a = {} } = h;
31
- r < 1 / 0 ? n.range = `bytes=${s}-${s + r}` : r === 1 / 0 && s !== 0 && (n.range = `bytes=${s}-`);
32
- const l = {
33
- ...this.baseOverrides,
34
- ...a,
35
- headers: {
36
- ...n,
37
- ...a.headers,
38
- ...this.baseOverrides.headers
39
- },
40
- method: "GET",
41
- redirect: "follow",
42
- mode: "cors",
43
- signal: c
44
- }, i = await this.fetch(this.url, l);
45
- if (!i.ok)
46
- throw new Error(`HTTP ${i.status} ${i.statusText} ${this.url}`);
47
- if (i.status === 200 && s === 0 || i.status === 206) {
48
- const f = await this.getBufferFromResponse(i), u = f.copy(e, t, 0, Math.min(r, f.length)), w = i.headers.get("content-range"), o = /\/(\d+)$/.exec(w || "");
49
- return o != null && o[1] && (this._stat = { size: parseInt(o[1], 10) }), { bytesRead: u, buffer: e };
50
- }
51
- throw i.status === 200 ? new Error("${this.url} fetch returned status 200, expected 206") : new Error(`HTTP ${i.status} fetching ${this.url}`);
52
- }
53
- async readFile(e = {}) {
54
- let t, r;
55
- typeof e == "string" ? (t = e, r = {}) : (t = e.encoding, r = e, delete r.encoding);
56
- const { headers: s = {}, signal: h, overrides: n = {} } = r, c = {
57
- headers: s,
58
- method: "GET",
59
- redirect: "follow",
60
- mode: "cors",
61
- signal: h,
62
- ...this.baseOverrides,
63
- ...n
64
- }, a = await this.fetch(this.url, c);
65
- if (!a)
66
- throw new Error("generic-filehandle failed to fetch");
67
- if (a.status !== 200)
68
- throw Object.assign(new Error(`HTTP ${a.status} fetching ${this.url}`), {
69
- status: a.status
70
- });
71
- if (t === "utf8")
72
- return a.text();
73
- if (t)
74
- throw new Error(`unsupported encoding: ${t}`);
75
- return this.getBufferFromResponse(a);
76
- }
77
- async stat() {
78
- if (!this._stat) {
79
- const e = d.Buffer.allocUnsafe(10);
80
- if (await this.read(e, 0, 10, 0), !this._stat)
81
- throw new Error(`unable to determine size of file at ${this.url}`);
82
- }
83
- return this._stat;
84
- }
85
- async close() {
86
- }
87
- }
88
- export {
89
- b as R
90
- };