@genome-spy/app 0.56.1 → 0.57.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/_commonjsHelpers-DjF3Plf2.js +26 -0
- package/dist/{index-BpoXW6_f.js → index-Bg62fPK7.js} +367 -388
- package/dist/index-C159nEYc.js +212 -0
- package/dist/index-CfEH2hsw.js +626 -0
- package/dist/{index-_ftu0t0z.js → index-CubKalvr.js} +1 -1
- package/dist/{index-WACuLhO6.js → index-DNzxWHJt.js} +2 -2
- package/dist/{index-HGQZ77IK.js → index-DhPRJZz0.js} +2 -2
- package/dist/{index-B6haPltu.js → index-DluFz_0j.js} +1 -1
- package/dist/{index-COovE1Oo.js → index-Dpv0n-cZ.js} +288 -287
- package/dist/{index-CjesiOz_.js → index-DutovjI-.js} +24 -24
- package/dist/index.es.js +9329 -8978
- package/dist/index.js +598 -793
- package/dist/{long-BXK3UEks.js → long-DM5IWGqg.js} +2 -2
- package/dist/remoteFile-DwSeXAZ0.js +94 -0
- package/dist/style.css +1 -1
- package/package.json +3 -3
- package/dist/_commonjsHelpers-DSebQMb9.js +0 -28
- package/dist/index-BhtH2nrr.js +0 -513
- package/dist/index-nCZhu2o-.js +0 -613
- package/dist/remoteFile-DuIsnepi.js +0 -90
@@ -1,8 +1,8 @@
|
|
1
|
-
import { L as
|
2
|
-
import { b as I } from "./index-
|
3
|
-
import { L as
|
4
|
-
import { R } from "./remoteFile-
|
5
|
-
import {
|
1
|
+
import { L as j, u as R, a as V } from "./long-DM5IWGqg.js";
|
2
|
+
import { b as I } from "./index-DluFz_0j.js";
|
3
|
+
import { L as C } from "./__vite-browser-external-C--ziKoh.js";
|
4
|
+
import { R as k } from "./remoteFile-DwSeXAZ0.js";
|
5
|
+
import { A as Q, L as Y } from "./index-C159nEYc.js";
|
6
6
|
class D {
|
7
7
|
constructor(e, t) {
|
8
8
|
this.blockPosition = e, this.dataPosition = t;
|
@@ -22,7 +22,7 @@ class D {
|
|
22
22
|
return t;
|
23
23
|
}
|
24
24
|
}
|
25
|
-
function
|
25
|
+
function E(o, e = 0, t = !1) {
|
26
26
|
if (t)
|
27
27
|
throw new Error("big-endian virtual file offsets not implemented");
|
28
28
|
return new D(o[e + 7] * 1099511627776 + o[e + 6] * 4294967296 + o[e + 5] * 16777216 + o[e + 4] * 65536 + o[e + 3] * 256 + o[e + 2], o[e + 1] << 8 | o[e]);
|
@@ -44,15 +44,15 @@ class $ {
|
|
44
44
|
return this._fetchedSize !== void 0 ? this._fetchedSize : this.maxv.blockPosition + 65536 - this.minv.blockPosition;
|
45
45
|
}
|
46
46
|
}
|
47
|
-
function
|
47
|
+
function W(o) {
|
48
48
|
return new Promise((e) => setTimeout(e, o));
|
49
49
|
}
|
50
|
-
function
|
50
|
+
function X(o) {
|
51
51
|
if (o.greaterThan(Number.MAX_SAFE_INTEGER) || o.lessThan(Number.MIN_SAFE_INTEGER))
|
52
52
|
throw new Error("integer overflow");
|
53
53
|
return o.toNumber();
|
54
54
|
}
|
55
|
-
function
|
55
|
+
function J(o) {
|
56
56
|
if (o && o.aborted)
|
57
57
|
if (typeof DOMException > "u") {
|
58
58
|
const e = new Error("aborted");
|
@@ -60,10 +60,10 @@ function K(o) {
|
|
60
60
|
} else
|
61
61
|
throw new DOMException("aborted", "AbortError");
|
62
62
|
}
|
63
|
-
function
|
63
|
+
function K(o, e) {
|
64
64
|
return e.minv.blockPosition - o.maxv.blockPosition < 65e3 && e.maxv.blockPosition - o.minv.blockPosition < 5e6;
|
65
65
|
}
|
66
|
-
function
|
66
|
+
function Z(o = {}) {
|
67
67
|
return "aborted" in o ? { signal: o } : o;
|
68
68
|
}
|
69
69
|
function U(o, e) {
|
@@ -72,29 +72,29 @@ function U(o, e) {
|
|
72
72
|
if (o.length === 0)
|
73
73
|
return o;
|
74
74
|
o.sort((r, s) => {
|
75
|
-
const
|
76
|
-
return
|
75
|
+
const i = r.minv.blockPosition - s.minv.blockPosition;
|
76
|
+
return i === 0 ? r.minv.dataPosition - s.minv.dataPosition : i;
|
77
77
|
});
|
78
78
|
for (const r of o)
|
79
|
-
(!e || r.maxv.compareTo(e) > 0) && (n === void 0 ? (t.push(r), n = r) :
|
79
|
+
(!e || r.maxv.compareTo(e) > 0) && (n === void 0 ? (t.push(r), n = r) : K(n, r) ? r.maxv.compareTo(n.maxv) > 0 && (n.maxv = r.maxv) : (t.push(r), n = r));
|
80
80
|
return t;
|
81
81
|
}
|
82
82
|
function z(o, e) {
|
83
|
-
return { lineCount:
|
83
|
+
return { lineCount: X(j.fromBytesLE(Array.prototype.slice.call(o, e, e + 8), !0)) };
|
84
84
|
}
|
85
85
|
function L(o, e) {
|
86
86
|
return o ? o.compareTo(e) > 0 ? e : o : e;
|
87
87
|
}
|
88
|
-
function
|
88
|
+
function ee(o, e = (t) => t) {
|
89
89
|
let t = 0, n = 0;
|
90
90
|
const r = [], s = {};
|
91
|
-
for (let
|
92
|
-
if (!o[
|
93
|
-
if (n <
|
94
|
-
let
|
95
|
-
|
91
|
+
for (let i = 0; i < o.length; i += 1)
|
92
|
+
if (!o[i]) {
|
93
|
+
if (n < i) {
|
94
|
+
let c = o.toString("utf8", n, i);
|
95
|
+
c = e(c), r[t] = c, s[c] = t;
|
96
96
|
}
|
97
|
-
n =
|
97
|
+
n = i + 1, t += 1;
|
98
98
|
}
|
99
99
|
return { refNameToId: s, refIdToName: r };
|
100
100
|
}
|
@@ -107,14 +107,14 @@ class O {
|
|
107
107
|
this.filehandle = e, this.renameRefSeq = t;
|
108
108
|
}
|
109
109
|
}
|
110
|
-
const
|
111
|
-
function
|
110
|
+
const te = 21578050;
|
111
|
+
function ne(o, e) {
|
112
112
|
return o - o % e;
|
113
113
|
}
|
114
|
-
function
|
114
|
+
function re(o, e) {
|
115
115
|
return o - o % e + e;
|
116
116
|
}
|
117
|
-
function
|
117
|
+
function se(o, e) {
|
118
118
|
return e -= 1, [
|
119
119
|
[0, 0],
|
120
120
|
[1 + (o >> 26), 1 + (e >> 26)],
|
@@ -132,74 +132,74 @@ class v extends O {
|
|
132
132
|
// fetch and parse the index
|
133
133
|
async _parse(e) {
|
134
134
|
const t = await this.filehandle.readFile(e);
|
135
|
-
if (t.readUInt32LE(0) !==
|
135
|
+
if (t.readUInt32LE(0) !== te)
|
136
136
|
throw new Error("Not a BAI file");
|
137
137
|
const n = t.readInt32LE(4), s = ((1 << (5 + 1) * 3) - 1) / 7;
|
138
|
-
let
|
139
|
-
const
|
140
|
-
for (let
|
141
|
-
const l = t.readInt32LE(
|
142
|
-
let
|
143
|
-
|
144
|
-
const
|
145
|
-
for (let
|
146
|
-
const
|
147
|
-
if (
|
148
|
-
|
138
|
+
let i = 8, c;
|
139
|
+
const d = new Array(n);
|
140
|
+
for (let a = 0; a < n; a++) {
|
141
|
+
const l = t.readInt32LE(i);
|
142
|
+
let x;
|
143
|
+
i += 4;
|
144
|
+
const h = {};
|
145
|
+
for (let b = 0; b < l; b += 1) {
|
146
|
+
const u = t.readUInt32LE(i);
|
147
|
+
if (i += 4, u === s + 1)
|
148
|
+
i += 4, x = z(t, i + 16), i += 32;
|
149
149
|
else {
|
150
|
-
if (
|
150
|
+
if (u > s + 1)
|
151
151
|
throw new Error("bai index contains too many bins, please use CSI");
|
152
152
|
{
|
153
|
-
const
|
154
|
-
|
155
|
-
const
|
156
|
-
for (let
|
157
|
-
const y =
|
158
|
-
|
159
|
-
const S =
|
160
|
-
|
153
|
+
const g = t.readInt32LE(i);
|
154
|
+
i += 4;
|
155
|
+
const p = new Array(g);
|
156
|
+
for (let w = 0; w < g; w++) {
|
157
|
+
const y = E(t, i);
|
158
|
+
i += 8;
|
159
|
+
const S = E(t, i);
|
160
|
+
i += 8, c = L(c, y), p[w] = new $(y, S, u);
|
161
161
|
}
|
162
|
-
|
162
|
+
h[u] = p;
|
163
163
|
}
|
164
164
|
}
|
165
165
|
}
|
166
|
-
const
|
167
|
-
|
168
|
-
const
|
169
|
-
for (let
|
170
|
-
const
|
171
|
-
|
166
|
+
const f = t.readInt32LE(i);
|
167
|
+
i += 4;
|
168
|
+
const m = new Array(f);
|
169
|
+
for (let b = 0; b < f; b++) {
|
170
|
+
const u = E(t, i);
|
171
|
+
i += 8, c = L(c, u), m[b] = u;
|
172
172
|
}
|
173
|
-
|
173
|
+
d[a] = { binIndex: h, linearIndex: m, stats: x };
|
174
174
|
}
|
175
175
|
return {
|
176
176
|
bai: !0,
|
177
|
-
firstDataLine:
|
177
|
+
firstDataLine: c,
|
178
178
|
maxBlockSize: 65536,
|
179
|
-
indices:
|
179
|
+
indices: d,
|
180
180
|
refCount: n
|
181
181
|
};
|
182
182
|
}
|
183
183
|
async indexCov(e, t, n, r = {}) {
|
184
|
-
const
|
185
|
-
if (!
|
184
|
+
const i = t !== void 0, d = (await this.parse(r)).indices[e];
|
185
|
+
if (!d)
|
186
186
|
return [];
|
187
|
-
const { linearIndex:
|
188
|
-
if (
|
187
|
+
const { linearIndex: a = [], stats: l } = d;
|
188
|
+
if (a.length === 0)
|
189
189
|
return [];
|
190
|
-
const
|
191
|
-
if (
|
190
|
+
const x = n === void 0 ? (a.length - 1) * 16384 : re(n, 16384), h = t === void 0 ? 0 : ne(t, 16384), f = i ? new Array((x - h) / 16384) : new Array(a.length - 1), m = a[a.length - 1].blockPosition;
|
191
|
+
if (x > (a.length - 1) * 16384)
|
192
192
|
throw new Error("query outside of range of linear index");
|
193
|
-
let
|
194
|
-
for (let
|
195
|
-
|
196
|
-
score:
|
197
|
-
start:
|
198
|
-
end:
|
199
|
-
},
|
200
|
-
return
|
201
|
-
...
|
202
|
-
score:
|
193
|
+
let b = a[h / 16384].blockPosition;
|
194
|
+
for (let u = h / 16384, g = 0; u < x / 16384; u++, g++)
|
195
|
+
f[g] = {
|
196
|
+
score: a[u + 1].blockPosition - b,
|
197
|
+
start: u * 16384,
|
198
|
+
end: u * 16384 + 16384
|
199
|
+
}, b = a[u + 1].blockPosition;
|
200
|
+
return f.map((u) => ({
|
201
|
+
...u,
|
202
|
+
score: u.score * ((l == null ? void 0 : l.lineCount) || 0) / m
|
203
203
|
}));
|
204
204
|
}
|
205
205
|
async blocksForRange(e, t, n, r = {}) {
|
@@ -207,25 +207,25 @@ class v extends O {
|
|
207
207
|
const s = await this.parse(r);
|
208
208
|
if (!s)
|
209
209
|
return [];
|
210
|
-
const
|
211
|
-
if (!
|
210
|
+
const i = s.indices[e];
|
211
|
+
if (!i)
|
212
212
|
return [];
|
213
|
-
const
|
214
|
-
for (const [
|
215
|
-
for (let
|
216
|
-
if (
|
217
|
-
const
|
218
|
-
for (const
|
219
|
-
|
213
|
+
const c = se(t, n), d = [];
|
214
|
+
for (const [f, m] of c)
|
215
|
+
for (let b = f; b <= m; b++)
|
216
|
+
if (i.binIndex[b]) {
|
217
|
+
const u = i.binIndex[b];
|
218
|
+
for (const g of u)
|
219
|
+
d.push(g);
|
220
220
|
}
|
221
|
-
const
|
221
|
+
const a = i.linearIndex.length;
|
222
222
|
let l;
|
223
|
-
const
|
224
|
-
for (let
|
225
|
-
const
|
226
|
-
|
223
|
+
const x = Math.min(t >> 14, a - 1), h = Math.min(n >> 14, a - 1);
|
224
|
+
for (let f = x; f <= h; ++f) {
|
225
|
+
const m = i.linearIndex[f];
|
226
|
+
m && (!l || m.compareTo(l) < 0) && (l = m);
|
227
227
|
}
|
228
|
-
return U(
|
228
|
+
return U(d, l);
|
229
229
|
}
|
230
230
|
async parse(e = {}) {
|
231
231
|
return this.setupP || (this.setupP = this._parse(e).catch((t) => {
|
@@ -237,10 +237,7 @@ class v extends O {
|
|
237
237
|
return !!(!((n = (await this.parse(t)).indices[e]) === null || n === void 0) && n.binIndex);
|
238
238
|
}
|
239
239
|
}
|
240
|
-
|
241
|
-
return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
|
242
|
-
}
|
243
|
-
const oe = new Int32Array([
|
240
|
+
let T = [
|
244
241
|
0,
|
245
242
|
1996959894,
|
246
243
|
3993919788,
|
@@ -497,42 +494,23 @@ const oe = new Int32Array([
|
|
497
494
|
3272380065,
|
498
495
|
1510334235,
|
499
496
|
755167117
|
500
|
-
]
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
if (typeof o == "string")
|
507
|
-
return Buffer.from(o);
|
508
|
-
throw new Error("input must be buffer, number, or string, received " + typeof o);
|
509
|
-
}
|
510
|
-
function ce(o) {
|
511
|
-
const e = H(4);
|
512
|
-
return e.writeInt32BE(o, 0), e;
|
513
|
-
}
|
514
|
-
function T(o, e) {
|
515
|
-
o = H(o), Buffer.isBuffer(e) && (e = e.readUInt32BE(0));
|
516
|
-
let t = ~~e ^ -1;
|
517
|
-
for (var n = 0; n < o.length; n++)
|
518
|
-
t = oe[(t ^ o[n]) & 255] ^ t >>> 8;
|
497
|
+
];
|
498
|
+
typeof Int32Array < "u" && (T = new Int32Array(T));
|
499
|
+
const ae = (o, e) => {
|
500
|
+
let t = e === 0 ? 0 : ~~e ^ -1;
|
501
|
+
for (let n = 0; n < o.length; n++)
|
502
|
+
t = T[(t ^ o[n]) & 255] ^ t >>> 8;
|
519
503
|
return t ^ -1;
|
504
|
+
}, M = (o, e) => I.Buffer.from(o, e);
|
505
|
+
function ie(o, e) {
|
506
|
+
const t = (n, r) => e(M(n), r) >>> 0;
|
507
|
+
return t.signed = (n, r) => e(M(n), r), t.unsigned = t, t.model = o, t;
|
520
508
|
}
|
521
|
-
|
522
|
-
|
523
|
-
}
|
524
|
-
M.signed = function() {
|
525
|
-
return T.apply(null, arguments);
|
526
|
-
};
|
527
|
-
M.unsigned = function() {
|
528
|
-
return T.apply(null, arguments) >>> 0;
|
529
|
-
};
|
530
|
-
var he = M;
|
531
|
-
const de = /* @__PURE__ */ ae(he), fe = 21582659, le = 38359875;
|
532
|
-
function ue(o, e) {
|
509
|
+
const oe = ie("crc-32", ae), de = 21582659, ce = 38359875;
|
510
|
+
function fe(o, e) {
|
533
511
|
return o * 2 ** e;
|
534
512
|
}
|
535
|
-
function
|
513
|
+
function F(o, e) {
|
536
514
|
return Math.floor(o / 2 ** e);
|
537
515
|
}
|
538
516
|
class P extends O {
|
@@ -550,88 +528,88 @@ class P extends O {
|
|
550
528
|
const n = e.readInt32LE(t), r = n & 65536 ? "zero-based-half-open" : "1-based-closed", s = { 0: "generic", 1: "SAM", 2: "VCF" }[n & 15];
|
551
529
|
if (!s)
|
552
530
|
throw new Error(`invalid Tabix preset format flags ${n}`);
|
553
|
-
const
|
531
|
+
const i = {
|
554
532
|
ref: e.readInt32LE(t + 4),
|
555
533
|
start: e.readInt32LE(t + 8),
|
556
534
|
end: e.readInt32LE(t + 12)
|
557
|
-
},
|
535
|
+
}, c = e.readInt32LE(t + 16), d = c ? String.fromCharCode(c) : "", a = e.readInt32LE(t + 20), l = e.readInt32LE(t + 24);
|
558
536
|
return {
|
559
|
-
columnNumbers:
|
537
|
+
columnNumbers: i,
|
560
538
|
coordinateType: r,
|
561
|
-
metaValue:
|
562
|
-
metaChar:
|
563
|
-
skipLines:
|
539
|
+
metaValue: c,
|
540
|
+
metaChar: d,
|
541
|
+
skipLines: a,
|
564
542
|
format: s,
|
565
543
|
formatFlags: n,
|
566
|
-
...
|
544
|
+
...ee(e.subarray(t + 28, t + 28 + l), this.renameRefSeq)
|
567
545
|
};
|
568
546
|
}
|
569
547
|
// fetch and parse the index
|
570
548
|
async _parse(e) {
|
571
|
-
const t = await this.filehandle.readFile(e), n = await
|
549
|
+
const t = await this.filehandle.readFile(e), n = await R(t);
|
572
550
|
let r;
|
573
|
-
if (n.readUInt32LE(0) ===
|
551
|
+
if (n.readUInt32LE(0) === de)
|
574
552
|
r = 1;
|
575
|
-
else if (n.readUInt32LE(0) ===
|
553
|
+
else if (n.readUInt32LE(0) === ce)
|
576
554
|
r = 2;
|
577
555
|
else
|
578
556
|
throw new Error("Not a CSI file");
|
579
557
|
this.minShift = n.readInt32LE(4), this.depth = n.readInt32LE(8), this.maxBinNumber = ((1 << (this.depth + 1) * 3) - 1) / 7;
|
580
|
-
const s = n.readInt32LE(12),
|
581
|
-
let
|
582
|
-
const l = new Array(
|
583
|
-
for (let
|
584
|
-
const
|
585
|
-
|
586
|
-
const
|
587
|
-
let
|
588
|
-
for (let
|
589
|
-
const
|
590
|
-
if (
|
591
|
-
|
558
|
+
const s = n.readInt32LE(12), i = s >= 30 ? this.parseAuxData(n, 16) : void 0, c = n.readInt32LE(16 + s);
|
559
|
+
let d = 16 + s + 4, a;
|
560
|
+
const l = new Array(c);
|
561
|
+
for (let x = 0; x < c; x++) {
|
562
|
+
const h = n.readInt32LE(d);
|
563
|
+
d += 4;
|
564
|
+
const f = {};
|
565
|
+
let m;
|
566
|
+
for (let b = 0; b < h; b++) {
|
567
|
+
const u = n.readUInt32LE(d);
|
568
|
+
if (d += 4, u > this.maxBinNumber)
|
569
|
+
m = z(n, d + 28), d += 44;
|
592
570
|
else {
|
593
|
-
|
594
|
-
const
|
595
|
-
|
596
|
-
const
|
597
|
-
for (let
|
598
|
-
const y =
|
599
|
-
|
600
|
-
const S =
|
601
|
-
|
571
|
+
a = L(a, E(n, d)), d += 8;
|
572
|
+
const g = n.readInt32LE(d);
|
573
|
+
d += 4;
|
574
|
+
const p = new Array(g);
|
575
|
+
for (let w = 0; w < g; w += 1) {
|
576
|
+
const y = E(n, d);
|
577
|
+
d += 8;
|
578
|
+
const S = E(n, d);
|
579
|
+
d += 8, a = L(a, y), p[w] = new $(y, S, u);
|
602
580
|
}
|
603
|
-
|
581
|
+
f[u] = p;
|
604
582
|
}
|
605
583
|
}
|
606
|
-
l[
|
584
|
+
l[x] = { binIndex: f, stats: m };
|
607
585
|
}
|
608
586
|
return {
|
609
587
|
csiVersion: r,
|
610
|
-
firstDataLine:
|
588
|
+
firstDataLine: a,
|
611
589
|
indices: l,
|
612
|
-
refCount:
|
590
|
+
refCount: c,
|
613
591
|
csi: !0,
|
614
592
|
maxBlockSize: 65536,
|
615
|
-
...
|
593
|
+
...i
|
616
594
|
};
|
617
595
|
}
|
618
596
|
async blocksForRange(e, t, n, r = {}) {
|
619
597
|
t < 0 && (t = 0);
|
620
|
-
const s = await this.parse(r),
|
621
|
-
if (!
|
598
|
+
const s = await this.parse(r), i = s == null ? void 0 : s.indices[e];
|
599
|
+
if (!i)
|
622
600
|
return [];
|
623
|
-
const
|
624
|
-
if (
|
601
|
+
const c = this.reg2bins(t, n);
|
602
|
+
if (c.length === 0)
|
625
603
|
return [];
|
626
|
-
const
|
627
|
-
for (const [
|
628
|
-
for (let
|
629
|
-
if (
|
630
|
-
const
|
631
|
-
for (const
|
632
|
-
|
604
|
+
const d = [];
|
605
|
+
for (const [a, l] of c)
|
606
|
+
for (let x = a; x <= l; x++)
|
607
|
+
if (i.binIndex[x]) {
|
608
|
+
const h = i.binIndex[x];
|
609
|
+
for (const f of h)
|
610
|
+
d.push(f);
|
633
611
|
}
|
634
|
-
return U(
|
612
|
+
return U(d, new D(0, 0));
|
635
613
|
}
|
636
614
|
/**
|
637
615
|
* calculate the list of bins that may overlap with region [beg,end)
|
@@ -640,14 +618,14 @@ class P extends O {
|
|
640
618
|
reg2bins(e, t) {
|
641
619
|
e -= 1, e < 1 && (e = 1), t > 2 ** 50 && (t = 2 ** 34), t -= 1;
|
642
620
|
let n = 0, r = 0, s = this.minShift + this.depth * 3;
|
643
|
-
const
|
644
|
-
for (; n <= this.depth; s -= 3, r +=
|
645
|
-
const
|
646
|
-
if (
|
621
|
+
const i = [];
|
622
|
+
for (; n <= this.depth; s -= 3, r += fe(1, n * 3), n += 1) {
|
623
|
+
const c = r + F(e, s), d = r + F(t, s);
|
624
|
+
if (d - c + i.length > this.maxBinNumber)
|
647
625
|
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`);
|
648
|
-
|
626
|
+
i.push([c, d]);
|
649
627
|
}
|
650
|
-
return
|
628
|
+
return i;
|
651
629
|
}
|
652
630
|
async parse(e = {}) {
|
653
631
|
return this.setupP || (this.setupP = this._parse(e).catch((t) => {
|
@@ -659,7 +637,7 @@ class P extends O {
|
|
659
637
|
return !!(!((n = (await this.parse(t)).indices[e]) === null || n === void 0) && n.binIndex);
|
660
638
|
}
|
661
639
|
}
|
662
|
-
const
|
640
|
+
const _ = {
|
663
641
|
// the read is paired in sequencing, no matter whether it is mapped in a pair
|
664
642
|
BAM_FPAIRED: 1,
|
665
643
|
// the read is mapped in a proper pair
|
@@ -684,12 +662,12 @@ const b = {
|
|
684
662
|
BAM_FDUP: 1024,
|
685
663
|
// supplementary alignment
|
686
664
|
BAM_FSUPPLEMENTARY: 2048
|
687
|
-
},
|
688
|
-
class
|
665
|
+
}, B = "=ACMGRSVTWYHKDBN".split(""), A = "MIDNSHP=X???????".split("");
|
666
|
+
class he {
|
689
667
|
constructor(e) {
|
690
668
|
this.data = {}, this._tagList = [], this._allTagsParsed = !1;
|
691
669
|
const { bytes: t, fileOffset: n } = e, { byteArray: r, start: s } = t;
|
692
|
-
this.data = {}, this.bytes = t, this._id = n, this._refID = r.readInt32LE(s + 4), this.
|
670
|
+
this.data = { start: r.readInt32LE(s + 8) }, this.bytes = t, this._id = n, this._refID = r.readInt32LE(s + 4), this.flags = (r.readInt32LE(s + 16) & 4294901760) >> 16;
|
693
671
|
}
|
694
672
|
get(e) {
|
695
673
|
return this[e] ? this.data[e] ? this.data[e] : (this.data[e] = this[e](), this.data[e]) : this._get(e.toLowerCase());
|
@@ -772,100 +750,100 @@ class me {
|
|
772
750
|
const { byteArray: t, start: n } = this.bytes;
|
773
751
|
let r = this._tagOffset || n + 36 + this.get("_l_read_name") + this.get("_n_cigar_op") * 4 + this.get("_seq_bytes") + this.get("seq_length");
|
774
752
|
const s = this.bytes.end;
|
775
|
-
let
|
776
|
-
for (; r < s &&
|
777
|
-
const
|
778
|
-
|
779
|
-
const
|
753
|
+
let i;
|
754
|
+
for (; r < s && i !== e; ) {
|
755
|
+
const c = String.fromCharCode(t[r], t[r + 1]);
|
756
|
+
i = c.toLowerCase();
|
757
|
+
const d = String.fromCharCode(t[r + 2]);
|
780
758
|
r += 3;
|
781
|
-
let
|
782
|
-
switch (
|
759
|
+
let a;
|
760
|
+
switch (d) {
|
783
761
|
case "A": {
|
784
|
-
|
762
|
+
a = String.fromCharCode(t[r]), r += 1;
|
785
763
|
break;
|
786
764
|
}
|
787
765
|
case "i": {
|
788
|
-
|
766
|
+
a = t.readInt32LE(r), r += 4;
|
789
767
|
break;
|
790
768
|
}
|
791
769
|
case "I": {
|
792
|
-
|
770
|
+
a = t.readUInt32LE(r), r += 4;
|
793
771
|
break;
|
794
772
|
}
|
795
773
|
case "c": {
|
796
|
-
|
774
|
+
a = t.readInt8(r), r += 1;
|
797
775
|
break;
|
798
776
|
}
|
799
777
|
case "C": {
|
800
|
-
|
778
|
+
a = t.readUInt8(r), r += 1;
|
801
779
|
break;
|
802
780
|
}
|
803
781
|
case "s": {
|
804
|
-
|
782
|
+
a = t.readInt16LE(r), r += 2;
|
805
783
|
break;
|
806
784
|
}
|
807
785
|
case "S": {
|
808
|
-
|
786
|
+
a = t.readUInt16LE(r), r += 2;
|
809
787
|
break;
|
810
788
|
}
|
811
789
|
case "f": {
|
812
|
-
|
790
|
+
a = t.readFloatLE(r), r += 4;
|
813
791
|
break;
|
814
792
|
}
|
815
793
|
case "Z":
|
816
794
|
case "H": {
|
817
|
-
for (
|
795
|
+
for (a = ""; r <= s; ) {
|
818
796
|
const l = t[r++];
|
819
797
|
if (l === 0)
|
820
798
|
break;
|
821
|
-
|
799
|
+
a += String.fromCharCode(l);
|
822
800
|
}
|
823
801
|
break;
|
824
802
|
}
|
825
803
|
case "B": {
|
826
|
-
|
827
|
-
const l = t[r++],
|
828
|
-
if (r += 4,
|
829
|
-
if (
|
830
|
-
for (let
|
831
|
-
const
|
832
|
-
|
804
|
+
a = "";
|
805
|
+
const l = t[r++], x = String.fromCharCode(l), h = t.readInt32LE(r);
|
806
|
+
if (r += 4, x === "i")
|
807
|
+
if (c === "CG")
|
808
|
+
for (let f = 0; f < h; f++) {
|
809
|
+
const m = t.readInt32LE(r), b = m >> 4, u = A[m & 15];
|
810
|
+
a += b + u, r += 4;
|
833
811
|
}
|
834
812
|
else
|
835
|
-
for (let
|
836
|
-
|
837
|
-
if (
|
838
|
-
if (
|
839
|
-
for (let
|
840
|
-
const
|
841
|
-
|
813
|
+
for (let f = 0; f < h; f++)
|
814
|
+
a += t.readInt32LE(r), f + 1 < h && (a += ","), r += 4;
|
815
|
+
if (x === "I")
|
816
|
+
if (c === "CG")
|
817
|
+
for (let f = 0; f < h; f++) {
|
818
|
+
const m = t.readUInt32LE(r), b = m >> 4, u = A[m & 15];
|
819
|
+
a += b + u, r += 4;
|
842
820
|
}
|
843
821
|
else
|
844
|
-
for (let
|
845
|
-
|
846
|
-
if (
|
847
|
-
for (let
|
848
|
-
|
849
|
-
if (
|
850
|
-
for (let
|
851
|
-
|
852
|
-
if (
|
853
|
-
for (let
|
854
|
-
|
855
|
-
if (
|
856
|
-
for (let
|
857
|
-
|
858
|
-
if (
|
859
|
-
for (let
|
860
|
-
|
822
|
+
for (let f = 0; f < h; f++)
|
823
|
+
a += t.readUInt32LE(r), f + 1 < h && (a += ","), r += 4;
|
824
|
+
if (x === "s")
|
825
|
+
for (let f = 0; f < h; f++)
|
826
|
+
a += t.readInt16LE(r), f + 1 < h && (a += ","), r += 2;
|
827
|
+
if (x === "S")
|
828
|
+
for (let f = 0; f < h; f++)
|
829
|
+
a += t.readUInt16LE(r), f + 1 < h && (a += ","), r += 2;
|
830
|
+
if (x === "c")
|
831
|
+
for (let f = 0; f < h; f++)
|
832
|
+
a += t.readInt8(r), f + 1 < h && (a += ","), r += 1;
|
833
|
+
if (x === "C")
|
834
|
+
for (let f = 0; f < h; f++)
|
835
|
+
a += t.readUInt8(r), f + 1 < h && (a += ","), r += 1;
|
836
|
+
if (x === "f")
|
837
|
+
for (let f = 0; f < h; f++)
|
838
|
+
a += t.readFloatLE(r), f + 1 < h && (a += ","), r += 4;
|
861
839
|
break;
|
862
840
|
}
|
863
841
|
default:
|
864
|
-
console.warn(`Unknown BAM tag type '${
|
842
|
+
console.warn(`Unknown BAM tag type '${d}', tags may be incomplete`), a = void 0, r = s;
|
865
843
|
}
|
866
|
-
if (this._tagOffset = r, this._tagList.push(
|
867
|
-
return
|
868
|
-
this.data[
|
844
|
+
if (this._tagOffset = r, this._tagList.push(c), i === e)
|
845
|
+
return a;
|
846
|
+
this.data[i] = a;
|
869
847
|
}
|
870
848
|
this._allTagsParsed = !0;
|
871
849
|
}
|
@@ -875,58 +853,59 @@ class me {
|
|
875
853
|
_parseCigar(e) {
|
876
854
|
return (
|
877
855
|
//@ts-ignore
|
878
|
-
e.match(/\d+\D/g).map((t) => [
|
856
|
+
e.match(/\d+\D/g).map((t) => [/\D/.exec(t)[0].toUpperCase(), Number.parseInt(t, 10)])
|
879
857
|
);
|
880
858
|
}
|
881
859
|
/**
|
882
|
-
* @returns {boolean} true if the read is paired, regardless of whether both
|
860
|
+
* @returns {boolean} true if the read is paired, regardless of whether both
|
861
|
+
* segments are mapped
|
883
862
|
*/
|
884
863
|
isPaired() {
|
885
|
-
return !!(this.flags &
|
864
|
+
return !!(this.flags & _.BAM_FPAIRED);
|
886
865
|
}
|
887
866
|
/** @returns {boolean} true if the read is paired, and both segments are mapped */
|
888
867
|
isProperlyPaired() {
|
889
|
-
return !!(this.flags &
|
868
|
+
return !!(this.flags & _.BAM_FPROPER_PAIR);
|
890
869
|
}
|
891
870
|
/** @returns {boolean} true if the read itself is unmapped; conflictive with isProperlyPaired */
|
892
871
|
isSegmentUnmapped() {
|
893
|
-
return !!(this.flags &
|
872
|
+
return !!(this.flags & _.BAM_FUNMAP);
|
894
873
|
}
|
895
874
|
/** @returns {boolean} true if the read itself is unmapped; conflictive with isProperlyPaired */
|
896
875
|
isMateUnmapped() {
|
897
|
-
return !!(this.flags &
|
876
|
+
return !!(this.flags & _.BAM_FMUNMAP);
|
898
877
|
}
|
899
878
|
/** @returns {boolean} true if the read is mapped to the reverse strand */
|
900
879
|
isReverseComplemented() {
|
901
|
-
return !!(this.flags &
|
880
|
+
return !!(this.flags & _.BAM_FREVERSE);
|
902
881
|
}
|
903
882
|
/** @returns {boolean} true if the mate is mapped to the reverse strand */
|
904
883
|
isMateReverseComplemented() {
|
905
|
-
return !!(this.flags &
|
884
|
+
return !!(this.flags & _.BAM_FMREVERSE);
|
906
885
|
}
|
907
886
|
/** @returns {boolean} true if this is read number 1 in a pair */
|
908
887
|
isRead1() {
|
909
|
-
return !!(this.flags &
|
888
|
+
return !!(this.flags & _.BAM_FREAD1);
|
910
889
|
}
|
911
890
|
/** @returns {boolean} true if this is read number 2 in a pair */
|
912
891
|
isRead2() {
|
913
|
-
return !!(this.flags &
|
892
|
+
return !!(this.flags & _.BAM_FREAD2);
|
914
893
|
}
|
915
894
|
/** @returns {boolean} true if this is a secondary alignment */
|
916
895
|
isSecondary() {
|
917
|
-
return !!(this.flags &
|
896
|
+
return !!(this.flags & _.BAM_FSECONDARY);
|
918
897
|
}
|
919
898
|
/** @returns {boolean} true if this read has failed QC checks */
|
920
899
|
isFailedQc() {
|
921
|
-
return !!(this.flags &
|
900
|
+
return !!(this.flags & _.BAM_FQCFAIL);
|
922
901
|
}
|
923
902
|
/** @returns {boolean} true if the read is an optical or PCR duplicate */
|
924
903
|
isDuplicate() {
|
925
|
-
return !!(this.flags &
|
904
|
+
return !!(this.flags & _.BAM_FDUP);
|
926
905
|
}
|
927
906
|
/** @returns {boolean} true if this is a supplementary alignment */
|
928
907
|
isSupplementary() {
|
929
|
-
return !!(this.flags &
|
908
|
+
return !!(this.flags & _.BAM_FSUPPLEMENTARY);
|
930
909
|
}
|
931
910
|
cigar() {
|
932
911
|
if (this.isSegmentUnmapped())
|
@@ -934,12 +913,12 @@ class me {
|
|
934
913
|
const { byteArray: e, start: t } = this.bytes, n = this.get("_n_cigar_op");
|
935
914
|
let r = t + 36 + this.get("_l_read_name");
|
936
915
|
const s = this.get("seq_length");
|
937
|
-
let
|
938
|
-
if (l === "S" &&
|
939
|
-
return r += 4,
|
940
|
-
for (let
|
941
|
-
|
942
|
-
return this.data.length_on_ref =
|
916
|
+
let i = "", c = 0, d = e.readInt32LE(r), a = d >> 4, l = A[d & 15];
|
917
|
+
if (l === "S" && a === s)
|
918
|
+
return r += 4, d = e.readInt32LE(r), a = d >> 4, l = A[d & 15], l !== "N" && console.warn("CG tag with no N tag"), this.data.length_on_ref = a, this.get("CG");
|
919
|
+
for (let x = 0; x < n; ++x)
|
920
|
+
d = e.readInt32LE(r), a = d >> 4, l = A[d & 15], i += a + l, l !== "H" && l !== "S" && l !== "I" && (c += a), r += 4;
|
921
|
+
return this.data.length_on_ref = c, i;
|
943
922
|
}
|
944
923
|
length_on_ref() {
|
945
924
|
return this.data.length_on_ref ? this.data.length_on_ref : (this.get("cigar"), this.data.length_on_ref);
|
@@ -961,12 +940,12 @@ class me {
|
|
961
940
|
}
|
962
941
|
seq() {
|
963
942
|
const { byteArray: e, start: t } = this.bytes, n = t + 36 + this.get("_l_read_name") + this.get("_n_cigar_op") * 4, r = this.get("_seq_bytes"), s = this.get("seq_length");
|
964
|
-
let
|
965
|
-
for (let
|
966
|
-
const
|
967
|
-
|
943
|
+
let i = "", c = 0;
|
944
|
+
for (let d = 0; d < r; ++d) {
|
945
|
+
const a = e[n + d];
|
946
|
+
i += B[(a & 240) >> 4], c++, c < s && (i += B[a & 15], c++);
|
968
947
|
}
|
969
|
-
return
|
948
|
+
return i;
|
970
949
|
}
|
971
950
|
// adapted from igv.js
|
972
951
|
getPairOrientation() {
|
@@ -1004,28 +983,28 @@ class me {
|
|
1004
983
|
return e;
|
1005
984
|
}
|
1006
985
|
}
|
1007
|
-
function
|
986
|
+
function H(o) {
|
1008
987
|
const e = o.split(/\r?\n/), t = [];
|
1009
988
|
for (const n of e) {
|
1010
989
|
const [r, ...s] = n.split(/\t/);
|
1011
990
|
r && t.push({
|
1012
991
|
tag: r.slice(1),
|
1013
|
-
data: s.map((
|
1014
|
-
const
|
1015
|
-
return { tag:
|
992
|
+
data: s.map((i) => {
|
993
|
+
const c = i.indexOf(":"), d = i.slice(0, c), a = i.slice(c + 1);
|
994
|
+
return { tag: d, value: a };
|
1016
995
|
})
|
1017
996
|
});
|
1018
997
|
}
|
1019
998
|
return t;
|
1020
999
|
}
|
1021
|
-
const
|
1022
|
-
async function
|
1000
|
+
const G = 21840194, q = 65536;
|
1001
|
+
async function le(o) {
|
1023
1002
|
let e = [];
|
1024
1003
|
for await (const t of o)
|
1025
1004
|
e = e.concat(t);
|
1026
1005
|
return e;
|
1027
1006
|
}
|
1028
|
-
class
|
1007
|
+
class xe {
|
1029
1008
|
read() {
|
1030
1009
|
throw new Error("never called");
|
1031
1010
|
}
|
@@ -1039,71 +1018,71 @@ class _e {
|
|
1039
1018
|
throw new Error("never called");
|
1040
1019
|
}
|
1041
1020
|
}
|
1042
|
-
class
|
1043
|
-
constructor({ bamFilehandle: e, bamPath: t, bamUrl: n, baiPath: r, baiFilehandle: s, baiUrl:
|
1044
|
-
if (this.htsget = !1, this.featureCache = new
|
1045
|
-
cache: new
|
1021
|
+
class ue {
|
1022
|
+
constructor({ bamFilehandle: e, bamPath: t, bamUrl: n, baiPath: r, baiFilehandle: s, baiUrl: i, csiPath: c, csiFilehandle: d, csiUrl: a, htsget: l, yieldThreadTime: x = 100, renameRefSeqs: h = (f) => f }) {
|
1023
|
+
if (this.htsget = !1, this.featureCache = new Q({
|
1024
|
+
cache: new Y({
|
1046
1025
|
maxSize: 50
|
1047
1026
|
}),
|
1048
|
-
fill: async (
|
1049
|
-
const { chunk:
|
1050
|
-
chunk:
|
1051
|
-
opts: { ...
|
1027
|
+
fill: async (f, m) => {
|
1028
|
+
const { chunk: b, opts: u } = f, { data: g, cpositions: p, dpositions: w } = await this._readChunk({
|
1029
|
+
chunk: b,
|
1030
|
+
opts: { ...u, signal: m }
|
1052
1031
|
});
|
1053
|
-
return this.readBamFeatures(p, w,
|
1032
|
+
return this.readBamFeatures(g, p, w, b);
|
1054
1033
|
}
|
1055
|
-
}), this.renameRefSeq =
|
1034
|
+
}), this.renameRefSeq = h, e)
|
1056
1035
|
this.bam = e;
|
1057
1036
|
else if (t)
|
1058
|
-
this.bam = new
|
1037
|
+
this.bam = new C(t);
|
1059
1038
|
else if (n)
|
1060
|
-
this.bam = new
|
1039
|
+
this.bam = new k(n);
|
1061
1040
|
else if (l)
|
1062
|
-
this.htsget = !0, this.bam = new
|
1041
|
+
this.htsget = !0, this.bam = new xe();
|
1063
1042
|
else
|
1064
1043
|
throw new Error("unable to initialize bam");
|
1065
|
-
if (
|
1066
|
-
this.index = new P({ filehandle:
|
1067
|
-
else if (
|
1068
|
-
this.index = new P({ filehandle: new
|
1069
|
-
else if (
|
1070
|
-
this.index = new P({ filehandle: new
|
1044
|
+
if (d)
|
1045
|
+
this.index = new P({ filehandle: d });
|
1046
|
+
else if (c)
|
1047
|
+
this.index = new P({ filehandle: new C(c) });
|
1048
|
+
else if (a)
|
1049
|
+
this.index = new P({ filehandle: new k(a) });
|
1071
1050
|
else if (s)
|
1072
1051
|
this.index = new v({ filehandle: s });
|
1073
1052
|
else if (r)
|
1074
|
-
this.index = new v({ filehandle: new
|
1075
|
-
else if (
|
1076
|
-
this.index = new v({ filehandle: new
|
1053
|
+
this.index = new v({ filehandle: new C(r) });
|
1054
|
+
else if (i)
|
1055
|
+
this.index = new v({ filehandle: new k(i) });
|
1077
1056
|
else if (t)
|
1078
|
-
this.index = new v({ filehandle: new
|
1057
|
+
this.index = new v({ filehandle: new C(`${t}.bai`) });
|
1079
1058
|
else if (n)
|
1080
|
-
this.index = new v({ filehandle: new
|
1059
|
+
this.index = new v({ filehandle: new k(`${n}.bai`) });
|
1081
1060
|
else if (l)
|
1082
1061
|
this.htsget = !0;
|
1083
1062
|
else
|
1084
1063
|
throw new Error("unable to infer index format");
|
1085
|
-
this.yieldThreadTime =
|
1064
|
+
this.yieldThreadTime = x;
|
1086
1065
|
}
|
1087
1066
|
async getHeaderPre(e) {
|
1088
|
-
const t =
|
1067
|
+
const t = Z(e);
|
1089
1068
|
if (!this.index)
|
1090
1069
|
return;
|
1091
1070
|
const n = await this.index.parse(t), r = n.firstDataLine ? n.firstDataLine.blockPosition + 65535 : void 0;
|
1092
1071
|
let s;
|
1093
1072
|
if (r) {
|
1094
|
-
const l = r + q,
|
1095
|
-
if (!
|
1073
|
+
const l = r + q, x = await this.bam.read(I.Buffer.alloc(l), 0, l, 0, t);
|
1074
|
+
if (!x.bytesRead)
|
1096
1075
|
throw new Error("Error reading header");
|
1097
|
-
s =
|
1076
|
+
s = x.buffer.subarray(0, Math.min(x.bytesRead, r));
|
1098
1077
|
} else
|
1099
1078
|
s = await this.bam.readFile(t);
|
1100
|
-
const
|
1101
|
-
if (
|
1079
|
+
const i = await R(s);
|
1080
|
+
if (i.readInt32LE(0) !== G)
|
1102
1081
|
throw new Error("Not a BAM file");
|
1103
|
-
const
|
1104
|
-
this.header =
|
1105
|
-
const { chrToIndex:
|
1106
|
-
return this.chrToIndex =
|
1082
|
+
const c = i.readInt32LE(4);
|
1083
|
+
this.header = i.toString("utf8", 8, 8 + c);
|
1084
|
+
const { chrToIndex: d, indexToChr: a } = await this._readRefSeqs(c + 8, 65535, t);
|
1085
|
+
return this.chrToIndex = d, this.indexToChr = a, H(this.header);
|
1107
1086
|
}
|
1108
1087
|
getHeader(e) {
|
1109
1088
|
return this.headerP || (this.headerP = this.getHeaderPre(e).catch((t) => {
|
@@ -1118,78 +1097,78 @@ class pe {
|
|
1118
1097
|
async _readRefSeqs(e, t, n) {
|
1119
1098
|
if (e > t)
|
1120
1099
|
return this._readRefSeqs(e, t * 2, n);
|
1121
|
-
const r = t + q, { bytesRead: s, buffer:
|
1100
|
+
const r = t + q, { bytesRead: s, buffer: i } = await this.bam.read(I.Buffer.alloc(r), 0, t, 0, n);
|
1122
1101
|
if (!s)
|
1123
1102
|
throw new Error("Error reading refseqs from header");
|
1124
|
-
const
|
1125
|
-
let
|
1126
|
-
const l = {},
|
1127
|
-
for (let
|
1128
|
-
const
|
1129
|
-
if (l[
|
1103
|
+
const c = await R(i.subarray(0, Math.min(s, t))), d = c.readInt32LE(e);
|
1104
|
+
let a = e + 4;
|
1105
|
+
const l = {}, x = [];
|
1106
|
+
for (let h = 0; h < d; h += 1) {
|
1107
|
+
const f = c.readInt32LE(a), m = this.renameRefSeq(c.toString("utf8", a + 4, a + 4 + f - 1)), b = c.readInt32LE(a + f + 4);
|
1108
|
+
if (l[m] = h, x.push({ refName: m, length: b }), a = a + 8 + f, a > c.length)
|
1130
1109
|
return console.warn(`BAM header is very big. Re-fetching ${t} bytes.`), this._readRefSeqs(e, t * 2, n);
|
1131
1110
|
}
|
1132
|
-
return { chrToIndex: l, indexToChr:
|
1111
|
+
return { chrToIndex: l, indexToChr: x };
|
1133
1112
|
}
|
1134
1113
|
async getRecordsForRange(e, t, n, r) {
|
1135
|
-
return
|
1114
|
+
return le(this.streamRecordsForRange(e, t, n, r));
|
1136
1115
|
}
|
1137
1116
|
async *streamRecordsForRange(e, t, n, r) {
|
1138
1117
|
var s;
|
1139
1118
|
await this.getHeader(r);
|
1140
|
-
const
|
1141
|
-
if (
|
1119
|
+
const i = (s = this.chrToIndex) === null || s === void 0 ? void 0 : s[e];
|
1120
|
+
if (i === void 0 || !this.index)
|
1142
1121
|
yield [];
|
1143
1122
|
else {
|
1144
|
-
const
|
1145
|
-
yield* this._fetchChunkFeatures(
|
1123
|
+
const c = await this.index.blocksForRange(i, t - 1, n, r);
|
1124
|
+
yield* this._fetchChunkFeatures(c, i, t, n, r);
|
1146
1125
|
}
|
1147
1126
|
}
|
1148
1127
|
async *_fetchChunkFeatures(e, t, n, r, s = {}) {
|
1149
|
-
const { viewAsPairs:
|
1150
|
-
let
|
1151
|
-
for (const
|
1152
|
-
const l = await this.featureCache.get(
|
1153
|
-
for (const
|
1154
|
-
if (
|
1155
|
-
if (
|
1156
|
-
|
1128
|
+
const { viewAsPairs: i } = s, c = [];
|
1129
|
+
let d = !1;
|
1130
|
+
for (const a of e) {
|
1131
|
+
const l = await this.featureCache.get(a.toString(), { chunk: a, opts: s }, s.signal), x = [];
|
1132
|
+
for (const h of l)
|
1133
|
+
if (h.seq_id() === t)
|
1134
|
+
if (h.get("start") >= r) {
|
1135
|
+
d = !0;
|
1157
1136
|
break;
|
1158
|
-
} else
|
1159
|
-
if (
|
1137
|
+
} else h.get("end") >= n && x.push(h);
|
1138
|
+
if (c.push(x), yield x, d)
|
1160
1139
|
break;
|
1161
1140
|
}
|
1162
|
-
|
1141
|
+
J(s.signal), i && (yield this.fetchPairs(t, c, s));
|
1163
1142
|
}
|
1164
1143
|
async fetchPairs(e, t, n) {
|
1165
|
-
const { pairAcrossChr: r, maxInsertSize: s = 2e5 } = n,
|
1166
|
-
t.map((
|
1167
|
-
const
|
1168
|
-
for (const
|
1169
|
-
const
|
1170
|
-
|
1144
|
+
const { pairAcrossChr: r, maxInsertSize: s = 2e5 } = n, i = {}, c = {};
|
1145
|
+
t.map((h) => {
|
1146
|
+
const f = {};
|
1147
|
+
for (const m of h) {
|
1148
|
+
const b = m.name(), u = m.id();
|
1149
|
+
f[b] || (f[b] = 0), f[b]++, c[u] = 1;
|
1171
1150
|
}
|
1172
|
-
for (const [
|
1173
|
-
|
1151
|
+
for (const [m, b] of Object.entries(f))
|
1152
|
+
b === 1 && (i[m] = !0);
|
1174
1153
|
});
|
1175
|
-
const
|
1176
|
-
t.map((
|
1177
|
-
for (const
|
1178
|
-
const
|
1179
|
-
this.index &&
|
1154
|
+
const d = [];
|
1155
|
+
t.map((h) => {
|
1156
|
+
for (const f of h) {
|
1157
|
+
const m = f.name(), b = f.get("start"), u = f._next_pos(), g = f._next_refid();
|
1158
|
+
this.index && i[m] && (r || g === e && Math.abs(b - u) < s) && d.push(this.index.blocksForRange(g, u, u + 1, n));
|
1180
1159
|
}
|
1181
1160
|
});
|
1182
|
-
const
|
1183
|
-
for (const
|
1184
|
-
|
1185
|
-
return (await Promise.all([...
|
1186
|
-
const { data:
|
1187
|
-
chunk:
|
1161
|
+
const a = /* @__PURE__ */ new Map(), l = await Promise.all(d);
|
1162
|
+
for (const h of l.flat())
|
1163
|
+
a.has(h.toString()) || a.set(h.toString(), h);
|
1164
|
+
return (await Promise.all([...a.values()].map(async (h) => {
|
1165
|
+
const { data: f, cpositions: m, dpositions: b, chunk: u } = await this._readChunk({
|
1166
|
+
chunk: h,
|
1188
1167
|
opts: n
|
1189
|
-
}),
|
1190
|
-
for (const
|
1191
|
-
|
1192
|
-
return
|
1168
|
+
}), g = [];
|
1169
|
+
for (const p of await this.readBamFeatures(f, m, b, u))
|
1170
|
+
i[p.get("name")] && !c[p.id()] && g.push(p);
|
1171
|
+
return g;
|
1193
1172
|
}))).flat();
|
1194
1173
|
}
|
1195
1174
|
async _readRegion(e, t, n = {}) {
|
@@ -1197,22 +1176,22 @@ class pe {
|
|
1197
1176
|
return s.subarray(0, Math.min(r, t));
|
1198
1177
|
}
|
1199
1178
|
async _readChunk({ chunk: e, opts: t }) {
|
1200
|
-
const n = await this._readRegion(e.minv.blockPosition, e.fetchedSize(), t), { buffer: r, cpositions: s, dpositions:
|
1201
|
-
return { data: r, cpositions: s, dpositions:
|
1179
|
+
const n = await this._readRegion(e.minv.blockPosition, e.fetchedSize(), t), { buffer: r, cpositions: s, dpositions: i } = await V(n, e);
|
1180
|
+
return { data: r, cpositions: s, dpositions: i, chunk: e };
|
1202
1181
|
}
|
1203
1182
|
async readBamFeatures(e, t, n, r) {
|
1204
1183
|
let s = 0;
|
1205
|
-
const
|
1206
|
-
let
|
1184
|
+
const i = [];
|
1185
|
+
let c = 0, d = +Date.now();
|
1207
1186
|
for (; s + 4 < e.length; ) {
|
1208
|
-
const
|
1187
|
+
const a = e.readInt32LE(s), l = s + 4 + a - 1;
|
1209
1188
|
if (n) {
|
1210
|
-
for (; s + r.minv.dataPosition >= n[
|
1189
|
+
for (; s + r.minv.dataPosition >= n[c++]; )
|
1211
1190
|
;
|
1212
|
-
|
1191
|
+
c--;
|
1213
1192
|
}
|
1214
1193
|
if (l < e.length) {
|
1215
|
-
const
|
1194
|
+
const x = new he({
|
1216
1195
|
bytes: {
|
1217
1196
|
byteArray: e,
|
1218
1197
|
start: s,
|
@@ -1238,16 +1217,16 @@ class pe {
|
|
1238
1217
|
//
|
1239
1218
|
// the +1 is just to avoid any possible uniqueId 0 but this does not
|
1240
1219
|
// realistically happen
|
1241
|
-
fileOffset: t.length > 0 ? t[
|
1220
|
+
fileOffset: t.length > 0 ? t[c] * 256 + (s - n[c]) + r.minv.dataPosition + 1 : (
|
1242
1221
|
// must be slice, not subarray for buffer polyfill on web
|
1243
|
-
|
1222
|
+
oe.signed(e.slice(s, l))
|
1244
1223
|
)
|
1245
1224
|
});
|
1246
|
-
|
1225
|
+
i.push(x), this.yieldThreadTime && +Date.now() - d > this.yieldThreadTime && (await W(1), d = +Date.now());
|
1247
1226
|
}
|
1248
1227
|
s = l + 1;
|
1249
1228
|
}
|
1250
|
-
return
|
1229
|
+
return i;
|
1251
1230
|
}
|
1252
1231
|
async hasRefSeq(e) {
|
1253
1232
|
var t, n;
|
@@ -1272,8 +1251,8 @@ class pe {
|
|
1272
1251
|
if (!this.index)
|
1273
1252
|
return [];
|
1274
1253
|
await this.index.parse();
|
1275
|
-
const
|
1276
|
-
return
|
1254
|
+
const i = (s = this.chrToIndex) === null || s === void 0 ? void 0 : s[e];
|
1255
|
+
return i === void 0 ? [] : this.index.blocksForRange(i, t, n, r);
|
1277
1256
|
}
|
1278
1257
|
}
|
1279
1258
|
async function N(o, e) {
|
@@ -1282,35 +1261,35 @@ async function N(o, e) {
|
|
1282
1261
|
if (r.startsWith("data:"))
|
1283
1262
|
return I.Buffer.from(r.split(",")[1], "base64");
|
1284
1263
|
{
|
1285
|
-
const { referer:
|
1264
|
+
const { referer: i, ...c } = s, d = await fetch(r, {
|
1286
1265
|
...e,
|
1287
|
-
headers: { ...e == null ? void 0 : e.headers, ...
|
1266
|
+
headers: { ...e == null ? void 0 : e.headers, ...c }
|
1288
1267
|
});
|
1289
|
-
if (!
|
1290
|
-
throw new Error(`HTTP ${
|
1291
|
-
return I.Buffer.from(await
|
1268
|
+
if (!d.ok)
|
1269
|
+
throw new Error(`HTTP ${d.status} fetching ${r}: ${await d.text()}`);
|
1270
|
+
return I.Buffer.from(await d.arrayBuffer());
|
1292
1271
|
}
|
1293
1272
|
}));
|
1294
|
-
return I.Buffer.concat(await Promise.all(t.map((n) =>
|
1273
|
+
return I.Buffer.concat(await Promise.all(t.map((n) => R(n))));
|
1295
1274
|
}
|
1296
|
-
class
|
1275
|
+
class we extends ue {
|
1297
1276
|
constructor(e) {
|
1298
1277
|
super({ htsget: !0 }), this.baseUrl = e.baseUrl, this.trackId = e.trackId;
|
1299
1278
|
}
|
1300
1279
|
async *streamRecordsForRange(e, t, n, r) {
|
1301
1280
|
var s;
|
1302
|
-
const
|
1303
|
-
if (
|
1281
|
+
const c = `${`${this.baseUrl}/${this.trackId}`}?referenceName=${e}&start=${t}&end=${n}&format=BAM`, d = (s = this.chrToIndex) === null || s === void 0 ? void 0 : s[e];
|
1282
|
+
if (d === void 0)
|
1304
1283
|
yield [];
|
1305
1284
|
else {
|
1306
|
-
const
|
1307
|
-
if (!
|
1308
|
-
throw new Error(`HTTP ${
|
1309
|
-
const l = await
|
1285
|
+
const a = await fetch(c, { ...r });
|
1286
|
+
if (!a.ok)
|
1287
|
+
throw new Error(`HTTP ${a.status} fetching ${c}: ${await a.text()}`);
|
1288
|
+
const l = await a.json(), x = await N(l.htsget.urls.slice(1), r);
|
1310
1289
|
yield* this._fetchChunkFeatures([
|
1311
1290
|
// fake stuff to pretend to be a Chunk
|
1312
1291
|
{
|
1313
|
-
buffer:
|
1292
|
+
buffer: x,
|
1314
1293
|
_fetchedSize: void 0,
|
1315
1294
|
bin: 0,
|
1316
1295
|
compareTo() {
|
@@ -1336,7 +1315,7 @@ class ye extends pe {
|
|
1336
1315
|
return `${e}_${t}_${n}`;
|
1337
1316
|
}
|
1338
1317
|
}
|
1339
|
-
],
|
1318
|
+
], d, t, n, r);
|
1340
1319
|
}
|
1341
1320
|
}
|
1342
1321
|
async _readChunk({ chunk: e }) {
|
@@ -1349,22 +1328,22 @@ class ye extends pe {
|
|
1349
1328
|
if (!n.ok)
|
1350
1329
|
throw new Error(`HTTP ${n.status} fetching ${t}: ${await n.text()}`);
|
1351
1330
|
const r = await n.json(), s = await N(r.htsget.urls, e);
|
1352
|
-
if (s.readInt32LE(0) !==
|
1331
|
+
if (s.readInt32LE(0) !== G)
|
1353
1332
|
throw new Error("Not a BAM file");
|
1354
|
-
const
|
1355
|
-
for (const [
|
1356
|
-
let
|
1357
|
-
for (const
|
1358
|
-
|
1359
|
-
l[
|
1333
|
+
const i = s.readInt32LE(4), c = s.toString("utf8", 8, 8 + i), d = H(c), a = [], l = {}, x = d.filter((h) => h.tag === "SQ");
|
1334
|
+
for (const [h, f] of x.entries()) {
|
1335
|
+
let m = "", b = 0;
|
1336
|
+
for (const u of f.data)
|
1337
|
+
u.tag === "SN" ? m = u.value : u.tag === "LN" && (b = +u.value);
|
1338
|
+
l[m] = h, a[h] = { refName: m, length: b };
|
1360
1339
|
}
|
1361
|
-
return this.chrToIndex = l, this.indexToChr =
|
1340
|
+
return this.chrToIndex = l, this.indexToChr = a, d;
|
1362
1341
|
}
|
1363
1342
|
}
|
1364
1343
|
export {
|
1365
1344
|
v as BAI,
|
1366
|
-
|
1367
|
-
|
1345
|
+
ue as BamFile,
|
1346
|
+
he as BamRecord,
|
1368
1347
|
P as CSI,
|
1369
|
-
|
1348
|
+
we as HtsgetFile
|
1370
1349
|
};
|