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