@genome-spy/core 0.65.0 → 0.67.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/bundle/browser-BRemItdO.js +138 -0
- package/dist/bundle/{index-CD7FLu9x.js → index-BatuyGAI.js} +23 -21
- package/dist/bundle/{index-C0llXMqm.js → index-ByuE8dvu.js} +140 -88
- package/dist/bundle/index-Cq3QFUxX.js +1781 -0
- package/dist/bundle/index-D28m8tSW.js +1607 -0
- package/dist/bundle/index-DbJ0oeYM.js +631 -0
- package/dist/bundle/index.es.js +15821 -14601
- package/dist/bundle/index.js +214 -212
- package/dist/bundle/{inflate-DRgHi_KK.js → inflate-GtwLkvSP.js} +222 -224
- package/dist/bundle/unzip-NywezaRR.js +1492 -0
- package/dist/schema.json +13 -3
- package/dist/src/config/scaleDefaults.d.ts +8 -0
- package/dist/src/config/scaleDefaults.d.ts.map +1 -0
- package/dist/src/config/scaleDefaults.js +45 -0
- package/dist/src/data/flowHandle.d.ts +2 -0
- package/dist/src/data/flowHandle.d.ts.map +1 -1
- package/dist/src/data/flowHandle.js +1 -0
- package/dist/src/data/flowInit.d.ts +12 -4
- package/dist/src/data/flowInit.d.ts.map +1 -1
- package/dist/src/data/flowInit.js +115 -16
- package/dist/src/data/sources/lazy/axisTickSource.js +1 -1
- package/dist/src/data/sources/lazy/singleAxisLazySource.d.ts +1 -1
- package/dist/src/data/sources/lazy/singleAxisLazySource.d.ts.map +1 -1
- package/dist/src/data/sources/lazy/singleAxisLazySource.js +10 -3
- package/dist/src/data/sources/lazy/singleAxisWindowedSource.d.ts.map +1 -1
- package/dist/src/data/sources/lazy/singleAxisWindowedSource.js +5 -1
- package/dist/src/data/transforms/filterScoredLabels.d.ts +1 -1
- package/dist/src/data/transforms/filterScoredLabels.d.ts.map +1 -1
- package/dist/src/data/transforms/filterScoredLabels.js +1 -1
- package/dist/src/data/transforms/linearizeGenomicCoordinate.d.ts.map +1 -1
- package/dist/src/data/transforms/linearizeGenomicCoordinate.js +2 -1
- package/dist/src/encoder/encoder.d.ts +1 -1
- package/dist/src/encoder/encoder.d.ts.map +1 -1
- package/dist/src/encoder/encoder.js +1 -1
- package/dist/src/genome/scaleLocus.d.ts +39 -0
- package/dist/src/genome/scaleLocus.d.ts.map +1 -1
- package/dist/src/genome/scaleLocus.js +76 -0
- package/dist/src/genomeSpy/canvasExport.d.ts +19 -0
- package/dist/src/genomeSpy/canvasExport.d.ts.map +1 -0
- package/dist/src/genomeSpy/canvasExport.js +66 -0
- package/dist/src/genomeSpy/containerUi.d.ts +17 -0
- package/dist/src/genomeSpy/containerUi.d.ts.map +1 -0
- package/dist/src/genomeSpy/containerUi.js +78 -0
- package/dist/src/genomeSpy/eventListenerRegistry.d.ts +19 -0
- package/dist/src/genomeSpy/eventListenerRegistry.d.ts.map +1 -0
- package/dist/src/genomeSpy/eventListenerRegistry.js +38 -0
- package/dist/src/genomeSpy/inputBindingManager.d.ts +14 -0
- package/dist/src/genomeSpy/inputBindingManager.d.ts.map +1 -0
- package/dist/src/genomeSpy/inputBindingManager.js +63 -0
- package/dist/src/genomeSpy/interactionController.d.ts +40 -0
- package/dist/src/genomeSpy/interactionController.d.ts.map +1 -0
- package/dist/src/genomeSpy/interactionController.js +371 -0
- package/dist/src/genomeSpy/keyboardListenerManager.d.ts +10 -0
- package/dist/src/genomeSpy/keyboardListenerManager.d.ts.map +1 -0
- package/dist/src/genomeSpy/keyboardListenerManager.js +31 -0
- package/dist/src/genomeSpy/loadingIndicatorManager.d.ts +15 -0
- package/dist/src/genomeSpy/loadingIndicatorManager.d.ts.map +1 -0
- package/dist/src/genomeSpy/loadingIndicatorManager.js +92 -0
- package/dist/src/genomeSpy/renderCoordinator.d.ts +22 -0
- package/dist/src/genomeSpy/renderCoordinator.d.ts.map +1 -0
- package/dist/src/genomeSpy/renderCoordinator.js +118 -0
- package/dist/src/genomeSpy/viewContextFactory.d.ts +18 -0
- package/dist/src/genomeSpy/viewContextFactory.d.ts.map +1 -0
- package/dist/src/genomeSpy/viewContextFactory.js +79 -0
- package/dist/src/genomeSpy/viewDataInit.d.ts +22 -0
- package/dist/src/genomeSpy/viewDataInit.d.ts.map +1 -0
- package/dist/src/genomeSpy/viewDataInit.js +160 -0
- package/dist/src/genomeSpy/viewDataInit.test.d.ts +2 -0
- package/dist/src/genomeSpy/viewDataInit.test.d.ts.map +1 -0
- package/dist/src/genomeSpy/viewHierarchyConfig.d.ts +14 -0
- package/dist/src/genomeSpy/viewHierarchyConfig.d.ts.map +1 -0
- package/dist/src/genomeSpy/viewHierarchyConfig.js +24 -0
- package/dist/src/genomeSpy/viewHighlight.d.ts +5 -0
- package/dist/src/genomeSpy/viewHighlight.d.ts.map +1 -0
- package/dist/src/genomeSpy/viewHighlight.js +30 -0
- package/dist/src/genomeSpy.d.ts +17 -71
- package/dist/src/genomeSpy.d.ts.map +1 -1
- package/dist/src/genomeSpy.js +197 -741
- package/dist/src/gl/dataToVertices.d.ts.map +1 -1
- package/dist/src/gl/dataToVertices.js +16 -4
- package/dist/src/gl/glslScaleGenerator.d.ts +1 -1
- package/dist/src/gl/webGLHelper.d.ts +2 -2
- package/dist/src/gl/webGLHelper.d.ts.map +1 -1
- package/dist/src/gl/webGLHelper.js +4 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -12
- package/dist/src/marks/mark.d.ts.map +1 -1
- package/dist/src/marks/mark.js +4 -2
- package/dist/src/{view → scales}/axisResolution.d.ts +9 -16
- package/dist/src/scales/axisResolution.d.ts.map +1 -0
- package/dist/src/{view → scales}/axisResolution.js +29 -18
- package/dist/src/scales/axisResolution.test.d.ts.map +1 -0
- package/dist/src/scales/scaleDomainAggregator.d.ts +57 -0
- package/dist/src/scales/scaleDomainAggregator.d.ts.map +1 -0
- package/dist/src/scales/scaleDomainAggregator.js +167 -0
- package/dist/src/scales/scaleDomainAggregator.test.d.ts +2 -0
- package/dist/src/scales/scaleDomainAggregator.test.d.ts.map +1 -0
- package/dist/src/scales/scaleInstanceManager.d.ts +40 -0
- package/dist/src/scales/scaleInstanceManager.d.ts.map +1 -0
- package/dist/src/scales/scaleInstanceManager.js +317 -0
- package/dist/src/scales/scaleInstanceManager.test.d.ts +2 -0
- package/dist/src/scales/scaleInstanceManager.test.d.ts.map +1 -0
- package/dist/src/scales/scaleInteractionController.d.ts +73 -0
- package/dist/src/scales/scaleInteractionController.d.ts.map +1 -0
- package/dist/src/scales/scaleInteractionController.js +336 -0
- package/dist/src/scales/scaleInteractionController.test.d.ts +2 -0
- package/dist/src/scales/scaleInteractionController.test.d.ts.map +1 -0
- package/dist/src/scales/scalePropsResolver.d.ts +23 -0
- package/dist/src/scales/scalePropsResolver.d.ts.map +1 -0
- package/dist/src/scales/scalePropsResolver.js +74 -0
- package/dist/src/{view → scales}/scaleResolution.d.ts +53 -35
- package/dist/src/scales/scaleResolution.d.ts.map +1 -0
- package/dist/src/scales/scaleResolution.js +732 -0
- package/dist/src/scales/scaleResolution.test.d.ts.map +1 -0
- package/dist/src/scales/scaleResolutionConstants.d.ts +6 -0
- package/dist/src/scales/scaleResolutionConstants.d.ts.map +1 -0
- package/dist/src/scales/scaleResolutionConstants.js +5 -0
- package/dist/src/scales/scaleRules.d.ts +16 -0
- package/dist/src/scales/scaleRules.d.ts.map +1 -0
- package/dist/src/scales/scaleRules.js +103 -0
- package/dist/src/scales/scaleRules.test.d.ts +2 -0
- package/dist/src/scales/scaleRules.test.d.ts.map +1 -0
- package/dist/src/spec/channel.d.ts +13 -18
- package/dist/src/spec/scale.d.ts +6 -0
- package/dist/src/types/embedApi.d.ts +5 -0
- package/dist/src/types/scaleResolutionApi.d.ts +1 -1
- package/dist/src/utils/domainArray.d.ts.map +1 -1
- package/dist/src/utils/domainArray.js +3 -0
- package/dist/src/utils/indexer.d.ts +3 -0
- package/dist/src/utils/indexer.d.ts.map +1 -1
- package/dist/src/utils/indexer.js +3 -0
- package/dist/src/view/concatView.d.ts +18 -0
- package/dist/src/view/concatView.d.ts.map +1 -1
- package/dist/src/view/concatView.js +73 -0
- package/dist/src/view/concatView.test.d.ts +2 -0
- package/dist/src/view/concatView.test.d.ts.map +1 -0
- package/dist/src/view/containerMutationHelper.d.ts +74 -0
- package/dist/src/view/containerMutationHelper.d.ts.map +1 -0
- package/dist/src/view/containerMutationHelper.js +118 -0
- package/dist/src/view/containerView.d.ts +0 -7
- package/dist/src/view/containerView.d.ts.map +1 -1
- package/dist/src/view/containerView.js +0 -10
- package/dist/src/view/facetView.d.ts.map +1 -1
- package/dist/src/view/facetView.js +0 -15
- package/dist/src/view/flowBuilder.d.ts +5 -3
- package/dist/src/view/flowBuilder.d.ts.map +1 -1
- package/dist/src/view/flowBuilder.js +69 -6
- package/dist/src/view/gridView/gridChild.d.ts +11 -0
- package/dist/src/view/gridView/gridChild.d.ts.map +1 -1
- package/dist/src/view/gridView/gridChild.js +32 -6
- package/dist/src/view/gridView/gridView.d.ts +39 -1
- package/dist/src/view/gridView/gridView.d.ts.map +1 -1
- package/dist/src/view/gridView/gridView.js +106 -48
- package/dist/src/view/gridView/gridView.test.d.ts +2 -0
- package/dist/src/view/gridView/gridView.test.d.ts.map +1 -0
- package/dist/src/view/gridView/scrollbar.d.ts +39 -8
- package/dist/src/view/gridView/scrollbar.d.ts.map +1 -1
- package/dist/src/view/gridView/scrollbar.js +184 -69
- package/dist/src/view/layerView.d.ts +14 -0
- package/dist/src/view/layerView.d.ts.map +1 -1
- package/dist/src/view/layerView.js +66 -0
- package/dist/src/view/layerView.test.d.ts +2 -0
- package/dist/src/view/layerView.test.d.ts.map +1 -0
- package/dist/src/view/testUtils.d.ts.map +1 -1
- package/dist/src/view/testUtils.js +7 -1
- package/dist/src/view/unitView.d.ts.map +1 -1
- package/dist/src/view/unitView.js +41 -36
- package/dist/src/view/view.d.ts +18 -6
- package/dist/src/view/view.d.ts.map +1 -1
- package/dist/src/view/view.js +30 -4
- package/package.json +2 -2
- package/dist/bundle/browser-txUcLy2H.js +0 -123
- package/dist/bundle/index-BQpbYrv4.js +0 -1712
- package/dist/bundle/index-BhtHKLUo.js +0 -73
- package/dist/bundle/index-CCe8rnZz.js +0 -716
- package/dist/bundle/index-DhcU-Gk-.js +0 -1487
- package/dist/src/data/collector.test.js +0 -138
- package/dist/src/data/dataFlow.test.js +0 -38
- package/dist/src/data/flow.test.js +0 -81
- package/dist/src/data/flowInit.test.js +0 -413
- package/dist/src/data/flowNode.test.js +0 -50
- package/dist/src/data/flowOptimizer.test.js +0 -209
- package/dist/src/data/formats/fasta.test.js +0 -27
- package/dist/src/data/sources/inlineSource.test.js +0 -63
- package/dist/src/data/sources/sequenceSource.test.js +0 -81
- package/dist/src/data/transforms/aggregate.test.js +0 -134
- package/dist/src/data/transforms/clone.test.js +0 -11
- package/dist/src/data/transforms/coverage.test.js +0 -238
- package/dist/src/data/transforms/filter.test.js +0 -20
- package/dist/src/data/transforms/flatten.test.js +0 -96
- package/dist/src/data/transforms/flattenDelimited.test.js +0 -90
- package/dist/src/data/transforms/flattenSequence.test.js +0 -34
- package/dist/src/data/transforms/formula.test.js +0 -25
- package/dist/src/data/transforms/identifier.test.js +0 -92
- package/dist/src/data/transforms/pileup.test.js +0 -70
- package/dist/src/data/transforms/project.test.js +0 -32
- package/dist/src/data/transforms/regexExtract.test.js +0 -70
- package/dist/src/data/transforms/regexFold.test.js +0 -201
- package/dist/src/data/transforms/sample.test.js +0 -38
- package/dist/src/data/transforms/stack.test.js +0 -91
- package/dist/src/encoder/accessor.test.js +0 -162
- package/dist/src/encoder/encoder.test.js +0 -105
- package/dist/src/genome/genome.test.js +0 -268
- package/dist/src/genome/genomes.test.js +0 -8
- package/dist/src/genome/scaleIndex.test.js +0 -78
- package/dist/src/genome/scaleLocus.test.js +0 -4
- package/dist/src/scale/scale.test.js +0 -326
- package/dist/src/scale/ticks.test.js +0 -46
- package/dist/src/selection/selection.test.js +0 -14
- package/dist/src/utils/addBaseUrl.test.js +0 -30
- package/dist/src/utils/binnedIndex.test.js +0 -201
- package/dist/src/utils/cloner.test.js +0 -35
- package/dist/src/utils/coalesce.test.js +0 -16
- package/dist/src/utils/concatIterables.test.js +0 -8
- package/dist/src/utils/domainArray.test.js +0 -130
- package/dist/src/utils/indexer.test.js +0 -49
- package/dist/src/utils/interactionEvent.test.js +0 -35
- package/dist/src/utils/iterateNestedMaps.test.js +0 -33
- package/dist/src/utils/kWayMerge.test.js +0 -30
- package/dist/src/utils/mergeObjects.test.js +0 -42
- package/dist/src/utils/numberExtractor.test.js +0 -6
- package/dist/src/utils/propertyCacher.test.js +0 -89
- package/dist/src/utils/propertyCoalescer.test.js +0 -25
- package/dist/src/utils/radixSort.test.js +0 -51
- package/dist/src/utils/reservationMap.test.js +0 -20
- package/dist/src/utils/ringBuffer.test.js +0 -39
- package/dist/src/utils/topK.test.js +0 -54
- package/dist/src/utils/trees.test.js +0 -135
- package/dist/src/utils/url.test.js +0 -28
- package/dist/src/utils/variableTools.test.js +0 -13
- package/dist/src/view/axisResolution.d.ts.map +0 -1
- package/dist/src/view/axisResolution.test.d.ts.map +0 -1
- package/dist/src/view/axisResolution.test.js +0 -206
- package/dist/src/view/flowBuilder.test.js +0 -125
- package/dist/src/view/gridView/selectionRect.test.js +0 -87
- package/dist/src/view/layout/flexLayout.test.js +0 -323
- package/dist/src/view/layout/grid.test.js +0 -71
- package/dist/src/view/layout/rectangle.test.js +0 -192
- package/dist/src/view/paramMediator.test.js +0 -282
- package/dist/src/view/scaleResolution.d.ts.map +0 -1
- package/dist/src/view/scaleResolution.js +0 -1059
- package/dist/src/view/scaleResolution.test.d.ts.map +0 -1
- package/dist/src/view/scaleResolution.test.js +0 -645
- package/dist/src/view/view.test.js +0 -245
- package/dist/src/view/viewDispose.test.js +0 -110
- package/dist/src/view/viewFactory.test.js +0 -25
- package/dist/src/view/viewUtils.test.js +0 -87
- /package/dist/src/{view → scales}/axisResolution.test.d.ts +0 -0
- /package/dist/src/{view → scales}/scaleResolution.test.d.ts +0 -0
|
@@ -0,0 +1,1607 @@
|
|
|
1
|
+
import { Q as V, u as D, a as Y } from "./unzip-NywezaRR.js";
|
|
2
|
+
import { LocalFile as v, RemoteFile as B } from "./browser-BRemItdO.js";
|
|
3
|
+
let G = class {
|
|
4
|
+
constructor(e, n, t, s) {
|
|
5
|
+
this.minv = e, this.maxv = n, this.bin = t, this._fetchedSize = s;
|
|
6
|
+
}
|
|
7
|
+
toUniqueString() {
|
|
8
|
+
return `${this.minv.toString()}..${this.maxv.toString()} (bin ${this.bin}, fetchedSize ${this.fetchedSize()})`;
|
|
9
|
+
}
|
|
10
|
+
toString() {
|
|
11
|
+
return this.toUniqueString();
|
|
12
|
+
}
|
|
13
|
+
compareTo(e) {
|
|
14
|
+
return this.minv.compareTo(e.minv) || this.maxv.compareTo(e.maxv) || this.bin - e.bin;
|
|
15
|
+
}
|
|
16
|
+
fetchedSize() {
|
|
17
|
+
return this._fetchedSize !== void 0 ? this._fetchedSize : this.maxv.blockPosition + 65536 - this.minv.blockPosition;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const q = 65536, J = q * q;
|
|
21
|
+
function X(h, e = 0) {
|
|
22
|
+
const n = h[e] | h[e + 1] << 8 | h[e + 2] << 16 | h[e + 3] << 24;
|
|
23
|
+
return ((h[e + 4] | h[e + 5] << 8 | h[e + 6] << 16 | h[e + 7] << 24) >>> 0) * J + (n >>> 0);
|
|
24
|
+
}
|
|
25
|
+
function Z(h = {}) {
|
|
26
|
+
return "aborted" in h ? { signal: h } : h;
|
|
27
|
+
}
|
|
28
|
+
function N(h, e) {
|
|
29
|
+
const n = h.length;
|
|
30
|
+
if (n === 0)
|
|
31
|
+
return h;
|
|
32
|
+
let t;
|
|
33
|
+
if (e) {
|
|
34
|
+
const a = e.blockPosition, x = e.dataPosition;
|
|
35
|
+
t = [];
|
|
36
|
+
for (let u = 0; u < n; u++) {
|
|
37
|
+
const c = h[u], d = c.maxv;
|
|
38
|
+
(d.blockPosition - a || d.dataPosition - x) > 0 && t.push(c);
|
|
39
|
+
}
|
|
40
|
+
if (t.length === 0)
|
|
41
|
+
return t;
|
|
42
|
+
} else
|
|
43
|
+
t = h;
|
|
44
|
+
t.sort((a, x) => {
|
|
45
|
+
const u = a.minv.blockPosition - x.minv.blockPosition;
|
|
46
|
+
return u !== 0 ? u : a.minv.dataPosition - x.minv.dataPosition;
|
|
47
|
+
});
|
|
48
|
+
const s = [];
|
|
49
|
+
let r = t[0];
|
|
50
|
+
s.push(r);
|
|
51
|
+
let o = r.minv.blockPosition, i = r.maxv.blockPosition;
|
|
52
|
+
for (let a = 1; a < t.length; a++) {
|
|
53
|
+
const x = t[a], u = x.minv.blockPosition, c = x.maxv.blockPosition;
|
|
54
|
+
if (u - i < 65e3 && c - o < 5e6) {
|
|
55
|
+
const d = x.maxv, f = r.maxv;
|
|
56
|
+
(c - i || d.dataPosition - f.dataPosition) > 0 && (r.maxv = d, i = c);
|
|
57
|
+
} else
|
|
58
|
+
s.push(x), r = x, o = u, i = c;
|
|
59
|
+
}
|
|
60
|
+
return s;
|
|
61
|
+
}
|
|
62
|
+
function H(h, e) {
|
|
63
|
+
return {
|
|
64
|
+
lineCount: X(h, e)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function M(h, e) {
|
|
68
|
+
return h ? h.compareTo(e) > 0 ? e : h : e;
|
|
69
|
+
}
|
|
70
|
+
function ee(h, e = (n) => n) {
|
|
71
|
+
let n = 0, t = 0;
|
|
72
|
+
const s = [], r = {};
|
|
73
|
+
for (let o = 0; o < h.length; o += 1)
|
|
74
|
+
if (!h[o]) {
|
|
75
|
+
if (t < o) {
|
|
76
|
+
let i = "";
|
|
77
|
+
for (let a = t; a < o; a++)
|
|
78
|
+
i += String.fromCharCode(h[a]);
|
|
79
|
+
i = e(i), s[n] = i, r[i] = n;
|
|
80
|
+
}
|
|
81
|
+
t = o + 1, n += 1;
|
|
82
|
+
}
|
|
83
|
+
return { refNameToId: r, refIdToName: s };
|
|
84
|
+
}
|
|
85
|
+
function te(h) {
|
|
86
|
+
let e = 0;
|
|
87
|
+
for (const s of h)
|
|
88
|
+
e += s.length;
|
|
89
|
+
const n = new Uint8Array(e);
|
|
90
|
+
let t = 0;
|
|
91
|
+
for (const s of h)
|
|
92
|
+
n.set(s, t), t += s.length;
|
|
93
|
+
return n;
|
|
94
|
+
}
|
|
95
|
+
function ne(h, e, n) {
|
|
96
|
+
return !!((h & e) !== e || h & n);
|
|
97
|
+
}
|
|
98
|
+
function re(h, e) {
|
|
99
|
+
return e === "*" ? h === void 0 : `${h}` != `${e}`;
|
|
100
|
+
}
|
|
101
|
+
function se(h) {
|
|
102
|
+
if (!h)
|
|
103
|
+
return "";
|
|
104
|
+
const { flagInclude: e = 0, flagExclude: n = 0, tagFilter: t } = h, s = t ? `:${t.tag}=${t.value ?? "*"}` : "";
|
|
105
|
+
return `:f${e}x${n}${s}`;
|
|
106
|
+
}
|
|
107
|
+
let j = class {
|
|
108
|
+
constructor({ filehandle: e, renameRefSeq: n = (t) => t }) {
|
|
109
|
+
this.filehandle = e, this.renameRefSeq = n;
|
|
110
|
+
}
|
|
111
|
+
async estimatedBytesForRegions(e, n) {
|
|
112
|
+
const t = await Promise.all(e.map((o) => this.blocksForRange(o.refId, o.start, o.end, n))), s = N(t.flat());
|
|
113
|
+
let r = 0;
|
|
114
|
+
for (const o of s)
|
|
115
|
+
r += o.fetchedSize();
|
|
116
|
+
return r;
|
|
117
|
+
}
|
|
118
|
+
}, Q = class {
|
|
119
|
+
constructor(e, n) {
|
|
120
|
+
this.blockPosition = e, this.dataPosition = n;
|
|
121
|
+
}
|
|
122
|
+
toString() {
|
|
123
|
+
return `${this.blockPosition}:${this.dataPosition}`;
|
|
124
|
+
}
|
|
125
|
+
compareTo(e) {
|
|
126
|
+
return this.blockPosition - e.blockPosition || this.dataPosition - e.dataPosition;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
function S(h, e = 0, n = !1) {
|
|
130
|
+
if (n)
|
|
131
|
+
throw new Error("big-endian virtual file offsets not implemented");
|
|
132
|
+
return new Q(h[e + 7] * 1099511627776 + h[e + 6] * 4294967296 + h[e + 5] * 16777216 + h[e + 4] * 65536 + h[e + 3] * 256 + h[e + 2], h[e + 1] << 8 | h[e]);
|
|
133
|
+
}
|
|
134
|
+
const ie = 21578050;
|
|
135
|
+
function ae(h, e) {
|
|
136
|
+
return h - h % e;
|
|
137
|
+
}
|
|
138
|
+
function oe(h, e) {
|
|
139
|
+
return h - h % e + e;
|
|
140
|
+
}
|
|
141
|
+
function ce(h, e) {
|
|
142
|
+
return e -= 1, [
|
|
143
|
+
[0, 0],
|
|
144
|
+
[1 + (h >> 26), 1 + (e >> 26)],
|
|
145
|
+
[9 + (h >> 23), 9 + (e >> 23)],
|
|
146
|
+
[73 + (h >> 20), 73 + (e >> 20)],
|
|
147
|
+
[585 + (h >> 17), 585 + (e >> 17)],
|
|
148
|
+
[4681 + (h >> 14), 4681 + (e >> 14)]
|
|
149
|
+
];
|
|
150
|
+
}
|
|
151
|
+
class F extends j {
|
|
152
|
+
async lineCount(e, n) {
|
|
153
|
+
var s, r;
|
|
154
|
+
return ((r = (s = (await this.parse(n)).indices(e)) == null ? void 0 : s.stats) == null ? void 0 : r.lineCount) || 0;
|
|
155
|
+
}
|
|
156
|
+
async _parse(e) {
|
|
157
|
+
const n = await this.filehandle.readFile(), t = new DataView(n.buffer);
|
|
158
|
+
if (t.getUint32(0, !0) !== ie)
|
|
159
|
+
throw new Error("Not a BAI file");
|
|
160
|
+
const s = t.getInt32(4, !0), o = ((1 << (5 + 1) * 3) - 1) / 7;
|
|
161
|
+
let i = 8, a;
|
|
162
|
+
const x = [];
|
|
163
|
+
for (let d = 0; d < s; d++) {
|
|
164
|
+
x.push(i);
|
|
165
|
+
const f = t.getInt32(i, !0);
|
|
166
|
+
i += 4;
|
|
167
|
+
for (let l = 0; l < f; l += 1) {
|
|
168
|
+
const g = t.getUint32(i, !0);
|
|
169
|
+
if (i += 4, g === o + 1)
|
|
170
|
+
i += 4, i += 32;
|
|
171
|
+
else {
|
|
172
|
+
if (g > o + 1)
|
|
173
|
+
throw new Error("bai index contains too many bins, please use CSI");
|
|
174
|
+
{
|
|
175
|
+
const _ = t.getInt32(i, !0);
|
|
176
|
+
i += 4;
|
|
177
|
+
for (let m = 0; m < _; m++)
|
|
178
|
+
i += 8, i += 8;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const b = t.getInt32(i, !0);
|
|
183
|
+
i += 4;
|
|
184
|
+
const w = new Array(b);
|
|
185
|
+
for (let l = 0; l < b; l++) {
|
|
186
|
+
const g = S(n, i);
|
|
187
|
+
i += 8, a = M(a, g), w[l] = g;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const u = new V({
|
|
191
|
+
maxSize: 5
|
|
192
|
+
});
|
|
193
|
+
function c(d) {
|
|
194
|
+
let f = x[d];
|
|
195
|
+
if (f === void 0)
|
|
196
|
+
return;
|
|
197
|
+
const b = t.getInt32(f, !0);
|
|
198
|
+
let w;
|
|
199
|
+
f += 4;
|
|
200
|
+
const l = {};
|
|
201
|
+
for (let m = 0; m < b; m += 1) {
|
|
202
|
+
const p = t.getUint32(f, !0);
|
|
203
|
+
if (f += 4, p === o + 1)
|
|
204
|
+
f += 4, w = H(n, f + 16), f += 32;
|
|
205
|
+
else {
|
|
206
|
+
if (p > o + 1)
|
|
207
|
+
throw new Error("bai index contains too many bins, please use CSI");
|
|
208
|
+
{
|
|
209
|
+
const y = t.getInt32(f, !0);
|
|
210
|
+
f += 4;
|
|
211
|
+
const C = new Array(y);
|
|
212
|
+
for (let I = 0; I < y; I++) {
|
|
213
|
+
const k = S(n, f);
|
|
214
|
+
f += 8;
|
|
215
|
+
const R = S(n, f);
|
|
216
|
+
f += 8, a = M(a, k), C[I] = new G(k, R, p);
|
|
217
|
+
}
|
|
218
|
+
l[p] = C;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const g = t.getInt32(f, !0);
|
|
223
|
+
f += 4;
|
|
224
|
+
const _ = new Array(g);
|
|
225
|
+
for (let m = 0; m < g; m++) {
|
|
226
|
+
const p = S(n, f);
|
|
227
|
+
f += 8, a = M(a, p), _[m] = p;
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
binIndex: l,
|
|
231
|
+
linearIndex: _,
|
|
232
|
+
stats: w
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
bai: !0,
|
|
237
|
+
firstDataLine: a,
|
|
238
|
+
maxBlockSize: 65536,
|
|
239
|
+
indices: (d) => {
|
|
240
|
+
if (!u.has(d)) {
|
|
241
|
+
const f = c(d);
|
|
242
|
+
return f && u.set(d, f), f;
|
|
243
|
+
}
|
|
244
|
+
return u.get(d);
|
|
245
|
+
},
|
|
246
|
+
refCount: s
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
async indexCov(e, n, t, s) {
|
|
250
|
+
const o = n !== void 0, a = (await this.parse(s)).indices(e);
|
|
251
|
+
if (!a)
|
|
252
|
+
return [];
|
|
253
|
+
const { linearIndex: x, stats: u } = a;
|
|
254
|
+
if (x.length === 0)
|
|
255
|
+
return [];
|
|
256
|
+
const c = t === void 0 ? (x.length - 1) * 16384 : oe(t, 16384), d = n === void 0 ? 0 : ae(n, 16384), f = o ? new Array((c - d) / 16384) : new Array(x.length - 1), b = x[x.length - 1].blockPosition;
|
|
257
|
+
if (c > (x.length - 1) * 16384)
|
|
258
|
+
throw new Error("query outside of range of linear index");
|
|
259
|
+
let w = x[d / 16384].blockPosition;
|
|
260
|
+
for (let l = d / 16384, g = 0; l < c / 16384; l++, g++)
|
|
261
|
+
f[g] = {
|
|
262
|
+
score: x[l + 1].blockPosition - w,
|
|
263
|
+
start: l * 16384,
|
|
264
|
+
end: l * 16384 + 16384
|
|
265
|
+
}, w = x[l + 1].blockPosition;
|
|
266
|
+
return f.map((l) => ({
|
|
267
|
+
...l,
|
|
268
|
+
score: l.score * ((u == null ? void 0 : u.lineCount) || 0) / b
|
|
269
|
+
}));
|
|
270
|
+
}
|
|
271
|
+
async blocksForRange(e, n, t, s = {}) {
|
|
272
|
+
n < 0 && (n = 0);
|
|
273
|
+
const r = await this.parse(s);
|
|
274
|
+
if (!r)
|
|
275
|
+
return [];
|
|
276
|
+
const o = r.indices(e);
|
|
277
|
+
if (!o)
|
|
278
|
+
return [];
|
|
279
|
+
const i = ce(n, t), a = [], { binIndex: x } = o;
|
|
280
|
+
for (const [b, w] of i)
|
|
281
|
+
for (let l = b; l <= w; l++) {
|
|
282
|
+
const g = x[l];
|
|
283
|
+
if (g)
|
|
284
|
+
for (let _ = 0, m = g.length; _ < m; _++)
|
|
285
|
+
a.push(g[_]);
|
|
286
|
+
}
|
|
287
|
+
const { linearIndex: u } = o, c = u.length, d = Math.min(n >> 14, c - 1), f = u[d];
|
|
288
|
+
return N(a, f);
|
|
289
|
+
}
|
|
290
|
+
async parse(e = {}) {
|
|
291
|
+
return this.setupP || (this.setupP = this._parse(e).catch((n) => {
|
|
292
|
+
throw this.setupP = void 0, n;
|
|
293
|
+
})), this.setupP;
|
|
294
|
+
}
|
|
295
|
+
async hasRefSeq(e, n = {}) {
|
|
296
|
+
var s;
|
|
297
|
+
return !!((s = (await this.parse(n)).indices(e)) != null && s.binIndex);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
let U = [
|
|
301
|
+
0,
|
|
302
|
+
1996959894,
|
|
303
|
+
3993919788,
|
|
304
|
+
2567524794,
|
|
305
|
+
124634137,
|
|
306
|
+
1886057615,
|
|
307
|
+
3915621685,
|
|
308
|
+
2657392035,
|
|
309
|
+
249268274,
|
|
310
|
+
2044508324,
|
|
311
|
+
3772115230,
|
|
312
|
+
2547177864,
|
|
313
|
+
162941995,
|
|
314
|
+
2125561021,
|
|
315
|
+
3887607047,
|
|
316
|
+
2428444049,
|
|
317
|
+
498536548,
|
|
318
|
+
1789927666,
|
|
319
|
+
4089016648,
|
|
320
|
+
2227061214,
|
|
321
|
+
450548861,
|
|
322
|
+
1843258603,
|
|
323
|
+
4107580753,
|
|
324
|
+
2211677639,
|
|
325
|
+
325883990,
|
|
326
|
+
1684777152,
|
|
327
|
+
4251122042,
|
|
328
|
+
2321926636,
|
|
329
|
+
335633487,
|
|
330
|
+
1661365465,
|
|
331
|
+
4195302755,
|
|
332
|
+
2366115317,
|
|
333
|
+
997073096,
|
|
334
|
+
1281953886,
|
|
335
|
+
3579855332,
|
|
336
|
+
2724688242,
|
|
337
|
+
1006888145,
|
|
338
|
+
1258607687,
|
|
339
|
+
3524101629,
|
|
340
|
+
2768942443,
|
|
341
|
+
901097722,
|
|
342
|
+
1119000684,
|
|
343
|
+
3686517206,
|
|
344
|
+
2898065728,
|
|
345
|
+
853044451,
|
|
346
|
+
1172266101,
|
|
347
|
+
3705015759,
|
|
348
|
+
2882616665,
|
|
349
|
+
651767980,
|
|
350
|
+
1373503546,
|
|
351
|
+
3369554304,
|
|
352
|
+
3218104598,
|
|
353
|
+
565507253,
|
|
354
|
+
1454621731,
|
|
355
|
+
3485111705,
|
|
356
|
+
3099436303,
|
|
357
|
+
671266974,
|
|
358
|
+
1594198024,
|
|
359
|
+
3322730930,
|
|
360
|
+
2970347812,
|
|
361
|
+
795835527,
|
|
362
|
+
1483230225,
|
|
363
|
+
3244367275,
|
|
364
|
+
3060149565,
|
|
365
|
+
1994146192,
|
|
366
|
+
31158534,
|
|
367
|
+
2563907772,
|
|
368
|
+
4023717930,
|
|
369
|
+
1907459465,
|
|
370
|
+
112637215,
|
|
371
|
+
2680153253,
|
|
372
|
+
3904427059,
|
|
373
|
+
2013776290,
|
|
374
|
+
251722036,
|
|
375
|
+
2517215374,
|
|
376
|
+
3775830040,
|
|
377
|
+
2137656763,
|
|
378
|
+
141376813,
|
|
379
|
+
2439277719,
|
|
380
|
+
3865271297,
|
|
381
|
+
1802195444,
|
|
382
|
+
476864866,
|
|
383
|
+
2238001368,
|
|
384
|
+
4066508878,
|
|
385
|
+
1812370925,
|
|
386
|
+
453092731,
|
|
387
|
+
2181625025,
|
|
388
|
+
4111451223,
|
|
389
|
+
1706088902,
|
|
390
|
+
314042704,
|
|
391
|
+
2344532202,
|
|
392
|
+
4240017532,
|
|
393
|
+
1658658271,
|
|
394
|
+
366619977,
|
|
395
|
+
2362670323,
|
|
396
|
+
4224994405,
|
|
397
|
+
1303535960,
|
|
398
|
+
984961486,
|
|
399
|
+
2747007092,
|
|
400
|
+
3569037538,
|
|
401
|
+
1256170817,
|
|
402
|
+
1037604311,
|
|
403
|
+
2765210733,
|
|
404
|
+
3554079995,
|
|
405
|
+
1131014506,
|
|
406
|
+
879679996,
|
|
407
|
+
2909243462,
|
|
408
|
+
3663771856,
|
|
409
|
+
1141124467,
|
|
410
|
+
855842277,
|
|
411
|
+
2852801631,
|
|
412
|
+
3708648649,
|
|
413
|
+
1342533948,
|
|
414
|
+
654459306,
|
|
415
|
+
3188396048,
|
|
416
|
+
3373015174,
|
|
417
|
+
1466479909,
|
|
418
|
+
544179635,
|
|
419
|
+
3110523913,
|
|
420
|
+
3462522015,
|
|
421
|
+
1591671054,
|
|
422
|
+
702138776,
|
|
423
|
+
2966460450,
|
|
424
|
+
3352799412,
|
|
425
|
+
1504918807,
|
|
426
|
+
783551873,
|
|
427
|
+
3082640443,
|
|
428
|
+
3233442989,
|
|
429
|
+
3988292384,
|
|
430
|
+
2596254646,
|
|
431
|
+
62317068,
|
|
432
|
+
1957810842,
|
|
433
|
+
3939845945,
|
|
434
|
+
2647816111,
|
|
435
|
+
81470997,
|
|
436
|
+
1943803523,
|
|
437
|
+
3814918930,
|
|
438
|
+
2489596804,
|
|
439
|
+
225274430,
|
|
440
|
+
2053790376,
|
|
441
|
+
3826175755,
|
|
442
|
+
2466906013,
|
|
443
|
+
167816743,
|
|
444
|
+
2097651377,
|
|
445
|
+
4027552580,
|
|
446
|
+
2265490386,
|
|
447
|
+
503444072,
|
|
448
|
+
1762050814,
|
|
449
|
+
4150417245,
|
|
450
|
+
2154129355,
|
|
451
|
+
426522225,
|
|
452
|
+
1852507879,
|
|
453
|
+
4275313526,
|
|
454
|
+
2312317920,
|
|
455
|
+
282753626,
|
|
456
|
+
1742555852,
|
|
457
|
+
4189708143,
|
|
458
|
+
2394877945,
|
|
459
|
+
397917763,
|
|
460
|
+
1622183637,
|
|
461
|
+
3604390888,
|
|
462
|
+
2714866558,
|
|
463
|
+
953729732,
|
|
464
|
+
1340076626,
|
|
465
|
+
3518719985,
|
|
466
|
+
2797360999,
|
|
467
|
+
1068828381,
|
|
468
|
+
1219638859,
|
|
469
|
+
3624741850,
|
|
470
|
+
2936675148,
|
|
471
|
+
906185462,
|
|
472
|
+
1090812512,
|
|
473
|
+
3747672003,
|
|
474
|
+
2825379669,
|
|
475
|
+
829329135,
|
|
476
|
+
1181335161,
|
|
477
|
+
3412177804,
|
|
478
|
+
3160834842,
|
|
479
|
+
628085408,
|
|
480
|
+
1382605366,
|
|
481
|
+
3423369109,
|
|
482
|
+
3138078467,
|
|
483
|
+
570562233,
|
|
484
|
+
1426400815,
|
|
485
|
+
3317316542,
|
|
486
|
+
2998733608,
|
|
487
|
+
733239954,
|
|
488
|
+
1555261956,
|
|
489
|
+
3268935591,
|
|
490
|
+
3050360625,
|
|
491
|
+
752459403,
|
|
492
|
+
1541320221,
|
|
493
|
+
2607071920,
|
|
494
|
+
3965973030,
|
|
495
|
+
1969922972,
|
|
496
|
+
40735498,
|
|
497
|
+
2617837225,
|
|
498
|
+
3943577151,
|
|
499
|
+
1913087877,
|
|
500
|
+
83908371,
|
|
501
|
+
2512341634,
|
|
502
|
+
3803740692,
|
|
503
|
+
2075208622,
|
|
504
|
+
213261112,
|
|
505
|
+
2463272603,
|
|
506
|
+
3855990285,
|
|
507
|
+
2094854071,
|
|
508
|
+
198958881,
|
|
509
|
+
2262029012,
|
|
510
|
+
4057260610,
|
|
511
|
+
1759359992,
|
|
512
|
+
534414190,
|
|
513
|
+
2176718541,
|
|
514
|
+
4139329115,
|
|
515
|
+
1873836001,
|
|
516
|
+
414664567,
|
|
517
|
+
2282248934,
|
|
518
|
+
4279200368,
|
|
519
|
+
1711684554,
|
|
520
|
+
285281116,
|
|
521
|
+
2405801727,
|
|
522
|
+
4167216745,
|
|
523
|
+
1634467795,
|
|
524
|
+
376229701,
|
|
525
|
+
2685067896,
|
|
526
|
+
3608007406,
|
|
527
|
+
1308918612,
|
|
528
|
+
956543938,
|
|
529
|
+
2808555105,
|
|
530
|
+
3495958263,
|
|
531
|
+
1231636301,
|
|
532
|
+
1047427035,
|
|
533
|
+
2932959818,
|
|
534
|
+
3654703836,
|
|
535
|
+
1088359270,
|
|
536
|
+
936918e3,
|
|
537
|
+
2847714899,
|
|
538
|
+
3736837829,
|
|
539
|
+
1202900863,
|
|
540
|
+
817233897,
|
|
541
|
+
3183342108,
|
|
542
|
+
3401237130,
|
|
543
|
+
1404277552,
|
|
544
|
+
615818150,
|
|
545
|
+
3134207493,
|
|
546
|
+
3453421203,
|
|
547
|
+
1423857449,
|
|
548
|
+
601450431,
|
|
549
|
+
3009837614,
|
|
550
|
+
3294710456,
|
|
551
|
+
1567103746,
|
|
552
|
+
711928724,
|
|
553
|
+
3020668471,
|
|
554
|
+
3272380065,
|
|
555
|
+
1510334235,
|
|
556
|
+
755167117
|
|
557
|
+
];
|
|
558
|
+
typeof Int32Array < "u" && (U = new Int32Array(U));
|
|
559
|
+
const de = (h, e) => {
|
|
560
|
+
let n = -1;
|
|
561
|
+
for (let t = 0; t < h.length; t++)
|
|
562
|
+
n = U[(n ^ h[t]) & 255] ^ n >>> 8;
|
|
563
|
+
return n ^ -1;
|
|
564
|
+
}, fe = 21582659, he = 38359875;
|
|
565
|
+
function ue(h, e) {
|
|
566
|
+
return h * 2 ** e;
|
|
567
|
+
}
|
|
568
|
+
function L(h, e) {
|
|
569
|
+
return Math.floor(h / 2 ** e);
|
|
570
|
+
}
|
|
571
|
+
let $ = class extends j {
|
|
572
|
+
constructor() {
|
|
573
|
+
super(...arguments), this.maxBinNumber = 0, this.depth = 0, this.minShift = 0;
|
|
574
|
+
}
|
|
575
|
+
async lineCount(e, n) {
|
|
576
|
+
var s, r;
|
|
577
|
+
return ((r = (s = (await this.parse(n)).indices(e)) == null ? void 0 : s.stats) == null ? void 0 : r.lineCount) || 0;
|
|
578
|
+
}
|
|
579
|
+
async indexCov() {
|
|
580
|
+
return [];
|
|
581
|
+
}
|
|
582
|
+
parseAuxData(e, n) {
|
|
583
|
+
const t = new DataView(e.buffer), s = t.getUint32(n, !0), r = s & 65536 ? "zero-based-half-open" : "1-based-closed", o = { 0: "generic", 1: "SAM", 2: "VCF" }[s & 15];
|
|
584
|
+
if (!o)
|
|
585
|
+
throw new Error(`invalid Tabix preset format flags ${s}`);
|
|
586
|
+
const i = {
|
|
587
|
+
ref: t.getInt32(n + 4, !0),
|
|
588
|
+
start: t.getInt32(n + 8, !0),
|
|
589
|
+
end: t.getInt32(n + 12, !0)
|
|
590
|
+
}, a = t.getInt32(n + 16, !0), x = a ? String.fromCharCode(a) : "", u = t.getInt32(n + 20, !0), c = t.getInt32(n + 24, !0);
|
|
591
|
+
return {
|
|
592
|
+
columnNumbers: i,
|
|
593
|
+
coordinateType: r,
|
|
594
|
+
metaValue: a,
|
|
595
|
+
metaChar: x,
|
|
596
|
+
skipLines: u,
|
|
597
|
+
format: o,
|
|
598
|
+
formatFlags: s,
|
|
599
|
+
...ee(e.subarray(n + 28, n + 28 + c), this.renameRefSeq)
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
// fetch and parse the index
|
|
603
|
+
async _parse(e) {
|
|
604
|
+
const n = await this.filehandle.readFile(e), t = await D(n), s = new DataView(t.buffer);
|
|
605
|
+
let r;
|
|
606
|
+
const o = s.getUint32(0, !0);
|
|
607
|
+
if (o === fe)
|
|
608
|
+
r = 1;
|
|
609
|
+
else if (o === he)
|
|
610
|
+
r = 2;
|
|
611
|
+
else
|
|
612
|
+
throw new Error(`Not a CSI file ${o}`);
|
|
613
|
+
this.minShift = s.getInt32(4, !0), this.depth = s.getInt32(8, !0), this.maxBinNumber = ((1 << (this.depth + 1) * 3) - 1) / 7;
|
|
614
|
+
const i = this.maxBinNumber, a = s.getInt32(12, !0), x = a >= 30 ? this.parseAuxData(t, 16) : void 0, u = s.getInt32(16 + a, !0);
|
|
615
|
+
let c = 16 + a + 4, d;
|
|
616
|
+
const f = [];
|
|
617
|
+
for (let l = 0; l < u; l++) {
|
|
618
|
+
f.push(c);
|
|
619
|
+
const g = s.getInt32(c, !0);
|
|
620
|
+
c += 4;
|
|
621
|
+
for (let _ = 0; _ < g; _++) {
|
|
622
|
+
const m = s.getUint32(c, !0);
|
|
623
|
+
if (c += 4, m > this.maxBinNumber)
|
|
624
|
+
c += 44;
|
|
625
|
+
else {
|
|
626
|
+
c += 8;
|
|
627
|
+
const p = s.getInt32(c, !0);
|
|
628
|
+
c += 4;
|
|
629
|
+
for (let y = 0; y < p; y += 1) {
|
|
630
|
+
const C = S(t, c);
|
|
631
|
+
c += 8, c += 8, d = M(d, C);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
const b = new V({
|
|
637
|
+
maxSize: 5
|
|
638
|
+
});
|
|
639
|
+
function w(l) {
|
|
640
|
+
let g = f[l];
|
|
641
|
+
if (g === void 0)
|
|
642
|
+
return;
|
|
643
|
+
const _ = s.getInt32(g, !0);
|
|
644
|
+
g += 4;
|
|
645
|
+
const m = {};
|
|
646
|
+
let p;
|
|
647
|
+
for (let y = 0; y < _; y++) {
|
|
648
|
+
const C = s.getUint32(g, !0);
|
|
649
|
+
if (g += 4, C > i)
|
|
650
|
+
p = H(t, g + 28), g += 44;
|
|
651
|
+
else {
|
|
652
|
+
d = M(d, S(t, g)), g += 8;
|
|
653
|
+
const I = s.getInt32(g, !0);
|
|
654
|
+
g += 4;
|
|
655
|
+
const k = new Array(I);
|
|
656
|
+
for (let R = 0; R < I; R += 1) {
|
|
657
|
+
const T = S(t, g);
|
|
658
|
+
g += 8;
|
|
659
|
+
const P = S(t, g);
|
|
660
|
+
g += 8, k[R] = new G(T, P, C);
|
|
661
|
+
}
|
|
662
|
+
m[C] = k;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
return {
|
|
666
|
+
binIndex: m,
|
|
667
|
+
stats: p
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
return {
|
|
671
|
+
csiVersion: r,
|
|
672
|
+
firstDataLine: d,
|
|
673
|
+
indices: (l) => {
|
|
674
|
+
if (!b.has(l)) {
|
|
675
|
+
const g = w(l);
|
|
676
|
+
return g && b.set(l, g), g;
|
|
677
|
+
}
|
|
678
|
+
return b.get(l);
|
|
679
|
+
},
|
|
680
|
+
refCount: u,
|
|
681
|
+
csi: !0,
|
|
682
|
+
maxBlockSize: 65536,
|
|
683
|
+
...x
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
async blocksForRange(e, n, t, s = {}) {
|
|
687
|
+
n < 0 && (n = 0);
|
|
688
|
+
const o = (await this.parse(s)).indices(e);
|
|
689
|
+
if (!o)
|
|
690
|
+
return [];
|
|
691
|
+
const i = this.reg2bins(n, t);
|
|
692
|
+
if (i.length === 0)
|
|
693
|
+
return [];
|
|
694
|
+
const a = [], { binIndex: x } = o;
|
|
695
|
+
for (const [u, c] of i)
|
|
696
|
+
for (let d = u; d <= c; d++) {
|
|
697
|
+
const f = x[d];
|
|
698
|
+
if (f)
|
|
699
|
+
for (let b = 0, w = f.length; b < w; b++)
|
|
700
|
+
a.push(f[b]);
|
|
701
|
+
}
|
|
702
|
+
return N(a, new Q(0, 0));
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* calculate the list of bins that may overlap with region [beg,end)
|
|
706
|
+
* (zero-based half-open)
|
|
707
|
+
*/
|
|
708
|
+
reg2bins(e, n) {
|
|
709
|
+
e -= 1, e < 1 && (e = 1), n > 2 ** 50 && (n = 2 ** 34), n -= 1;
|
|
710
|
+
let t = 0, s = 0, r = this.minShift + this.depth * 3;
|
|
711
|
+
const o = [];
|
|
712
|
+
for (; t <= this.depth; r -= 3, s += ue(1, t * 3), t += 1) {
|
|
713
|
+
const i = s + L(e, r), a = s + L(n, r);
|
|
714
|
+
if (a - i + o.length > this.maxBinNumber)
|
|
715
|
+
throw new Error(`query ${e}-${n} is too large for current binning scheme (shift ${this.minShift}, depth ${this.depth}), try a smaller query or a coarser index binning scheme`);
|
|
716
|
+
o.push([i, a]);
|
|
717
|
+
}
|
|
718
|
+
return o;
|
|
719
|
+
}
|
|
720
|
+
async parse(e = {}) {
|
|
721
|
+
return this.setupP || (this.setupP = this._parse(e).catch((n) => {
|
|
722
|
+
throw this.setupP = void 0, n;
|
|
723
|
+
})), this.setupP;
|
|
724
|
+
}
|
|
725
|
+
async hasRefSeq(e, n = {}) {
|
|
726
|
+
var s;
|
|
727
|
+
return !!((s = (await this.parse(n)).indices(e)) != null && s.binIndex);
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
class le {
|
|
731
|
+
read() {
|
|
732
|
+
throw new Error("never called");
|
|
733
|
+
}
|
|
734
|
+
stat() {
|
|
735
|
+
throw new Error("never called");
|
|
736
|
+
}
|
|
737
|
+
readFile() {
|
|
738
|
+
throw new Error("never called");
|
|
739
|
+
}
|
|
740
|
+
close() {
|
|
741
|
+
throw new Error("never called");
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
const xe = 3, be = 4, A = {
|
|
745
|
+
// the read is paired in sequencing, no matter whether it is mapped in a pair
|
|
746
|
+
BAM_FPAIRED: 1,
|
|
747
|
+
// the read is mapped in a proper pair
|
|
748
|
+
BAM_FPROPER_PAIR: 2,
|
|
749
|
+
// the read itself is unmapped; conflictive with BAM_FPROPER_PAIR
|
|
750
|
+
BAM_FUNMAP: 4,
|
|
751
|
+
// the mate is unmapped
|
|
752
|
+
BAM_FMUNMAP: 8,
|
|
753
|
+
// the read is mapped to the reverse strand
|
|
754
|
+
BAM_FREVERSE: 16,
|
|
755
|
+
// the mate is mapped to the reverse strand
|
|
756
|
+
BAM_FMREVERSE: 32,
|
|
757
|
+
// this is read1
|
|
758
|
+
BAM_FREAD1: 64,
|
|
759
|
+
// this is read2
|
|
760
|
+
BAM_FREAD2: 128,
|
|
761
|
+
// not primary alignment
|
|
762
|
+
BAM_FSECONDARY: 256,
|
|
763
|
+
// QC failure
|
|
764
|
+
BAM_FQCFAIL: 512,
|
|
765
|
+
// optical or PCR duplicate
|
|
766
|
+
BAM_FDUP: 1024,
|
|
767
|
+
// supplementary alignment
|
|
768
|
+
BAM_FSUPPLEMENTARY: 2048
|
|
769
|
+
}, E = "=ACMGRSVTWYHKDBN".split(""), ge = [
|
|
770
|
+
77,
|
|
771
|
+
73,
|
|
772
|
+
68,
|
|
773
|
+
78,
|
|
774
|
+
83,
|
|
775
|
+
72,
|
|
776
|
+
80,
|
|
777
|
+
61,
|
|
778
|
+
88,
|
|
779
|
+
63,
|
|
780
|
+
63,
|
|
781
|
+
63,
|
|
782
|
+
63,
|
|
783
|
+
63,
|
|
784
|
+
63,
|
|
785
|
+
63
|
|
786
|
+
], O = 461;
|
|
787
|
+
class we {
|
|
788
|
+
constructor(e) {
|
|
789
|
+
this.bytes = e.bytes, this.fileOffset = e.fileOffset, this._dataView = new DataView(this.bytes.byteArray.buffer);
|
|
790
|
+
}
|
|
791
|
+
get byteArray() {
|
|
792
|
+
return this.bytes.byteArray;
|
|
793
|
+
}
|
|
794
|
+
get flags() {
|
|
795
|
+
return this._cachedFlags === void 0 && (this._cachedFlags = (this._dataView.getInt32(this.bytes.start + 16, !0) & 4294901760) >> 16), this._cachedFlags;
|
|
796
|
+
}
|
|
797
|
+
get ref_id() {
|
|
798
|
+
return this._cachedRefId === void 0 && (this._cachedRefId = this._dataView.getInt32(this.bytes.start + 4, !0)), this._cachedRefId;
|
|
799
|
+
}
|
|
800
|
+
get start() {
|
|
801
|
+
return this._cachedStart === void 0 && (this._cachedStart = this._dataView.getInt32(this.bytes.start + 8, !0)), this._cachedStart;
|
|
802
|
+
}
|
|
803
|
+
get end() {
|
|
804
|
+
return this._cachedEnd === void 0 && (this._cachedEnd = this.start + this.length_on_ref), this._cachedEnd;
|
|
805
|
+
}
|
|
806
|
+
get mq() {
|
|
807
|
+
const e = (this.bin_mq_nl & 65280) >> 8;
|
|
808
|
+
return e === 255 ? void 0 : e;
|
|
809
|
+
}
|
|
810
|
+
get score() {
|
|
811
|
+
return this.mq;
|
|
812
|
+
}
|
|
813
|
+
get qual() {
|
|
814
|
+
if (this.isSegmentUnmapped())
|
|
815
|
+
return null;
|
|
816
|
+
{
|
|
817
|
+
const e = this.b0 + this.read_name_length + this.num_cigar_bytes + this.num_seq_bytes;
|
|
818
|
+
return this.byteArray.subarray(e, e + this.seq_length);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
get strand() {
|
|
822
|
+
return this.isReverseComplemented() ? -1 : 1;
|
|
823
|
+
}
|
|
824
|
+
get b0() {
|
|
825
|
+
return this.bytes.start + 36;
|
|
826
|
+
}
|
|
827
|
+
get tagsStart() {
|
|
828
|
+
return this._cachedTagsStart === void 0 && (this._cachedTagsStart = this.b0 + this.read_name_length + this.num_cigar_bytes + this.num_seq_bytes + this.seq_length), this._cachedTagsStart;
|
|
829
|
+
}
|
|
830
|
+
// batch fromCharCode: fastest for typical name lengths (see benchmarks/string-building.bench.ts)
|
|
831
|
+
get name() {
|
|
832
|
+
const e = this.read_name_length - 1, n = this.b0, t = this.byteArray, s = new Array(e);
|
|
833
|
+
for (let r = 0; r < e; r++)
|
|
834
|
+
s[r] = t[n + r];
|
|
835
|
+
return String.fromCharCode(...s);
|
|
836
|
+
}
|
|
837
|
+
get NUMERIC_MD() {
|
|
838
|
+
if (this._cachedNUMERIC_MD === void 0) {
|
|
839
|
+
const e = this.getTagRaw("MD");
|
|
840
|
+
this._cachedNUMERIC_MD = e instanceof Uint8Array ? e : null;
|
|
841
|
+
}
|
|
842
|
+
return this._cachedNUMERIC_MD === null ? void 0 : this._cachedNUMERIC_MD;
|
|
843
|
+
}
|
|
844
|
+
get tags() {
|
|
845
|
+
return this._cachedTags === void 0 && (this._cachedTags = this._computeTags()), this._cachedTags;
|
|
846
|
+
}
|
|
847
|
+
getTag(e) {
|
|
848
|
+
return this._cachedTags !== void 0 ? this._cachedTags[e] : this._findTag(e, !1);
|
|
849
|
+
}
|
|
850
|
+
getTagRaw(e) {
|
|
851
|
+
return this._findTag(e, !0);
|
|
852
|
+
}
|
|
853
|
+
_findTag(e, n) {
|
|
854
|
+
const t = e.charCodeAt(0), s = e.charCodeAt(1);
|
|
855
|
+
let r = this.tagsStart;
|
|
856
|
+
const o = this.bytes.end, i = this.byteArray;
|
|
857
|
+
for (; r < o; ) {
|
|
858
|
+
const a = i[r], x = i[r + 1], u = i[r + 2];
|
|
859
|
+
r += 3;
|
|
860
|
+
const c = a === t && x === s;
|
|
861
|
+
switch (u) {
|
|
862
|
+
case 65:
|
|
863
|
+
if (c)
|
|
864
|
+
return String.fromCharCode(i[r]);
|
|
865
|
+
r += 1;
|
|
866
|
+
break;
|
|
867
|
+
case 105:
|
|
868
|
+
if (c)
|
|
869
|
+
return this._dataView.getInt32(r, !0);
|
|
870
|
+
r += 4;
|
|
871
|
+
break;
|
|
872
|
+
case 73:
|
|
873
|
+
if (c)
|
|
874
|
+
return this._dataView.getUint32(r, !0);
|
|
875
|
+
r += 4;
|
|
876
|
+
break;
|
|
877
|
+
case 99:
|
|
878
|
+
if (c)
|
|
879
|
+
return this._dataView.getInt8(r);
|
|
880
|
+
r += 1;
|
|
881
|
+
break;
|
|
882
|
+
case 67:
|
|
883
|
+
if (c)
|
|
884
|
+
return this._dataView.getUint8(r);
|
|
885
|
+
r += 1;
|
|
886
|
+
break;
|
|
887
|
+
case 115:
|
|
888
|
+
if (c)
|
|
889
|
+
return this._dataView.getInt16(r, !0);
|
|
890
|
+
r += 2;
|
|
891
|
+
break;
|
|
892
|
+
case 83:
|
|
893
|
+
if (c)
|
|
894
|
+
return this._dataView.getUint16(r, !0);
|
|
895
|
+
r += 2;
|
|
896
|
+
break;
|
|
897
|
+
case 102:
|
|
898
|
+
if (c)
|
|
899
|
+
return this._dataView.getFloat32(r, !0);
|
|
900
|
+
r += 4;
|
|
901
|
+
break;
|
|
902
|
+
case 90:
|
|
903
|
+
// 'Z'
|
|
904
|
+
case 72: {
|
|
905
|
+
if (c) {
|
|
906
|
+
const d = r;
|
|
907
|
+
for (; r < o && i[r] !== 0; )
|
|
908
|
+
r++;
|
|
909
|
+
if (n)
|
|
910
|
+
return i.subarray(d, r);
|
|
911
|
+
const f = [];
|
|
912
|
+
for (let b = d; b < r; b++)
|
|
913
|
+
f.push(String.fromCharCode(i[b]));
|
|
914
|
+
return f.join("");
|
|
915
|
+
}
|
|
916
|
+
for (; r <= o && i[r++] !== 0; )
|
|
917
|
+
;
|
|
918
|
+
break;
|
|
919
|
+
}
|
|
920
|
+
case 66: {
|
|
921
|
+
const d = i[r++], f = this._dataView.getInt32(r, !0);
|
|
922
|
+
r += 4;
|
|
923
|
+
const b = i.byteOffset + r;
|
|
924
|
+
if (c)
|
|
925
|
+
if (d === 105) {
|
|
926
|
+
if (b % 4 === 0)
|
|
927
|
+
return new Int32Array(i.buffer, b, f);
|
|
928
|
+
const w = new Array(f);
|
|
929
|
+
for (let l = 0; l < f; l++)
|
|
930
|
+
w[l] = this._dataView.getInt32(r + l * 4, !0);
|
|
931
|
+
return w;
|
|
932
|
+
} else if (d === 73) {
|
|
933
|
+
if (b % 4 === 0)
|
|
934
|
+
return new Uint32Array(i.buffer, b, f);
|
|
935
|
+
const w = new Array(f);
|
|
936
|
+
for (let l = 0; l < f; l++)
|
|
937
|
+
w[l] = this._dataView.getUint32(r + l * 4, !0);
|
|
938
|
+
return w;
|
|
939
|
+
} else if (d === 115) {
|
|
940
|
+
if (b % 2 === 0)
|
|
941
|
+
return new Int16Array(i.buffer, b, f);
|
|
942
|
+
const w = new Array(f);
|
|
943
|
+
for (let l = 0; l < f; l++)
|
|
944
|
+
w[l] = this._dataView.getInt16(r + l * 2, !0);
|
|
945
|
+
return w;
|
|
946
|
+
} else if (d === 83) {
|
|
947
|
+
if (b % 2 === 0)
|
|
948
|
+
return new Uint16Array(i.buffer, b, f);
|
|
949
|
+
const w = new Array(f);
|
|
950
|
+
for (let l = 0; l < f; l++)
|
|
951
|
+
w[l] = this._dataView.getUint16(r + l * 2, !0);
|
|
952
|
+
return w;
|
|
953
|
+
} else {
|
|
954
|
+
if (d === 99)
|
|
955
|
+
return new Int8Array(i.buffer, b, f);
|
|
956
|
+
if (d === 67)
|
|
957
|
+
return new Uint8Array(i.buffer, b, f);
|
|
958
|
+
if (d === 102) {
|
|
959
|
+
if (b % 4 === 0)
|
|
960
|
+
return new Float32Array(i.buffer, b, f);
|
|
961
|
+
const w = new Array(f);
|
|
962
|
+
for (let l = 0; l < f; l++)
|
|
963
|
+
w[l] = this._dataView.getFloat32(r + l * 4, !0);
|
|
964
|
+
return w;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
d === 105 || d === 73 || d === 102 ? r += f << 2 : d === 115 || d === 83 ? r += f << 1 : (d === 99 || d === 67) && (r += f);
|
|
968
|
+
break;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
_computeTags() {
|
|
974
|
+
let e = this.tagsStart;
|
|
975
|
+
const n = this.bytes.end, t = this.byteArray, s = {};
|
|
976
|
+
for (; e < n; ) {
|
|
977
|
+
const r = String.fromCharCode(t[e], t[e + 1]), o = t[e + 2];
|
|
978
|
+
switch (e += 3, o) {
|
|
979
|
+
case 65:
|
|
980
|
+
s[r] = String.fromCharCode(t[e]), e += 1;
|
|
981
|
+
break;
|
|
982
|
+
case 105:
|
|
983
|
+
s[r] = this._dataView.getInt32(e, !0), e += 4;
|
|
984
|
+
break;
|
|
985
|
+
case 73:
|
|
986
|
+
s[r] = this._dataView.getUint32(e, !0), e += 4;
|
|
987
|
+
break;
|
|
988
|
+
case 99:
|
|
989
|
+
s[r] = this._dataView.getInt8(e), e += 1;
|
|
990
|
+
break;
|
|
991
|
+
case 67:
|
|
992
|
+
s[r] = this._dataView.getUint8(e), e += 1;
|
|
993
|
+
break;
|
|
994
|
+
case 115:
|
|
995
|
+
s[r] = this._dataView.getInt16(e, !0), e += 2;
|
|
996
|
+
break;
|
|
997
|
+
case 83:
|
|
998
|
+
s[r] = this._dataView.getUint16(e, !0), e += 2;
|
|
999
|
+
break;
|
|
1000
|
+
case 102:
|
|
1001
|
+
s[r] = this._dataView.getFloat32(e, !0), e += 4;
|
|
1002
|
+
break;
|
|
1003
|
+
case 90:
|
|
1004
|
+
// 'Z'
|
|
1005
|
+
case 72: {
|
|
1006
|
+
const i = [];
|
|
1007
|
+
for (; e <= n; ) {
|
|
1008
|
+
const a = t[e++];
|
|
1009
|
+
if (a !== 0)
|
|
1010
|
+
i.push(String.fromCharCode(a));
|
|
1011
|
+
else
|
|
1012
|
+
break;
|
|
1013
|
+
}
|
|
1014
|
+
s[r] = i.join("");
|
|
1015
|
+
break;
|
|
1016
|
+
}
|
|
1017
|
+
case 66: {
|
|
1018
|
+
const i = t[e++], a = this._dataView.getInt32(e, !0);
|
|
1019
|
+
e += 4;
|
|
1020
|
+
const x = t.byteOffset + e;
|
|
1021
|
+
if (i === 105) {
|
|
1022
|
+
if (x % 4 === 0)
|
|
1023
|
+
s[r] = new Int32Array(t.buffer, x, a);
|
|
1024
|
+
else {
|
|
1025
|
+
const u = new Array(a);
|
|
1026
|
+
for (let c = 0; c < a; c++)
|
|
1027
|
+
u[c] = this._dataView.getInt32(e + c * 4, !0);
|
|
1028
|
+
s[r] = u;
|
|
1029
|
+
}
|
|
1030
|
+
e += a << 2;
|
|
1031
|
+
} else if (i === 73) {
|
|
1032
|
+
if (x % 4 === 0)
|
|
1033
|
+
s[r] = new Uint32Array(t.buffer, x, a);
|
|
1034
|
+
else {
|
|
1035
|
+
const u = new Array(a);
|
|
1036
|
+
for (let c = 0; c < a; c++)
|
|
1037
|
+
u[c] = this._dataView.getUint32(e + c * 4, !0);
|
|
1038
|
+
s[r] = u;
|
|
1039
|
+
}
|
|
1040
|
+
e += a << 2;
|
|
1041
|
+
} else if (i === 115) {
|
|
1042
|
+
if (x % 2 === 0)
|
|
1043
|
+
s[r] = new Int16Array(t.buffer, x, a);
|
|
1044
|
+
else {
|
|
1045
|
+
const u = new Array(a);
|
|
1046
|
+
for (let c = 0; c < a; c++)
|
|
1047
|
+
u[c] = this._dataView.getInt16(e + c * 2, !0);
|
|
1048
|
+
s[r] = u;
|
|
1049
|
+
}
|
|
1050
|
+
e += a << 1;
|
|
1051
|
+
} else if (i === 83) {
|
|
1052
|
+
if (x % 2 === 0)
|
|
1053
|
+
s[r] = new Uint16Array(t.buffer, x, a);
|
|
1054
|
+
else {
|
|
1055
|
+
const u = new Array(a);
|
|
1056
|
+
for (let c = 0; c < a; c++)
|
|
1057
|
+
u[c] = this._dataView.getUint16(e + c * 2, !0);
|
|
1058
|
+
s[r] = u;
|
|
1059
|
+
}
|
|
1060
|
+
e += a << 1;
|
|
1061
|
+
} else if (i === 99)
|
|
1062
|
+
s[r] = new Int8Array(t.buffer, x, a), e += a;
|
|
1063
|
+
else if (i === 67)
|
|
1064
|
+
s[r] = new Uint8Array(t.buffer, x, a), e += a;
|
|
1065
|
+
else if (i === 102) {
|
|
1066
|
+
if (x % 4 === 0)
|
|
1067
|
+
s[r] = new Float32Array(t.buffer, x, a);
|
|
1068
|
+
else {
|
|
1069
|
+
const u = new Array(a);
|
|
1070
|
+
for (let c = 0; c < a; c++)
|
|
1071
|
+
u[c] = this._dataView.getFloat32(e + c * 4, !0);
|
|
1072
|
+
s[r] = u;
|
|
1073
|
+
}
|
|
1074
|
+
e += a << 2;
|
|
1075
|
+
}
|
|
1076
|
+
break;
|
|
1077
|
+
}
|
|
1078
|
+
default:
|
|
1079
|
+
console.error("Unknown BAM tag type", o);
|
|
1080
|
+
break;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
return s;
|
|
1084
|
+
}
|
|
1085
|
+
isPaired() {
|
|
1086
|
+
return !!(this.flags & A.BAM_FPAIRED);
|
|
1087
|
+
}
|
|
1088
|
+
isProperlyPaired() {
|
|
1089
|
+
return !!(this.flags & A.BAM_FPROPER_PAIR);
|
|
1090
|
+
}
|
|
1091
|
+
isSegmentUnmapped() {
|
|
1092
|
+
return !!(this.flags & A.BAM_FUNMAP);
|
|
1093
|
+
}
|
|
1094
|
+
isMateUnmapped() {
|
|
1095
|
+
return !!(this.flags & A.BAM_FMUNMAP);
|
|
1096
|
+
}
|
|
1097
|
+
isReverseComplemented() {
|
|
1098
|
+
return !!(this.flags & A.BAM_FREVERSE);
|
|
1099
|
+
}
|
|
1100
|
+
isMateReverseComplemented() {
|
|
1101
|
+
return !!(this.flags & A.BAM_FMREVERSE);
|
|
1102
|
+
}
|
|
1103
|
+
isRead1() {
|
|
1104
|
+
return !!(this.flags & A.BAM_FREAD1);
|
|
1105
|
+
}
|
|
1106
|
+
isRead2() {
|
|
1107
|
+
return !!(this.flags & A.BAM_FREAD2);
|
|
1108
|
+
}
|
|
1109
|
+
isSecondary() {
|
|
1110
|
+
return !!(this.flags & A.BAM_FSECONDARY);
|
|
1111
|
+
}
|
|
1112
|
+
isFailedQc() {
|
|
1113
|
+
return !!(this.flags & A.BAM_FQCFAIL);
|
|
1114
|
+
}
|
|
1115
|
+
isDuplicate() {
|
|
1116
|
+
return !!(this.flags & A.BAM_FDUP);
|
|
1117
|
+
}
|
|
1118
|
+
isSupplementary() {
|
|
1119
|
+
return !!(this.flags & A.BAM_FSUPPLEMENTARY);
|
|
1120
|
+
}
|
|
1121
|
+
get cigarAndLength() {
|
|
1122
|
+
return this._cachedCigarAndLength === void 0 && (this._cachedCigarAndLength = this._computeCigarAndLength()), this._cachedCigarAndLength;
|
|
1123
|
+
}
|
|
1124
|
+
// Benchmark results for CIGAR parsing strategies (see benchmarks/cigar-lifecycle.bench.ts):
|
|
1125
|
+
//
|
|
1126
|
+
// Aligned data:
|
|
1127
|
+
// - Plain array is 1.6-1.8x faster than Uint32Array for small CIGARs (≤50 ops)
|
|
1128
|
+
// - Uint32Array view is 1.3-2.2x faster for large CIGARs (≥200 ops)
|
|
1129
|
+
// - Crossover point is around 50-100 ops
|
|
1130
|
+
//
|
|
1131
|
+
// Unaligned data (requires slice+copy for Uint32Array):
|
|
1132
|
+
// - Plain array is 3.7-6.1x faster for typical sizes (50-200 ops)
|
|
1133
|
+
// - Plain array is 9-10x faster for small CIGARs (1-7 ops)
|
|
1134
|
+
// - Uint32Array slice+copy only wins at extreme sizes (10000 ops: 1.4x faster)
|
|
1135
|
+
//
|
|
1136
|
+
// Using |0 to force 32-bit integers in plain array path:
|
|
1137
|
+
// - 1.67x faster for medium CIGARs (50 ops)
|
|
1138
|
+
// - Neutral for small CIGARs (1-7 ops)
|
|
1139
|
+
//
|
|
1140
|
+
// Strategy: use plain array with |0 for small aligned (≤50 ops) and all unaligned,
|
|
1141
|
+
// Uint32Array view only for large aligned CIGARs.
|
|
1142
|
+
_computeCigarAndLength() {
|
|
1143
|
+
if (this.isSegmentUnmapped())
|
|
1144
|
+
return {
|
|
1145
|
+
length_on_ref: 0,
|
|
1146
|
+
NUMERIC_CIGAR: new Uint32Array(0)
|
|
1147
|
+
};
|
|
1148
|
+
const e = this.num_cigar_ops;
|
|
1149
|
+
let n = this.b0 + this.read_name_length;
|
|
1150
|
+
const t = this._dataView.getInt32(n, !0), s = t >> 4;
|
|
1151
|
+
if ((t & 15) === be && s === this.seq_length) {
|
|
1152
|
+
n += 4;
|
|
1153
|
+
const u = this._dataView.getInt32(n, !0), c = u >> 4;
|
|
1154
|
+
return (u & 15) !== xe && console.warn("CG tag with no N tag"), {
|
|
1155
|
+
NUMERIC_CIGAR: this.tags.CG,
|
|
1156
|
+
length_on_ref: c
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
const o = this.byteArray.byteOffset + n;
|
|
1160
|
+
if (o % 4 === 0 && e > 50) {
|
|
1161
|
+
const u = new Uint32Array(this.byteArray.buffer, o, e);
|
|
1162
|
+
let c = 0;
|
|
1163
|
+
for (let d = 0; d < e; ++d) {
|
|
1164
|
+
const f = u[d];
|
|
1165
|
+
c += (f >> 4) * (O >> (f & 15) & 1);
|
|
1166
|
+
}
|
|
1167
|
+
return {
|
|
1168
|
+
NUMERIC_CIGAR: u,
|
|
1169
|
+
length_on_ref: c
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
const a = new Array(e);
|
|
1173
|
+
let x = 0;
|
|
1174
|
+
for (let u = 0; u < e; ++u) {
|
|
1175
|
+
const c = this._dataView.getInt32(n + u * 4, !0) | 0;
|
|
1176
|
+
a[u] = c, x += (c >> 4) * (O >> (c & 15) & 1);
|
|
1177
|
+
}
|
|
1178
|
+
return {
|
|
1179
|
+
NUMERIC_CIGAR: a,
|
|
1180
|
+
length_on_ref: x
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
get length_on_ref() {
|
|
1184
|
+
return this.cigarAndLength.length_on_ref;
|
|
1185
|
+
}
|
|
1186
|
+
get NUMERIC_CIGAR() {
|
|
1187
|
+
return this.cigarAndLength.NUMERIC_CIGAR;
|
|
1188
|
+
}
|
|
1189
|
+
get CIGAR() {
|
|
1190
|
+
const e = this.NUMERIC_CIGAR;
|
|
1191
|
+
let n = "";
|
|
1192
|
+
for (let t = 0, s = e.length; t < s; t++) {
|
|
1193
|
+
const r = e[t], o = r >> 4, i = ge[r & 15];
|
|
1194
|
+
n += o + String.fromCharCode(i);
|
|
1195
|
+
}
|
|
1196
|
+
return n;
|
|
1197
|
+
}
|
|
1198
|
+
get num_cigar_ops() {
|
|
1199
|
+
return this.flag_nc & 65535;
|
|
1200
|
+
}
|
|
1201
|
+
get num_cigar_bytes() {
|
|
1202
|
+
return this.num_cigar_ops << 2;
|
|
1203
|
+
}
|
|
1204
|
+
get read_name_length() {
|
|
1205
|
+
return this.bin_mq_nl & 255;
|
|
1206
|
+
}
|
|
1207
|
+
get num_seq_bytes() {
|
|
1208
|
+
return this.seq_length + 1 >> 1;
|
|
1209
|
+
}
|
|
1210
|
+
get NUMERIC_SEQ() {
|
|
1211
|
+
const e = this.b0 + this.read_name_length + this.num_cigar_bytes;
|
|
1212
|
+
return this.byteArray.subarray(e, e + this.num_seq_bytes);
|
|
1213
|
+
}
|
|
1214
|
+
get seq() {
|
|
1215
|
+
const e = this.NUMERIC_SEQ, n = this.seq_length, t = new Array(n);
|
|
1216
|
+
let s = 0;
|
|
1217
|
+
const r = n >> 1;
|
|
1218
|
+
for (let o = 0; o < r; ++o) {
|
|
1219
|
+
const i = e[o];
|
|
1220
|
+
t[s++] = E[(i & 240) >> 4], t[s++] = E[i & 15];
|
|
1221
|
+
}
|
|
1222
|
+
if (s < n) {
|
|
1223
|
+
const o = e[r];
|
|
1224
|
+
t[s] = E[(o & 240) >> 4];
|
|
1225
|
+
}
|
|
1226
|
+
return t.join("");
|
|
1227
|
+
}
|
|
1228
|
+
// adapted from igv.js
|
|
1229
|
+
// uses template literal instead of array+join (6.4x faster, see benchmarks/string-building.bench.ts)
|
|
1230
|
+
get pair_orientation() {
|
|
1231
|
+
if (!this.isSegmentUnmapped() && !this.isMateUnmapped() && this.ref_id === this.next_refid) {
|
|
1232
|
+
const e = this.isReverseComplemented() ? "R" : "F", n = this.isMateReverseComplemented() ? "R" : "F";
|
|
1233
|
+
let t = " ", s = " ";
|
|
1234
|
+
return this.isRead1() ? (t = "1", s = "2") : this.isRead2() && (t = "2", s = "1"), this.template_length > 0 ? `${e}${t}${n}${s}` : `${n}${s}${e}${t}`;
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
get bin_mq_nl() {
|
|
1238
|
+
return this._dataView.getInt32(this.bytes.start + 12, !0);
|
|
1239
|
+
}
|
|
1240
|
+
get flag_nc() {
|
|
1241
|
+
return this._dataView.getInt32(this.bytes.start + 16, !0);
|
|
1242
|
+
}
|
|
1243
|
+
get seq_length() {
|
|
1244
|
+
return this._dataView.getInt32(this.bytes.start + 20, !0);
|
|
1245
|
+
}
|
|
1246
|
+
get next_refid() {
|
|
1247
|
+
return this._dataView.getInt32(this.bytes.start + 24, !0);
|
|
1248
|
+
}
|
|
1249
|
+
get next_pos() {
|
|
1250
|
+
return this._dataView.getInt32(this.bytes.start + 28, !0);
|
|
1251
|
+
}
|
|
1252
|
+
get template_length() {
|
|
1253
|
+
return this._dataView.getInt32(this.bytes.start + 32, !0);
|
|
1254
|
+
}
|
|
1255
|
+
seqAt(e) {
|
|
1256
|
+
if (e < this.seq_length) {
|
|
1257
|
+
const n = e >> 1, t = this.byteArray[this.b0 + this.read_name_length + this.num_cigar_bytes + n];
|
|
1258
|
+
return e % 2 === 0 ? E[(t & 240) >> 4] : E[t & 15];
|
|
1259
|
+
} else
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
toJSON() {
|
|
1263
|
+
const e = {};
|
|
1264
|
+
for (const n of Object.keys(this))
|
|
1265
|
+
n.startsWith("_") || n === "bytes" || (e[n] = this[n]);
|
|
1266
|
+
return e;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
function K(h) {
|
|
1270
|
+
const e = h.split(/\r?\n/), n = [];
|
|
1271
|
+
for (const t of e) {
|
|
1272
|
+
const [s, ...r] = t.split(/\t/);
|
|
1273
|
+
s && n.push({
|
|
1274
|
+
tag: s.slice(1),
|
|
1275
|
+
data: r.map((o) => {
|
|
1276
|
+
const i = o.indexOf(":"), a = o.slice(0, i), x = o.slice(i + 1);
|
|
1277
|
+
return { tag: a, value: x };
|
|
1278
|
+
})
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
return n;
|
|
1282
|
+
}
|
|
1283
|
+
const W = 21840194, _e = 65536;
|
|
1284
|
+
class me {
|
|
1285
|
+
constructor({ bamFilehandle: e, bamPath: n, bamUrl: t, baiPath: s, baiFilehandle: r, baiUrl: o, csiPath: i, csiFilehandle: a, csiUrl: x, htsget: u, renameRefSeqs: c = (f) => f, recordClass: d }) {
|
|
1286
|
+
if (this.htsget = !1, this.chunkFeatureCache = new V({
|
|
1287
|
+
maxSize: 100
|
|
1288
|
+
}), this.renameRefSeq = c, this.RecordClass = d ?? we, e)
|
|
1289
|
+
this.bam = e;
|
|
1290
|
+
else if (n)
|
|
1291
|
+
this.bam = new v(n);
|
|
1292
|
+
else if (t)
|
|
1293
|
+
this.bam = new B(t);
|
|
1294
|
+
else if (u)
|
|
1295
|
+
this.htsget = !0, this.bam = new le();
|
|
1296
|
+
else
|
|
1297
|
+
throw new Error("unable to initialize bam");
|
|
1298
|
+
if (a)
|
|
1299
|
+
this.index = new $({ filehandle: a });
|
|
1300
|
+
else if (i)
|
|
1301
|
+
this.index = new $({ filehandle: new v(i) });
|
|
1302
|
+
else if (x)
|
|
1303
|
+
this.index = new $({ filehandle: new B(x) });
|
|
1304
|
+
else if (r)
|
|
1305
|
+
this.index = new F({ filehandle: r });
|
|
1306
|
+
else if (s)
|
|
1307
|
+
this.index = new F({ filehandle: new v(s) });
|
|
1308
|
+
else if (o)
|
|
1309
|
+
this.index = new F({ filehandle: new B(o) });
|
|
1310
|
+
else if (n)
|
|
1311
|
+
this.index = new F({ filehandle: new v(`${n}.bai`) });
|
|
1312
|
+
else if (t)
|
|
1313
|
+
this.index = new F({ filehandle: new B(`${t}.bai`) });
|
|
1314
|
+
else if (u)
|
|
1315
|
+
this.htsget = !0;
|
|
1316
|
+
else
|
|
1317
|
+
throw new Error("unable to infer index format");
|
|
1318
|
+
}
|
|
1319
|
+
async getHeaderPre(e) {
|
|
1320
|
+
const n = Z(e);
|
|
1321
|
+
if (!this.index)
|
|
1322
|
+
return;
|
|
1323
|
+
const t = await this.index.parse(n), s = t.firstDataLine === void 0 ? await this.bam.readFile() : (
|
|
1324
|
+
// the logic indexData.firstDataLine is a virtualOffset telling us
|
|
1325
|
+
// where the data is. It is in the middle of a virtualOffset
|
|
1326
|
+
// (provided by the bgzip block offset at blockPosition + the
|
|
1327
|
+
// virtualOffset dataPosition, so we add one extra blockLen to make
|
|
1328
|
+
// sure we consume the full header)
|
|
1329
|
+
await this.bam.read(t.firstDataLine.blockPosition + _e, 0)
|
|
1330
|
+
), r = await D(s), o = new DataView(r.buffer);
|
|
1331
|
+
if (o.getInt32(0, !0) !== W)
|
|
1332
|
+
throw new Error("Not a BAM file");
|
|
1333
|
+
const i = o.getInt32(4, !0), a = new TextDecoder("utf8");
|
|
1334
|
+
this.header = a.decode(r.subarray(8, 8 + i));
|
|
1335
|
+
const { chrToIndex: x, indexToChr: u } = this._parseRefSeqs(r, i + 8);
|
|
1336
|
+
return this.chrToIndex = x, this.indexToChr = u, K(this.header);
|
|
1337
|
+
}
|
|
1338
|
+
getHeader(e) {
|
|
1339
|
+
return this.headerP || (this.headerP = this.getHeaderPre(e).catch((n) => {
|
|
1340
|
+
throw this.headerP = void 0, n;
|
|
1341
|
+
})), this.headerP;
|
|
1342
|
+
}
|
|
1343
|
+
async getHeaderText(e = {}) {
|
|
1344
|
+
return await this.getHeader(e), this.header;
|
|
1345
|
+
}
|
|
1346
|
+
_parseRefSeqs(e, n) {
|
|
1347
|
+
const t = new DataView(e.buffer), s = t.getInt32(n, !0);
|
|
1348
|
+
let r = n + 4;
|
|
1349
|
+
const o = {}, i = [], a = new TextDecoder("utf8");
|
|
1350
|
+
for (let x = 0; x < s; x += 1) {
|
|
1351
|
+
if (r + 8 > e.length)
|
|
1352
|
+
throw new Error(`Insufficient data for reference sequences: need more than ${e.length} bytes`);
|
|
1353
|
+
const u = t.getInt32(r, !0), c = this.renameRefSeq(a.decode(e.subarray(r + 4, r + 4 + u - 1))), d = t.getInt32(r + u + 4, !0);
|
|
1354
|
+
o[c] = x, i.push({
|
|
1355
|
+
refName: c,
|
|
1356
|
+
length: d
|
|
1357
|
+
}), r = r + 8 + u;
|
|
1358
|
+
}
|
|
1359
|
+
return { chrToIndex: o, indexToChr: i };
|
|
1360
|
+
}
|
|
1361
|
+
async getRecordsForRange(e, n, t, s) {
|
|
1362
|
+
var i;
|
|
1363
|
+
await this.getHeader(s);
|
|
1364
|
+
const r = (i = this.chrToIndex) == null ? void 0 : i[e];
|
|
1365
|
+
if (r === void 0 || !this.index)
|
|
1366
|
+
return [];
|
|
1367
|
+
const o = await this.index.blocksForRange(r, n - 1, t, s);
|
|
1368
|
+
return this._fetchChunkFeaturesDirect(o, r, n, t, s);
|
|
1369
|
+
}
|
|
1370
|
+
chunkCacheKey(e, n) {
|
|
1371
|
+
const { minv: t, maxv: s } = e;
|
|
1372
|
+
return `${t.blockPosition}:${t.dataPosition}-${s.blockPosition}:${s.dataPosition}${se(n)}`;
|
|
1373
|
+
}
|
|
1374
|
+
blocksOverlap(e, n, t, s) {
|
|
1375
|
+
return e <= s && n >= t;
|
|
1376
|
+
}
|
|
1377
|
+
// Evict any cached chunks that overlap with the given block range
|
|
1378
|
+
evictOverlappingChunks(e, n) {
|
|
1379
|
+
for (const [t, s] of this.chunkFeatureCache)
|
|
1380
|
+
this.blocksOverlap(e, n, s.minBlock, s.maxBlock) && this.chunkFeatureCache.delete(t);
|
|
1381
|
+
}
|
|
1382
|
+
async _fetchChunkFeaturesDirect(e, n, t, s, r = {}) {
|
|
1383
|
+
const { viewAsPairs: o, filterBy: i } = r, { flagInclude: a = 0, flagExclude: x = 0, tagFilter: u } = i || {}, c = [];
|
|
1384
|
+
for (let d = 0, f = e.length; d < f; d++) {
|
|
1385
|
+
const b = e[d], w = this.chunkCacheKey(b, i), l = b.minv.blockPosition, g = b.maxv.blockPosition;
|
|
1386
|
+
let _;
|
|
1387
|
+
const m = this.chunkFeatureCache.get(w);
|
|
1388
|
+
if (m)
|
|
1389
|
+
_ = m.features;
|
|
1390
|
+
else {
|
|
1391
|
+
this.evictOverlappingChunks(l, g);
|
|
1392
|
+
const { data: y, cpositions: C, dpositions: I } = await this._readChunk({
|
|
1393
|
+
chunk: b,
|
|
1394
|
+
opts: r
|
|
1395
|
+
}), k = await this.readBamFeatures(y, C, I, b);
|
|
1396
|
+
if (i) {
|
|
1397
|
+
_ = [];
|
|
1398
|
+
for (let R = 0, T = k.length; R < T; R++) {
|
|
1399
|
+
const P = k[R];
|
|
1400
|
+
ne(P.flags, a, x) || u && re(P.tags[u.tag], u.value) || _.push(P);
|
|
1401
|
+
}
|
|
1402
|
+
} else
|
|
1403
|
+
_ = k;
|
|
1404
|
+
this.chunkFeatureCache.set(w, {
|
|
1405
|
+
minBlock: l,
|
|
1406
|
+
maxBlock: g,
|
|
1407
|
+
features: _
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
let p = !1;
|
|
1411
|
+
for (let y = 0, C = _.length; y < C; y++) {
|
|
1412
|
+
const I = _[y];
|
|
1413
|
+
if (I.ref_id === n)
|
|
1414
|
+
if (I.start >= s) {
|
|
1415
|
+
p = !0;
|
|
1416
|
+
break;
|
|
1417
|
+
} else I.end >= t && c.push(I);
|
|
1418
|
+
}
|
|
1419
|
+
if (p)
|
|
1420
|
+
break;
|
|
1421
|
+
}
|
|
1422
|
+
if (o) {
|
|
1423
|
+
const d = await this.fetchPairs(n, c, r);
|
|
1424
|
+
for (let f = 0, b = d.length; f < b; f++)
|
|
1425
|
+
c.push(d[f]);
|
|
1426
|
+
}
|
|
1427
|
+
return c;
|
|
1428
|
+
}
|
|
1429
|
+
async fetchPairs(e, n, t) {
|
|
1430
|
+
const { pairAcrossChr: s, maxInsertSize: r = 2e5 } = t, o = {}, i = {};
|
|
1431
|
+
for (let d = 0, f = n.length; d < f; d++) {
|
|
1432
|
+
const b = n[d], w = b.name;
|
|
1433
|
+
o[w] = (o[w] || 0) + 1, i[b.fileOffset] = 1;
|
|
1434
|
+
}
|
|
1435
|
+
const a = [];
|
|
1436
|
+
for (let d = 0, f = n.length; d < f; d++) {
|
|
1437
|
+
const b = n[d], w = b.name;
|
|
1438
|
+
this.index && o[w] === 1 && (s || b.next_refid === e && Math.abs(b.start - b.next_pos) < r) && a.push(this.index.blocksForRange(b.next_refid, b.next_pos, b.next_pos + 1, t));
|
|
1439
|
+
}
|
|
1440
|
+
const x = /* @__PURE__ */ new Map(), u = await Promise.all(a);
|
|
1441
|
+
for (let d = 0, f = u.length; d < f; d++) {
|
|
1442
|
+
const b = u[d];
|
|
1443
|
+
for (let w = 0, l = b.length; w < l; w++) {
|
|
1444
|
+
const g = b[w], _ = g.toString();
|
|
1445
|
+
x.has(_) || x.set(_, g);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
return (await Promise.all([...x.values()].map(async (d) => {
|
|
1449
|
+
const { data: f, cpositions: b, dpositions: w, chunk: l } = await this._readChunk({
|
|
1450
|
+
chunk: d,
|
|
1451
|
+
opts: t
|
|
1452
|
+
}), g = [], _ = await this.readBamFeatures(f, b, w, l);
|
|
1453
|
+
for (let m = 0, p = _.length; m < p; m++) {
|
|
1454
|
+
const y = _[m];
|
|
1455
|
+
o[y.name] === 1 && !i[y.fileOffset] && g.push(y);
|
|
1456
|
+
}
|
|
1457
|
+
return g;
|
|
1458
|
+
}))).flat();
|
|
1459
|
+
}
|
|
1460
|
+
async _readChunk({ chunk: e, opts: n }) {
|
|
1461
|
+
const t = await this.bam.read(e.fetchedSize(), e.minv.blockPosition, n), { buffer: s, cpositions: r, dpositions: o } = await Y(t, e);
|
|
1462
|
+
return { data: s, cpositions: r, dpositions: o, chunk: e };
|
|
1463
|
+
}
|
|
1464
|
+
async readBamFeatures(e, n, t, s) {
|
|
1465
|
+
let r = 0;
|
|
1466
|
+
const o = [];
|
|
1467
|
+
let i = 0;
|
|
1468
|
+
const a = new DataView(e.buffer), x = t.length > 0, u = n.length > 0;
|
|
1469
|
+
for (; r + 4 < e.length; ) {
|
|
1470
|
+
const c = a.getInt32(r, !0), d = r + 4 + c - 1;
|
|
1471
|
+
if (x) {
|
|
1472
|
+
for (; r + s.minv.dataPosition >= t[i++]; )
|
|
1473
|
+
;
|
|
1474
|
+
i--;
|
|
1475
|
+
}
|
|
1476
|
+
if (d < e.length) {
|
|
1477
|
+
const f = new this.RecordClass({
|
|
1478
|
+
bytes: {
|
|
1479
|
+
byteArray: e,
|
|
1480
|
+
start: r,
|
|
1481
|
+
end: d
|
|
1482
|
+
},
|
|
1483
|
+
fileOffset: u ? n[i] * 256 + (r - t[i]) + s.minv.dataPosition + 1 : de(e.subarray(r, d)) >>> 0
|
|
1484
|
+
});
|
|
1485
|
+
o.push(f);
|
|
1486
|
+
}
|
|
1487
|
+
r = d + 1;
|
|
1488
|
+
}
|
|
1489
|
+
return o;
|
|
1490
|
+
}
|
|
1491
|
+
async hasRefSeq(e) {
|
|
1492
|
+
var t, s;
|
|
1493
|
+
const n = (t = this.chrToIndex) == null ? void 0 : t[e];
|
|
1494
|
+
return n === void 0 ? !1 : (s = this.index) == null ? void 0 : s.hasRefSeq(n);
|
|
1495
|
+
}
|
|
1496
|
+
async lineCount(e) {
|
|
1497
|
+
var t;
|
|
1498
|
+
const n = (t = this.chrToIndex) == null ? void 0 : t[e];
|
|
1499
|
+
return n === void 0 || !this.index ? 0 : this.index.lineCount(n);
|
|
1500
|
+
}
|
|
1501
|
+
async indexCov(e, n, t) {
|
|
1502
|
+
var r;
|
|
1503
|
+
if (!this.index)
|
|
1504
|
+
return [];
|
|
1505
|
+
await this.index.parse();
|
|
1506
|
+
const s = (r = this.chrToIndex) == null ? void 0 : r[e];
|
|
1507
|
+
return s === void 0 ? [] : this.index.indexCov(s, n, t);
|
|
1508
|
+
}
|
|
1509
|
+
async blocksForRange(e, n, t, s) {
|
|
1510
|
+
var o;
|
|
1511
|
+
if (!this.index)
|
|
1512
|
+
return [];
|
|
1513
|
+
await this.index.parse();
|
|
1514
|
+
const r = (o = this.chrToIndex) == null ? void 0 : o[e];
|
|
1515
|
+
return r === void 0 ? [] : this.index.blocksForRange(r, n, t, s);
|
|
1516
|
+
}
|
|
1517
|
+
clearFeatureCache() {
|
|
1518
|
+
this.chunkFeatureCache.clear();
|
|
1519
|
+
}
|
|
1520
|
+
async estimatedBytesForRegions(e, n) {
|
|
1521
|
+
if (!this.index)
|
|
1522
|
+
return 0;
|
|
1523
|
+
if (await this.getHeader(n), !this.chrToIndex)
|
|
1524
|
+
throw new Error("Header not yet parsed");
|
|
1525
|
+
return this.index.estimatedBytesForRegions(e.map((t) => {
|
|
1526
|
+
const s = this.chrToIndex[t.refName];
|
|
1527
|
+
if (s === void 0)
|
|
1528
|
+
throw new Error(`Unknown reference name: ${t.refName}`);
|
|
1529
|
+
return {
|
|
1530
|
+
refId: s,
|
|
1531
|
+
start: t.start,
|
|
1532
|
+
end: t.end
|
|
1533
|
+
};
|
|
1534
|
+
}), n);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
async function z(h, e) {
|
|
1538
|
+
const n = await Promise.all(h.map(async (t) => {
|
|
1539
|
+
const { url: s, headers: r } = t;
|
|
1540
|
+
if (s.startsWith("data:")) {
|
|
1541
|
+
const o = await fetch(s);
|
|
1542
|
+
if (!o.ok)
|
|
1543
|
+
throw new Error("failed to decode base64");
|
|
1544
|
+
const i = await o.arrayBuffer();
|
|
1545
|
+
return new Uint8Array(i);
|
|
1546
|
+
} else {
|
|
1547
|
+
const { referer: o, ...i } = r, a = await fetch(s, {
|
|
1548
|
+
...e,
|
|
1549
|
+
headers: { ...e == null ? void 0 : e.headers, ...i }
|
|
1550
|
+
});
|
|
1551
|
+
if (!a.ok)
|
|
1552
|
+
throw new Error(`HTTP ${a.status} fetching ${s}: ${await a.text()}`);
|
|
1553
|
+
return new Uint8Array(await a.arrayBuffer());
|
|
1554
|
+
}
|
|
1555
|
+
}));
|
|
1556
|
+
return te(await Promise.all(n.map((t) => D(t))));
|
|
1557
|
+
}
|
|
1558
|
+
class Re extends me {
|
|
1559
|
+
constructor(e) {
|
|
1560
|
+
super({ htsget: !0, recordClass: e.recordClass }), this.baseUrl = e.baseUrl, this.trackId = e.trackId;
|
|
1561
|
+
}
|
|
1562
|
+
async getRecordsForRange(e, n, t, s) {
|
|
1563
|
+
var f;
|
|
1564
|
+
const o = `${`${this.baseUrl}/${this.trackId}`}?referenceName=${e}&start=${n}&end=${t}&format=BAM`, i = (f = this.chrToIndex) == null ? void 0 : f[e];
|
|
1565
|
+
if (i === void 0)
|
|
1566
|
+
return [];
|
|
1567
|
+
const a = await fetch(o, { ...s });
|
|
1568
|
+
if (!a.ok)
|
|
1569
|
+
throw new Error(`HTTP ${a.status} fetching ${o}: ${await a.text()}`);
|
|
1570
|
+
const x = await a.json(), u = await z(x.htsget.urls.slice(1), s), c = await this.readBamFeatures(u, [], [], {
|
|
1571
|
+
minv: { dataPosition: 0, blockPosition: 0 },
|
|
1572
|
+
maxv: { dataPosition: 0, blockPosition: 0 }
|
|
1573
|
+
}), d = [];
|
|
1574
|
+
for (let b = 0, w = c.length; b < w; b++) {
|
|
1575
|
+
const l = c[b];
|
|
1576
|
+
if (l.ref_id === i) {
|
|
1577
|
+
if (l.start >= t)
|
|
1578
|
+
break;
|
|
1579
|
+
l.end >= n && d.push(l);
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
return d;
|
|
1583
|
+
}
|
|
1584
|
+
async getHeader(e = {}) {
|
|
1585
|
+
const n = `${this.baseUrl}/${this.trackId}?referenceName=na&class=header`, t = await fetch(n, e);
|
|
1586
|
+
if (!t.ok)
|
|
1587
|
+
throw new Error(`HTTP ${t.status} fetching ${n}: ${await t.text()}`);
|
|
1588
|
+
const s = await t.json(), r = await z(s.htsget.urls, e), o = new DataView(r.buffer);
|
|
1589
|
+
if (o.getInt32(0, !0) !== W)
|
|
1590
|
+
throw new Error("Not a BAM file");
|
|
1591
|
+
const i = o.getInt32(4, !0), x = new TextDecoder("utf8").decode(r.subarray(8, 8 + i)), u = K(x), c = [], d = {}, f = u.filter((b) => b.tag === "SQ");
|
|
1592
|
+
for (const [b, w] of f.entries()) {
|
|
1593
|
+
let l = "", g = 0;
|
|
1594
|
+
for (const _ of w.data)
|
|
1595
|
+
_.tag === "SN" ? l = _.value : _.tag === "LN" && (g = +_.value);
|
|
1596
|
+
d[l] = b, c[b] = { refName: l, length: g };
|
|
1597
|
+
}
|
|
1598
|
+
return this.chrToIndex = d, this.indexToChr = c, u;
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
export {
|
|
1602
|
+
F as BAI,
|
|
1603
|
+
me as BamFile,
|
|
1604
|
+
we as BamRecord,
|
|
1605
|
+
$ as CSI,
|
|
1606
|
+
Re as HtsgetFile
|
|
1607
|
+
};
|