@genome-spy/core 0.64.0 → 0.65.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.
Files changed (104) hide show
  1. package/dist/bundle/{index-CCJIjehY.js → AbortablePromiseCache-CcuMrnn7.js} +22 -91
  2. package/dist/bundle/browser-txUcLy2H.js +123 -0
  3. package/dist/bundle/index-BQpbYrv4.js +1712 -0
  4. package/dist/bundle/index-BhtHKLUo.js +73 -0
  5. package/dist/bundle/index-C0llXMqm.js +280 -0
  6. package/dist/bundle/index-CCe8rnZz.js +716 -0
  7. package/dist/bundle/index-CD7FLu9x.js +269 -0
  8. package/dist/bundle/{index-C08YCM2T.js → index-D-w7Mmt9.js} +246 -126
  9. package/dist/bundle/index-D74H8TTz.js +508 -0
  10. package/dist/bundle/index-DhcU-Gk-.js +1487 -0
  11. package/dist/bundle/index.es.js +4878 -4680
  12. package/dist/bundle/index.js +151 -167
  13. package/dist/bundle/inflate-DRgHi_KK.js +1050 -0
  14. package/dist/schema.json +9 -1
  15. package/dist/src/data/collector.d.ts +7 -2
  16. package/dist/src/data/collector.d.ts.map +1 -1
  17. package/dist/src/data/collector.js +13 -2
  18. package/dist/src/data/dataFlow.d.ts +20 -42
  19. package/dist/src/data/dataFlow.d.ts.map +1 -1
  20. package/dist/src/data/dataFlow.js +57 -80
  21. package/dist/src/data/dataFlow.test.js +35 -2
  22. package/dist/src/data/flowHandle.d.ts +15 -0
  23. package/dist/src/data/flowHandle.d.ts.map +1 -0
  24. package/dist/src/data/flowHandle.js +13 -0
  25. package/dist/src/data/flowInit.d.ts +85 -0
  26. package/dist/src/data/flowInit.d.ts.map +1 -0
  27. package/dist/src/data/flowInit.js +238 -0
  28. package/dist/src/data/flowInit.test.d.ts +2 -0
  29. package/dist/src/data/flowInit.test.d.ts.map +1 -0
  30. package/dist/src/data/flowInit.test.js +413 -0
  31. package/dist/src/data/flowOptimizer.d.ts +6 -4
  32. package/dist/src/data/flowOptimizer.d.ts.map +1 -1
  33. package/dist/src/data/flowOptimizer.js +29 -14
  34. package/dist/src/data/flowOptimizer.test.js +20 -15
  35. package/dist/src/data/sources/lazy/bamSource.js +1 -1
  36. package/dist/src/data/sources/lazy/bigBedSource.js +1 -1
  37. package/dist/src/data/sources/lazy/bigWigSource.js +1 -1
  38. package/dist/src/data/sources/lazy/gff3Source.d.ts +2 -6
  39. package/dist/src/data/sources/lazy/gff3Source.d.ts.map +1 -1
  40. package/dist/src/data/sources/lazy/gff3Source.js +4 -8
  41. package/dist/src/data/sources/lazy/indexedFastaSource.d.ts.map +1 -1
  42. package/dist/src/data/sources/lazy/indexedFastaSource.js +17 -17
  43. package/dist/src/data/sources/lazy/tabixSource.js +1 -1
  44. package/dist/src/genomeSpy.d.ts +1 -1
  45. package/dist/src/genomeSpy.d.ts.map +1 -1
  46. package/dist/src/genomeSpy.js +18 -61
  47. package/dist/src/marks/mark.d.ts +1 -0
  48. package/dist/src/marks/mark.d.ts.map +1 -1
  49. package/dist/src/marks/mark.js +22 -1
  50. package/dist/src/spec/sampleView.d.ts +3 -2
  51. package/dist/src/types/viewContext.d.ts +1 -1
  52. package/dist/src/view/axisResolution.d.ts +5 -0
  53. package/dist/src/view/axisResolution.d.ts.map +1 -1
  54. package/dist/src/view/axisResolution.js +16 -1
  55. package/dist/src/view/facetView.d.ts.map +1 -1
  56. package/dist/src/view/facetView.js +1 -0
  57. package/dist/src/view/flowBuilder.d.ts +2 -2
  58. package/dist/src/view/flowBuilder.d.ts.map +1 -1
  59. package/dist/src/view/flowBuilder.js +21 -4
  60. package/dist/src/view/gridView/gridView.d.ts.map +1 -1
  61. package/dist/src/view/gridView/gridView.js +13 -0
  62. package/dist/src/view/gridView/selectionRect.d.ts +8 -4
  63. package/dist/src/view/gridView/selectionRect.d.ts.map +1 -1
  64. package/dist/src/view/gridView/selectionRect.js +28 -3
  65. package/dist/src/view/gridView/selectionRect.test.d.ts +2 -0
  66. package/dist/src/view/gridView/selectionRect.test.d.ts.map +1 -0
  67. package/dist/src/view/gridView/selectionRect.test.js +87 -0
  68. package/dist/src/view/paramMediator.d.ts +2 -1
  69. package/dist/src/view/paramMediator.d.ts.map +1 -1
  70. package/dist/src/view/paramMediator.js +13 -1
  71. package/dist/src/view/paramMediator.test.js +22 -0
  72. package/dist/src/view/scaleResolution.d.ts +5 -0
  73. package/dist/src/view/scaleResolution.d.ts.map +1 -1
  74. package/dist/src/view/scaleResolution.js +10 -0
  75. package/dist/src/view/testUtils.d.ts.map +1 -1
  76. package/dist/src/view/testUtils.js +16 -4
  77. package/dist/src/view/unitView.d.ts.map +1 -1
  78. package/dist/src/view/unitView.js +58 -8
  79. package/dist/src/view/view.d.ts +17 -1
  80. package/dist/src/view/view.d.ts.map +1 -1
  81. package/dist/src/view/view.js +57 -1
  82. package/dist/src/view/viewDispose.test.d.ts +2 -0
  83. package/dist/src/view/viewDispose.test.d.ts.map +1 -0
  84. package/dist/src/view/viewDispose.test.js +110 -0
  85. package/dist/src/view/viewUtils.d.ts +4 -4
  86. package/dist/src/view/viewUtils.d.ts.map +1 -1
  87. package/dist/src/view/viewUtils.js +19 -15
  88. package/dist/src/view/viewUtils.test.d.ts +2 -0
  89. package/dist/src/view/viewUtils.test.d.ts.map +1 -0
  90. package/dist/src/view/viewUtils.test.js +87 -0
  91. package/package.json +10 -10
  92. package/dist/bundle/__vite-browser-external-C--ziKoh.js +0 -8
  93. package/dist/bundle/_commonjsHelpers-DjF3Plf2.js +0 -26
  94. package/dist/bundle/index-5ajWdKly.js +0 -1319
  95. package/dist/bundle/index-B03-Om4z.js +0 -274
  96. package/dist/bundle/index-BftNdA0O.js +0 -27
  97. package/dist/bundle/index-Bg7C4Xat.js +0 -2750
  98. package/dist/bundle/index-C3QR8Lv6.js +0 -2131
  99. package/dist/bundle/index-DTcHjAHp.js +0 -505
  100. package/dist/bundle/index-DnIkxb0L.js +0 -1025
  101. package/dist/bundle/index-Ww3TAo6_.js +0 -71
  102. package/dist/bundle/index-g8iXgW0W.js +0 -651
  103. package/dist/bundle/long-B-FASCSo.js +0 -2387
  104. package/dist/bundle/remoteFile-BuaqFGWk.js +0 -94
