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