@genome-spy/app 0.56.1 → 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.
@@ -0,0 +1,626 @@
1
+ import { A as J, L as K } from "./index-CCJIjehY.js";
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";
5
+ import { u as $, L as H, a as Z } from "./long-BviWyoZx.js";
6
+ function j(o) {
7
+ if (o.greaterThan(Number.MAX_SAFE_INTEGER) || o.lessThan(Number.MIN_SAFE_INTEGER))
8
+ throw new Error("integer overflow");
9
+ return o.toNumber();
10
+ }
11
+ class ee extends Error {
12
+ }
13
+ function L(o) {
14
+ if (o && o.aborted) {
15
+ if (typeof DOMException < "u")
16
+ throw new DOMException("aborted", "AbortError");
17
+ {
18
+ const e = new ee("aborted");
19
+ throw e.code = "ERR_ABORTED", e;
20
+ }
21
+ }
22
+ }
23
+ function te(o, e) {
24
+ return e.minv.blockPosition - o.maxv.blockPosition < 65e3 && e.maxv.blockPosition - o.minv.blockPosition < 5e6;
25
+ }
26
+ function X(o, e) {
27
+ const t = [];
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;
32
+ }), o.forEach((i) => {
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
+ }), t);
35
+ }
36
+ class V {
37
+ constructor(e, t) {
38
+ this.blockPosition = e, this.dataPosition = t;
39
+ }
40
+ toString() {
41
+ return `${this.blockPosition}:${this.dataPosition}`;
42
+ }
43
+ compareTo(e) {
44
+ return this.blockPosition - e.blockPosition || this.dataPosition - e.dataPosition;
45
+ }
46
+ }
47
+ function T(o, e = 0, t = !1) {
48
+ if (t)
49
+ throw new Error("big-endian virtual file offsets not implemented");
50
+ return new V(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]);
51
+ }
52
+ class D {
53
+ constructor(e, t, n, i = void 0) {
54
+ this.minv = e, this.maxv = t, this.bin = n, this._fetchedSize = i;
55
+ }
56
+ toUniqueString() {
57
+ return `${this.minv}..${this.maxv} (bin ${this.bin}, fetchedSize ${this.fetchedSize()})`;
58
+ }
59
+ toString() {
60
+ return this.toUniqueString();
61
+ }
62
+ compareTo(e) {
63
+ return this.minv.compareTo(e.minv) || this.maxv.compareTo(e.maxv) || this.bin - e.bin;
64
+ }
65
+ fetchedSize() {
66
+ return this._fetchedSize !== void 0 ? this._fetchedSize : this.maxv.blockPosition + 65536 - this.minv.blockPosition;
67
+ }
68
+ }
69
+ class W {
70
+ constructor({ filehandle: e, renameRefSeqs: t = (n) => n }) {
71
+ this.filehandle = e, this.renameRefSeq = t;
72
+ }
73
+ async getMetadata(e = {}) {
74
+ const { indices: t, ...n } = await this.parse(e);
75
+ return n;
76
+ }
77
+ _findFirstData(e, t) {
78
+ return e ? e.compareTo(t) > 0 ? t : e : t;
79
+ }
80
+ async parse(e = {}) {
81
+ return this.parseP || (this.parseP = this._parse(e).catch((t) => {
82
+ throw this.parseP = void 0, t;
83
+ })), this.parseP;
84
+ }
85
+ async hasRefSeq(e, t = {}) {
86
+ var n;
87
+ return !!(!((n = (await this.parse(t)).indices[e]) === null || n === void 0) && n.binIndex);
88
+ }
89
+ }
90
+ const ne = 21578324, U = 14;
91
+ function ie(o, e) {
92
+ return o += 1, e -= 1, [
93
+ [0, 0],
94
+ [1 + (o >> 26), 1 + (e >> 26)],
95
+ [9 + (o >> 23), 9 + (e >> 23)],
96
+ [73 + (o >> 20), 73 + (e >> 20)],
97
+ [585 + (o >> 17), 585 + (e >> 17)],
98
+ [4681 + (o >> 14), 4681 + (e >> 14)]
99
+ ];
100
+ }
101
+ class k extends W {
102
+ async lineCount(e, t = {}) {
103
+ const n = await this.parse(t), i = n.refNameToId[e];
104
+ if (i === void 0 || !n.indices[i])
105
+ return -1;
106
+ const { stats: r } = n.indices[i];
107
+ return r ? r.lineCount : -1;
108
+ }
109
+ // fetch and parse the index
110
+ async _parse(e = {}) {
111
+ const t = await this.filehandle.readFile(e), n = await $(t);
112
+ if (L(e.signal), n.readUInt32LE(0) !== ne)
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 = {
115
+ 0: "generic",
116
+ 1: "SAM",
117
+ 2: "VCF"
118
+ }[a & 15];
119
+ if (!d)
120
+ throw new Error(`invalid Tabix preset format flags ${a}`);
121
+ const l = {
122
+ ref: n.readInt32LE(12),
123
+ start: n.readInt32LE(16),
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;
127
+ return {
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)
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;
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, _);
147
+ }
148
+ S[_] = O;
149
+ }
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 };
157
+ }),
158
+ metaChar: w,
159
+ maxBinNumber: f,
160
+ maxRefLength: I,
161
+ skipLines: m,
162
+ firstDataLine: g,
163
+ columnNumbers: l,
164
+ coordinateType: r,
165
+ format: d,
166
+ refIdToName: x,
167
+ refNameToId: p,
168
+ maxBlockSize: 65536
169
+ };
170
+ }
171
+ parsePseudoBin(e, t) {
172
+ return { lineCount: j(H.fromBytesLE(e.slice(t + 16, t + 24), !0)) };
173
+ }
174
+ _parseNameBytes(e) {
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;
182
+ }
183
+ n = r + 1, t += 1;
184
+ }
185
+ return { refNameToId: a, refIdToName: i };
186
+ }
187
+ async blocksForRange(e, t, n, i = {}) {
188
+ t < 0 && (t = 0);
189
+ const a = await this.parse(i), r = a.refNameToId[e];
190
+ if (r === void 0)
191
+ return [];
192
+ const s = a.indices[r];
193
+ if (!s)
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);
208
+ }
209
+ return X(u, f);
210
+ }
211
+ }
212
+ const re = 21582659, se = 38359875;
213
+ function ae(o, e) {
214
+ return o * 2 ** e;
215
+ }
216
+ function G(o, e) {
217
+ return Math.floor(o / 2 ** e);
218
+ }
219
+ class M extends W {
220
+ constructor(e) {
221
+ super(e), this.maxBinNumber = 0, this.depth = 0, this.minShift = 0;
222
+ }
223
+ async lineCount(e, t = {}) {
224
+ const n = await this.parse(t), i = n.refNameToId[e];
225
+ if (i === void 0 || !n.indices[i])
226
+ return -1;
227
+ const { stats: r } = n.indices[i];
228
+ return r ? r.lineCount : -1;
229
+ }
230
+ indexCov() {
231
+ throw new Error("CSI indexes do not support indexcov");
232
+ }
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)
236
+ throw new Error(`invalid Tabix preset format flags ${n}`);
237
+ const r = {
238
+ ref: e.readInt32LE(t + 4),
239
+ start: e.readInt32LE(t + 8),
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));
242
+ return {
243
+ refIdToName: c,
244
+ refNameToId: f,
245
+ skipLines: l,
246
+ metaChar: d,
247
+ columnNumbers: r,
248
+ format: a,
249
+ coordinateType: i
250
+ };
251
+ }
252
+ _parseNameBytes(e) {
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;
260
+ }
261
+ n = r + 1, t += 1;
262
+ }
263
+ return { refNameToId: a, refIdToName: i };
264
+ }
265
+ // fetch and parse the index
266
+ async _parse(e = {}) {
267
+ const t = await $(await this.filehandle.readFile(e));
268
+ let n;
269
+ if (t.readUInt32LE(0) === re)
270
+ n = 1;
271
+ else if (t.readUInt32LE(0) === se)
272
+ n = 2;
273
+ else
274
+ throw new Error("Not a CSI file");
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) : {
277
+ refIdToName: [],
278
+ refNameToId: {},
279
+ metaChar: null,
280
+ columnNumbers: { ref: 0, start: 1, end: 2 },
281
+ coordinateType: "zero-based-half-open",
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);
292
+ if (m > this.maxBinNumber)
293
+ I = this.parsePseudoBin(t, l + 4), l += 48;
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);
303
+ }
304
+ f[m] = x;
305
+ }
306
+ }
307
+ return { binIndex: f, stats: I };
308
+ });
309
+ return {
310
+ ...r,
311
+ csi: !0,
312
+ refCount: s,
313
+ maxBlockSize: 65536,
314
+ firstDataLine: d,
315
+ csiVersion: n,
316
+ indices: u,
317
+ depth: this.depth,
318
+ maxBinNumber: this.maxBinNumber,
319
+ maxRefLength: i
320
+ };
321
+ }
322
+ parsePseudoBin(e, t) {
323
+ return { lineCount: j(H.fromBytesLE(e.slice(t + 28, t + 36), !0)) };
324
+ }
325
+ async blocksForRange(e, t, n, i = {}) {
326
+ t < 0 && (t = 0);
327
+ const a = await this.parse(i), r = a.refNameToId[e];
328
+ if (r === void 0)
329
+ return [];
330
+ const s = a.indices[r];
331
+ if (!s)
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));
340
+ }
341
+ /**
342
+ * calculate the list of bins that may overlap with region [beg,end) (zero-based half-open)
343
+ */
344
+ reg2bins(e, t) {
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)
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]);
353
+ }
354
+ return r;
355
+ }
356
+ }
357
+ const z = typeof TextDecoder < "u" ? new TextDecoder("utf8") : void 0;
358
+ function oe(o) {
359
+ return new Promise((e) => setTimeout(e, o));
360
+ }
361
+ class ue {
362
+ /**
363
+ * @param {object} args
364
+ *
365
+ * @param {string} [args.path]
366
+ *
367
+ * @param {filehandle} [args.filehandle]
368
+ *
369
+ * @param {string} [args.tbiPath]
370
+ *
371
+ * @param {filehandle} [args.tbiFilehandle]
372
+ *
373
+ * @param {string} [args.csiPath]
374
+ *
375
+ * @param {filehandle} [args.csiFilehandle]
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
379
+ *
380
+ * @param {function} [args.renameRefSeqs] optional function with sig `string
381
+ * => string` to transform reference sequence names for the purpose of
382
+ * indexing and querying. note that the data that is returned is not altered,
383
+ * just the names of the reference sequences that are used for querying.
384
+ */
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 }) {
386
+ if (t)
387
+ this.filehandle = t;
388
+ else if (e)
389
+ this.filehandle = new B(e);
390
+ else if (n)
391
+ this.filehandle = new A(n);
392
+ else
393
+ throw new TypeError("must provide either filehandle or path");
394
+ if (r)
395
+ this.index = new k({
396
+ filehandle: r,
397
+ renameRefSeqs: c
398
+ });
399
+ else if (l)
400
+ this.index = new M({
401
+ filehandle: l,
402
+ renameRefSeqs: c
403
+ });
404
+ else if (i)
405
+ this.index = new k({
406
+ filehandle: new B(i),
407
+ renameRefSeqs: c
408
+ });
409
+ else if (s)
410
+ this.index = new M({
411
+ filehandle: new B(s),
412
+ renameRefSeqs: c
413
+ });
414
+ else if (e)
415
+ this.index = new k({
416
+ filehandle: new B(`${e}.tbi`),
417
+ renameRefSeqs: c
418
+ });
419
+ else if (d)
420
+ this.index = new M({
421
+ filehandle: new A(d)
422
+ });
423
+ else if (a)
424
+ this.index = new k({
425
+ filehandle: new A(a)
426
+ });
427
+ else if (n)
428
+ this.index = new k({
429
+ filehandle: new A(`${n}.tbi`)
430
+ });
431
+ else
432
+ 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
+ });
437
+ }
438
+ /**
439
+ * @param refName name of the reference sequence
440
+ *
441
+ * @param start start of the region (in 0-based half-open coordinates)
442
+ *
443
+ * @param end end of the region (in 0-based half-open coordinates)
444
+ *
445
+ * @param opts callback called for each line in the region. can also pass a
446
+ * object param containing obj.lineCallback, obj.signal, etc
447
+ *
448
+ * @returns promise that is resolved when the whole read is finished,
449
+ * rejected on error
450
+ */
451
+ 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))
459
+ throw new TypeError("invalid start and end coordinates. start must be less than or equal to end");
460
+ if (u === c)
461
+ 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();
476
+ if (x) {
477
+ for (; h + w.minv.dataPosition >= x[g++]; )
478
+ ;
479
+ g--;
480
+ }
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)
485
+ d(
486
+ S.trim(),
487
+ // cpositions[pos] refers to actual file offset of a bgzip block boundaries
488
+ //
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
491
+ //
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
496
+ );
497
+ else if (E !== void 0 && E >= c)
498
+ return;
499
+ this.yieldTime && I - Date.now() > this.yieldTime && (I = Date.now(), L(r), await oe(1)), h = C + 1;
500
+ }
501
+ }
502
+ }
503
+ async getMetadata(e = {}) {
504
+ return this.index.getMetadata(e);
505
+ }
506
+ /**
507
+ * get a buffer containing the "header" region of the file, which are the
508
+ * bytes up to the first non-meta line
509
+ */
510
+ async getHeaderBuffer(e = {}) {
511
+ 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);
514
+ 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);
520
+ }
521
+ return s;
522
+ }
523
+ /**
524
+ * get a string containing the "header" region of the file, is the portion up
525
+ * to the first non-meta line
526
+ *
527
+ * @returns {Promise} for a string
528
+ */
529
+ async getHeader(e = {}) {
530
+ return (await this.getHeaderBuffer(e)).toString("utf8");
531
+ }
532
+ /**
533
+ * get an array of reference sequence names, in the order in which they occur
534
+ * in the file. reference sequence renaming is not applied to these names.
535
+ */
536
+ async getReferenceSequenceNames(e = {}) {
537
+ return (await this.getMetadata(e)).refIdToName;
538
+ }
539
+ /**
540
+ * @param {object} metadata metadata object from the parsed index, containing
541
+ * columnNumbers, metaChar, and format
542
+ *
543
+ * @param {string} regionRefName
544
+ *
545
+ * @param {number} regionStart region start coordinate (0-based-half-open)
546
+ *
547
+ * @param {number} regionEnd region end coordinate (0-based-half-open)
548
+ *
549
+ * @param {array[string]} line
550
+ *
551
+ * @returns {object} like `{startCoordinate, overlaps}`. overlaps is boolean,
552
+ * true if line is a data line that overlaps the given region
553
+ */
554
+ checkLine(e, t, n, i, a) {
555
+ const { columnNumbers: r, metaChar: s, coordinateType: d, format: l } = e;
556
+ if (s && a.startsWith(s))
557
+ 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)
577
+ break;
578
+ }
579
+ return { startCoordinate: p, overlaps: !0 };
580
+ }
581
+ _getVcfEnd(e, t, n) {
582
+ 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);
590
+ break;
591
+ }
592
+ r = n[s];
593
+ }
594
+ } else if (a)
595
+ return e + 1;
596
+ return i;
597
+ }
598
+ /**
599
+ * return the approximate number of data lines in the given reference
600
+ * sequence
601
+ *
602
+ * @param refSeq reference sequence name
603
+ *
604
+ * @returns number of data lines present on that reference sequence
605
+ */
606
+ async lineCount(e, t = {}) {
607
+ return this.index.lineCount(e, t);
608
+ }
609
+ 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);
612
+ }
613
+ /**
614
+ * read and uncompress the data in a chunk (composed of one or more
615
+ * contiguous bgzip blocks) of the file
616
+ */
617
+ async readChunk(e, t = {}) {
618
+ const n = await this._readRegion(e.minv.blockPosition, e.fetchedSize(), t);
619
+ return Z(n, e);
620
+ }
621
+ }
622
+ export {
623
+ M as CSI,
624
+ k as TBI,
625
+ ue as TabixIndexedFile
626
+ };