@genome-spy/app 0.73.0 → 0.74.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/AbortablePromiseCache-3gHJdF3E.js +96 -0
- package/dist/blosc-oa0DlI6G.js +692 -0
- package/dist/browser-Dvlo92rx.js +126 -0
- package/dist/chunk-CPXzm0be.js +11 -0
- package/dist/chunk-INHXZS53-fPMmEwMt.js +13 -0
- package/dist/esm-B8-vSu-c.js +369 -0
- package/dist/esm-BDFRLEuD.js +1248 -0
- package/dist/esm-BygJiwh0.js +573 -0
- package/dist/esm-CGX-qz1d.js +155 -0
- package/dist/esm-Cmo4qEPr.js +1015 -0
- package/dist/esm-CuMSzCHy.js +298 -0
- package/dist/esm-D-WfYOx7.js +461 -0
- package/dist/esm-DCCYNvaz.js +1426 -0
- package/dist/esm-n0auOe11.js +121 -0
- package/dist/index.es.js +41039 -52718
- package/dist/index.js +1088 -1095
- package/dist/lz4-jZ0zyLBa.js +626 -0
- package/dist/parquetRead-CJe1UPsz.js +1609 -0
- package/dist/schema.json +8821 -2763
- package/dist/style.css +2 -1
- package/dist/zstd-C6ksIG9r.js +583 -0
- package/package.json +14 -5
- package/dist/AbortablePromiseCache-Dj0vzLnp.js +0 -149
- package/dist/blosc-D1xNXZJs.js +0 -719
- package/dist/browser-0iNU5Wit.js +0 -138
- package/dist/chunk-INHXZS53-DiyuLb3Z.js +0 -14
- package/dist/index-BUsSzlHg.js +0 -1771
- package/dist/index-BYsZN7b0.js +0 -1597
- package/dist/index-C7wOh6y1.js +0 -657
- package/dist/index-CRaQAuki.js +0 -326
- package/dist/index-D9v1PCj9.js +0 -507
- package/dist/index-GDOuv_D5.js +0 -266
- package/dist/index-Gt44EOIH.js +0 -628
- package/dist/inflate-GtwLkvSP.js +0 -1048
- package/dist/lz4-1Ws5oVWR.js +0 -640
- package/dist/parquetRead-BnAGCa4_.js +0 -1663
- package/dist/unzip-Bac01w6X.js +0 -1492
- package/dist/zstd-C4EcZnjq.js +0 -603
package/dist/index-Gt44EOIH.js
DELETED
|
@@ -1,628 +0,0 @@
|
|
|
1
|
-
import { A as J } from "./AbortablePromiseCache-Dj0vzLnp.js";
|
|
2
|
-
import { u as q, Q as U, a as K } from "./unzip-Bac01w6X.js";
|
|
3
|
-
import { LocalFile as R, RemoteFile as F } from "./browser-0iNU5Wit.js";
|
|
4
|
-
class L {
|
|
5
|
-
constructor(e, t, n, i) {
|
|
6
|
-
this.minv = e, this.maxv = t, this.bin = n, this._fetchedSize = i;
|
|
7
|
-
}
|
|
8
|
-
toUniqueString() {
|
|
9
|
-
return `${this.minv}..${this.maxv} (bin ${this.bin}, fetchedSize ${this.fetchedSize()})`;
|
|
10
|
-
}
|
|
11
|
-
toString() {
|
|
12
|
-
return this.toUniqueString();
|
|
13
|
-
}
|
|
14
|
-
compareTo(e) {
|
|
15
|
-
return this.minv.compareTo(e.minv) || this.maxv.compareTo(e.maxv) || this.bin - e.bin;
|
|
16
|
-
}
|
|
17
|
-
fetchedSize() {
|
|
18
|
-
return this._fetchedSize !== void 0 ? this._fetchedSize : this.maxv.blockPosition + 65536 - this.minv.blockPosition;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
class j {
|
|
22
|
-
constructor({ filehandle: e, renameRefSeqs: t = (n) => n }) {
|
|
23
|
-
this.filehandle = e, this.renameRefSeq = t;
|
|
24
|
-
}
|
|
25
|
-
async getMetadata(e = {}) {
|
|
26
|
-
const { indices: t, ...n } = await this.parse(e);
|
|
27
|
-
return n;
|
|
28
|
-
}
|
|
29
|
-
_findFirstData(e, t) {
|
|
30
|
-
return e ? e.compareTo(t) > 0 ? t : e : t;
|
|
31
|
-
}
|
|
32
|
-
async parse(e = {}) {
|
|
33
|
-
return this.parseP || (this.parseP = this._parse(e).catch((t) => {
|
|
34
|
-
throw this.parseP = void 0, t;
|
|
35
|
-
})), this.parseP;
|
|
36
|
-
}
|
|
37
|
-
async hasRefSeq(e, t = {}) {
|
|
38
|
-
return !!(await this.parse(t)).indices[e]?.binIndex;
|
|
39
|
-
}
|
|
40
|
-
_parseNameBytes(e) {
|
|
41
|
-
let t = 0, n = 0;
|
|
42
|
-
const i = [], o = {}, r = new TextDecoder("utf8");
|
|
43
|
-
for (let s = 0; s < e.length; s += 1)
|
|
44
|
-
if (!e[s]) {
|
|
45
|
-
if (n < s) {
|
|
46
|
-
const c = this.renameRefSeq(r.decode(e.subarray(n, s)));
|
|
47
|
-
i[t] = c, o[c] = t;
|
|
48
|
-
}
|
|
49
|
-
n = s + 1, t += 1;
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
refNameToId: o,
|
|
53
|
-
refIdToName: i
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const H = 65536, Z = H * H;
|
|
58
|
-
function Q(a, e = 0) {
|
|
59
|
-
const t = a[e] | a[e + 1] << 8 | a[e + 2] << 16 | a[e + 3] << 24;
|
|
60
|
-
return ((a[e + 4] | a[e + 5] << 8 | a[e + 6] << 16 | a[e + 7] << 24) >>> 0) * Z + (t >>> 0);
|
|
61
|
-
}
|
|
62
|
-
function ee(a, e) {
|
|
63
|
-
return e.minv.blockPosition - a.maxv.blockPosition < 65e3 && e.maxv.blockPosition - a.minv.blockPosition < 5e6;
|
|
64
|
-
}
|
|
65
|
-
function X(a, e) {
|
|
66
|
-
const t = [];
|
|
67
|
-
let n;
|
|
68
|
-
if (a.length === 0)
|
|
69
|
-
return a;
|
|
70
|
-
a.sort(function(i, o) {
|
|
71
|
-
const r = i.minv.blockPosition - o.minv.blockPosition;
|
|
72
|
-
return r === 0 ? i.minv.dataPosition - o.minv.dataPosition : r;
|
|
73
|
-
});
|
|
74
|
-
for (const i of a)
|
|
75
|
-
(!e || i.maxv.compareTo(e) > 0) && (n === void 0 ? (t.push(i), n = i) : ee(n, i) ? i.maxv.compareTo(n.maxv) > 0 && (n.maxv = i.maxv) : (t.push(i), n = i));
|
|
76
|
-
return t;
|
|
77
|
-
}
|
|
78
|
-
class E {
|
|
79
|
-
constructor(e, t) {
|
|
80
|
-
this.blockPosition = e, this.dataPosition = t;
|
|
81
|
-
}
|
|
82
|
-
toString() {
|
|
83
|
-
return `${this.blockPosition}:${this.dataPosition}`;
|
|
84
|
-
}
|
|
85
|
-
compareTo(e) {
|
|
86
|
-
return this.blockPosition - e.blockPosition || this.dataPosition - e.dataPosition;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function A(a, e = 0) {
|
|
90
|
-
return new E(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]);
|
|
91
|
-
}
|
|
92
|
-
const te = 21582659, ne = 38359875, ie = {
|
|
93
|
-
0: "generic",
|
|
94
|
-
1: "SAM",
|
|
95
|
-
2: "VCF"
|
|
96
|
-
};
|
|
97
|
-
function se(a, e) {
|
|
98
|
-
return a * 2 ** e;
|
|
99
|
-
}
|
|
100
|
-
function W(a, e) {
|
|
101
|
-
return Math.floor(a / 2 ** e);
|
|
102
|
-
}
|
|
103
|
-
class V extends j {
|
|
104
|
-
constructor(e) {
|
|
105
|
-
super(e), this.maxBinNumber = 0, this.depth = 0, this.minShift = 0;
|
|
106
|
-
}
|
|
107
|
-
async lineCount(e, t = {}) {
|
|
108
|
-
const n = await this.parse(t), i = n.refNameToId[e];
|
|
109
|
-
if (i === void 0 || !n.indices[i])
|
|
110
|
-
return -1;
|
|
111
|
-
const { stats: r } = n.indices[i];
|
|
112
|
-
return r ? r.lineCount : -1;
|
|
113
|
-
}
|
|
114
|
-
indexCov() {
|
|
115
|
-
throw new Error("CSI indexes do not support indexcov");
|
|
116
|
-
}
|
|
117
|
-
parseAuxData(e, t) {
|
|
118
|
-
const n = new DataView(e.buffer), i = n.getInt32(t, !0), o = i & 65536 ? "zero-based-half-open" : "1-based-closed", r = ie[i & 15];
|
|
119
|
-
if (!r)
|
|
120
|
-
throw new Error(`invalid Tabix preset format flags ${i}`);
|
|
121
|
-
const s = {
|
|
122
|
-
ref: n.getInt32(t + 4, !0),
|
|
123
|
-
start: n.getInt32(t + 8, !0),
|
|
124
|
-
end: n.getInt32(t + 12, !0)
|
|
125
|
-
}, c = n.getInt32(t + 16, !0), u = c ? String.fromCharCode(c) : void 0, f = n.getInt32(t + 20, !0), m = n.getInt32(t + 24, !0), { refIdToName: d, refNameToId: l } = this._parseNameBytes(e.subarray(t + 28, t + 28 + m));
|
|
126
|
-
return {
|
|
127
|
-
refIdToName: d,
|
|
128
|
-
refNameToId: l,
|
|
129
|
-
skipLines: f,
|
|
130
|
-
metaChar: u,
|
|
131
|
-
columnNumbers: s,
|
|
132
|
-
format: r,
|
|
133
|
-
coordinateType: o
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
async _parse(e = {}) {
|
|
137
|
-
const t = await q(await this.filehandle.readFile(e)), n = new DataView(t.buffer);
|
|
138
|
-
let i;
|
|
139
|
-
if (n.getUint32(0, !0) === te)
|
|
140
|
-
i = 1;
|
|
141
|
-
else if (n.getUint32(0, !0) === ne)
|
|
142
|
-
i = 2;
|
|
143
|
-
else
|
|
144
|
-
throw new Error("Not a CSI file");
|
|
145
|
-
this.minShift = n.getInt32(4, !0), this.depth = n.getInt32(8, !0), this.maxBinNumber = ((1 << (this.depth + 1) * 3) - 1) / 7;
|
|
146
|
-
const o = 2 ** (this.minShift + this.depth * 3), r = n.getInt32(12, !0), s = r && r >= 30 ? this.parseAuxData(t, 16) : {
|
|
147
|
-
refIdToName: [],
|
|
148
|
-
refNameToId: {},
|
|
149
|
-
metaChar: void 0,
|
|
150
|
-
columnNumbers: { ref: 0, start: 1, end: 2 },
|
|
151
|
-
coordinateType: "zero-based-half-open",
|
|
152
|
-
format: "generic"
|
|
153
|
-
}, c = n.getInt32(16 + r, !0);
|
|
154
|
-
let u, f = 16 + r + 4;
|
|
155
|
-
const m = new Array(c).fill(0).map(() => {
|
|
156
|
-
const d = n.getInt32(f, !0);
|
|
157
|
-
f += 4;
|
|
158
|
-
const l = {};
|
|
159
|
-
let h;
|
|
160
|
-
for (let S = 0; S < d; S += 1) {
|
|
161
|
-
const C = n.getUint32(f, !0);
|
|
162
|
-
if (C > this.maxBinNumber)
|
|
163
|
-
h = this.parsePseudoBin(t, f + 4), f += 48;
|
|
164
|
-
else {
|
|
165
|
-
const I = A(t, f + 4);
|
|
166
|
-
u = this._findFirstData(u, I);
|
|
167
|
-
const k = n.getInt32(f + 12, !0);
|
|
168
|
-
f += 16;
|
|
169
|
-
const w = new Array(k);
|
|
170
|
-
for (let b = 0; b < k; b += 1) {
|
|
171
|
-
const x = A(t, f), g = A(t, f + 8);
|
|
172
|
-
f += 16, w[b] = new L(x, g, C);
|
|
173
|
-
}
|
|
174
|
-
l[C] = w;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return { binIndex: l, stats: h };
|
|
178
|
-
});
|
|
179
|
-
return {
|
|
180
|
-
...s,
|
|
181
|
-
csi: !0,
|
|
182
|
-
refCount: c,
|
|
183
|
-
maxBlockSize: 65536,
|
|
184
|
-
firstDataLine: u,
|
|
185
|
-
csiVersion: i,
|
|
186
|
-
indices: m,
|
|
187
|
-
depth: this.depth,
|
|
188
|
-
maxBinNumber: this.maxBinNumber,
|
|
189
|
-
maxRefLength: o
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
parsePseudoBin(e, t) {
|
|
193
|
-
return {
|
|
194
|
-
lineCount: Q(e, t + 28)
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
async blocksForRange(e, t, n, i = {}) {
|
|
198
|
-
t < 0 && (t = 0);
|
|
199
|
-
const o = await this.parse(i), r = o.refNameToId[e];
|
|
200
|
-
if (r === void 0)
|
|
201
|
-
return [];
|
|
202
|
-
const s = o.indices[r];
|
|
203
|
-
if (!s)
|
|
204
|
-
return [];
|
|
205
|
-
const c = this.reg2bins(t, n), u = [];
|
|
206
|
-
for (const [f, m] of c)
|
|
207
|
-
for (let d = f; d <= m; d++)
|
|
208
|
-
if (s.binIndex[d])
|
|
209
|
-
for (const l of s.binIndex[d])
|
|
210
|
-
u.push(new L(l.minv, l.maxv, d));
|
|
211
|
-
return X(u, new E(0, 0));
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* calculate the list of bins that may overlap with region [beg,end) (zero-based half-open)
|
|
215
|
-
*/
|
|
216
|
-
reg2bins(e, t) {
|
|
217
|
-
e -= 1, e < 1 && (e = 1), t > 2 ** 50 && (t = 2 ** 34), t -= 1;
|
|
218
|
-
let n = 0, i = 0, o = this.minShift + this.depth * 3;
|
|
219
|
-
const r = [];
|
|
220
|
-
for (; n <= this.depth; o -= 3, i += se(1, n * 3), n += 1) {
|
|
221
|
-
const s = i + W(e, o), c = i + W(t, o);
|
|
222
|
-
if (c - s + r.length > this.maxBinNumber)
|
|
223
|
-
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`);
|
|
224
|
-
r.push([s, c]);
|
|
225
|
-
}
|
|
226
|
-
return r;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
const re = 21578324, G = 14;
|
|
230
|
-
function ae(a, e) {
|
|
231
|
-
return a += 1, e -= 1, [
|
|
232
|
-
[0, 0],
|
|
233
|
-
[1 + (a >> 26), 1 + (e >> 26)],
|
|
234
|
-
[9 + (a >> 23), 9 + (e >> 23)],
|
|
235
|
-
[73 + (a >> 20), 73 + (e >> 20)],
|
|
236
|
-
[585 + (a >> 17), 585 + (e >> 17)],
|
|
237
|
-
[4681 + (a >> 14), 4681 + (e >> 14)]
|
|
238
|
-
];
|
|
239
|
-
}
|
|
240
|
-
class D extends j {
|
|
241
|
-
async lineCount(e, t = {}) {
|
|
242
|
-
const n = await this.parse(t), i = n.refNameToId[e];
|
|
243
|
-
return i === void 0 || !n.indices[i] ? -1 : n.indices[i].stats?.lineCount ?? -1;
|
|
244
|
-
}
|
|
245
|
-
// fetch and parse the index
|
|
246
|
-
async _parse(e = {}) {
|
|
247
|
-
const t = await this.filehandle.readFile(e), n = await q(t), i = new DataView(n.buffer);
|
|
248
|
-
if (i.getUint32(0, !0) !== re)
|
|
249
|
-
throw new Error("Not a TBI file");
|
|
250
|
-
const r = i.getUint32(4, !0), s = i.getUint32(8, !0), c = s & 65536 ? "zero-based-half-open" : "1-based-closed", f = {
|
|
251
|
-
0: "generic",
|
|
252
|
-
1: "SAM",
|
|
253
|
-
2: "VCF"
|
|
254
|
-
}[s & 15];
|
|
255
|
-
if (!f)
|
|
256
|
-
throw new Error(`invalid Tabix preset format flags ${s}`);
|
|
257
|
-
const m = {
|
|
258
|
-
ref: i.getInt32(12, !0),
|
|
259
|
-
start: i.getInt32(16, !0),
|
|
260
|
-
end: i.getInt32(20, !0)
|
|
261
|
-
}, d = i.getInt32(24, !0), l = 5, h = ((1 << (l + 1) * 3) - 1) / 7, S = 2 ** (14 + l * 3), C = d ? String.fromCharCode(d) : void 0, I = i.getInt32(28, !0), k = i.getInt32(32, !0), { refNameToId: w, refIdToName: b } = this._parseNameBytes(n.slice(36, 36 + k));
|
|
262
|
-
let x = 36 + k, g;
|
|
263
|
-
return {
|
|
264
|
-
indices: new Array(r).fill(0).map(() => {
|
|
265
|
-
const y = i.getInt32(x, !0);
|
|
266
|
-
x += 4;
|
|
267
|
-
const B = {};
|
|
268
|
-
let M;
|
|
269
|
-
for (let T = 0; T < y; T += 1) {
|
|
270
|
-
const v = i.getUint32(x, !0);
|
|
271
|
-
if (x += 4, v > h + 1)
|
|
272
|
-
throw new Error("tabix index contains too many bins, please use a CSI index");
|
|
273
|
-
if (v === h + 1) {
|
|
274
|
-
const _ = i.getInt32(x, !0);
|
|
275
|
-
x += 4, _ === 2 && (M = this.parsePseudoBin(n, x)), x += 16 * _;
|
|
276
|
-
} else {
|
|
277
|
-
const _ = i.getInt32(x, !0);
|
|
278
|
-
x += 4;
|
|
279
|
-
const O = new Array(_);
|
|
280
|
-
for (let z = 0; z < _; z += 1) {
|
|
281
|
-
const $ = A(n, x), Y = A(n, x + 8);
|
|
282
|
-
x += 16, g = this._findFirstData(g, $), O[z] = new L($, Y, v);
|
|
283
|
-
}
|
|
284
|
-
B[v] = O;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
const P = i.getInt32(x, !0);
|
|
288
|
-
x += 4;
|
|
289
|
-
const N = new Array(P);
|
|
290
|
-
for (let T = 0; T < P; T += 1)
|
|
291
|
-
N[T] = A(n, x), x += 8, g = this._findFirstData(g, N[T]);
|
|
292
|
-
return {
|
|
293
|
-
binIndex: B,
|
|
294
|
-
linearIndex: N,
|
|
295
|
-
stats: M
|
|
296
|
-
};
|
|
297
|
-
}),
|
|
298
|
-
metaChar: C,
|
|
299
|
-
maxBinNumber: h,
|
|
300
|
-
maxRefLength: S,
|
|
301
|
-
skipLines: I,
|
|
302
|
-
firstDataLine: g,
|
|
303
|
-
columnNumbers: m,
|
|
304
|
-
coordinateType: c,
|
|
305
|
-
format: f,
|
|
306
|
-
refIdToName: b,
|
|
307
|
-
refNameToId: w,
|
|
308
|
-
maxBlockSize: 65536
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
parsePseudoBin(e, t) {
|
|
312
|
-
return {
|
|
313
|
-
lineCount: Q(e, t + 16)
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
async blocksForRange(e, t, n, i = {}) {
|
|
317
|
-
t < 0 && (t = 0);
|
|
318
|
-
const o = await this.parse(i), r = o.refNameToId[e];
|
|
319
|
-
if (r === void 0)
|
|
320
|
-
return [];
|
|
321
|
-
const s = o.indices[r];
|
|
322
|
-
if (!s)
|
|
323
|
-
return [];
|
|
324
|
-
(s.linearIndex.length > 0 ? s.linearIndex[t >> G >= s.linearIndex.length ? s.linearIndex.length - 1 : t >> G] : new E(0, 0)) || console.warn("querying outside of possible tabix range");
|
|
325
|
-
const u = ae(t, n), f = [];
|
|
326
|
-
for (const [S, C] of u)
|
|
327
|
-
for (let I = S; I <= C; I++)
|
|
328
|
-
if (s.binIndex[I])
|
|
329
|
-
for (const k of s.binIndex[I])
|
|
330
|
-
f.push(new L(k.minv, k.maxv, I));
|
|
331
|
-
const m = s.linearIndex.length;
|
|
332
|
-
let d;
|
|
333
|
-
const l = Math.min(t >> 14, m - 1), h = Math.min(n >> 14, m - 1);
|
|
334
|
-
for (let S = l; S <= h; ++S) {
|
|
335
|
-
const C = s.linearIndex[S];
|
|
336
|
-
C && (!d || C.compareTo(d) < 0) && (d = C);
|
|
337
|
-
}
|
|
338
|
-
return X(f, d);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
class he {
|
|
342
|
-
/**
|
|
343
|
-
* @param {object} args
|
|
344
|
-
*
|
|
345
|
-
* @param {string} [args.path]
|
|
346
|
-
*
|
|
347
|
-
* @param {filehandle} [args.filehandle]
|
|
348
|
-
*
|
|
349
|
-
* @param {string} [args.tbiPath]
|
|
350
|
-
*
|
|
351
|
-
* @param {filehandle} [args.tbiFilehandle]
|
|
352
|
-
*
|
|
353
|
-
* @param {string} [args.csiPath]
|
|
354
|
-
*
|
|
355
|
-
* @param {filehandle} [args.csiFilehandle]
|
|
356
|
-
*
|
|
357
|
-
* @param {url} [args.url]
|
|
358
|
-
*
|
|
359
|
-
* @param {csiUrl} [args.csiUrl]
|
|
360
|
-
*
|
|
361
|
-
* @param {tbiUrl} [args.tbiUrl]
|
|
362
|
-
*
|
|
363
|
-
* @param {function} [args.renameRefSeqs] optional function with sig `string
|
|
364
|
-
* => string` to transform reference sequence names for the purpose of
|
|
365
|
-
* indexing and querying. note that the data that is returned is not altered,
|
|
366
|
-
* just the names of the reference sequences that are used for querying.
|
|
367
|
-
*/
|
|
368
|
-
constructor({ path: e, filehandle: t, url: n, tbiPath: i, tbiUrl: o, tbiFilehandle: r, csiPath: s, csiUrl: c, csiFilehandle: u, renameRefSeqs: f, chunkCacheSize: m = 5 * 2 ** 20 }) {
|
|
369
|
-
this.cache = new U({
|
|
370
|
-
maxSize: 1e3
|
|
371
|
-
});
|
|
372
|
-
const d = f ?? ((l) => l);
|
|
373
|
-
if (t)
|
|
374
|
-
this.filehandle = t;
|
|
375
|
-
else if (e)
|
|
376
|
-
this.filehandle = new R(e);
|
|
377
|
-
else if (n)
|
|
378
|
-
this.filehandle = new F(n);
|
|
379
|
-
else
|
|
380
|
-
throw new TypeError("must provide either filehandle or path");
|
|
381
|
-
if (r)
|
|
382
|
-
this.index = new D({
|
|
383
|
-
filehandle: r,
|
|
384
|
-
renameRefSeqs: d
|
|
385
|
-
});
|
|
386
|
-
else if (u)
|
|
387
|
-
this.index = new V({
|
|
388
|
-
filehandle: u,
|
|
389
|
-
renameRefSeqs: d
|
|
390
|
-
});
|
|
391
|
-
else if (i)
|
|
392
|
-
this.index = new D({
|
|
393
|
-
filehandle: new R(i),
|
|
394
|
-
renameRefSeqs: d
|
|
395
|
-
});
|
|
396
|
-
else if (s)
|
|
397
|
-
this.index = new V({
|
|
398
|
-
filehandle: new R(s),
|
|
399
|
-
renameRefSeqs: d
|
|
400
|
-
});
|
|
401
|
-
else if (e)
|
|
402
|
-
this.index = new D({
|
|
403
|
-
filehandle: new R(`${e}.tbi`),
|
|
404
|
-
renameRefSeqs: d
|
|
405
|
-
});
|
|
406
|
-
else if (c)
|
|
407
|
-
this.index = new V({
|
|
408
|
-
filehandle: new F(c)
|
|
409
|
-
});
|
|
410
|
-
else if (o)
|
|
411
|
-
this.index = new D({
|
|
412
|
-
filehandle: new F(o)
|
|
413
|
-
});
|
|
414
|
-
else if (n)
|
|
415
|
-
this.index = new D({
|
|
416
|
-
filehandle: new F(`${n}.tbi`)
|
|
417
|
-
});
|
|
418
|
-
else
|
|
419
|
-
throw new TypeError("must provide one of tbiFilehandle, tbiPath, csiFilehandle, csiPath, tbiUrl, csiUrl");
|
|
420
|
-
this.renameRefSeq = d, this.hasCustomRenameRefSeq = f !== void 0, this.chunkCache = new J({
|
|
421
|
-
cache: new U({ maxSize: Math.floor(m / 65536) }),
|
|
422
|
-
fill: (l, h) => this.readChunk(l, { signal: h })
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* @param refName name of the reference sequence
|
|
427
|
-
*
|
|
428
|
-
* @param start start of the region (in 0-based half-open coordinates)
|
|
429
|
-
*
|
|
430
|
-
* @param end end of the region (in 0-based half-open coordinates)
|
|
431
|
-
*
|
|
432
|
-
* @param opts callback called for each line in the region. can also pass a
|
|
433
|
-
* object param containing obj.lineCallback, obj.signal, etc
|
|
434
|
-
*
|
|
435
|
-
* @returns promise that is resolved when the whole read is finished,
|
|
436
|
-
* rejected on error
|
|
437
|
-
*/
|
|
438
|
-
calculateFileOffset(e, t, n, i, o) {
|
|
439
|
-
return e[n] * 256 + (i - t[n]) + o + 1;
|
|
440
|
-
}
|
|
441
|
-
async getLines(e, t, n, i) {
|
|
442
|
-
let o, r = {}, s;
|
|
443
|
-
typeof i == "function" ? s = i : (r = i, s = i.lineCallback, o = i.signal);
|
|
444
|
-
const c = await this.index.getMetadata(r), u = t ?? 0, f = n ?? c.maxRefLength;
|
|
445
|
-
if (!(u <= f))
|
|
446
|
-
throw new TypeError("invalid start and end coordinates. start must be less than or equal to end");
|
|
447
|
-
if (u === f)
|
|
448
|
-
return;
|
|
449
|
-
const m = await this.index.blocksForRange(e, u, f, r), d = new TextDecoder("utf8"), l = c.format === "VCF", h = {
|
|
450
|
-
ref: c.columnNumbers.ref || 0,
|
|
451
|
-
start: c.columnNumbers.start || 0,
|
|
452
|
-
end: l ? 8 : c.columnNumbers.end || 0
|
|
453
|
-
}, S = Math.max(h.ref, h.start, h.end), C = c.metaChar?.charCodeAt(0), I = c.coordinateType === "1-based-closed" ? -1 : 0, k = !this.hasCustomRenameRefSeq;
|
|
454
|
-
for (const w of m) {
|
|
455
|
-
const { buffer: b, cpositions: x, dpositions: g } = await this.chunkCache.get(w.toString(), w, o);
|
|
456
|
-
let p = 0, y = 0;
|
|
457
|
-
const B = d.decode(b);
|
|
458
|
-
if (b.length == B.length)
|
|
459
|
-
for (; p < B.length; ) {
|
|
460
|
-
const P = B.indexOf(`
|
|
461
|
-
`, p);
|
|
462
|
-
if (P === -1)
|
|
463
|
-
break;
|
|
464
|
-
const N = B.slice(p, P);
|
|
465
|
-
if (g) {
|
|
466
|
-
const v = p + w.minv.dataPosition;
|
|
467
|
-
for (; y < g.length && v >= g[y]; )
|
|
468
|
-
y++;
|
|
469
|
-
}
|
|
470
|
-
const T = this.checkLine(e, u, f, N, h.ref, h.start, h.end, S, C, I, l, k);
|
|
471
|
-
if (T === null)
|
|
472
|
-
return;
|
|
473
|
-
T !== void 0 && s(N, this.calculateFileOffset(x, g, y, p, w.minv.dataPosition), T.start, T.end), p = P + 1;
|
|
474
|
-
}
|
|
475
|
-
else
|
|
476
|
-
for (; p < b.length; ) {
|
|
477
|
-
const P = b.indexOf(10, p);
|
|
478
|
-
if (P === -1)
|
|
479
|
-
break;
|
|
480
|
-
const N = b.slice(p, P), T = d.decode(N);
|
|
481
|
-
if (g) {
|
|
482
|
-
const _ = p + w.minv.dataPosition;
|
|
483
|
-
for (; y < g.length && _ >= g[y]; )
|
|
484
|
-
y++;
|
|
485
|
-
}
|
|
486
|
-
const v = this.checkLine(e, u, f, T, h.ref, h.start, h.end, S, C, I, l, k);
|
|
487
|
-
if (v === null)
|
|
488
|
-
return;
|
|
489
|
-
v !== void 0 && s(T, this.calculateFileOffset(x, g, y, p, w.minv.dataPosition), v.start, v.end), p = P + 1;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
async getMetadata(e = {}) {
|
|
494
|
-
return this.index.getMetadata(e);
|
|
495
|
-
}
|
|
496
|
-
/**
|
|
497
|
-
* get a buffer containing the "header" region of the file, which are the
|
|
498
|
-
* bytes up to the first non-meta line
|
|
499
|
-
*/
|
|
500
|
-
async getHeaderBuffer(e = {}) {
|
|
501
|
-
const { firstDataLine: t, metaChar: n, maxBlockSize: i } = await this.getMetadata(e), o = (t?.blockPosition || 0) + i, r = await this.filehandle.read(o, 0, e), s = await q(r);
|
|
502
|
-
if (n) {
|
|
503
|
-
let c = -1;
|
|
504
|
-
const u = 10, f = n.charCodeAt(0);
|
|
505
|
-
for (let m = 0, d = s.length; m < d; m++) {
|
|
506
|
-
const l = s[m];
|
|
507
|
-
if (m === c + 1 && l !== f)
|
|
508
|
-
break;
|
|
509
|
-
l === u && (c = m);
|
|
510
|
-
}
|
|
511
|
-
return s.subarray(0, c + 1);
|
|
512
|
-
}
|
|
513
|
-
return s;
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* get a string containing the "header" region of the file, is the portion up
|
|
517
|
-
* to the first non-meta line
|
|
518
|
-
*/
|
|
519
|
-
async getHeader(e = {}) {
|
|
520
|
-
const t = new TextDecoder("utf8"), n = await this.getHeaderBuffer(e);
|
|
521
|
-
return t.decode(n);
|
|
522
|
-
}
|
|
523
|
-
/**
|
|
524
|
-
* get an array of reference sequence names, in the order in which they occur
|
|
525
|
-
* in the file. reference sequence renaming is not applied to these names.
|
|
526
|
-
*/
|
|
527
|
-
async getReferenceSequenceNames(e = {}) {
|
|
528
|
-
return (await this.getMetadata(e)).refIdToName;
|
|
529
|
-
}
|
|
530
|
-
/**
|
|
531
|
-
* @param {string} regionRefName
|
|
532
|
-
*
|
|
533
|
-
* @param {number} regionStart region start coordinate (0-based-half-open)
|
|
534
|
-
*
|
|
535
|
-
* @param {number} regionEnd region end coordinate (0-based-half-open)
|
|
536
|
-
*
|
|
537
|
-
* @param {string} line
|
|
538
|
-
*
|
|
539
|
-
* @param {number} refColumn column number for ref
|
|
540
|
-
*
|
|
541
|
-
* @param {number} startColumn column number for start
|
|
542
|
-
*
|
|
543
|
-
* @param {number} endColumn column number for end
|
|
544
|
-
*
|
|
545
|
-
* @param {number} maxColumn pre-calculated max column
|
|
546
|
-
*
|
|
547
|
-
* @param {number} metaCharCode pre-calculated metaChar code
|
|
548
|
-
*
|
|
549
|
-
* @param {number} coordinateOffset 0 or -1 for coordinate adjustment
|
|
550
|
-
*
|
|
551
|
-
* @param {boolean} isVCF whether this is VCF format
|
|
552
|
-
*
|
|
553
|
-
* @param {boolean} isIdentityRename whether renameRefSeq is the identity function
|
|
554
|
-
*
|
|
555
|
-
* @returns {{ start: number, end: number } | null | undefined} coordinates if overlapping, null if should stop processing, undefined otherwise
|
|
556
|
-
*/
|
|
557
|
-
checkLine(e, t, n, i, o, r, s, c, u, f, m, d) {
|
|
558
|
-
if (u !== void 0 && i.charCodeAt(0) === u)
|
|
559
|
-
return;
|
|
560
|
-
if (i.length < 500) {
|
|
561
|
-
const w = i.split(" "), b = w[o - 1];
|
|
562
|
-
if (!(d ? b === e : this.renameRefSeq(b) === e))
|
|
563
|
-
return;
|
|
564
|
-
const g = +w[r - 1] + f;
|
|
565
|
-
if (g >= n)
|
|
566
|
-
return null;
|
|
567
|
-
let p;
|
|
568
|
-
return s === 0 || s === r ? p = g + 1 : m ? p = this._getVcfEnd(g, w[3], w[s - 1]) : p = +w[s - 1], p <= t ? void 0 : { start: g, end: p };
|
|
569
|
-
}
|
|
570
|
-
let l = -1;
|
|
571
|
-
const h = [-1];
|
|
572
|
-
for (let w = 0; w < c; w++) {
|
|
573
|
-
const b = i.indexOf(" ", l + 1);
|
|
574
|
-
if (b === -1) {
|
|
575
|
-
h.push(i.length);
|
|
576
|
-
break;
|
|
577
|
-
}
|
|
578
|
-
h.push(b), l = b;
|
|
579
|
-
}
|
|
580
|
-
const S = i.slice(h[o - 1] + 1, h[o]);
|
|
581
|
-
if (!(d ? S === e : this.renameRefSeq(S) === e))
|
|
582
|
-
return;
|
|
583
|
-
const I = +i.slice(h[r - 1] + 1, h[r]) + f;
|
|
584
|
-
if (I >= n)
|
|
585
|
-
return null;
|
|
586
|
-
let k;
|
|
587
|
-
if (s === 0 || s === r ? k = I + 1 : m ? k = this._getVcfEnd(I, i.slice(h[3] + 1, h[4]), i.slice(h[s - 1] + 1, h[s])) : k = +i.slice(h[s - 1] + 1, h[s]), !(k <= t))
|
|
588
|
-
return { start: I, end: k };
|
|
589
|
-
}
|
|
590
|
-
_getVcfEnd(e, t, n) {
|
|
591
|
-
let i = e + t.length;
|
|
592
|
-
if (n.includes("SVTYPE=TRA"))
|
|
593
|
-
return e + 1;
|
|
594
|
-
if (n[0] !== ".") {
|
|
595
|
-
const r = n.indexOf("END=");
|
|
596
|
-
if (r !== -1 && (r === 0 || n[r - 1] === ";")) {
|
|
597
|
-
const s = r + 4;
|
|
598
|
-
let c = n.indexOf(";", s);
|
|
599
|
-
c === -1 && (c = n.length), i = Number.parseInt(n.slice(s, c), 10);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
return i;
|
|
603
|
-
}
|
|
604
|
-
/**
|
|
605
|
-
* return the approximate number of data lines in the given reference
|
|
606
|
-
* sequence
|
|
607
|
-
*
|
|
608
|
-
* @param refSeq reference sequence name
|
|
609
|
-
*
|
|
610
|
-
* @returns number of data lines present on that reference sequence
|
|
611
|
-
*/
|
|
612
|
-
async lineCount(e, t = {}) {
|
|
613
|
-
return this.index.lineCount(e, t);
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* read and uncompress the data in a chunk (composed of one or more
|
|
617
|
-
* contiguous bgzip blocks) of the file
|
|
618
|
-
*/
|
|
619
|
-
async readChunk(e, t = {}) {
|
|
620
|
-
const n = await this.filehandle.read(e.fetchedSize(), e.minv.blockPosition, t);
|
|
621
|
-
return K(n, e, this.cache);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
export {
|
|
625
|
-
V as CSI,
|
|
626
|
-
D as TBI,
|
|
627
|
-
he as TabixIndexedFile
|
|
628
|
-
};
|