@genome-spy/app 0.58.0 → 0.58.1
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-Dec7VcMU.js → index-DKe9Bhvi.js} +280 -255
- package/dist/index.es.js +3 -3
- package/dist/index.js +153 -152
- package/package.json +3 -3
@@ -1,7 +1,7 @@
|
|
1
1
|
import { A as J, L as K } from "./index-CCJIjehY.js";
|
2
2
|
import { b as Q } from "./index-BftNdA0O.js";
|
3
|
-
import { L as
|
4
|
-
import { R as
|
3
|
+
import { L as R } from "./__vite-browser-external-C--ziKoh.js";
|
4
|
+
import { R as F } from "./remoteFile-BuaqFGWk.js";
|
5
5
|
import { u as $, L as H, a as Z } from "./long-BviWyoZx.js";
|
6
6
|
function j(o) {
|
7
7
|
if (o.greaterThan(Number.MAX_SAFE_INTEGER) || o.lessThan(Number.MIN_SAFE_INTEGER))
|
@@ -10,7 +10,7 @@ function j(o) {
|
|
10
10
|
}
|
11
11
|
class ee extends Error {
|
12
12
|
}
|
13
|
-
function
|
13
|
+
function _(o) {
|
14
14
|
if (o && o.aborted) {
|
15
15
|
if (typeof DOMException < "u")
|
16
16
|
throw new DOMException("aborted", "AbortError");
|
@@ -26,9 +26,9 @@ function te(o, e) {
|
|
26
26
|
function X(o, e) {
|
27
27
|
const t = [];
|
28
28
|
let n = null;
|
29
|
-
return o.length === 0 ? o : (o.sort(function(i,
|
30
|
-
const
|
31
|
-
return
|
29
|
+
return o.length === 0 ? o : (o.sort(function(i, s) {
|
30
|
+
const a = i.minv.blockPosition - s.minv.blockPosition;
|
31
|
+
return a !== 0 ? a : i.minv.dataPosition - s.minv.dataPosition;
|
32
32
|
}), o.forEach((i) => {
|
33
33
|
(!e || i.maxv.compareTo(e) > 0) && (n === null ? (t.push(i), n = i) : te(n, i) ? i.maxv.compareTo(n.maxv) > 0 && (n.maxv = i.maxv) : (t.push(i), n = i));
|
34
34
|
}), t);
|
@@ -98,73 +98,73 @@ function ie(o, e) {
|
|
98
98
|
[4681 + (o >> 14), 4681 + (e >> 14)]
|
99
99
|
];
|
100
100
|
}
|
101
|
-
class
|
101
|
+
class y extends W {
|
102
102
|
async lineCount(e, t = {}) {
|
103
103
|
const n = await this.parse(t), i = n.refNameToId[e];
|
104
104
|
if (i === void 0 || !n.indices[i])
|
105
105
|
return -1;
|
106
|
-
const { stats:
|
107
|
-
return
|
106
|
+
const { stats: a } = n.indices[i];
|
107
|
+
return a ? a.lineCount : -1;
|
108
108
|
}
|
109
109
|
// fetch and parse the index
|
110
110
|
async _parse(e = {}) {
|
111
111
|
const t = await this.filehandle.readFile(e), n = await $(t);
|
112
|
-
if (
|
112
|
+
if (_(e.signal), n.readUInt32LE(0) !== ne)
|
113
113
|
throw new Error("Not a TBI file");
|
114
|
-
const i = n.readInt32LE(4),
|
114
|
+
const i = n.readInt32LE(4), s = n.readInt32LE(8), a = s & 65536 ? "zero-based-half-open" : "1-based-closed", f = {
|
115
115
|
0: "generic",
|
116
116
|
1: "SAM",
|
117
117
|
2: "VCF"
|
118
|
-
}[
|
119
|
-
if (!
|
120
|
-
throw new Error(`invalid Tabix preset format flags ${
|
121
|
-
const
|
118
|
+
}[s & 15];
|
119
|
+
if (!f)
|
120
|
+
throw new Error(`invalid Tabix preset format flags ${s}`);
|
121
|
+
const d = {
|
122
122
|
ref: n.readInt32LE(12),
|
123
123
|
start: n.readInt32LE(16),
|
124
124
|
end: n.readInt32LE(20)
|
125
|
-
}, u = n.readInt32LE(24),
|
126
|
-
let
|
125
|
+
}, u = n.readInt32LE(24), h = 5, c = ((1 << (h + 1) * 3) - 1) / 7, b = 2 ** (14 + h * 3), I = u ? String.fromCharCode(u) : null, m = n.readInt32LE(28), w = n.readInt32LE(32), { refNameToId: x, refIdToName: p } = this._parseNameBytes(n.slice(36, 36 + w));
|
126
|
+
let l = 36 + w, g;
|
127
127
|
return {
|
128
128
|
indices: new Array(i).fill(0).map(() => {
|
129
|
-
const
|
130
|
-
|
131
|
-
const
|
132
|
-
let
|
133
|
-
for (let
|
134
|
-
const
|
135
|
-
if (
|
129
|
+
const E = n.readInt32LE(l);
|
130
|
+
l += 4;
|
131
|
+
const v = {};
|
132
|
+
let N;
|
133
|
+
for (let C = 0; C < E; C += 1) {
|
134
|
+
const A = n.readUInt32LE(l);
|
135
|
+
if (l += 4, A > c + 1)
|
136
136
|
throw new Error("tabix index contains too many bins, please use a CSI index");
|
137
|
-
if (
|
138
|
-
const
|
139
|
-
|
137
|
+
if (A === c + 1) {
|
138
|
+
const k = n.readInt32LE(l);
|
139
|
+
l += 4, k === 2 && (N = this.parsePseudoBin(n, l)), l += 16 * k;
|
140
140
|
} else {
|
141
|
-
const
|
142
|
-
|
143
|
-
const O = new Array(
|
144
|
-
for (let
|
145
|
-
const q = T(n,
|
146
|
-
|
141
|
+
const k = n.readInt32LE(l);
|
142
|
+
l += 4;
|
143
|
+
const O = new Array(k);
|
144
|
+
for (let M = 0; M < k; M += 1) {
|
145
|
+
const q = T(n, l), Y = T(n, l + 8);
|
146
|
+
l += 16, g = this._findFirstData(g, q), O[M] = new D(q, Y, A);
|
147
147
|
}
|
148
|
-
|
148
|
+
v[A] = O;
|
149
149
|
}
|
150
150
|
}
|
151
|
-
const
|
152
|
-
|
153
|
-
const
|
154
|
-
for (let
|
155
|
-
|
156
|
-
return { binIndex:
|
151
|
+
const B = n.readInt32LE(l);
|
152
|
+
l += 4;
|
153
|
+
const L = new Array(B);
|
154
|
+
for (let C = 0; C < B; C += 1)
|
155
|
+
L[C] = T(n, l), l += 8, g = this._findFirstData(g, L[C]);
|
156
|
+
return { binIndex: v, linearIndex: L, stats: N };
|
157
157
|
}),
|
158
|
-
metaChar:
|
159
|
-
maxBinNumber:
|
160
|
-
maxRefLength:
|
158
|
+
metaChar: I,
|
159
|
+
maxBinNumber: c,
|
160
|
+
maxRefLength: b,
|
161
161
|
skipLines: m,
|
162
162
|
firstDataLine: g,
|
163
|
-
columnNumbers:
|
164
|
-
coordinateType:
|
165
|
-
format:
|
166
|
-
refIdToName:
|
167
|
-
refNameToId:
|
163
|
+
columnNumbers: d,
|
164
|
+
coordinateType: a,
|
165
|
+
format: f,
|
166
|
+
refIdToName: p,
|
167
|
+
refNameToId: x,
|
168
168
|
maxBlockSize: 65536
|
169
169
|
};
|
170
170
|
}
|
@@ -173,40 +173,40 @@ class k extends W {
|
|
173
173
|
}
|
174
174
|
_parseNameBytes(e) {
|
175
175
|
let t = 0, n = 0;
|
176
|
-
const i = [],
|
177
|
-
for (let
|
178
|
-
if (!e[
|
179
|
-
if (n <
|
180
|
-
let
|
181
|
-
|
176
|
+
const i = [], s = {};
|
177
|
+
for (let a = 0; a < e.length; a += 1)
|
178
|
+
if (!e[a]) {
|
179
|
+
if (n < a) {
|
180
|
+
let r = e.toString("utf8", n, a);
|
181
|
+
r = this.renameRefSeq(r), i[t] = r, s[r] = t;
|
182
182
|
}
|
183
|
-
n =
|
183
|
+
n = a + 1, t += 1;
|
184
184
|
}
|
185
|
-
return { refNameToId:
|
185
|
+
return { refNameToId: s, refIdToName: i };
|
186
186
|
}
|
187
187
|
async blocksForRange(e, t, n, i = {}) {
|
188
188
|
t < 0 && (t = 0);
|
189
|
-
const
|
190
|
-
if (
|
189
|
+
const s = await this.parse(i), a = s.refNameToId[e];
|
190
|
+
if (a === void 0)
|
191
191
|
return [];
|
192
|
-
const
|
193
|
-
if (!
|
192
|
+
const r = s.indices[a];
|
193
|
+
if (!r)
|
194
194
|
return [];
|
195
|
-
(
|
196
|
-
const
|
197
|
-
for (const [m,
|
198
|
-
for (let
|
199
|
-
if (
|
200
|
-
for (const
|
201
|
-
u.push(new D(
|
202
|
-
const
|
203
|
-
let
|
204
|
-
const
|
205
|
-
for (let m =
|
206
|
-
const
|
207
|
-
|
195
|
+
(r.linearIndex.length ? r.linearIndex[t >> U >= r.linearIndex.length ? r.linearIndex.length - 1 : t >> U] : new V(0, 0)) || console.warn("querying outside of possible tabix range");
|
196
|
+
const d = ie(t, n), u = [];
|
197
|
+
for (const [m, w] of d)
|
198
|
+
for (let x = m; x <= w; x++)
|
199
|
+
if (r.binIndex[x])
|
200
|
+
for (const p of r.binIndex[x])
|
201
|
+
u.push(new D(p.minv, p.maxv, x));
|
202
|
+
const h = r.linearIndex.length;
|
203
|
+
let c = null;
|
204
|
+
const b = Math.min(t >> 14, h - 1), I = Math.min(n >> 14, h - 1);
|
205
|
+
for (let m = b; m <= I; ++m) {
|
206
|
+
const w = r.linearIndex[m];
|
207
|
+
w && (!c || w.compareTo(c) < 0) && (c = w);
|
208
208
|
}
|
209
|
-
return X(u,
|
209
|
+
return X(u, c);
|
210
210
|
}
|
211
211
|
}
|
212
212
|
const re = 21582659, se = 38359875;
|
@@ -216,7 +216,7 @@ function ae(o, e) {
|
|
216
216
|
function G(o, e) {
|
217
217
|
return Math.floor(o / 2 ** e);
|
218
218
|
}
|
219
|
-
class
|
219
|
+
class z extends W {
|
220
220
|
constructor(e) {
|
221
221
|
super(e), this.maxBinNumber = 0, this.depth = 0, this.minShift = 0;
|
222
222
|
}
|
@@ -224,43 +224,43 @@ class M extends W {
|
|
224
224
|
const n = await this.parse(t), i = n.refNameToId[e];
|
225
225
|
if (i === void 0 || !n.indices[i])
|
226
226
|
return -1;
|
227
|
-
const { stats:
|
228
|
-
return
|
227
|
+
const { stats: a } = n.indices[i];
|
228
|
+
return a ? a.lineCount : -1;
|
229
229
|
}
|
230
230
|
indexCov() {
|
231
231
|
throw new Error("CSI indexes do not support indexcov");
|
232
232
|
}
|
233
233
|
parseAuxData(e, t) {
|
234
|
-
const n = e.readInt32LE(t), i = n & 65536 ? "zero-based-half-open" : "1-based-closed",
|
235
|
-
if (!
|
234
|
+
const n = e.readInt32LE(t), i = n & 65536 ? "zero-based-half-open" : "1-based-closed", s = { 0: "generic", 1: "SAM", 2: "VCF" }[n & 15];
|
235
|
+
if (!s)
|
236
236
|
throw new Error(`invalid Tabix preset format flags ${n}`);
|
237
|
-
const
|
237
|
+
const a = {
|
238
238
|
ref: e.readInt32LE(t + 4),
|
239
239
|
start: e.readInt32LE(t + 8),
|
240
240
|
end: e.readInt32LE(t + 12)
|
241
|
-
},
|
241
|
+
}, r = e.readInt32LE(t + 16), f = r ? String.fromCharCode(r) : null, d = e.readInt32LE(t + 20), u = e.readInt32LE(t + 24), { refIdToName: h, refNameToId: c } = this._parseNameBytes(e.slice(t + 28, t + 28 + u));
|
242
242
|
return {
|
243
|
-
refIdToName:
|
244
|
-
refNameToId:
|
245
|
-
skipLines:
|
246
|
-
metaChar:
|
247
|
-
columnNumbers:
|
248
|
-
format:
|
243
|
+
refIdToName: h,
|
244
|
+
refNameToId: c,
|
245
|
+
skipLines: d,
|
246
|
+
metaChar: f,
|
247
|
+
columnNumbers: a,
|
248
|
+
format: s,
|
249
249
|
coordinateType: i
|
250
250
|
};
|
251
251
|
}
|
252
252
|
_parseNameBytes(e) {
|
253
253
|
let t = 0, n = 0;
|
254
|
-
const i = [],
|
255
|
-
for (let
|
256
|
-
if (!e[
|
257
|
-
if (n <
|
258
|
-
let
|
259
|
-
|
254
|
+
const i = [], s = {};
|
255
|
+
for (let a = 0; a < e.length; a += 1)
|
256
|
+
if (!e[a]) {
|
257
|
+
if (n < a) {
|
258
|
+
let r = e.toString("utf8", n, a);
|
259
|
+
r = this.renameRefSeq(r), i[t] = r, s[r] = t;
|
260
260
|
}
|
261
|
-
n =
|
261
|
+
n = a + 1, t += 1;
|
262
262
|
}
|
263
|
-
return { refNameToId:
|
263
|
+
return { refNameToId: s, refIdToName: i };
|
264
264
|
}
|
265
265
|
// fetch and parse the index
|
266
266
|
async _parse(e = {}) {
|
@@ -273,45 +273,45 @@ class M extends W {
|
|
273
273
|
else
|
274
274
|
throw new Error("Not a CSI file");
|
275
275
|
this.minShift = t.readInt32LE(4), this.depth = t.readInt32LE(8), this.maxBinNumber = ((1 << (this.depth + 1) * 3) - 1) / 7;
|
276
|
-
const i = 2 ** (this.minShift + this.depth * 3),
|
276
|
+
const i = 2 ** (this.minShift + this.depth * 3), s = t.readInt32LE(12), a = s && s >= 30 ? this.parseAuxData(t, 16) : {
|
277
277
|
refIdToName: [],
|
278
278
|
refNameToId: {},
|
279
279
|
metaChar: null,
|
280
280
|
columnNumbers: { ref: 0, start: 1, end: 2 },
|
281
281
|
coordinateType: "zero-based-half-open",
|
282
282
|
format: "generic"
|
283
|
-
},
|
284
|
-
let
|
285
|
-
const u = new Array(
|
286
|
-
const
|
287
|
-
|
288
|
-
const
|
289
|
-
let
|
290
|
-
for (let
|
291
|
-
const m = t.readUInt32LE(
|
283
|
+
}, r = t.readInt32LE(16 + s);
|
284
|
+
let f, d = 16 + s + 4;
|
285
|
+
const u = new Array(r).fill(0).map(() => {
|
286
|
+
const h = t.readInt32LE(d);
|
287
|
+
d += 4;
|
288
|
+
const c = {};
|
289
|
+
let b;
|
290
|
+
for (let I = 0; I < h; I += 1) {
|
291
|
+
const m = t.readUInt32LE(d);
|
292
292
|
if (m > this.maxBinNumber)
|
293
|
-
|
293
|
+
b = this.parsePseudoBin(t, d + 4), d += 48;
|
294
294
|
else {
|
295
|
-
const
|
296
|
-
|
297
|
-
const
|
298
|
-
|
299
|
-
const
|
300
|
-
for (let
|
301
|
-
const g = T(t,
|
302
|
-
|
295
|
+
const w = T(t, d + 4);
|
296
|
+
f = this._findFirstData(f, w);
|
297
|
+
const x = t.readInt32LE(d + 12);
|
298
|
+
d += 16;
|
299
|
+
const p = new Array(x);
|
300
|
+
for (let l = 0; l < x; l += 1) {
|
301
|
+
const g = T(t, d), P = T(t, d + 8);
|
302
|
+
d += 16, p[l] = new D(g, P, m);
|
303
303
|
}
|
304
|
-
|
304
|
+
c[m] = p;
|
305
305
|
}
|
306
306
|
}
|
307
|
-
return { binIndex:
|
307
|
+
return { binIndex: c, stats: b };
|
308
308
|
});
|
309
309
|
return {
|
310
|
-
...
|
310
|
+
...a,
|
311
311
|
csi: !0,
|
312
|
-
refCount:
|
312
|
+
refCount: r,
|
313
313
|
maxBlockSize: 65536,
|
314
|
-
firstDataLine:
|
314
|
+
firstDataLine: f,
|
315
315
|
csiVersion: n,
|
316
316
|
indices: u,
|
317
317
|
depth: this.depth,
|
@@ -324,40 +324,40 @@ class M extends W {
|
|
324
324
|
}
|
325
325
|
async blocksForRange(e, t, n, i = {}) {
|
326
326
|
t < 0 && (t = 0);
|
327
|
-
const
|
328
|
-
if (
|
327
|
+
const s = await this.parse(i), a = s.refNameToId[e];
|
328
|
+
if (a === void 0)
|
329
329
|
return [];
|
330
|
-
const
|
331
|
-
if (!
|
330
|
+
const r = s.indices[a];
|
331
|
+
if (!r)
|
332
332
|
return [];
|
333
|
-
const
|
334
|
-
for (const [u,
|
335
|
-
for (let
|
336
|
-
if (
|
337
|
-
for (const
|
338
|
-
|
339
|
-
return X(
|
333
|
+
const f = this.reg2bins(t, n), d = [];
|
334
|
+
for (const [u, h] of f)
|
335
|
+
for (let c = u; c <= h; c++)
|
336
|
+
if (r.binIndex[c])
|
337
|
+
for (const b of r.binIndex[c])
|
338
|
+
d.push(new D(b.minv, b.maxv, c));
|
339
|
+
return X(d, new V(0, 0));
|
340
340
|
}
|
341
341
|
/**
|
342
342
|
* calculate the list of bins that may overlap with region [beg,end) (zero-based half-open)
|
343
343
|
*/
|
344
344
|
reg2bins(e, t) {
|
345
345
|
e -= 1, e < 1 && (e = 1), t > 2 ** 50 && (t = 2 ** 34), t -= 1;
|
346
|
-
let n = 0, i = 0,
|
347
|
-
const
|
348
|
-
for (; n <= this.depth;
|
349
|
-
const
|
350
|
-
if (
|
346
|
+
let n = 0, i = 0, s = this.minShift + this.depth * 3;
|
347
|
+
const a = [];
|
348
|
+
for (; n <= this.depth; s -= 3, i += ae(1, n * 3), n += 1) {
|
349
|
+
const r = i + G(e, s), f = i + G(t, s);
|
350
|
+
if (f - r + a.length > this.maxBinNumber)
|
351
351
|
throw new Error(`query ${e}-${t} is too large for current binning scheme (shift ${this.minShift}, depth ${this.depth}), try a smaller query or a coarser index binning scheme`);
|
352
|
-
|
352
|
+
a.push([r, f]);
|
353
353
|
}
|
354
|
-
return
|
354
|
+
return a;
|
355
355
|
}
|
356
356
|
}
|
357
|
-
const z = typeof TextDecoder < "u" ? new TextDecoder("utf8") : void 0;
|
358
357
|
function oe(o) {
|
359
|
-
return
|
358
|
+
return /^[\u0000-\u007F]*$/.test(o);
|
360
359
|
}
|
360
|
+
const S = typeof TextDecoder < "u" ? new TextDecoder("utf8") : void 0;
|
361
361
|
class ue {
|
362
362
|
/**
|
363
363
|
* @param {object} args
|
@@ -374,65 +374,68 @@ class ue {
|
|
374
374
|
*
|
375
375
|
* @param {filehandle} [args.csiFilehandle]
|
376
376
|
*
|
377
|
-
* @param {
|
378
|
-
*
|
377
|
+
* @param {url} [args.url]
|
378
|
+
*
|
379
|
+
* @param {csiUrl} [args.csiUrl]
|
380
|
+
*
|
381
|
+
* @param {tbiUrl} [args.tbiUrl]
|
379
382
|
*
|
380
383
|
* @param {function} [args.renameRefSeqs] optional function with sig `string
|
381
384
|
* => string` to transform reference sequence names for the purpose of
|
382
385
|
* indexing and querying. note that the data that is returned is not altered,
|
383
386
|
* just the names of the reference sequences that are used for querying.
|
384
387
|
*/
|
385
|
-
constructor({ path: e, filehandle: t, url: n, tbiPath: i, tbiUrl:
|
388
|
+
constructor({ path: e, filehandle: t, url: n, tbiPath: i, tbiUrl: s, tbiFilehandle: a, csiPath: r, csiUrl: f, csiFilehandle: d, renameRefSeqs: u = (c) => c, chunkCacheSize: h = 5 * 2 ** 20 }) {
|
386
389
|
if (t)
|
387
390
|
this.filehandle = t;
|
388
391
|
else if (e)
|
389
|
-
this.filehandle = new
|
392
|
+
this.filehandle = new R(e);
|
390
393
|
else if (n)
|
391
|
-
this.filehandle = new
|
394
|
+
this.filehandle = new F(n);
|
392
395
|
else
|
393
396
|
throw new TypeError("must provide either filehandle or path");
|
394
|
-
if (
|
395
|
-
this.index = new
|
396
|
-
filehandle:
|
397
|
-
renameRefSeqs:
|
397
|
+
if (a)
|
398
|
+
this.index = new y({
|
399
|
+
filehandle: a,
|
400
|
+
renameRefSeqs: u
|
398
401
|
});
|
399
|
-
else if (
|
400
|
-
this.index = new
|
401
|
-
filehandle:
|
402
|
-
renameRefSeqs:
|
402
|
+
else if (d)
|
403
|
+
this.index = new z({
|
404
|
+
filehandle: d,
|
405
|
+
renameRefSeqs: u
|
403
406
|
});
|
404
407
|
else if (i)
|
405
|
-
this.index = new
|
406
|
-
filehandle: new
|
407
|
-
renameRefSeqs:
|
408
|
+
this.index = new y({
|
409
|
+
filehandle: new R(i),
|
410
|
+
renameRefSeqs: u
|
408
411
|
});
|
409
|
-
else if (
|
410
|
-
this.index = new
|
411
|
-
filehandle: new
|
412
|
-
renameRefSeqs:
|
412
|
+
else if (r)
|
413
|
+
this.index = new z({
|
414
|
+
filehandle: new R(r),
|
415
|
+
renameRefSeqs: u
|
413
416
|
});
|
414
417
|
else if (e)
|
415
|
-
this.index = new
|
416
|
-
filehandle: new
|
417
|
-
renameRefSeqs:
|
418
|
+
this.index = new y({
|
419
|
+
filehandle: new R(`${e}.tbi`),
|
420
|
+
renameRefSeqs: u
|
418
421
|
});
|
419
|
-
else if (
|
420
|
-
this.index = new
|
421
|
-
filehandle: new
|
422
|
+
else if (f)
|
423
|
+
this.index = new z({
|
424
|
+
filehandle: new F(f)
|
422
425
|
});
|
423
|
-
else if (
|
424
|
-
this.index = new
|
425
|
-
filehandle: new
|
426
|
+
else if (s)
|
427
|
+
this.index = new y({
|
428
|
+
filehandle: new F(s)
|
426
429
|
});
|
427
430
|
else if (n)
|
428
|
-
this.index = new
|
429
|
-
filehandle: new
|
431
|
+
this.index = new y({
|
432
|
+
filehandle: new F(`${n}.tbi`)
|
430
433
|
});
|
431
434
|
else
|
432
435
|
throw new TypeError("must provide one of tbiFilehandle, tbiPath, csiFilehandle, csiPath, tbiUrl, csiUrl");
|
433
|
-
this.renameRefSeq =
|
434
|
-
cache: new K({ maxSize: Math.floor(
|
435
|
-
fill: (
|
436
|
+
this.renameRefSeq = u, this.chunkCache = new J({
|
437
|
+
cache: new K({ maxSize: Math.floor(h / 65536) }),
|
438
|
+
fill: (c, b) => this.readChunk(c, { signal: b })
|
436
439
|
});
|
437
440
|
}
|
438
441
|
/**
|
@@ -449,54 +452,62 @@ class ue {
|
|
449
452
|
* rejected on error
|
450
453
|
*/
|
451
454
|
async getLines(e, t, n, i) {
|
452
|
-
var a;
|
453
|
-
let r,
|
454
|
-
typeof i == "function" ? d = i : (
|
455
|
-
const
|
456
|
-
|
457
|
-
const
|
458
|
-
if (!(
|
455
|
+
var s, a;
|
456
|
+
let r, f = {}, d;
|
457
|
+
typeof i == "function" ? d = i : (f = i, d = i.lineCallback, r = i.signal);
|
458
|
+
const u = await this.index.getMetadata(f);
|
459
|
+
_(r);
|
460
|
+
const h = t ?? 0, c = n ?? u.maxRefLength;
|
461
|
+
if (!(h <= c))
|
459
462
|
throw new TypeError("invalid start and end coordinates. start must be less than or equal to end");
|
460
|
-
if (
|
463
|
+
if (h === c)
|
461
464
|
return;
|
462
|
-
const
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
465
|
+
const b = await this.index.blocksForRange(e, h, c, f);
|
466
|
+
_(r);
|
467
|
+
for (const I of b) {
|
468
|
+
const { buffer: m, cpositions: w, dpositions: x } = await this.chunkCache.get(I.toString(), I, r);
|
469
|
+
_(r);
|
470
|
+
let p = 0, l = 0;
|
471
|
+
const g = (s = S == null ? void 0 : S.decode(m)) !== null && s !== void 0 ? s : m.toString(), P = m.length < 5e8 && oe(g);
|
472
|
+
for (; p < g.length; ) {
|
473
|
+
let E, v;
|
474
|
+
if (P) {
|
475
|
+
if (v = g.indexOf(`
|
476
|
+
`, p), v === -1)
|
477
|
+
break;
|
478
|
+
E = g.slice(p, v);
|
479
|
+
} else {
|
480
|
+
if (v = m.indexOf(`
|
481
|
+
`, p), v === -1)
|
482
|
+
break;
|
483
|
+
const L = m.slice(p, v);
|
484
|
+
E = (a = S == null ? void 0 : S.decode(L)) !== null && a !== void 0 ? a : L.toString();
|
485
|
+
}
|
476
486
|
if (x) {
|
477
|
-
for (;
|
487
|
+
for (; p + I.minv.dataPosition >= x[l++]; )
|
478
488
|
;
|
479
|
-
|
489
|
+
l--;
|
480
490
|
}
|
481
|
-
const { startCoordinate:
|
482
|
-
if (
|
483
|
-
throw new Error(`Lines not sorted by start coordinate (${m} > ${E}), this file is not usable with Tabix.`);
|
484
|
-
if (m = E, P)
|
491
|
+
const { startCoordinate: N, overlaps: B } = this.checkLine(u, e, h, c, E);
|
492
|
+
if (B)
|
485
493
|
d(
|
486
|
-
|
487
|
-
// cpositions[pos] refers to actual file offset of a bgzip block
|
494
|
+
E,
|
495
|
+
// cpositions[pos] refers to actual file offset of a bgzip block
|
496
|
+
// boundaries
|
488
497
|
//
|
489
|
-
// we multiply by (1 <<8) in order to make sure each block has a
|
490
|
-
// address space so that data in that block could never
|
498
|
+
// we multiply by (1 <<8) in order to make sure each block has a
|
499
|
+
// "unique" address space so that data in that block could never
|
500
|
+
// overlap
|
491
501
|
//
|
492
|
-
// then the blockStart-dpositions is an uncompressed file offset
|
493
|
-
// that bgzip block boundary, and since the cpositions are
|
494
|
-
// (1 << 8) these uncompressed offsets get a unique
|
495
|
-
|
502
|
+
// then the blockStart-dpositions is an uncompressed file offset
|
503
|
+
// from that bgzip block boundary, and since the cpositions are
|
504
|
+
// multiplied by (1 << 8) these uncompressed offsets get a unique
|
505
|
+
// space
|
506
|
+
w[l] * 256 + (p - x[l]) + I.minv.dataPosition + 1
|
496
507
|
);
|
497
|
-
else if (
|
508
|
+
else if (N !== void 0 && N >= c)
|
498
509
|
return;
|
499
|
-
|
510
|
+
p = v + 1;
|
500
511
|
}
|
501
512
|
}
|
502
513
|
}
|
@@ -509,16 +520,16 @@ class ue {
|
|
509
520
|
*/
|
510
521
|
async getHeaderBuffer(e = {}) {
|
511
522
|
const { firstDataLine: t, metaChar: n, maxBlockSize: i } = await this.getMetadata(e);
|
512
|
-
|
513
|
-
const
|
523
|
+
_(e.signal);
|
524
|
+
const s = ((t == null ? void 0 : t.blockPosition) || 0) + i, a = await this._readRegion(0, s, e), r = await $(a);
|
514
525
|
if (n) {
|
515
|
-
let
|
516
|
-
const
|
517
|
-
for (let
|
518
|
-
|
519
|
-
return
|
526
|
+
let f = -1;
|
527
|
+
const d = 10, u = n.charCodeAt(0);
|
528
|
+
for (let h = 0; h < r.length && !(h === f + 1 && r[h] !== u); h += 1)
|
529
|
+
r[h] === d && (f = h);
|
530
|
+
return r.subarray(0, f + 1);
|
520
531
|
}
|
521
|
-
return
|
532
|
+
return r;
|
522
533
|
}
|
523
534
|
/**
|
524
535
|
* get a string containing the "header" region of the file, is the portion up
|
@@ -551,47 +562,61 @@ class ue {
|
|
551
562
|
* @returns {object} like `{startCoordinate, overlaps}`. overlaps is boolean,
|
552
563
|
* true if line is a data line that overlaps the given region
|
553
564
|
*/
|
554
|
-
checkLine(e, t, n, i,
|
555
|
-
const { columnNumbers:
|
556
|
-
if (
|
565
|
+
checkLine(e, t, n, i, s) {
|
566
|
+
const { columnNumbers: a, metaChar: r, coordinateType: f, format: d } = e;
|
567
|
+
if (r && s.startsWith(r))
|
557
568
|
return { overlaps: !1 };
|
558
|
-
let { ref: u, start:
|
559
|
-
u || (u = 0),
|
560
|
-
const
|
561
|
-
let
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
569
|
+
let { ref: u, start: h, end: c } = a;
|
570
|
+
u || (u = 0), h || (h = 0), c || (c = 0), d === "VCF" && (c = 8);
|
571
|
+
const b = Math.max(u, h, c);
|
572
|
+
let I = 1, m = 0, w = "", x = -1 / 0;
|
573
|
+
const p = s.length;
|
574
|
+
for (let l = 0; l < p + 1; l++)
|
575
|
+
if (s[l] === " " || l === p) {
|
576
|
+
if (I === u) {
|
577
|
+
if (this.renameRefSeq(s.slice(m, l)) !== t)
|
578
|
+
return {
|
579
|
+
overlaps: !1
|
580
|
+
};
|
581
|
+
} else if (I === h) {
|
582
|
+
if (x = parseInt(s.slice(m, l), 10), f === "1-based-closed" && (x -= 1), x >= i)
|
583
|
+
return {
|
584
|
+
startCoordinate: x,
|
585
|
+
overlaps: !1
|
586
|
+
};
|
587
|
+
if ((c === 0 || c === h) && x + 1 <= n)
|
588
|
+
return {
|
589
|
+
startCoordinate: x,
|
590
|
+
overlaps: !1
|
591
|
+
};
|
592
|
+
} else if (d === "VCF" && I === 4)
|
593
|
+
w = s.slice(m, l);
|
594
|
+
else if (I === c && (d === "VCF" ? this._getVcfEnd(x, w, s.slice(m, l)) : Number.parseInt(s.slice(m, l), 10)) <= n)
|
595
|
+
return {
|
596
|
+
overlaps: !1
|
597
|
+
};
|
598
|
+
if (m = l + 1, I += 1, I > b)
|
577
599
|
break;
|
578
600
|
}
|
579
|
-
return {
|
601
|
+
return {
|
602
|
+
startCoordinate: x,
|
603
|
+
overlaps: !0
|
604
|
+
};
|
580
605
|
}
|
581
606
|
_getVcfEnd(e, t, n) {
|
582
607
|
let i = e + t.length;
|
583
|
-
const
|
584
|
-
if (n[0] !== "." && !
|
585
|
-
let
|
586
|
-
for (let
|
587
|
-
if (
|
588
|
-
let
|
589
|
-
|
608
|
+
const s = n.includes("SVTYPE=TRA");
|
609
|
+
if (n[0] !== "." && !s) {
|
610
|
+
let a = ";";
|
611
|
+
for (let r = 0; r < n.length; r += 1) {
|
612
|
+
if (a === ";" && n.slice(r, r + 4) === "END=") {
|
613
|
+
let f = n.indexOf(";", r);
|
614
|
+
f === -1 && (f = n.length), i = parseInt(n.slice(r + 4, f), 10);
|
590
615
|
break;
|
591
616
|
}
|
592
|
-
|
617
|
+
a = n[r];
|
593
618
|
}
|
594
|
-
} else if (
|
619
|
+
} else if (s)
|
595
620
|
return e + 1;
|
596
621
|
return i;
|
597
622
|
}
|
@@ -607,8 +632,8 @@ class ue {
|
|
607
632
|
return this.index.lineCount(e, t);
|
608
633
|
}
|
609
634
|
async _readRegion(e, t, n = {}) {
|
610
|
-
const i = Q.Buffer.alloc(t), { bytesRead:
|
611
|
-
return
|
635
|
+
const i = Q.Buffer.alloc(t), { bytesRead: s, buffer: a } = await this.filehandle.read(i, 0, t, e, n);
|
636
|
+
return a.subarray(0, s);
|
612
637
|
}
|
613
638
|
/**
|
614
639
|
* read and uncompress the data in a chunk (composed of one or more
|
@@ -620,7 +645,7 @@ class ue {
|
|
620
645
|
}
|
621
646
|
}
|
622
647
|
export {
|
623
|
-
|
624
|
-
|
648
|
+
z as CSI,
|
649
|
+
y as TBI,
|
625
650
|
ue as TabixIndexedFile
|
626
651
|
};
|