@genome-spy/app 0.79.0 → 0.80.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,461 +0,0 @@
1
- import { n as e, r as t } from "./esm-Cx-EbkOj.js";
2
- import { t as n } from "./esm-VvpZ9hsq.js";
3
- import { n as r, r as i } from "./esm-BLPinjwY.js";
4
- import { t as a } from "./AbortablePromiseCache-BTmAcN-t.js";
5
- //#region ../core/node_modules/@gmod/tabix/esm/chunk.js
6
- var o = class {
7
- constructor(e, t, n, r) {
8
- this.minv = e, this.maxv = t, this.bin = n, this._fetchedSize = r;
9
- }
10
- toUniqueString() {
11
- return `${this.minv}..${this.maxv} (bin ${this.bin}, fetchedSize ${this.fetchedSize()})`;
12
- }
13
- toString() {
14
- return this.toUniqueString();
15
- }
16
- compareTo(e) {
17
- return this.minv.compareTo(e.minv) || this.maxv.compareTo(e.maxv) || this.bin - e.bin;
18
- }
19
- fetchedSize() {
20
- return this._fetchedSize === void 0 ? this.maxv.blockPosition + 65536 - this.minv.blockPosition : this._fetchedSize;
21
- }
22
- }, s = class {
23
- constructor({ filehandle: e, renameRefSeqs: t = (e) => e }) {
24
- this.filehandle = e, this.renameRefSeq = t;
25
- }
26
- async getMetadata(e = {}) {
27
- let { indices: t, ...n } = await this.parse(e);
28
- return n;
29
- }
30
- _findFirstData(e, t) {
31
- return e ? e.compareTo(t) > 0 ? t : e : t;
32
- }
33
- async parse(e = {}) {
34
- return this.parseP ||= this._parse(e).catch((e) => {
35
- throw this.parseP = void 0, e;
36
- }), this.parseP;
37
- }
38
- async hasRefSeq(e, t = {}) {
39
- return !!(await this.parse(t)).indices[e]?.binIndex;
40
- }
41
- _parseNameBytes(e) {
42
- let t = 0, n = 0, r = [], i = {}, a = new TextDecoder("utf8");
43
- for (let o = 0; o < e.length; o += 1) if (!e[o]) {
44
- if (n < o) {
45
- let s = this.renameRefSeq(a.decode(e.subarray(n, o)));
46
- r[t] = s, i[s] = t;
47
- }
48
- n = o + 1, t += 1;
49
- }
50
- return {
51
- refNameToId: i,
52
- refIdToName: r
53
- };
54
- }
55
- }, c = 65536, l = c * c;
56
- function u(e, t = 0) {
57
- let n = e[t] | e[t + 1] << 8 | e[t + 2] << 16 | e[t + 3] << 24;
58
- return ((e[t + 4] | e[t + 5] << 8 | e[t + 6] << 16 | e[t + 7] << 24) >>> 0) * l + (n >>> 0);
59
- }
60
- //#endregion
61
- //#region ../core/node_modules/@gmod/tabix/esm/util.js
62
- function d(e, t) {
63
- return t.minv.blockPosition - e.maxv.blockPosition < 65e3 && t.maxv.blockPosition - e.minv.blockPosition < 5e6;
64
- }
65
- function f(e, t) {
66
- let n = [], r;
67
- if (e.length === 0) return e;
68
- e.sort(function(e, t) {
69
- let n = e.minv.blockPosition - t.minv.blockPosition;
70
- return n === 0 ? e.minv.dataPosition - t.minv.dataPosition : n;
71
- });
72
- for (let i of e) (!t || i.maxv.compareTo(t) > 0) && (r === void 0 ? (n.push(i), r = i) : d(r, i) ? i.maxv.compareTo(r.maxv) > 0 && (r.maxv = i.maxv) : (n.push(i), r = i));
73
- return n;
74
- }
75
- //#endregion
76
- //#region ../core/node_modules/@gmod/tabix/esm/virtualOffset.js
77
- var p = class {
78
- constructor(e, t) {
79
- this.blockPosition = e, this.dataPosition = t;
80
- }
81
- toString() {
82
- return `${this.blockPosition}:${this.dataPosition}`;
83
- }
84
- compareTo(e) {
85
- return this.blockPosition - e.blockPosition || this.dataPosition - e.dataPosition;
86
- }
87
- };
88
- function m(e, t = 0) {
89
- return new p(e[t + 7] * 1099511627776 + e[t + 6] * 4294967296 + e[t + 5] * 16777216 + e[t + 4] * 65536 + e[t + 3] * 256 + e[t + 2], e[t + 1] << 8 | e[t]);
90
- }
91
- //#endregion
92
- //#region ../core/node_modules/@gmod/tabix/esm/csi.js
93
- var h = 21582659, g = 38359875, _ = {
94
- 0: "generic",
95
- 1: "SAM",
96
- 2: "VCF"
97
- };
98
- function v(e, t) {
99
- return e * 2 ** t;
100
- }
101
- function y(e, t) {
102
- return Math.floor(e / 2 ** t);
103
- }
104
- var b = class extends s {
105
- constructor(e) {
106
- super(e), this.maxBinNumber = 0, this.depth = 0, this.minShift = 0;
107
- }
108
- async lineCount(e, t = {}) {
109
- let n = await this.parse(t), r = n.refNameToId[e];
110
- if (r === void 0 || !n.indices[r]) return -1;
111
- let { stats: i } = n.indices[r];
112
- return i ? i.lineCount : -1;
113
- }
114
- indexCov() {
115
- throw Error("CSI indexes do not support indexcov");
116
- }
117
- parseAuxData(e, t) {
118
- let n = new DataView(e.buffer), r = n.getInt32(t, !0), i = r & 65536 ? "zero-based-half-open" : "1-based-closed", a = _[r & 15];
119
- if (!a) throw Error(`invalid Tabix preset format flags ${r}`);
120
- let o = {
121
- ref: n.getInt32(t + 4, !0),
122
- start: n.getInt32(t + 8, !0),
123
- end: n.getInt32(t + 12, !0)
124
- }, s = n.getInt32(t + 16, !0), c = s ? String.fromCharCode(s) : void 0, l = n.getInt32(t + 20, !0), u = n.getInt32(t + 24, !0), { refIdToName: d, refNameToId: f } = this._parseNameBytes(e.subarray(t + 28, t + 28 + u));
125
- return {
126
- refIdToName: d,
127
- refNameToId: f,
128
- skipLines: l,
129
- metaChar: c,
130
- columnNumbers: o,
131
- format: a,
132
- coordinateType: i
133
- };
134
- }
135
- async _parse(t = {}) {
136
- let n = await e(await this.filehandle.readFile(t)), r = new DataView(n.buffer), i;
137
- if (r.getUint32(0, !0) === h) i = 1;
138
- else if (r.getUint32(0, !0) === g) i = 2;
139
- else throw Error("Not a CSI file");
140
- this.minShift = r.getInt32(4, !0), this.depth = r.getInt32(8, !0), this.maxBinNumber = ((1 << (this.depth + 1) * 3) - 1) / 7;
141
- let a = 2 ** (this.minShift + this.depth * 3), s = r.getInt32(12, !0), c = s && s >= 30 ? this.parseAuxData(n, 16) : {
142
- refIdToName: [],
143
- refNameToId: {},
144
- metaChar: void 0,
145
- columnNumbers: {
146
- ref: 0,
147
- start: 1,
148
- end: 2
149
- },
150
- coordinateType: "zero-based-half-open",
151
- format: "generic"
152
- }, l = r.getInt32(16 + s, !0), u, d = 16 + s + 4, f = Array(l).fill(0).map(() => {
153
- let e = r.getInt32(d, !0);
154
- d += 4;
155
- let t = {}, i;
156
- for (let a = 0; a < e; a += 1) {
157
- let e = r.getUint32(d, !0);
158
- if (e > this.maxBinNumber) i = this.parsePseudoBin(n, d + 4), d += 48;
159
- else {
160
- let i = m(n, d + 4);
161
- u = this._findFirstData(u, i);
162
- let a = r.getInt32(d + 12, !0);
163
- d += 16;
164
- let s = Array(a);
165
- for (let t = 0; t < a; t += 1) {
166
- let r = m(n, d), i = m(n, d + 8);
167
- d += 16, s[t] = new o(r, i, e);
168
- }
169
- t[e] = s;
170
- }
171
- }
172
- return {
173
- binIndex: t,
174
- stats: i
175
- };
176
- });
177
- return {
178
- ...c,
179
- csi: !0,
180
- refCount: l,
181
- maxBlockSize: 65536,
182
- firstDataLine: u,
183
- csiVersion: i,
184
- indices: f,
185
- depth: this.depth,
186
- maxBinNumber: this.maxBinNumber,
187
- maxRefLength: a
188
- };
189
- }
190
- parsePseudoBin(e, t) {
191
- return { lineCount: u(e, t + 28) };
192
- }
193
- async blocksForRange(e, t, n, r = {}) {
194
- t < 0 && (t = 0);
195
- let i = await this.parse(r), a = i.refNameToId[e];
196
- if (a === void 0) return [];
197
- let s = i.indices[a];
198
- if (!s) return [];
199
- let c = this.reg2bins(t, n), l = [];
200
- for (let [e, t] of c) for (let n = e; n <= t; n++) if (s.binIndex[n]) for (let e of s.binIndex[n]) l.push(new o(e.minv, e.maxv, n));
201
- return f(l, new p(0, 0));
202
- }
203
- reg2bins(e, t) {
204
- --e, e < 1 && (e = 1), t > 2 ** 50 && (t = 2 ** 34), --t;
205
- let n = 0, r = 0, i = this.minShift + this.depth * 3, a = [];
206
- for (; n <= this.depth; i -= 3, r += v(1, n * 3), n += 1) {
207
- let n = r + y(e, i), o = r + y(t, i);
208
- if (o - n + a.length > this.maxBinNumber) throw 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`);
209
- a.push([n, o]);
210
- }
211
- return a;
212
- }
213
- }, x = 21578324, S = 14;
214
- function C(e, t) {
215
- return e += 1, --t, [
216
- [0, 0],
217
- [1 + (e >> 26), 1 + (t >> 26)],
218
- [9 + (e >> 23), 9 + (t >> 23)],
219
- [73 + (e >> 20), 73 + (t >> 20)],
220
- [585 + (e >> 17), 585 + (t >> 17)],
221
- [4681 + (e >> 14), 4681 + (t >> 14)]
222
- ];
223
- }
224
- var w = class extends s {
225
- async lineCount(e, t = {}) {
226
- let n = await this.parse(t), r = n.refNameToId[e];
227
- return r === void 0 || !n.indices[r] ? -1 : n.indices[r].stats?.lineCount ?? -1;
228
- }
229
- async _parse(t = {}) {
230
- let n = await e(await this.filehandle.readFile(t)), r = new DataView(n.buffer);
231
- if (r.getUint32(0, !0) !== x) throw Error("Not a TBI file");
232
- let i = r.getUint32(4, !0), a = r.getUint32(8, !0), s = a & 65536 ? "zero-based-half-open" : "1-based-closed", c = {
233
- 0: "generic",
234
- 1: "SAM",
235
- 2: "VCF"
236
- }[a & 15];
237
- if (!c) throw Error(`invalid Tabix preset format flags ${a}`);
238
- let l = {
239
- ref: r.getInt32(12, !0),
240
- start: r.getInt32(16, !0),
241
- end: r.getInt32(20, !0)
242
- }, u = r.getInt32(24, !0), d = 2 ** 29, f = u ? String.fromCharCode(u) : void 0, p = r.getInt32(28, !0), h = r.getInt32(32, !0), { refNameToId: g, refIdToName: _ } = this._parseNameBytes(n.slice(36, 36 + h)), v = 36 + h, y;
243
- return {
244
- indices: Array(i).fill(0).map(() => {
245
- let e = r.getInt32(v, !0);
246
- v += 4;
247
- let t = {}, i;
248
- for (let a = 0; a < e; a += 1) {
249
- let e = r.getUint32(v, !0);
250
- if (v += 4, e > 37450) throw Error("tabix index contains too many bins, please use a CSI index");
251
- if (e === 37450) {
252
- let e = r.getInt32(v, !0);
253
- v += 4, e === 2 && (i = this.parsePseudoBin(n, v)), v += 16 * e;
254
- } else {
255
- let i = r.getInt32(v, !0);
256
- v += 4;
257
- let a = Array(i);
258
- for (let t = 0; t < i; t += 1) {
259
- let r = m(n, v), i = m(n, v + 8);
260
- v += 16, y = this._findFirstData(y, r), a[t] = new o(r, i, e);
261
- }
262
- t[e] = a;
263
- }
264
- }
265
- let a = r.getInt32(v, !0);
266
- v += 4;
267
- let s = Array(a);
268
- for (let e = 0; e < a; e += 1) s[e] = m(n, v), v += 8, y = this._findFirstData(y, s[e]);
269
- return {
270
- binIndex: t,
271
- linearIndex: s,
272
- stats: i
273
- };
274
- }),
275
- metaChar: f,
276
- maxBinNumber: 37449,
277
- maxRefLength: d,
278
- skipLines: p,
279
- firstDataLine: y,
280
- columnNumbers: l,
281
- coordinateType: s,
282
- format: c,
283
- refIdToName: _,
284
- refNameToId: g,
285
- maxBlockSize: 65536
286
- };
287
- }
288
- parsePseudoBin(e, t) {
289
- return { lineCount: u(e, t + 16) };
290
- }
291
- async blocksForRange(e, t, n, r = {}) {
292
- t < 0 && (t = 0);
293
- let i = await this.parse(r), a = i.refNameToId[e];
294
- if (a === void 0) return [];
295
- let s = i.indices[a];
296
- if (!s) return [];
297
- (s.linearIndex.length > 0 ? s.linearIndex[t >> S >= s.linearIndex.length ? s.linearIndex.length - 1 : t >> S] : new p(0, 0)) || console.warn("querying outside of possible tabix range");
298
- let c = C(t, n), l = [];
299
- for (let [e, t] of c) for (let n = e; n <= t; n++) if (s.binIndex[n]) for (let e of s.binIndex[n]) l.push(new o(e.minv, e.maxv, n));
300
- let u = s.linearIndex.length, d, m = Math.min(t >> 14, u - 1), h = Math.min(n >> 14, u - 1);
301
- for (let e = m; e <= h; ++e) {
302
- let t = s.linearIndex[e];
303
- t && (!d || t.compareTo(d) < 0) && (d = t);
304
- }
305
- return f(l, d);
306
- }
307
- }, T = class {
308
- constructor({ path: e, filehandle: t, url: o, tbiPath: s, tbiUrl: c, tbiFilehandle: l, csiPath: u, csiUrl: d, csiFilehandle: f, renameRefSeqs: p, chunkCacheSize: m = 5 * 2 ** 20 }) {
309
- this.cache = new n({ maxSize: 1e3 });
310
- let h = p ?? ((e) => e);
311
- if (t) this.filehandle = t;
312
- else if (e) this.filehandle = new r(e);
313
- else if (o) this.filehandle = new i(o);
314
- else throw TypeError("must provide either filehandle or path");
315
- if (l) this.index = new w({
316
- filehandle: l,
317
- renameRefSeqs: h
318
- });
319
- else if (f) this.index = new b({
320
- filehandle: f,
321
- renameRefSeqs: h
322
- });
323
- else if (s) this.index = new w({
324
- filehandle: new r(s),
325
- renameRefSeqs: h
326
- });
327
- else if (u) this.index = new b({
328
- filehandle: new r(u),
329
- renameRefSeqs: h
330
- });
331
- else if (e) this.index = new w({
332
- filehandle: new r(`${e}.tbi`),
333
- renameRefSeqs: h
334
- });
335
- else if (d) this.index = new b({ filehandle: new i(d) });
336
- else if (c) this.index = new w({ filehandle: new i(c) });
337
- else if (o) this.index = new w({ filehandle: new i(`${o}.tbi`) });
338
- else throw TypeError("must provide one of tbiFilehandle, tbiPath, csiFilehandle, csiPath, tbiUrl, csiUrl");
339
- this.renameRefSeq = h, this.hasCustomRenameRefSeq = p !== void 0, this.chunkCache = new a({
340
- cache: new n({ maxSize: Math.floor(m / 65536) }),
341
- fill: (e, t) => this.readChunk(e, { signal: t })
342
- });
343
- }
344
- calculateFileOffset(e, t, n, r, i) {
345
- return e[n] * 256 + (r - t[n]) + i + 1;
346
- }
347
- async getLines(e, t, n, r) {
348
- let i, a = {}, o;
349
- typeof r == "function" ? o = r : (a = r, o = r.lineCallback, i = r.signal);
350
- let s = await this.index.getMetadata(a), c = t ?? 0, l = n ?? s.maxRefLength;
351
- if (!(c <= l)) throw TypeError("invalid start and end coordinates. start must be less than or equal to end");
352
- if (c === l) return;
353
- let u = await this.index.blocksForRange(e, c, l, a), d = new TextDecoder("utf8"), f = s.format === "VCF", p = {
354
- ref: s.columnNumbers.ref || 0,
355
- start: s.columnNumbers.start || 0,
356
- end: f ? 8 : s.columnNumbers.end || 0
357
- }, m = Math.max(p.ref, p.start, p.end), h = s.metaChar?.charCodeAt(0), g = s.coordinateType === "1-based-closed" ? -1 : 0, _ = !this.hasCustomRenameRefSeq;
358
- for (let t of u) {
359
- let { buffer: n, cpositions: r, dpositions: a } = await this.chunkCache.get(t.toString(), t, i), s = 0, u = 0, v = d.decode(n);
360
- if (n.length == v.length) for (; s < v.length;) {
361
- let n = v.indexOf("\n", s);
362
- if (n === -1) break;
363
- let i = v.slice(s, n);
364
- if (a) {
365
- let e = s + t.minv.dataPosition;
366
- for (; u < a.length && e >= a[u];) u++;
367
- }
368
- let d = this.checkLine(e, c, l, i, p.ref, p.start, p.end, m, h, g, f, _);
369
- if (d === null) return;
370
- d !== void 0 && o(i, this.calculateFileOffset(r, a, u, s, t.minv.dataPosition), d.start, d.end), s = n + 1;
371
- }
372
- else for (; s < n.length;) {
373
- let i = n.indexOf(10, s);
374
- if (i === -1) break;
375
- let v = n.slice(s, i), y = d.decode(v);
376
- if (a) {
377
- let e = s + t.minv.dataPosition;
378
- for (; u < a.length && e >= a[u];) u++;
379
- }
380
- let b = this.checkLine(e, c, l, y, p.ref, p.start, p.end, m, h, g, f, _);
381
- if (b === null) return;
382
- b !== void 0 && o(y, this.calculateFileOffset(r, a, u, s, t.minv.dataPosition), b.start, b.end), s = i + 1;
383
- }
384
- }
385
- }
386
- async getMetadata(e = {}) {
387
- return this.index.getMetadata(e);
388
- }
389
- async getHeaderBuffer(t = {}) {
390
- let { firstDataLine: n, metaChar: r, maxBlockSize: i } = await this.getMetadata(t), a = (n?.blockPosition || 0) + i, o = await e(await this.filehandle.read(a, 0, t));
391
- if (r) {
392
- let e = -1, t = r.charCodeAt(0);
393
- for (let n = 0, r = o.length; n < r; n++) {
394
- let r = o[n];
395
- if (n === e + 1 && r !== t) break;
396
- r === 10 && (e = n);
397
- }
398
- return o.subarray(0, e + 1);
399
- }
400
- return o;
401
- }
402
- async getHeader(e = {}) {
403
- let t = new TextDecoder("utf8"), n = await this.getHeaderBuffer(e);
404
- return t.decode(n);
405
- }
406
- async getReferenceSequenceNames(e = {}) {
407
- return (await this.getMetadata(e)).refIdToName;
408
- }
409
- checkLine(e, t, n, r, i, a, o, s, c, l, u, d) {
410
- if (c !== void 0 && r.charCodeAt(0) === c) return;
411
- if (r.length < 500) {
412
- let s = r.split(" "), c = s[i - 1];
413
- if (!(d ? c === e : this.renameRefSeq(c) === e)) return;
414
- let f = +s[a - 1] + l;
415
- if (f >= n) return null;
416
- let p;
417
- return p = o === 0 || o === a ? f + 1 : u ? this._getVcfEnd(f, s[3], s[o - 1]) : +s[o - 1], p <= t ? void 0 : {
418
- start: f,
419
- end: p
420
- };
421
- }
422
- let f = -1, p = [-1];
423
- for (let e = 0; e < s; e++) {
424
- let e = r.indexOf(" ", f + 1);
425
- if (e === -1) {
426
- p.push(r.length);
427
- break;
428
- }
429
- p.push(e), f = e;
430
- }
431
- let m = r.slice(p[i - 1] + 1, p[i]);
432
- if (!(d ? m === e : this.renameRefSeq(m) === e)) return;
433
- let h = +r.slice(p[a - 1] + 1, p[a]) + l;
434
- if (h >= n) return null;
435
- let g;
436
- if (g = o === 0 || o === a ? h + 1 : u ? this._getVcfEnd(h, r.slice(p[3] + 1, p[4]), r.slice(p[o - 1] + 1, p[o])) : +r.slice(p[o - 1] + 1, p[o]), !(g <= t)) return {
437
- start: h,
438
- end: g
439
- };
440
- }
441
- _getVcfEnd(e, t, n) {
442
- let r = e + t.length;
443
- if (n.includes("SVTYPE=TRA")) return e + 1;
444
- if (n[0] !== ".") {
445
- let e = n.indexOf("END=");
446
- if (e !== -1 && (e === 0 || n[e - 1] === ";")) {
447
- let t = e + 4, i = n.indexOf(";", t);
448
- i === -1 && (i = n.length), r = Number.parseInt(n.slice(t, i), 10);
449
- }
450
- }
451
- return r;
452
- }
453
- async lineCount(e, t = {}) {
454
- return this.index.lineCount(e, t);
455
- }
456
- async readChunk(e, n = {}) {
457
- return t(await this.filehandle.read(e.fetchedSize(), e.minv.blockPosition, n), e, this.cache);
458
- }
459
- };
460
- //#endregion
461
- export { b as CSI, w as TBI, T as TabixIndexedFile };