@@ -0,0 +1,716 @@
1
+ import { A as te } from "./AbortablePromiseCache-CcuMrnn7.js";
2
+ import { I as Y, Z } from "./inflate-DRgHi_KK.js";
3
+ import { LocalFile as E, RemoteFile as D } from "./browser-txUcLy2H.js";
4
+ import { L as H } from "./index-BhtHKLUo.js";
5
+ function ne(s) {
6
+ let e = 0;
7
+ for (const t of s)
8
+ e += t.length;
9
+ return e;
10
+ }
11
+ function K(s, e) {
12
+ const t = new Uint8Array(e ?? ne(s));
13
+ let n = 0;
14
+ for (const i of s)
15
+ t.set(i, n), n += i.length;
16
+ return t;
17
+ }
18
+ async function V(s) {
19
+ try {
20
+ let e, t = 0, n;
21
+ const i = [];
22
+ let o = 0;
23
+ do {
24
+ const a = s.subarray(t);
25
+ if (n = new Y(void 0), { strm: e } = n, n.push(a, Z), n.err)
26
+ throw new Error(n.msg);
27
+ t += e.next_in;
28
+ const r = n.result;
29
+ i.push(r), o += r.length;
30
+ } while (e.avail_in);
31
+ return K(i, o);
32
+ } catch (e) {
33
+ throw /incorrect header check/.exec(`${e}`) ? new Error("problem decompressing block: incorrect gzip header check") : e;
34
+ }
35
+ }
36
+ async function ie(s, e, t) {
37
+ try {
38
+ let n;
39
+ const { minv: i, maxv: o } = e;
40
+ let a = i.blockPosition, r = i.dataPosition;
41
+ const l = [], m = [], c = [];
42
+ let u = 0, f = !1, g = 0;
43
+ do {
44
+ const b = s.subarray(a - i.blockPosition), I = a.toString();
45
+ let x, h;
46
+ const p = t == null ? void 0 : t.get(I);
47
+ if (p)
48
+ x = p.buffer, h = p.nextIn, f = !0;
49
+ else {
50
+ const d = new Y(void 0);
51
+ if ({ strm: n } = d, d.push(b, Z), d.err)
52
+ throw new Error(d.msg);
53
+ x = d.result, h = n.next_in, f = !1, t == null || t.set(I, { buffer: x, nextIn: h });
54
+ }
55
+ l.push(x);
56
+ let w = x.length;
57
+ m.push(a), c.push(r), l.length === 1 && i.dataPosition && (l[0] = l[0].subarray(i.dataPosition), w = l[0].length);
58
+ const k = a;
59
+ if (a += h, r += w, k >= o.blockPosition) {
60
+ l[u] = l[u].subarray(0, o.blockPosition === i.blockPosition ? o.dataPosition - i.dataPosition + 1 : o.dataPosition + 1), g += l[u].length, m.push(a), c.push(r);
61
+ break;
62
+ }
63
+ g += w, u++;
64
+ } while (f ? a < s.length + i.blockPosition : (
65
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
66
+ n.avail_in
67
+ ));
68
+ return {
69
+ buffer: K(l, g),
70
+ cpositions: m,
71
+ dpositions: c
72
+ };
73
+ } catch (n) {
74
+ throw /incorrect header check/.exec(`${n}`) ? new Error("problem decompressing block: incorrect gzip header check") : n;
75
+ }
76
+ }
77
+ class L {
78
+ constructor(e, t, n, i) {
79
+ this.minv = e, this.maxv = t, this.bin = n, this._fetchedSize = i;
80
+ }
81
+ toUniqueString() {
82
+ return `${this.minv}..${this.maxv} (bin ${this.bin}, fetchedSize ${this.fetchedSize()})`;
83
+ }
84
+ toString() {
85
+ return this.toUniqueString();
86
+ }
87
+ compareTo(e) {
88
+ return this.minv.compareTo(e.minv) || this.maxv.compareTo(e.maxv) || this.bin - e.bin;
89
+ }
90
+ fetchedSize() {
91
+ return this._fetchedSize !== void 0 ? this._fetchedSize : this.maxv.blockPosition + 65536 - this.minv.blockPosition;
92
+ }
93
+ }
94
+ class X {
95
+ constructor({ filehandle: e, renameRefSeqs: t = (n) => n }) {
96
+ this.filehandle = e, this.renameRefSeq = t;
97
+ }
98
+ async getMetadata(e = {}) {
99
+ const { indices: t, ...n } = await this.parse(e);
100
+ return n;
101
+ }
102
+ _findFirstData(e, t) {
103
+ return e ? e.compareTo(t) > 0 ? t : e : t;
104
+ }
105
+ async parse(e = {}) {
106
+ return this.parseP || (this.parseP = this._parse(e).catch((t) => {
107
+ throw this.parseP = void 0, t;
108
+ })), this.parseP;
109
+ }
110
+ async hasRefSeq(e, t = {}) {
111
+ var i;
112
+ return !!((i = (await this.parse(t)).indices[e]) != null && i.binIndex);
113
+ }
114
+ _parseNameBytes(e) {
115
+ let t = 0, n = 0;
116
+ const i = [], o = {}, a = new TextDecoder("utf8");
117
+ for (let r = 0; r < e.length; r += 1)
118
+ if (!e[r]) {
119
+ if (n < r) {
120
+ const l = this.renameRefSeq(a.decode(e.subarray(n, r)));
121
+ i[t] = l, o[l] = t;
122
+ }
123
+ n = r + 1, t += 1;
124
+ }
125
+ return {
126
+ refNameToId: o,
127
+ refIdToName: i
128
+ };
129
+ }
130
+ }
131
+ const W = 65536, re = W * W;
132
+ function J(s, e = 0) {
133
+ const t = s[e] | s[e + 1] << 8 | s[e + 2] << 16 | s[e + 3] << 24;
134
+ return ((s[e + 4] | s[e + 5] << 8 | s[e + 6] << 16 | s[e + 7] << 24) >>> 0) * re + (t >>> 0);
135
+ }
136
+ class se extends Error {
137
+ }
138
+ function B(s) {
139
+ if (s && s.aborted)
140
+ if (typeof DOMException > "u") {
141
+ const e = new se("aborted");
142
+ throw e.code = "ERR_ABORTED", e;
143
+ } else
144
+ throw new DOMException("aborted", "AbortError");
145
+ }
146
+ function oe(s, e) {
147
+ return e.minv.blockPosition - s.maxv.blockPosition < 65e3 && e.maxv.blockPosition - s.minv.blockPosition < 5e6;
148
+ }
149
+ function Q(s, e) {
150
+ const t = [];
151
+ let n;
152
+ if (s.length === 0)
153
+ return s;
154
+ s.sort(function(i, o) {
155
+ const a = i.minv.blockPosition - o.minv.blockPosition;
156
+ return a === 0 ? i.minv.dataPosition - o.minv.dataPosition : a;
157
+ });
158
+ for (const i of s)
159
+ (!e || i.maxv.compareTo(e) > 0) && (n === void 0 ? (t.push(i), n = i) : oe(n, i) ? i.maxv.compareTo(n.maxv) > 0 && (n.maxv = i.maxv) : (t.push(i), n = i));
160
+ return t;
161
+ }
162
+ class $ {
163
+ constructor(e, t) {
164
+ this.blockPosition = e, this.dataPosition = t;
165
+ }
166
+ toString() {
167
+ return `${this.blockPosition}:${this.dataPosition}`;
168
+ }
169
+ compareTo(e) {
170
+ return this.blockPosition - e.blockPosition || this.dataPosition - e.dataPosition;
171
+ }
172
+ }
173
+ function T(s, e = 0) {
174
+ return new $(s[e + 7] * 1099511627776 + s[e + 6] * 4294967296 + s[e + 5] * 16777216 + s[e + 4] * 65536 + s[e + 3] * 256 + s[e + 2], s[e + 1] << 8 | s[e]);
175
+ }
176
+ const ae = 21582659, ce = 38359875, le = {
177
+ 0: "generic",
178
+ 1: "SAM",
179
+ 2: "VCF"
180
+ };
181
+ function fe(s, e) {
182
+ return s * 2 ** e;
183
+ }
184
+ function G(s, e) {
185
+ return Math.floor(s / 2 ** e);
186
+ }
187
+ class R extends X {
188
+ constructor(e) {
189
+ super(e), this.maxBinNumber = 0, this.depth = 0, this.minShift = 0;
190
+ }
191
+ async lineCount(e, t = {}) {
192
+ const n = await this.parse(t), i = n.refNameToId[e];
193
+ if (i === void 0 || !n.indices[i])
194
+ return -1;
195
+ const { stats: a } = n.indices[i];
196
+ return a ? a.lineCount : -1;
197
+ }
198
+ indexCov() {
199
+ throw new Error("CSI indexes do not support indexcov");
200
+ }
201
+ parseAuxData(e, t) {
202
+ const n = new DataView(e.buffer), i = n.getInt32(t, !0), o = i & 65536 ? "zero-based-half-open" : "1-based-closed", a = le[i & 15];
203
+ if (!a)
204
+ throw new Error(`invalid Tabix preset format flags ${i}`);
205
+ const r = {
206
+ ref: n.getInt32(t + 4, !0),
207
+ start: n.getInt32(t + 8, !0),
208
+ end: n.getInt32(t + 12, !0)
209
+ }, l = n.getInt32(t + 16, !0), m = l ? String.fromCharCode(l) : void 0, c = n.getInt32(t + 20, !0), u = n.getInt32(t + 24, !0), { refIdToName: f, refNameToId: g } = this._parseNameBytes(e.subarray(t + 28, t + 28 + u));
210
+ return {
211
+ refIdToName: f,
212
+ refNameToId: g,
213
+ skipLines: c,
214
+ metaChar: m,
215
+ columnNumbers: r,
216
+ format: a,
217
+ coordinateType: o
218
+ };
219
+ }
220
+ async _parse(e = {}) {
221
+ const t = await V(await this.filehandle.readFile(e)), n = new DataView(t.buffer);
222
+ let i;
223
+ if (n.getUint32(0, !0) === ae)
224
+ i = 1;
225
+ else if (n.getUint32(0, !0) === ce)
226
+ i = 2;
227
+ else
228
+ throw new Error("Not a CSI file");
229
+ this.minShift = n.getInt32(4, !0), this.depth = n.getInt32(8, !0), this.maxBinNumber = ((1 << (this.depth + 1) * 3) - 1) / 7;
230
+ const o = 2 ** (this.minShift + this.depth * 3), a = n.getInt32(12, !0), r = a && a >= 30 ? this.parseAuxData(t, 16) : {
231
+ refIdToName: [],
232
+ refNameToId: {},
233
+ metaChar: void 0,
234
+ columnNumbers: { ref: 0, start: 1, end: 2 },
235
+ coordinateType: "zero-based-half-open",
236
+ format: "generic"
237
+ }, l = n.getInt32(16 + a, !0);
238
+ let m, c = 16 + a + 4;
239
+ const u = new Array(l).fill(0).map(() => {
240
+ const f = n.getInt32(c, !0);
241
+ c += 4;
242
+ const g = {};
243
+ let b;
244
+ for (let I = 0; I < f; I += 1) {
245
+ const x = n.getUint32(c, !0);
246
+ if (x > this.maxBinNumber)
247
+ b = this.parsePseudoBin(t, c + 4), c += 48;
248
+ else {
249
+ const h = T(t, c + 4);
250
+ m = this._findFirstData(m, h);
251
+ const p = n.getInt32(c + 12, !0);
252
+ c += 16;
253
+ const w = new Array(p);
254
+ for (let k = 0; k < p; k += 1) {
255
+ const d = T(t, c), C = T(t, c + 8);
256
+ c += 16, w[k] = new L(d, C, x);
257
+ }
258
+ g[x] = w;
259
+ }
260
+ }
261
+ return { binIndex: g, stats: b };
262
+ });
263
+ return {
264
+ ...r,
265
+ csi: !0,
266
+ refCount: l,
267
+ maxBlockSize: 65536,
268
+ firstDataLine: m,
269
+ csiVersion: i,
270
+ indices: u,
271
+ depth: this.depth,
272
+ maxBinNumber: this.maxBinNumber,
273
+ maxRefLength: o
274
+ };
275
+ }
276
+ parsePseudoBin(e, t) {
277
+ return {
278
+ lineCount: J(e, t + 28)
279
+ };
280
+ }
281
+ async blocksForRange(e, t, n, i = {}) {
282
+ t < 0 && (t = 0);
283
+ const o = await this.parse(i), a = o.refNameToId[e];
284
+ if (a === void 0)
285
+ return [];
286
+ const r = o.indices[a];
287
+ if (!r)
288
+ return [];
289
+ const l = this.reg2bins(t, n), m = [];
290
+ for (const [c, u] of l)
291
+ for (let f = c; f <= u; f++)
292
+ if (r.binIndex[f])
293
+ for (const g of r.binIndex[f])
294
+ m.push(new L(g.minv, g.maxv, f));
295
+ return Q(m, new $(0, 0));
296
+ }
297
+ /**
298
+ * calculate the list of bins that may overlap with region [beg,end) (zero-based half-open)
299
+ */
300
+ reg2bins(e, t) {
301
+ e -= 1, e < 1 && (e = 1), t > 2 ** 50 && (t = 2 ** 34), t -= 1;
302
+ let n = 0, i = 0, o = this.minShift + this.depth * 3;
303
+ const a = [];
304
+ for (; n <= this.depth; o -= 3, i += fe(1, n * 3), n += 1) {
305
+ const r = i + G(e, o), l = i + G(t, o);
306
+ if (l - r + a.length > this.maxBinNumber)
307
+ 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`);
308
+ a.push([r, l]);
309
+ }
310
+ return a;
311
+ }
312
+ }
313
+ const he = 21578324, j = 14;
314
+ function de(s, e) {
315
+ return s += 1, e -= 1, [
316
+ [0, 0],
317
+ [1 + (s >> 26), 1 + (e >> 26)],
318
+ [9 + (s >> 23), 9 + (e >> 23)],
319
+ [73 + (s >> 20), 73 + (e >> 20)],
320
+ [585 + (s >> 17), 585 + (e >> 17)],
321
+ [4681 + (s >> 14), 4681 + (e >> 14)]
322
+ ];
323
+ }
324
+ class _ extends X {
325
+ async lineCount(e, t = {}) {
326
+ var a;
327
+ const n = await this.parse(t), i = n.refNameToId[e];
328
+ return i === void 0 || !n.indices[i] ? -1 : ((a = n.indices[i].stats) == null ? void 0 : a.lineCount) ?? -1;
329
+ }
330
+ // fetch and parse the index
331
+ async _parse(e = {}) {
332
+ const t = await this.filehandle.readFile(e), n = await V(t);
333
+ B(e.signal);
334
+ const i = new DataView(n.buffer);
335
+ if (i.getUint32(0, !0) !== he)
336
+ throw new Error("Not a TBI file");
337
+ const a = i.getUint32(4, !0), r = i.getUint32(8, !0), l = r & 65536 ? "zero-based-half-open" : "1-based-closed", c = {
338
+ 0: "generic",
339
+ 1: "SAM",
340
+ 2: "VCF"
341
+ }[r & 15];
342
+ if (!c)
343
+ throw new Error(`invalid Tabix preset format flags ${r}`);
344
+ const u = {
345
+ ref: i.getInt32(12, !0),
346
+ start: i.getInt32(16, !0),
347
+ end: i.getInt32(20, !0)
348
+ }, f = i.getInt32(24, !0), g = 5, b = ((1 << (g + 1) * 3) - 1) / 7, I = 2 ** (14 + g * 3), x = f ? String.fromCharCode(f) : void 0, h = i.getInt32(28, !0), p = i.getInt32(32, !0), { refNameToId: w, refIdToName: k } = this._parseNameBytes(n.slice(36, 36 + p));
349
+ let d = 36 + p, C;
350
+ return {
351
+ indices: new Array(a).fill(0).map(() => {
352
+ const P = i.getInt32(d, !0);
353
+ d += 4;
354
+ const S = {};
355
+ let A;
356
+ for (let v = 0; v < P; v += 1) {
357
+ const F = i.getUint32(d, !0);
358
+ if (d += 4, F > b + 1)
359
+ throw new Error("tabix index contains too many bins, please use a CSI index");
360
+ if (F === b + 1) {
361
+ const N = i.getInt32(d, !0);
362
+ d += 4, N === 2 && (A = this.parsePseudoBin(n, d)), d += 16 * N;
363
+ } else {
364
+ const N = i.getInt32(d, !0);
365
+ d += 4;
366
+ const U = new Array(N);
367
+ for (let M = 0; M < N; M += 1) {
368
+ const q = T(n, d), ee = T(n, d + 8);
369
+ d += 16, C = this._findFirstData(C, q), U[M] = new L(q, ee, F);
370
+ }
371
+ S[F] = U;
372
+ }
373
+ }
374
+ const O = i.getInt32(d, !0);
375
+ d += 4;
376
+ const z = new Array(O);
377
+ for (let v = 0; v < O; v += 1)
378
+ z[v] = T(n, d), d += 8, C = this._findFirstData(C, z[v]);
379
+ return {
380
+ binIndex: S,
381
+ linearIndex: z,
382
+ stats: A
383
+ };
384
+ }),
385
+ metaChar: x,
386
+ maxBinNumber: b,
387
+ maxRefLength: I,
388
+ skipLines: h,
389
+ firstDataLine: C,
390
+ columnNumbers: u,
391
+ coordinateType: l,
392
+ format: c,
393
+ refIdToName: k,
394
+ refNameToId: w,
395
+ maxBlockSize: 65536
396
+ };
397
+ }
398
+ parsePseudoBin(e, t) {
399
+ return {
400
+ lineCount: J(e, t + 16)
401
+ };
402
+ }
403
+ async blocksForRange(e, t, n, i = {}) {
404
+ t < 0 && (t = 0);
405
+ const o = await this.parse(i), a = o.refNameToId[e];
406
+ if (a === void 0)
407
+ return [];
408
+ const r = o.indices[a];
409
+ if (!r)
410
+ return [];
411
+ (r.linearIndex.length > 0 ? r.linearIndex[t >> j >= r.linearIndex.length ? r.linearIndex.length - 1 : t >> j] : new $(0, 0)) || console.warn("querying outside of possible tabix range");
412
+ const m = de(t, n), c = [];
413
+ for (const [I, x] of m)
414
+ for (let h = I; h <= x; h++)
415
+ if (r.binIndex[h])
416
+ for (const p of r.binIndex[h])
417
+ c.push(new L(p.minv, p.maxv, h));
418
+ const u = r.linearIndex.length;
419
+ let f;
420
+ const g = Math.min(t >> 14, u - 1), b = Math.min(n >> 14, u - 1);
421
+ for (let I = g; I <= b; ++I) {
422
+ const x = r.linearIndex[I];
423
+ x && (!f || x.compareTo(f) < 0) && (f = x);
424
+ }
425
+ return Q(c, f);
426
+ }
427
+ }
428
+ class pe {
429
+ /**
430
+ * @param {object} args
431
+ *
432
+ * @param {string} [args.path]
433
+ *
434
+ * @param {filehandle} [args.filehandle]
435
+ *
436
+ * @param {string} [args.tbiPath]
437
+ *
438
+ * @param {filehandle} [args.tbiFilehandle]
439
+ *
440
+ * @param {string} [args.csiPath]
441
+ *
442
+ * @param {filehandle} [args.csiFilehandle]
443
+ *
444
+ * @param {url} [args.url]
445
+ *
446
+ * @param {csiUrl} [args.csiUrl]
447
+ *
448
+ * @param {tbiUrl} [args.tbiUrl]
449
+ *
450
+ * @param {function} [args.renameRefSeqs] optional function with sig `string
451
+ * => string` to transform reference sequence names for the purpose of
452
+ * indexing and querying. note that the data that is returned is not altered,
453
+ * just the names of the reference sequences that are used for querying.
454
+ */
455
+ constructor({ path: e, filehandle: t, url: n, tbiPath: i, tbiUrl: o, tbiFilehandle: a, csiPath: r, csiUrl: l, csiFilehandle: m, renameRefSeqs: c = (f) => f, chunkCacheSize: u = 5 * 2 ** 20 }) {
456
+ if (this.cache = new H({
457
+ maxSize: 1e3
458
+ }), t)
459
+ this.filehandle = t;
460
+ else if (e)
461
+ this.filehandle = new E(e);
462
+ else if (n)
463
+ this.filehandle = new D(n);
464
+ else
465
+ throw new TypeError("must provide either filehandle or path");
466
+ if (a)
467
+ this.index = new _({
468
+ filehandle: a,
469
+ renameRefSeqs: c
470
+ });
471
+ else if (m)
472
+ this.index = new R({
473
+ filehandle: m,
474
+ renameRefSeqs: c
475
+ });
476
+ else if (i)
477
+ this.index = new _({
478
+ filehandle: new E(i),
479
+ renameRefSeqs: c
480
+ });
481
+ else if (r)
482
+ this.index = new R({
483
+ filehandle: new E(r),
484
+ renameRefSeqs: c
485
+ });
486
+ else if (e)
487
+ this.index = new _({
488
+ filehandle: new E(`${e}.tbi`),
489
+ renameRefSeqs: c
490
+ });
491
+ else if (l)
492
+ this.index = new R({
493
+ filehandle: new D(l)
494
+ });
495
+ else if (o)
496
+ this.index = new _({
497
+ filehandle: new D(o)
498
+ });
499
+ else if (n)
500
+ this.index = new _({
501
+ filehandle: new D(`${n}.tbi`)
502
+ });
503
+ else
504
+ throw new TypeError("must provide one of tbiFilehandle, tbiPath, csiFilehandle, csiPath, tbiUrl, csiUrl");
505
+ this.renameRefSeq = c, this.chunkCache = new te({
506
+ cache: new H({ maxSize: Math.floor(u / 65536) }),
507
+ fill: (f, g) => this.readChunk(f, { signal: g })
508
+ });
509
+ }
510
+ /**
511
+ * @param refName name of the reference sequence
512
+ *
513
+ * @param start start of the region (in 0-based half-open coordinates)
514
+ *
515
+ * @param end end of the region (in 0-based half-open coordinates)
516
+ *
517
+ * @param opts callback called for each line in the region. can also pass a
518
+ * object param containing obj.lineCallback, obj.signal, etc
519
+ *
520
+ * @returns promise that is resolved when the whole read is finished,
521
+ * rejected on error
522
+ */
523
+ calculateFileOffset(e, t, n, i, o) {
524
+ return e[n] * 256 + (i - t[n]) + o + 1;
525
+ }
526
+ async getLines(e, t, n, i) {
527
+ let o, a = {}, r;
528
+ typeof i == "function" ? r = i : (a = i, r = i.lineCallback, o = i.signal);
529
+ const l = await this.index.getMetadata(a);
530
+ B(o);
531
+ const m = t ?? 0, c = n ?? l.maxRefLength;
532
+ if (!(m <= c))
533
+ throw new TypeError("invalid start and end coordinates. start must be less than or equal to end");
534
+ if (m === c)
535
+ return;
536
+ const u = await this.index.blocksForRange(e, m, c, a);
537
+ B(o);
538
+ const f = new TextDecoder("utf8");
539
+ for (const g of u) {
540
+ const { buffer: b, cpositions: I, dpositions: x } = await this.chunkCache.get(g.toString(), g, o);
541
+ B(o);
542
+ let h = 0, p = 0;
543
+ const w = f.decode(b);
544
+ if (b.length == w.length)
545
+ for (; h < w.length; ) {
546
+ const d = w.indexOf(`
547
+ `, h);
548
+ if (d === -1)
549
+ break;
550
+ const C = w.slice(h, d);
551
+ if (x) {
552
+ const S = h + g.minv.dataPosition;
553
+ for (; p < x.length && S >= x[p]; )
554
+ p++;
555
+ }
556
+ const { startCoordinate: y, overlaps: P } = this.checkLine(l, e, m, c, C);
557
+ if (P)
558
+ r(C, this.calculateFileOffset(I, x, p, h, g.minv.dataPosition));
559
+ else if (y !== void 0 && y >= c)
560
+ return;
561
+ h = d + 1;
562
+ }
563
+ else
564
+ for (; h < b.length; ) {
565
+ const d = b.indexOf(10, h);
566
+ if (d === -1)
567
+ break;
568
+ const C = b.slice(h, d), y = f.decode(C);
569
+ if (x) {
570
+ const A = h + g.minv.dataPosition;
571
+ for (; p < x.length && A >= x[p]; )
572
+ p++;
573
+ }
574
+ const { startCoordinate: P, overlaps: S } = this.checkLine(l, e, m, c, y);
575
+ if (S)
576
+ r(y, this.calculateFileOffset(I, x, p, h, g.minv.dataPosition));
577
+ else if (P !== void 0 && P >= c)
578
+ return;
579
+ h = d + 1;
580
+ }
581
+ }
582
+ }
583
+ async getMetadata(e = {}) {
584
+ return this.index.getMetadata(e);
585
+ }
586
+ /**
587
+ * get a buffer containing the "header" region of the file, which are the
588
+ * bytes up to the first non-meta line
589
+ */
590
+ async getHeaderBuffer(e = {}) {
591
+ const { firstDataLine: t, metaChar: n, maxBlockSize: i } = await this.getMetadata(e);
592
+ B(e.signal);
593
+ const o = ((t == null ? void 0 : t.blockPosition) || 0) + i, a = await this.filehandle.read(o, 0, e), r = await V(a);
594
+ if (n) {
595
+ let l = -1;
596
+ const m = 10, c = n.charCodeAt(0);
597
+ for (let u = 0, f = r.length; u < f; u++) {
598
+ const g = r[u];
599
+ if (u === l + 1 && g !== c)
600
+ break;
601
+ g === m && (l = u);
602
+ }
603
+ return r.subarray(0, l + 1);
604
+ }
605
+ return r;
606
+ }
607
+ /**
608
+ * get a string containing the "header" region of the file, is the portion up
609
+ * to the first non-meta line
610
+ *
611
+ * @returns {Promise} for a string
612
+ */
613
+ async getHeader(e = {}) {
614
+ const t = new TextDecoder("utf8"), n = await this.getHeaderBuffer(e);
615
+ return t.decode(n);
616
+ }
617
+ /**
618
+ * get an array of reference sequence names, in the order in which they occur
619
+ * in the file. reference sequence renaming is not applied to these names.
620
+ */
621
+ async getReferenceSequenceNames(e = {}) {
622
+ return (await this.getMetadata(e)).refIdToName;
623
+ }
624
+ /**
625
+ * @param {object} metadata metadata object from the parsed index, containing
626
+ * columnNumbers, metaChar, and format
627
+ *
628
+ * @param {string} regionRefName
629
+ *
630
+ * @param {number} regionStart region start coordinate (0-based-half-open)
631
+ *
632
+ * @param {number} regionEnd region end coordinate (0-based-half-open)
633
+ *
634
+ * @param {array[string]} line
635
+ *
636
+ * @returns {object} like `{startCoordinate, overlaps}`. overlaps is boolean,
637
+ * true if line is a data line that overlaps the given region
638
+ */
639
+ checkLine(e, t, n, i, o) {
640
+ const { columnNumbers: a, metaChar: r, coordinateType: l, format: m } = e;
641
+ if (r && o.startsWith(r))
642
+ return { overlaps: !1 };
643
+ let { ref: c, start: u, end: f } = a;
644
+ c || (c = 0), u || (u = 0), f || (f = 0), m === "VCF" && (f = 8);
645
+ const g = Math.max(c, u, f);
646
+ let b = 1, I = 0, x = "", h = -1 / 0;
647
+ const p = o.length;
648
+ for (let w = 0; w < p + 1; w++)
649
+ if (o[w] === " " || w === p) {
650
+ if (b === c) {
651
+ if (this.renameRefSeq(o.slice(I, w)) !== t)
652
+ return {
653
+ overlaps: !1
654
+ };
655
+ } else if (b === u) {
656
+ if (h = Number.parseInt(o.slice(I, w), 10), l === "1-based-closed" && (h -= 1), h >= i)
657
+ return {
658
+ startCoordinate: h,
659
+ overlaps: !1
660
+ };
661
+ if ((f === 0 || f === u) && // if we have no end, we assume the feature is 1 bp long
662
+ h + 1 <= n)
663
+ return {
664
+ startCoordinate: h,
665
+ overlaps: !1
666
+ };
667
+ } else if (m === "VCF" && b === 4)
668
+ x = o.slice(I, w);
669
+ else if (b === f && (m === "VCF" ? this._getVcfEnd(h, x, o.slice(I, w)) : Number.parseInt(o.slice(I, w), 10)) <= n)
670
+ return {
671
+ overlaps: !1
672
+ };
673
+ if (b === g)
674
+ break;
675
+ I = w + 1, b += 1;
676
+ }
677
+ return {
678
+ startCoordinate: h,
679
+ overlaps: !0
680
+ };
681
+ }
682
+ _getVcfEnd(e, t, n) {
683
+ let i = e + t.length;
684
+ const o = n.includes("SVTYPE=TRA");
685
+ if (n[0] !== "." && !o) {
686
+ const r = /(?:^|;)END=([^;]+)/.exec(n);
687
+ r && (i = Number.parseInt(r[1], 10));
688
+ } else if (o)
689
+ return e + 1;
690
+ return i;
691
+ }
692
+ /**
693
+ * return the approximate number of data lines in the given reference
694
+ * sequence
695
+ *
696
+ * @param refSeq reference sequence name
697
+ *
698
+ * @returns number of data lines present on that reference sequence
699
+ */
700
+ async lineCount(e, t = {}) {
701
+ return this.index.lineCount(e, t);
702
+ }
703
+ /**
704
+ * read and uncompress the data in a chunk (composed of one or more
705
+ * contiguous bgzip blocks) of the file
706
+ */
707
+ async readChunk(e, t = {}) {
708
+ const n = await this.filehandle.read(e.fetchedSize(), e.minv.blockPosition, t);
709
+ return ie(n, e, this.cache);
710
+ }
711
+ }
712
+ export {
713
+ R as CSI,
714
+ _ as TBI,
715
+ pe as TabixIndexedFile
716
+ };