@genome-spy/app 0.57.0 → 0.58.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.css +1 -0
- package/dist/index-BftNdA0O.js +27 -0
- package/dist/index-C08YCM2T.js +539 -0
- package/dist/{index-C159nEYc.js → index-CCJIjehY.js} +89 -83
- package/dist/index-CalimFw3.js +2131 -0
- package/dist/{index-CfEH2hsw.js → index-DKe9Bhvi.js} +285 -260
- package/dist/index-DS2hvLgl.js +3425 -0
- package/dist/index-DTcHjAHp.js +505 -0
- package/dist/index-DnIkxb0L.js +1025 -0
- package/dist/{index-Bg62fPK7.js → index-DwLfOHEk.js} +435 -465
- package/dist/{index-DhPRJZz0.js → index-Ww3TAo6_.js} +7 -7
- package/dist/{index-DutovjI-.js → index-vgGDWUPz.js} +2 -2
- package/dist/index.es.js +5398 -6589
- package/dist/index.js +402 -397
- package/dist/long-BviWyoZx.js +2387 -0
- package/dist/{remoteFile-DwSeXAZ0.js → remoteFile-BuaqFGWk.js} +1 -1
- package/package.json +3 -3
- package/dist/index-CubKalvr.js +0 -500
- package/dist/index-DNzxWHJt.js +0 -2136
- package/dist/index-DluFz_0j.js +0 -1042
- package/dist/index-Dpv0n-cZ.js +0 -3998
- package/dist/long-DM5IWGqg.js +0 -2375
- package/dist/style.css +0 -1
@@ -1,9 +1,9 @@
|
|
1
|
-
import { L as
|
2
|
-
import { b as
|
1
|
+
import { L as Y, u as P, a as Q } from "./long-BviWyoZx.js";
|
2
|
+
import { b as y } from "./index-BftNdA0O.js";
|
3
3
|
import { L as C } from "./__vite-browser-external-C--ziKoh.js";
|
4
|
-
import { R as
|
5
|
-
import { A as
|
6
|
-
class
|
4
|
+
import { R as L } from "./remoteFile-BuaqFGWk.js";
|
5
|
+
import { A as W, L as X } from "./index-CCJIjehY.js";
|
6
|
+
class O {
|
7
7
|
constructor(e, t) {
|
8
8
|
this.blockPosition = e, this.dataPosition = t;
|
9
9
|
}
|
@@ -25,9 +25,9 @@ class D {
|
|
25
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
|
-
return new
|
28
|
+
return new O(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]);
|
29
29
|
}
|
30
|
-
class
|
30
|
+
class F {
|
31
31
|
constructor(e, t, n, r) {
|
32
32
|
this.minv = e, this.maxv = t, this.bin = n, this._fetchedSize = r;
|
33
33
|
}
|
@@ -44,15 +44,10 @@ 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 J(o) {
|
48
48
|
return new Promise((e) => setTimeout(e, o));
|
49
49
|
}
|
50
|
-
function
|
51
|
-
if (o.greaterThan(Number.MAX_SAFE_INTEGER) || o.lessThan(Number.MIN_SAFE_INTEGER))
|
52
|
-
throw new Error("integer overflow");
|
53
|
-
return o.toNumber();
|
54
|
-
}
|
55
|
-
function J(o) {
|
50
|
+
function K(o) {
|
56
51
|
if (o && o.aborted)
|
57
52
|
if (typeof DOMException > "u") {
|
58
53
|
const e = new Error("aborted");
|
@@ -60,13 +55,13 @@ function J(o) {
|
|
60
55
|
} else
|
61
56
|
throw new DOMException("aborted", "AbortError");
|
62
57
|
}
|
63
|
-
function
|
58
|
+
function Z(o, e) {
|
64
59
|
return e.minv.blockPosition - o.maxv.blockPosition < 65e3 && e.maxv.blockPosition - o.minv.blockPosition < 5e6;
|
65
60
|
}
|
66
|
-
function
|
61
|
+
function ee(o = {}) {
|
67
62
|
return "aborted" in o ? { signal: o } : o;
|
68
63
|
}
|
69
|
-
function
|
64
|
+
function z(o, e) {
|
70
65
|
const t = [];
|
71
66
|
let n;
|
72
67
|
if (o.length === 0)
|
@@ -76,16 +71,18 @@ function U(o, e) {
|
|
76
71
|
return i === 0 ? r.minv.dataPosition - s.minv.dataPosition : i;
|
77
72
|
});
|
78
73
|
for (const r of o)
|
79
|
-
(!e || r.maxv.compareTo(e) > 0) && (n === void 0 ? (t.push(r), n = r) :
|
74
|
+
(!e || r.maxv.compareTo(e) > 0) && (n === void 0 ? (t.push(r), n = r) : Z(n, r) ? r.maxv.compareTo(n.maxv) > 0 && (n.maxv = r.maxv) : (t.push(r), n = r));
|
80
75
|
return t;
|
81
76
|
}
|
82
|
-
function
|
83
|
-
return {
|
77
|
+
function G(o, e) {
|
78
|
+
return {
|
79
|
+
lineCount: Y.fromBytesLE(Array.prototype.slice.call(o, e, e + 8), !0).toNumber()
|
80
|
+
};
|
84
81
|
}
|
85
|
-
function
|
82
|
+
function S(o, e) {
|
86
83
|
return o ? o.compareTo(e) > 0 ? e : o : e;
|
87
84
|
}
|
88
|
-
function
|
85
|
+
function te(o, e = (t) => t) {
|
89
86
|
let t = 0, n = 0;
|
90
87
|
const r = [], s = {};
|
91
88
|
for (let i = 0; i < o.length; i += 1)
|
@@ -98,7 +95,7 @@ function ee(o, e = (t) => t) {
|
|
98
95
|
}
|
99
96
|
return { refNameToId: s, refIdToName: r };
|
100
97
|
}
|
101
|
-
class
|
98
|
+
class H {
|
102
99
|
/**
|
103
100
|
* @param {filehandle} filehandle
|
104
101
|
* @param {function} [renameRefSeqs]
|
@@ -107,14 +104,14 @@ class O {
|
|
107
104
|
this.filehandle = e, this.renameRefSeq = t;
|
108
105
|
}
|
109
106
|
}
|
110
|
-
const
|
111
|
-
function
|
107
|
+
const ne = 21578050;
|
108
|
+
function re(o, e) {
|
112
109
|
return o - o % e;
|
113
110
|
}
|
114
|
-
function
|
111
|
+
function se(o, e) {
|
115
112
|
return o - o % e + e;
|
116
113
|
}
|
117
|
-
function
|
114
|
+
function ie(o, e) {
|
118
115
|
return e -= 1, [
|
119
116
|
[0, 0],
|
120
117
|
[1 + (o >> 26), 1 + (e >> 26)],
|
@@ -124,7 +121,7 @@ function se(o, e) {
|
|
124
121
|
[4681 + (o >> 14), 4681 + (e >> 14)]
|
125
122
|
];
|
126
123
|
}
|
127
|
-
class v extends
|
124
|
+
class v extends H {
|
128
125
|
async lineCount(e, t) {
|
129
126
|
var n, r;
|
130
127
|
return ((r = (n = (await this.parse(t)).indices[e]) === null || n === void 0 ? void 0 : n.stats) === null || r === void 0 ? void 0 : r.lineCount) || 0;
|
@@ -132,74 +129,74 @@ class v extends O {
|
|
132
129
|
// fetch and parse the index
|
133
130
|
async _parse(e) {
|
134
131
|
const t = await this.filehandle.readFile(e);
|
135
|
-
if (t.readUInt32LE(0) !==
|
132
|
+
if (t.readUInt32LE(0) !== ne)
|
136
133
|
throw new Error("Not a BAI file");
|
137
134
|
const n = t.readInt32LE(4), s = ((1 << (5 + 1) * 3) - 1) / 7;
|
138
135
|
let i = 8, c;
|
139
|
-
const
|
140
|
-
for (let
|
141
|
-
const
|
142
|
-
let
|
136
|
+
const a = new Array(n);
|
137
|
+
for (let d = 0; d < n; d++) {
|
138
|
+
const f = t.readInt32LE(i);
|
139
|
+
let h;
|
143
140
|
i += 4;
|
144
|
-
const
|
145
|
-
for (let b = 0; b <
|
141
|
+
const l = {};
|
142
|
+
for (let b = 0; b < f; b += 1) {
|
146
143
|
const u = t.readUInt32LE(i);
|
147
144
|
if (i += 4, u === s + 1)
|
148
|
-
i += 4,
|
145
|
+
i += 4, h = G(t, i + 16), i += 32;
|
149
146
|
else {
|
150
147
|
if (u > s + 1)
|
151
148
|
throw new Error("bai index contains too many bins, please use CSI");
|
152
149
|
{
|
153
150
|
const g = t.readInt32LE(i);
|
154
151
|
i += 4;
|
155
|
-
const
|
156
|
-
for (let
|
157
|
-
const
|
152
|
+
const w = new Array(g);
|
153
|
+
for (let _ = 0; _ < g; _++) {
|
154
|
+
const I = E(t, i);
|
158
155
|
i += 8;
|
159
|
-
const
|
160
|
-
i += 8, c =
|
156
|
+
const M = E(t, i);
|
157
|
+
i += 8, c = S(c, I), w[_] = new F(I, M, u);
|
161
158
|
}
|
162
|
-
|
159
|
+
l[u] = w;
|
163
160
|
}
|
164
161
|
}
|
165
162
|
}
|
166
|
-
const
|
163
|
+
const x = t.readInt32LE(i);
|
167
164
|
i += 4;
|
168
|
-
const m = new Array(
|
169
|
-
for (let b = 0; b <
|
165
|
+
const m = new Array(x);
|
166
|
+
for (let b = 0; b < x; b++) {
|
170
167
|
const u = E(t, i);
|
171
|
-
i += 8, c =
|
168
|
+
i += 8, c = S(c, u), m[b] = u;
|
172
169
|
}
|
173
|
-
d
|
170
|
+
a[d] = { binIndex: l, linearIndex: m, stats: h };
|
174
171
|
}
|
175
172
|
return {
|
176
173
|
bai: !0,
|
177
174
|
firstDataLine: c,
|
178
175
|
maxBlockSize: 65536,
|
179
|
-
indices:
|
176
|
+
indices: a,
|
180
177
|
refCount: n
|
181
178
|
};
|
182
179
|
}
|
183
180
|
async indexCov(e, t, n, r = {}) {
|
184
|
-
const i = t !== void 0,
|
185
|
-
if (!
|
181
|
+
const i = t !== void 0, a = (await this.parse(r)).indices[e];
|
182
|
+
if (!a)
|
186
183
|
return [];
|
187
|
-
const { linearIndex:
|
188
|
-
if (
|
184
|
+
const { linearIndex: d = [], stats: f } = a;
|
185
|
+
if (d.length === 0)
|
189
186
|
return [];
|
190
|
-
const
|
191
|
-
if (
|
187
|
+
const h = n === void 0 ? (d.length - 1) * 16384 : se(n, 16384), l = t === void 0 ? 0 : re(t, 16384), x = i ? new Array((h - l) / 16384) : new Array(d.length - 1), m = d[d.length - 1].blockPosition;
|
188
|
+
if (h > (d.length - 1) * 16384)
|
192
189
|
throw new Error("query outside of range of linear index");
|
193
|
-
let b =
|
194
|
-
for (let u =
|
195
|
-
|
196
|
-
score:
|
190
|
+
let b = d[l / 16384].blockPosition;
|
191
|
+
for (let u = l / 16384, g = 0; u < h / 16384; u++, g++)
|
192
|
+
x[g] = {
|
193
|
+
score: d[u + 1].blockPosition - b,
|
197
194
|
start: u * 16384,
|
198
195
|
end: u * 16384 + 16384
|
199
|
-
}, b =
|
200
|
-
return
|
196
|
+
}, b = d[u + 1].blockPosition;
|
197
|
+
return x.map((u) => ({
|
201
198
|
...u,
|
202
|
-
score: u.score * ((
|
199
|
+
score: u.score * ((f == null ? void 0 : f.lineCount) || 0) / m
|
203
200
|
}));
|
204
201
|
}
|
205
202
|
async blocksForRange(e, t, n, r = {}) {
|
@@ -210,22 +207,22 @@ class v extends O {
|
|
210
207
|
const i = s.indices[e];
|
211
208
|
if (!i)
|
212
209
|
return [];
|
213
|
-
const c =
|
214
|
-
for (const [
|
215
|
-
for (let b =
|
210
|
+
const c = ie(t, n), a = [];
|
211
|
+
for (const [x, m] of c)
|
212
|
+
for (let b = x; b <= m; b++)
|
216
213
|
if (i.binIndex[b]) {
|
217
214
|
const u = i.binIndex[b];
|
218
215
|
for (const g of u)
|
219
|
-
|
216
|
+
a.push(new F(g.minv, g.maxv, b));
|
220
217
|
}
|
221
|
-
const
|
222
|
-
let
|
223
|
-
const
|
224
|
-
for (let
|
225
|
-
const m = i.linearIndex[
|
226
|
-
m && (!
|
218
|
+
const d = i.linearIndex.length;
|
219
|
+
let f;
|
220
|
+
const h = Math.min(t >> 14, d - 1), l = Math.min(n >> 14, d - 1);
|
221
|
+
for (let x = h; x <= l; ++x) {
|
222
|
+
const m = i.linearIndex[x];
|
223
|
+
m && (!f || m.compareTo(f) < 0) && (f = m);
|
227
224
|
}
|
228
|
-
return
|
225
|
+
return z(a, f);
|
229
226
|
}
|
230
227
|
async parse(e = {}) {
|
231
228
|
return this.setupP || (this.setupP = this._parse(e).catch((t) => {
|
@@ -237,7 +234,7 @@ class v extends O {
|
|
237
234
|
return !!(!((n = (await this.parse(t)).indices[e]) === null || n === void 0) && n.binIndex);
|
238
235
|
}
|
239
236
|
}
|
240
|
-
let
|
237
|
+
let B = [
|
241
238
|
0,
|
242
239
|
1996959894,
|
243
240
|
3993919788,
|
@@ -495,25 +492,25 @@ let T = [
|
|
495
492
|
1510334235,
|
496
493
|
755167117
|
497
494
|
];
|
498
|
-
typeof Int32Array < "u" && (
|
495
|
+
typeof Int32Array < "u" && (B = new Int32Array(B));
|
499
496
|
const ae = (o, e) => {
|
500
497
|
let t = e === 0 ? 0 : ~~e ^ -1;
|
501
498
|
for (let n = 0; n < o.length; n++)
|
502
|
-
t =
|
499
|
+
t = B[(t ^ o[n]) & 255] ^ t >>> 8;
|
503
500
|
return t ^ -1;
|
504
|
-
},
|
505
|
-
function
|
506
|
-
const t = (n, r) => e(
|
507
|
-
return t.signed = (n, r) => e(
|
501
|
+
}, N = (o, e) => y.Buffer.from(o, e);
|
502
|
+
function oe(o, e) {
|
503
|
+
const t = (n, r) => e(N(n), r) >>> 0;
|
504
|
+
return t.signed = (n, r) => e(N(n), r), t.unsigned = t, t.model = o, t;
|
508
505
|
}
|
509
|
-
const
|
510
|
-
function
|
506
|
+
const ce = oe("crc-32", ae), de = 21582659, fe = 38359875;
|
507
|
+
function he(o, e) {
|
511
508
|
return o * 2 ** e;
|
512
509
|
}
|
513
|
-
function
|
510
|
+
function q(o, e) {
|
514
511
|
return Math.floor(o / 2 ** e);
|
515
512
|
}
|
516
|
-
class
|
513
|
+
class T extends H {
|
517
514
|
constructor() {
|
518
515
|
super(...arguments), this.maxBinNumber = 0, this.depth = 0, this.minShift = 0;
|
519
516
|
}
|
@@ -532,61 +529,61 @@ class P extends O {
|
|
532
529
|
ref: e.readInt32LE(t + 4),
|
533
530
|
start: e.readInt32LE(t + 8),
|
534
531
|
end: e.readInt32LE(t + 12)
|
535
|
-
}, c = e.readInt32LE(t + 16),
|
532
|
+
}, c = e.readInt32LE(t + 16), a = c ? String.fromCharCode(c) : "", d = e.readInt32LE(t + 20), f = e.readInt32LE(t + 24);
|
536
533
|
return {
|
537
534
|
columnNumbers: i,
|
538
535
|
coordinateType: r,
|
539
536
|
metaValue: c,
|
540
|
-
metaChar:
|
541
|
-
skipLines:
|
537
|
+
metaChar: a,
|
538
|
+
skipLines: d,
|
542
539
|
format: s,
|
543
540
|
formatFlags: n,
|
544
|
-
...
|
541
|
+
...te(e.subarray(t + 28, t + 28 + f), this.renameRefSeq)
|
545
542
|
};
|
546
543
|
}
|
547
544
|
// fetch and parse the index
|
548
545
|
async _parse(e) {
|
549
|
-
const t = await this.filehandle.readFile(e), n = await
|
546
|
+
const t = await this.filehandle.readFile(e), n = await P(t);
|
550
547
|
let r;
|
551
548
|
if (n.readUInt32LE(0) === de)
|
552
549
|
r = 1;
|
553
|
-
else if (n.readUInt32LE(0) ===
|
550
|
+
else if (n.readUInt32LE(0) === fe)
|
554
551
|
r = 2;
|
555
552
|
else
|
556
553
|
throw new Error("Not a CSI file");
|
557
554
|
this.minShift = n.readInt32LE(4), this.depth = n.readInt32LE(8), this.maxBinNumber = ((1 << (this.depth + 1) * 3) - 1) / 7;
|
558
555
|
const s = n.readInt32LE(12), i = s >= 30 ? this.parseAuxData(n, 16) : void 0, c = n.readInt32LE(16 + s);
|
559
|
-
let
|
560
|
-
const
|
561
|
-
for (let
|
562
|
-
const
|
563
|
-
|
564
|
-
const
|
556
|
+
let a = 16 + s + 4, d;
|
557
|
+
const f = new Array(c);
|
558
|
+
for (let h = 0; h < c; h++) {
|
559
|
+
const l = n.readInt32LE(a);
|
560
|
+
a += 4;
|
561
|
+
const x = {};
|
565
562
|
let m;
|
566
|
-
for (let b = 0; b <
|
567
|
-
const u = n.readUInt32LE(
|
568
|
-
if (
|
569
|
-
m =
|
563
|
+
for (let b = 0; b < l; b++) {
|
564
|
+
const u = n.readUInt32LE(a);
|
565
|
+
if (a += 4, u > this.maxBinNumber)
|
566
|
+
m = G(n, a + 28), a += 44;
|
570
567
|
else {
|
571
|
-
|
572
|
-
const g = n.readInt32LE(
|
573
|
-
|
574
|
-
const
|
575
|
-
for (let
|
576
|
-
const
|
577
|
-
|
578
|
-
const
|
579
|
-
|
568
|
+
d = S(d, E(n, a)), a += 8;
|
569
|
+
const g = n.readInt32LE(a);
|
570
|
+
a += 4;
|
571
|
+
const w = new Array(g);
|
572
|
+
for (let _ = 0; _ < g; _ += 1) {
|
573
|
+
const I = E(n, a);
|
574
|
+
a += 8;
|
575
|
+
const M = E(n, a);
|
576
|
+
a += 8, d = S(d, I), w[_] = new F(I, M, u);
|
580
577
|
}
|
581
|
-
|
578
|
+
x[u] = w;
|
582
579
|
}
|
583
580
|
}
|
584
|
-
|
581
|
+
f[h] = { binIndex: x, stats: m };
|
585
582
|
}
|
586
583
|
return {
|
587
584
|
csiVersion: r,
|
588
|
-
firstDataLine:
|
589
|
-
indices:
|
585
|
+
firstDataLine: d,
|
586
|
+
indices: f,
|
590
587
|
refCount: c,
|
591
588
|
csi: !0,
|
592
589
|
maxBlockSize: 65536,
|
@@ -595,21 +592,21 @@ class P extends O {
|
|
595
592
|
}
|
596
593
|
async blocksForRange(e, t, n, r = {}) {
|
597
594
|
t < 0 && (t = 0);
|
598
|
-
const
|
595
|
+
const i = (await this.parse(r)).indices[e];
|
599
596
|
if (!i)
|
600
597
|
return [];
|
601
598
|
const c = this.reg2bins(t, n);
|
602
599
|
if (c.length === 0)
|
603
600
|
return [];
|
604
|
-
const
|
605
|
-
for (const [
|
606
|
-
for (let
|
607
|
-
if (i.binIndex[
|
608
|
-
const
|
609
|
-
for (const
|
610
|
-
|
601
|
+
const a = [];
|
602
|
+
for (const [d, f] of c)
|
603
|
+
for (let h = d; h <= f; h++)
|
604
|
+
if (i.binIndex[h]) {
|
605
|
+
const l = i.binIndex[h];
|
606
|
+
for (const x of l)
|
607
|
+
a.push(x);
|
611
608
|
}
|
612
|
-
return
|
609
|
+
return z(a, new O(0, 0));
|
613
610
|
}
|
614
611
|
/**
|
615
612
|
* calculate the list of bins that may overlap with region [beg,end)
|
@@ -619,11 +616,11 @@ class P extends O {
|
|
619
616
|
e -= 1, e < 1 && (e = 1), t > 2 ** 50 && (t = 2 ** 34), t -= 1;
|
620
617
|
let n = 0, r = 0, s = this.minShift + this.depth * 3;
|
621
618
|
const i = [];
|
622
|
-
for (; n <= this.depth; s -= 3, r +=
|
623
|
-
const c = r +
|
624
|
-
if (
|
619
|
+
for (; n <= this.depth; s -= 3, r += he(1, n * 3), n += 1) {
|
620
|
+
const c = r + q(e, s), a = r + q(t, s);
|
621
|
+
if (a - c + i.length > this.maxBinNumber)
|
625
622
|
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`);
|
626
|
-
i.push([c,
|
623
|
+
i.push([c, a]);
|
627
624
|
}
|
628
625
|
return i;
|
629
626
|
}
|
@@ -637,7 +634,7 @@ class P extends O {
|
|
637
634
|
return !!(!((n = (await this.parse(t)).indices[e]) === null || n === void 0) && n.binIndex);
|
638
635
|
}
|
639
636
|
}
|
640
|
-
const
|
637
|
+
const p = {
|
641
638
|
// the read is paired in sequencing, no matter whether it is mapped in a pair
|
642
639
|
BAM_FPAIRED: 1,
|
643
640
|
// the read is mapped in a proper pair
|
@@ -662,319 +659,273 @@ const _ = {
|
|
662
659
|
BAM_FDUP: 1024,
|
663
660
|
// supplementary alignment
|
664
661
|
BAM_FSUPPLEMENTARY: 2048
|
665
|
-
},
|
666
|
-
class
|
662
|
+
}, D = "=ACMGRSVTWYHKDBN".split(""), A = "MIDNSHP=X???????".split("");
|
663
|
+
class R {
|
667
664
|
constructor(e) {
|
668
|
-
this.
|
669
|
-
const { bytes: t, fileOffset: n } = e, { byteArray: r, start: s } = t;
|
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;
|
671
|
-
}
|
672
|
-
get(e) {
|
673
|
-
return this[e] ? this.data[e] ? this.data[e] : (this.data[e] = this[e](), this.data[e]) : this._get(e.toLowerCase());
|
674
|
-
}
|
675
|
-
end() {
|
676
|
-
return this.get("start") + this.get("length_on_ref");
|
677
|
-
}
|
678
|
-
seq_id() {
|
679
|
-
return this._refID;
|
680
|
-
}
|
681
|
-
// same as get(), except requires lower-case arguments. used
|
682
|
-
// internally to save lots of calls to field.toLowerCase()
|
683
|
-
_get(e) {
|
684
|
-
return e in this.data ? this.data[e] : (this.data[e] = this._parseTag(e), this.data[e]);
|
685
|
-
}
|
686
|
-
_tags() {
|
687
|
-
this._parseAllTags();
|
688
|
-
let e = ["seq"];
|
689
|
-
this.isSegmentUnmapped() || e.push("start", "end", "strand", "score", "qual", "MQ", "CIGAR", "length_on_ref", "template_length"), this.isPaired() && e.push("next_segment_position", "pair_orientation"), e = e.concat(this._tagList || []);
|
690
|
-
for (const n of Object.keys(this.data))
|
691
|
-
!n.startsWith("_") && n !== "next_seq_id" && e.push(n);
|
692
|
-
const t = {};
|
693
|
-
return e.filter((n) => {
|
694
|
-
if (n in this.data && this.data[n] === void 0 || n === "CG" || n === "cg")
|
695
|
-
return !1;
|
696
|
-
const r = n.toLowerCase(), s = t[r];
|
697
|
-
return t[r] = !0, !s;
|
698
|
-
});
|
665
|
+
this.bytes = e.bytes, this.fileOffset = e.fileOffset;
|
699
666
|
}
|
700
|
-
|
667
|
+
get byteArray() {
|
668
|
+
return this.bytes.byteArray;
|
701
669
|
}
|
702
|
-
|
703
|
-
return this.
|
670
|
+
get flags() {
|
671
|
+
return (this.byteArray.readInt32LE(this.bytes.start + 16) & 4294901760) >> 16;
|
704
672
|
}
|
705
|
-
|
706
|
-
return this.
|
673
|
+
get ref_id() {
|
674
|
+
return this.byteArray.readInt32LE(this.bytes.start + 4);
|
707
675
|
}
|
708
|
-
|
709
|
-
|
710
|
-
* Mapping quality score.
|
711
|
-
*/
|
712
|
-
mq() {
|
713
|
-
const e = (this.get("_bin_mq_nl") & 65280) >> 8;
|
714
|
-
return e === 255 ? void 0 : e;
|
676
|
+
get start() {
|
677
|
+
return this.byteArray.readInt32LE(this.bytes.start + 8);
|
715
678
|
}
|
716
|
-
|
717
|
-
return this.
|
679
|
+
get end() {
|
680
|
+
return this.start + this.length_on_ref;
|
681
|
+
}
|
682
|
+
get id() {
|
683
|
+
return this.fileOffset;
|
684
|
+
}
|
685
|
+
get mq() {
|
686
|
+
const e = (this.bin_mq_nl & 65280) >> 8;
|
687
|
+
return e === 255 ? void 0 : e;
|
718
688
|
}
|
719
|
-
|
720
|
-
|
721
|
-
return (e = this.qualRaw()) === null || e === void 0 ? void 0 : e.join(" ");
|
689
|
+
get score() {
|
690
|
+
return this.mq;
|
722
691
|
}
|
723
|
-
|
692
|
+
get qual() {
|
724
693
|
if (this.isSegmentUnmapped())
|
725
694
|
return;
|
726
|
-
const
|
727
|
-
return
|
695
|
+
const e = this.b0 + this.read_name_length + this.num_cigar_ops * 4 + this.num_seq_bytes;
|
696
|
+
return this.byteArray.subarray(e, e + this.seq_length);
|
728
697
|
}
|
729
|
-
strand() {
|
698
|
+
get strand() {
|
730
699
|
return this.isReverseComplemented() ? -1 : 1;
|
731
700
|
}
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
i
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
}
|
769
|
-
case "I": {
|
770
|
-
a = t.readUInt32LE(r), r += 4;
|
771
|
-
break;
|
772
|
-
}
|
773
|
-
case "c": {
|
774
|
-
a = t.readInt8(r), r += 1;
|
775
|
-
break;
|
776
|
-
}
|
777
|
-
case "C": {
|
778
|
-
a = t.readUInt8(r), r += 1;
|
779
|
-
break;
|
780
|
-
}
|
781
|
-
case "s": {
|
782
|
-
a = t.readInt16LE(r), r += 2;
|
783
|
-
break;
|
784
|
-
}
|
785
|
-
case "S": {
|
786
|
-
a = t.readUInt16LE(r), r += 2;
|
787
|
-
break;
|
788
|
-
}
|
789
|
-
case "f": {
|
790
|
-
a = t.readFloatLE(r), r += 4;
|
791
|
-
break;
|
701
|
+
get b0() {
|
702
|
+
return this.bytes.start + 36;
|
703
|
+
}
|
704
|
+
get name() {
|
705
|
+
return this.byteArray.toString("ascii", this.b0, this.b0 + this.read_name_length - 1);
|
706
|
+
}
|
707
|
+
get tags() {
|
708
|
+
const { byteArray: e } = this.bytes;
|
709
|
+
let t = this.b0 + this.read_name_length + this.num_cigar_ops * 4 + this.num_seq_bytes + this.seq_length;
|
710
|
+
const n = this.bytes.end, r = {};
|
711
|
+
for (; t < n; ) {
|
712
|
+
const s = String.fromCharCode(e[t], e[t + 1]), i = String.fromCharCode(e[t + 2]);
|
713
|
+
if (t += 3, i === "A")
|
714
|
+
r[s] = String.fromCharCode(e[t]), t += 1;
|
715
|
+
else if (i === "i")
|
716
|
+
r[s] = e.readInt32LE(t), t += 4;
|
717
|
+
else if (i === "I")
|
718
|
+
r[s] = e.readUInt32LE(t), t += 4;
|
719
|
+
else if (i === "c")
|
720
|
+
r[s] = e.readInt8(t), t += 1;
|
721
|
+
else if (i === "C")
|
722
|
+
r[s] = e.readUInt8(t), t += 1;
|
723
|
+
else if (i === "s")
|
724
|
+
r[s] = e.readInt16LE(t), t += 2;
|
725
|
+
else if (i === "S")
|
726
|
+
r[s] = e.readUInt16LE(t), t += 2;
|
727
|
+
else if (i === "f")
|
728
|
+
r[s] = e.readFloatLE(t), t += 4;
|
729
|
+
else if (i === "Z" || i === "H") {
|
730
|
+
const c = [];
|
731
|
+
for (; t <= n; ) {
|
732
|
+
const a = e[t++];
|
733
|
+
if (a !== 0)
|
734
|
+
c.push(String.fromCharCode(a));
|
735
|
+
else
|
736
|
+
break;
|
792
737
|
}
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
738
|
+
r[s] = c.join("");
|
739
|
+
} else if (i === "B") {
|
740
|
+
const c = e[t++], a = String.fromCharCode(c), d = e.readInt32LE(t);
|
741
|
+
if (t += 4, a === "i")
|
742
|
+
if (s === "CG") {
|
743
|
+
const f = [];
|
744
|
+
for (let h = 0; h < d; h++) {
|
745
|
+
const l = e.readInt32LE(t), x = l >> 4, m = A[l & 15];
|
746
|
+
f.push(x + m), t += 4;
|
747
|
+
}
|
748
|
+
r[s] = f.join("");
|
749
|
+
} else {
|
750
|
+
const f = [];
|
751
|
+
for (let h = 0; h < d; h++)
|
752
|
+
f.push(e.readInt32LE(t)), t += 4;
|
753
|
+
r[s] = f;
|
800
754
|
}
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
755
|
+
else if (a === "I")
|
756
|
+
if (s === "CG") {
|
757
|
+
const f = [];
|
758
|
+
for (let h = 0; h < d; h++) {
|
759
|
+
const l = e.readUInt32LE(t), x = l >> 4, m = A[l & 15];
|
760
|
+
f.push(x + m), t += 4;
|
761
|
+
}
|
762
|
+
r[s] = f.join("");
|
763
|
+
} else {
|
764
|
+
const f = [];
|
765
|
+
for (let h = 0; h < d; h++)
|
766
|
+
f.push(e.readUInt32LE(t)), t += 4;
|
767
|
+
r[s] = f;
|
768
|
+
}
|
769
|
+
else if (a === "s") {
|
770
|
+
const f = [];
|
771
|
+
for (let h = 0; h < d; h++)
|
772
|
+
f.push(e.readInt16LE(t)), t += 2;
|
773
|
+
r[s] = f;
|
774
|
+
} else if (a === "S") {
|
775
|
+
const f = [];
|
776
|
+
for (let h = 0; h < d; h++)
|
777
|
+
f.push(e.readUInt16LE(t)), t += 2;
|
778
|
+
r[s] = f;
|
779
|
+
} else if (a === "c") {
|
780
|
+
const f = [];
|
781
|
+
for (let h = 0; h < d; h++)
|
782
|
+
f.push(e.readInt8(t)), t += 1;
|
783
|
+
r[s] = f;
|
784
|
+
} else if (a === "C") {
|
785
|
+
const f = [];
|
786
|
+
for (let h = 0; h < d; h++)
|
787
|
+
f.push(e.readUInt8(t)), t += 1;
|
788
|
+
r[s] = f;
|
789
|
+
} else if (a === "f") {
|
790
|
+
const f = [];
|
791
|
+
for (let h = 0; h < d; h++)
|
792
|
+
f.push(e.readFloatLE(t)), t += 4;
|
793
|
+
r[s] = f;
|
840
794
|
}
|
841
|
-
|
842
|
-
|
795
|
+
} else {
|
796
|
+
console.error("Unknown BAM tag type", i);
|
797
|
+
break;
|
843
798
|
}
|
844
|
-
if (this._tagOffset = r, this._tagList.push(c), i === e)
|
845
|
-
return a;
|
846
|
-
this.data[i] = a;
|
847
799
|
}
|
848
|
-
|
849
|
-
}
|
850
|
-
_parseAllTags() {
|
851
|
-
this._parseTag("");
|
852
|
-
}
|
853
|
-
_parseCigar(e) {
|
854
|
-
return (
|
855
|
-
//@ts-ignore
|
856
|
-
e.match(/\d+\D/g).map((t) => [/\D/.exec(t)[0].toUpperCase(), Number.parseInt(t, 10)])
|
857
|
-
);
|
800
|
+
return r;
|
858
801
|
}
|
859
802
|
/**
|
860
803
|
* @returns {boolean} true if the read is paired, regardless of whether both
|
861
804
|
* segments are mapped
|
862
805
|
*/
|
863
806
|
isPaired() {
|
864
|
-
return !!(this.flags &
|
807
|
+
return !!(this.flags & p.BAM_FPAIRED);
|
865
808
|
}
|
866
809
|
/** @returns {boolean} true if the read is paired, and both segments are mapped */
|
867
810
|
isProperlyPaired() {
|
868
|
-
return !!(this.flags &
|
811
|
+
return !!(this.flags & p.BAM_FPROPER_PAIR);
|
869
812
|
}
|
870
813
|
/** @returns {boolean} true if the read itself is unmapped; conflictive with isProperlyPaired */
|
871
814
|
isSegmentUnmapped() {
|
872
|
-
return !!(this.flags &
|
815
|
+
return !!(this.flags & p.BAM_FUNMAP);
|
873
816
|
}
|
874
817
|
/** @returns {boolean} true if the read itself is unmapped; conflictive with isProperlyPaired */
|
875
818
|
isMateUnmapped() {
|
876
|
-
return !!(this.flags &
|
819
|
+
return !!(this.flags & p.BAM_FMUNMAP);
|
877
820
|
}
|
878
821
|
/** @returns {boolean} true if the read is mapped to the reverse strand */
|
879
822
|
isReverseComplemented() {
|
880
|
-
return !!(this.flags &
|
823
|
+
return !!(this.flags & p.BAM_FREVERSE);
|
881
824
|
}
|
882
825
|
/** @returns {boolean} true if the mate is mapped to the reverse strand */
|
883
826
|
isMateReverseComplemented() {
|
884
|
-
return !!(this.flags &
|
827
|
+
return !!(this.flags & p.BAM_FMREVERSE);
|
885
828
|
}
|
886
829
|
/** @returns {boolean} true if this is read number 1 in a pair */
|
887
830
|
isRead1() {
|
888
|
-
return !!(this.flags &
|
831
|
+
return !!(this.flags & p.BAM_FREAD1);
|
889
832
|
}
|
890
833
|
/** @returns {boolean} true if this is read number 2 in a pair */
|
891
834
|
isRead2() {
|
892
|
-
return !!(this.flags &
|
835
|
+
return !!(this.flags & p.BAM_FREAD2);
|
893
836
|
}
|
894
837
|
/** @returns {boolean} true if this is a secondary alignment */
|
895
838
|
isSecondary() {
|
896
|
-
return !!(this.flags &
|
839
|
+
return !!(this.flags & p.BAM_FSECONDARY);
|
897
840
|
}
|
898
841
|
/** @returns {boolean} true if this read has failed QC checks */
|
899
842
|
isFailedQc() {
|
900
|
-
return !!(this.flags &
|
843
|
+
return !!(this.flags & p.BAM_FQCFAIL);
|
901
844
|
}
|
902
845
|
/** @returns {boolean} true if the read is an optical or PCR duplicate */
|
903
846
|
isDuplicate() {
|
904
|
-
return !!(this.flags &
|
847
|
+
return !!(this.flags & p.BAM_FDUP);
|
905
848
|
}
|
906
849
|
/** @returns {boolean} true if this is a supplementary alignment */
|
907
850
|
isSupplementary() {
|
908
|
-
return !!(this.flags &
|
851
|
+
return !!(this.flags & p.BAM_FSUPPLEMENTARY);
|
909
852
|
}
|
910
|
-
|
853
|
+
get cigarAndLength() {
|
911
854
|
if (this.isSegmentUnmapped())
|
912
|
-
return
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
855
|
+
return {
|
856
|
+
length_on_ref: 0,
|
857
|
+
CIGAR: ""
|
858
|
+
};
|
859
|
+
const e = this.num_cigar_ops;
|
860
|
+
let t = this.b0 + this.read_name_length;
|
861
|
+
const n = [];
|
862
|
+
let r = this.byteArray.readInt32LE(t), s = r >> 4, i = A[r & 15];
|
863
|
+
if (i === "S" && s === this.seq_length)
|
864
|
+
return t += 4, r = this.byteArray.readInt32LE(t), s = r >> 4, i = A[r & 15], i !== "N" && console.warn("CG tag with no N tag"), {
|
865
|
+
CIGAR: this.tags.CG,
|
866
|
+
length_on_ref: s
|
867
|
+
};
|
868
|
+
{
|
869
|
+
let c = 0;
|
870
|
+
for (let a = 0; a < e; ++a)
|
871
|
+
r = this.byteArray.readInt32LE(t), s = r >> 4, i = A[r & 15], n.push(s + i), i !== "H" && i !== "S" && i !== "I" && (c += s), t += 4;
|
872
|
+
return {
|
873
|
+
CIGAR: n.join(""),
|
874
|
+
length_on_ref: c
|
875
|
+
};
|
876
|
+
}
|
922
877
|
}
|
923
|
-
length_on_ref() {
|
924
|
-
return this.
|
878
|
+
get length_on_ref() {
|
879
|
+
return this.cigarAndLength.length_on_ref;
|
925
880
|
}
|
926
|
-
|
927
|
-
return this.
|
881
|
+
get CIGAR() {
|
882
|
+
return this.cigarAndLength.CIGAR;
|
928
883
|
}
|
929
|
-
|
930
|
-
return this.
|
884
|
+
get num_cigar_ops() {
|
885
|
+
return this.flag_nc & 65535;
|
931
886
|
}
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
return this.
|
937
|
-
}
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
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++);
|
887
|
+
get read_name_length() {
|
888
|
+
return this.bin_mq_nl & 255;
|
889
|
+
}
|
890
|
+
get num_seq_bytes() {
|
891
|
+
return this.seq_length + 1 >> 1;
|
892
|
+
}
|
893
|
+
get seq() {
|
894
|
+
const { byteArray: e } = this.bytes, t = this.b0 + this.read_name_length + this.num_cigar_ops * 4, n = this.num_seq_bytes, r = this.seq_length, s = [];
|
895
|
+
let i = 0;
|
896
|
+
for (let c = 0; c < n; ++c) {
|
897
|
+
const a = e[t + c];
|
898
|
+
s.push(D[(a & 240) >> 4]), i++, i < r && (s.push(D[a & 15]), i++);
|
947
899
|
}
|
948
|
-
return
|
900
|
+
return s.join("");
|
949
901
|
}
|
950
902
|
// adapted from igv.js
|
951
|
-
|
952
|
-
if (!this.isSegmentUnmapped() && !this.isMateUnmapped() && this.
|
903
|
+
get pair_orientation() {
|
904
|
+
if (!this.isSegmentUnmapped() && !this.isMateUnmapped() && this.ref_id === this.next_refid) {
|
953
905
|
const e = this.isReverseComplemented() ? "R" : "F", t = this.isMateReverseComplemented() ? "R" : "F";
|
954
906
|
let n = " ", r = " ";
|
955
907
|
this.isRead1() ? (n = "1", r = "2") : this.isRead2() && (n = "2", r = "1");
|
956
908
|
const s = [];
|
957
|
-
return this.template_length
|
909
|
+
return this.template_length > 0 ? (s[0] = e, s[1] = n, s[2] = t, s[3] = r) : (s[2] = e, s[3] = n, s[0] = t, s[1] = r), s.join("");
|
958
910
|
}
|
959
|
-
return "";
|
960
911
|
}
|
961
|
-
|
962
|
-
return this.
|
912
|
+
get bin_mq_nl() {
|
913
|
+
return this.byteArray.readInt32LE(this.bytes.start + 12);
|
963
914
|
}
|
964
|
-
|
965
|
-
return this.
|
915
|
+
get flag_nc() {
|
916
|
+
return this.byteArray.readInt32LE(this.bytes.start + 16);
|
966
917
|
}
|
967
|
-
seq_length() {
|
968
|
-
return this.
|
918
|
+
get seq_length() {
|
919
|
+
return this.byteArray.readInt32LE(this.bytes.start + 20);
|
969
920
|
}
|
970
|
-
|
971
|
-
return this.
|
921
|
+
get next_refid() {
|
922
|
+
return this.byteArray.readInt32LE(this.bytes.start + 24);
|
972
923
|
}
|
973
|
-
|
974
|
-
return this.
|
924
|
+
get next_pos() {
|
925
|
+
return this.byteArray.readInt32LE(this.bytes.start + 28);
|
975
926
|
}
|
976
|
-
template_length() {
|
977
|
-
return this.
|
927
|
+
get template_length() {
|
928
|
+
return this.byteArray.readInt32LE(this.bytes.start + 32);
|
978
929
|
}
|
979
930
|
toJSON() {
|
980
931
|
const e = {};
|
@@ -983,21 +934,39 @@ class he {
|
|
983
934
|
return e;
|
984
935
|
}
|
985
936
|
}
|
986
|
-
function
|
937
|
+
function k(o, e) {
|
938
|
+
const t = Object.getOwnPropertyDescriptor(o.prototype, e);
|
939
|
+
if (!t)
|
940
|
+
throw new Error("OH NO, NO PROPERTY DESCRIPTOR");
|
941
|
+
const n = t.get;
|
942
|
+
if (!n)
|
943
|
+
throw new Error("OH NO, NOT A GETTER");
|
944
|
+
Object.defineProperty(o.prototype, e, {
|
945
|
+
get() {
|
946
|
+
const r = n.call(this);
|
947
|
+
return Object.defineProperty(this, e, { value: r }), r;
|
948
|
+
}
|
949
|
+
});
|
950
|
+
}
|
951
|
+
k(R, "tags");
|
952
|
+
k(R, "cigarAndLength");
|
953
|
+
k(R, "seq");
|
954
|
+
k(R, "qual");
|
955
|
+
function j(o) {
|
987
956
|
const e = o.split(/\r?\n/), t = [];
|
988
957
|
for (const n of e) {
|
989
958
|
const [r, ...s] = n.split(/\t/);
|
990
959
|
r && t.push({
|
991
960
|
tag: r.slice(1),
|
992
961
|
data: s.map((i) => {
|
993
|
-
const c = i.indexOf(":"),
|
994
|
-
return { tag:
|
962
|
+
const c = i.indexOf(":"), a = i.slice(0, c), d = i.slice(c + 1);
|
963
|
+
return { tag: a, value: d };
|
995
964
|
})
|
996
965
|
});
|
997
966
|
}
|
998
967
|
return t;
|
999
968
|
}
|
1000
|
-
const
|
969
|
+
const V = 21840194, $ = 65536;
|
1001
970
|
async function le(o) {
|
1002
971
|
let e = [];
|
1003
972
|
for await (const t of o)
|
@@ -1019,70 +988,70 @@ class xe {
|
|
1019
988
|
}
|
1020
989
|
}
|
1021
990
|
class ue {
|
1022
|
-
constructor({ bamFilehandle: e, bamPath: t, bamUrl: n, baiPath: r, baiFilehandle: s, baiUrl: i, csiPath: c, csiFilehandle:
|
1023
|
-
if (this.htsget = !1, this.featureCache = new
|
1024
|
-
cache: new
|
991
|
+
constructor({ bamFilehandle: e, bamPath: t, bamUrl: n, baiPath: r, baiFilehandle: s, baiUrl: i, csiPath: c, csiFilehandle: a, csiUrl: d, htsget: f, yieldThreadTime: h = 100, renameRefSeqs: l = (x) => x }) {
|
992
|
+
if (this.htsget = !1, this.featureCache = new W({
|
993
|
+
cache: new X({
|
1025
994
|
maxSize: 50
|
1026
995
|
}),
|
1027
|
-
fill: async (
|
1028
|
-
const { chunk: b, opts: u } =
|
996
|
+
fill: async (x, m) => {
|
997
|
+
const { chunk: b, opts: u } = x, { data: g, cpositions: w, dpositions: _ } = await this._readChunk({
|
1029
998
|
chunk: b,
|
1030
999
|
opts: { ...u, signal: m }
|
1031
1000
|
});
|
1032
|
-
return this.readBamFeatures(g,
|
1001
|
+
return this.readBamFeatures(g, w, _, b);
|
1033
1002
|
}
|
1034
|
-
}), this.renameRefSeq =
|
1003
|
+
}), this.renameRefSeq = l, e)
|
1035
1004
|
this.bam = e;
|
1036
1005
|
else if (t)
|
1037
1006
|
this.bam = new C(t);
|
1038
1007
|
else if (n)
|
1039
|
-
this.bam = new
|
1040
|
-
else if (
|
1008
|
+
this.bam = new L(n);
|
1009
|
+
else if (f)
|
1041
1010
|
this.htsget = !0, this.bam = new xe();
|
1042
1011
|
else
|
1043
1012
|
throw new Error("unable to initialize bam");
|
1044
|
-
if (
|
1045
|
-
this.index = new
|
1013
|
+
if (a)
|
1014
|
+
this.index = new T({ filehandle: a });
|
1046
1015
|
else if (c)
|
1047
|
-
this.index = new
|
1048
|
-
else if (
|
1049
|
-
this.index = new
|
1016
|
+
this.index = new T({ filehandle: new C(c) });
|
1017
|
+
else if (d)
|
1018
|
+
this.index = new T({ filehandle: new L(d) });
|
1050
1019
|
else if (s)
|
1051
1020
|
this.index = new v({ filehandle: s });
|
1052
1021
|
else if (r)
|
1053
1022
|
this.index = new v({ filehandle: new C(r) });
|
1054
1023
|
else if (i)
|
1055
|
-
this.index = new v({ filehandle: new
|
1024
|
+
this.index = new v({ filehandle: new L(i) });
|
1056
1025
|
else if (t)
|
1057
1026
|
this.index = new v({ filehandle: new C(`${t}.bai`) });
|
1058
1027
|
else if (n)
|
1059
|
-
this.index = new v({ filehandle: new
|
1060
|
-
else if (
|
1028
|
+
this.index = new v({ filehandle: new L(`${n}.bai`) });
|
1029
|
+
else if (f)
|
1061
1030
|
this.htsget = !0;
|
1062
1031
|
else
|
1063
1032
|
throw new Error("unable to infer index format");
|
1064
|
-
this.yieldThreadTime =
|
1033
|
+
this.yieldThreadTime = h;
|
1065
1034
|
}
|
1066
1035
|
async getHeaderPre(e) {
|
1067
|
-
const t =
|
1036
|
+
const t = ee(e);
|
1068
1037
|
if (!this.index)
|
1069
1038
|
return;
|
1070
1039
|
const n = await this.index.parse(t), r = n.firstDataLine ? n.firstDataLine.blockPosition + 65535 : void 0;
|
1071
1040
|
let s;
|
1072
1041
|
if (r) {
|
1073
|
-
const
|
1074
|
-
if (!
|
1042
|
+
const f = r + $, h = await this.bam.read(y.Buffer.alloc(f), 0, f, 0, t);
|
1043
|
+
if (!h.bytesRead)
|
1075
1044
|
throw new Error("Error reading header");
|
1076
|
-
s =
|
1045
|
+
s = h.buffer.subarray(0, Math.min(h.bytesRead, r));
|
1077
1046
|
} else
|
1078
1047
|
s = await this.bam.readFile(t);
|
1079
|
-
const i = await
|
1080
|
-
if (i.readInt32LE(0) !==
|
1048
|
+
const i = await P(s);
|
1049
|
+
if (i.readInt32LE(0) !== V)
|
1081
1050
|
throw new Error("Not a BAM file");
|
1082
1051
|
const c = i.readInt32LE(4);
|
1083
1052
|
this.header = i.toString("utf8", 8, 8 + c);
|
1084
|
-
const { chrToIndex:
|
1085
|
-
return this.chrToIndex =
|
1053
|
+
const { chrToIndex: a, indexToChr: d } = await this._readRefSeqs(c + 8, 65535, t);
|
1054
|
+
return this.chrToIndex = a, this.indexToChr = d, j(this.header);
|
1086
1055
|
}
|
1087
1056
|
getHeader(e) {
|
1088
1057
|
return this.headerP || (this.headerP = this.getHeaderPre(e).catch((t) => {
|
@@ -1097,18 +1066,18 @@ class ue {
|
|
1097
1066
|
async _readRefSeqs(e, t, n) {
|
1098
1067
|
if (e > t)
|
1099
1068
|
return this._readRefSeqs(e, t * 2, n);
|
1100
|
-
const r = t +
|
1069
|
+
const r = t + $, { bytesRead: s, buffer: i } = await this.bam.read(y.Buffer.alloc(r), 0, t, 0, n);
|
1101
1070
|
if (!s)
|
1102
1071
|
throw new Error("Error reading refseqs from header");
|
1103
|
-
const c = await
|
1104
|
-
let
|
1105
|
-
const
|
1106
|
-
for (let
|
1107
|
-
const
|
1108
|
-
if (
|
1072
|
+
const c = await P(i.subarray(0, Math.min(s, t))), a = c.readInt32LE(e);
|
1073
|
+
let d = e + 4;
|
1074
|
+
const f = {}, h = [];
|
1075
|
+
for (let l = 0; l < a; l += 1) {
|
1076
|
+
const x = c.readInt32LE(d), m = this.renameRefSeq(c.toString("utf8", d + 4, d + 4 + x - 1)), b = c.readInt32LE(d + x + 4);
|
1077
|
+
if (f[m] = l, h.push({ refName: m, length: b }), d = d + 8 + x, d > c.length)
|
1109
1078
|
return console.warn(`BAM header is very big. Re-fetching ${t} bytes.`), this._readRefSeqs(e, t * 2, n);
|
1110
1079
|
}
|
1111
|
-
return { chrToIndex:
|
1080
|
+
return { chrToIndex: f, indexToChr: h };
|
1112
1081
|
}
|
1113
1082
|
async getRecordsForRange(e, t, n, r) {
|
1114
1083
|
return le(this.streamRecordsForRange(e, t, n, r));
|
@@ -1126,76 +1095,76 @@ class ue {
|
|
1126
1095
|
}
|
1127
1096
|
async *_fetchChunkFeatures(e, t, n, r, s = {}) {
|
1128
1097
|
const { viewAsPairs: i } = s, c = [];
|
1129
|
-
let
|
1130
|
-
for (const
|
1131
|
-
const
|
1132
|
-
for (const
|
1133
|
-
if (
|
1134
|
-
if (
|
1135
|
-
|
1098
|
+
let a = !1;
|
1099
|
+
for (const d of e) {
|
1100
|
+
const f = await this.featureCache.get(d.toString(), { chunk: d, opts: s }, s.signal), h = [];
|
1101
|
+
for (const l of f)
|
1102
|
+
if (l.ref_id === t)
|
1103
|
+
if (l.start >= r) {
|
1104
|
+
a = !0;
|
1136
1105
|
break;
|
1137
|
-
} else
|
1138
|
-
if (c.push(
|
1106
|
+
} else l.end >= n && h.push(l);
|
1107
|
+
if (c.push(h), yield h, a)
|
1139
1108
|
break;
|
1140
1109
|
}
|
1141
|
-
|
1110
|
+
K(s.signal), i && (yield this.fetchPairs(t, c, s));
|
1142
1111
|
}
|
1143
1112
|
async fetchPairs(e, t, n) {
|
1144
1113
|
const { pairAcrossChr: r, maxInsertSize: s = 2e5 } = n, i = {}, c = {};
|
1145
|
-
t.map((
|
1146
|
-
const
|
1147
|
-
for (const m of
|
1148
|
-
const b = m.name
|
1149
|
-
|
1114
|
+
t.map((l) => {
|
1115
|
+
const x = {};
|
1116
|
+
for (const m of l) {
|
1117
|
+
const b = m.name, u = m.id;
|
1118
|
+
x[b] || (x[b] = 0), x[b]++, c[u] = 1;
|
1150
1119
|
}
|
1151
|
-
for (const [m, b] of Object.entries(
|
1120
|
+
for (const [m, b] of Object.entries(x))
|
1152
1121
|
b === 1 && (i[m] = !0);
|
1153
1122
|
});
|
1154
|
-
const
|
1155
|
-
t.map((
|
1156
|
-
for (const
|
1157
|
-
const m =
|
1158
|
-
this.index && i[m] && (r || g === e && Math.abs(b - u) < s) &&
|
1123
|
+
const a = [];
|
1124
|
+
t.map((l) => {
|
1125
|
+
for (const x of l) {
|
1126
|
+
const m = x.name, b = x.start, u = x.next_pos, g = x.next_refid;
|
1127
|
+
this.index && i[m] && (r || g === e && Math.abs(b - u) < s) && a.push(this.index.blocksForRange(g, u, u + 1, n));
|
1159
1128
|
}
|
1160
1129
|
});
|
1161
|
-
const
|
1162
|
-
for (const
|
1163
|
-
|
1164
|
-
return (await Promise.all([...
|
1165
|
-
const { data:
|
1166
|
-
chunk:
|
1130
|
+
const d = /* @__PURE__ */ new Map(), f = await Promise.all(a);
|
1131
|
+
for (const l of f.flat())
|
1132
|
+
d.has(l.toString()) || d.set(l.toString(), l);
|
1133
|
+
return (await Promise.all([...d.values()].map(async (l) => {
|
1134
|
+
const { data: x, cpositions: m, dpositions: b, chunk: u } = await this._readChunk({
|
1135
|
+
chunk: l,
|
1167
1136
|
opts: n
|
1168
1137
|
}), g = [];
|
1169
|
-
for (const
|
1170
|
-
i[
|
1138
|
+
for (const w of await this.readBamFeatures(x, m, b, u))
|
1139
|
+
i[w.name] && !c[w.id] && g.push(w);
|
1171
1140
|
return g;
|
1172
1141
|
}))).flat();
|
1173
1142
|
}
|
1174
1143
|
async _readRegion(e, t, n = {}) {
|
1175
|
-
const { bytesRead: r, buffer: s } = await this.bam.read(
|
1144
|
+
const { bytesRead: r, buffer: s } = await this.bam.read(y.Buffer.alloc(t), 0, t, e, n);
|
1176
1145
|
return s.subarray(0, Math.min(r, t));
|
1177
1146
|
}
|
1178
1147
|
async _readChunk({ chunk: e, opts: t }) {
|
1179
|
-
const n = await this._readRegion(e.minv.blockPosition, e.fetchedSize(), t), { buffer: r, cpositions: s, dpositions: i } = await
|
1148
|
+
const n = await this._readRegion(e.minv.blockPosition, e.fetchedSize(), t), { buffer: r, cpositions: s, dpositions: i } = await Q(n, e);
|
1180
1149
|
return { data: r, cpositions: s, dpositions: i, chunk: e };
|
1181
1150
|
}
|
1182
1151
|
async readBamFeatures(e, t, n, r) {
|
1183
1152
|
let s = 0;
|
1184
1153
|
const i = [];
|
1185
|
-
let c = 0,
|
1154
|
+
let c = 0, a = +Date.now();
|
1186
1155
|
for (; s + 4 < e.length; ) {
|
1187
|
-
const
|
1156
|
+
const d = e.readInt32LE(s), f = s + 4 + d - 1;
|
1188
1157
|
if (n) {
|
1189
1158
|
for (; s + r.minv.dataPosition >= n[c++]; )
|
1190
1159
|
;
|
1191
1160
|
c--;
|
1192
1161
|
}
|
1193
|
-
if (
|
1194
|
-
const
|
1162
|
+
if (f < e.length) {
|
1163
|
+
const h = new R({
|
1195
1164
|
bytes: {
|
1196
1165
|
byteArray: e,
|
1197
1166
|
start: s,
|
1198
|
-
end:
|
1167
|
+
end: f
|
1199
1168
|
},
|
1200
1169
|
// the below results in an automatically calculated file-offset based
|
1201
1170
|
// ID if the info for that is available, otherwise crc32 of the
|
@@ -1219,12 +1188,13 @@ class ue {
|
|
1219
1188
|
// realistically happen
|
1220
1189
|
fileOffset: t.length > 0 ? t[c] * 256 + (s - n[c]) + r.minv.dataPosition + 1 : (
|
1221
1190
|
// must be slice, not subarray for buffer polyfill on web
|
1222
|
-
|
1191
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
1192
|
+
ce.signed(e.slice(s, f))
|
1223
1193
|
)
|
1224
1194
|
});
|
1225
|
-
i.push(
|
1195
|
+
i.push(h), this.yieldThreadTime && +Date.now() - a > this.yieldThreadTime && (await J(1), a = +Date.now());
|
1226
1196
|
}
|
1227
|
-
s =
|
1197
|
+
s = f + 1;
|
1228
1198
|
}
|
1229
1199
|
return i;
|
1230
1200
|
}
|
@@ -1255,41 +1225,41 @@ class ue {
|
|
1255
1225
|
return i === void 0 ? [] : this.index.blocksForRange(i, t, n, r);
|
1256
1226
|
}
|
1257
1227
|
}
|
1258
|
-
async function
|
1228
|
+
async function U(o, e) {
|
1259
1229
|
const t = await Promise.all(o.map(async (n) => {
|
1260
1230
|
const { url: r, headers: s } = n;
|
1261
1231
|
if (r.startsWith("data:"))
|
1262
|
-
return
|
1232
|
+
return y.Buffer.from(r.split(",")[1], "base64");
|
1263
1233
|
{
|
1264
|
-
const { referer: i, ...c } = s,
|
1234
|
+
const { referer: i, ...c } = s, a = await fetch(r, {
|
1265
1235
|
...e,
|
1266
1236
|
headers: { ...e == null ? void 0 : e.headers, ...c }
|
1267
1237
|
});
|
1268
|
-
if (!
|
1269
|
-
throw new Error(`HTTP ${
|
1270
|
-
return
|
1238
|
+
if (!a.ok)
|
1239
|
+
throw new Error(`HTTP ${a.status} fetching ${r}: ${await a.text()}`);
|
1240
|
+
return y.Buffer.from(await a.arrayBuffer());
|
1271
1241
|
}
|
1272
1242
|
}));
|
1273
|
-
return
|
1243
|
+
return y.Buffer.concat(await Promise.all(t.map((n) => P(n))));
|
1274
1244
|
}
|
1275
|
-
class
|
1245
|
+
class _e extends ue {
|
1276
1246
|
constructor(e) {
|
1277
1247
|
super({ htsget: !0 }), this.baseUrl = e.baseUrl, this.trackId = e.trackId;
|
1278
1248
|
}
|
1279
1249
|
async *streamRecordsForRange(e, t, n, r) {
|
1280
1250
|
var s;
|
1281
|
-
const c = `${`${this.baseUrl}/${this.trackId}`}?referenceName=${e}&start=${t}&end=${n}&format=BAM`,
|
1282
|
-
if (
|
1251
|
+
const c = `${`${this.baseUrl}/${this.trackId}`}?referenceName=${e}&start=${t}&end=${n}&format=BAM`, a = (s = this.chrToIndex) === null || s === void 0 ? void 0 : s[e];
|
1252
|
+
if (a === void 0)
|
1283
1253
|
yield [];
|
1284
1254
|
else {
|
1285
|
-
const
|
1286
|
-
if (!
|
1287
|
-
throw new Error(`HTTP ${
|
1288
|
-
const
|
1255
|
+
const d = await fetch(c, { ...r });
|
1256
|
+
if (!d.ok)
|
1257
|
+
throw new Error(`HTTP ${d.status} fetching ${c}: ${await d.text()}`);
|
1258
|
+
const f = await d.json(), h = await U(f.htsget.urls.slice(1), r);
|
1289
1259
|
yield* this._fetchChunkFeatures([
|
1290
1260
|
// fake stuff to pretend to be a Chunk
|
1291
1261
|
{
|
1292
|
-
buffer:
|
1262
|
+
buffer: h,
|
1293
1263
|
_fetchedSize: void 0,
|
1294
1264
|
bin: 0,
|
1295
1265
|
compareTo() {
|
@@ -1315,7 +1285,7 @@ class we extends ue {
|
|
1315
1285
|
return `${e}_${t}_${n}`;
|
1316
1286
|
}
|
1317
1287
|
}
|
1318
|
-
],
|
1288
|
+
], a, t, n, r);
|
1319
1289
|
}
|
1320
1290
|
}
|
1321
1291
|
async _readChunk({ chunk: e }) {
|
@@ -1327,23 +1297,23 @@ class we extends ue {
|
|
1327
1297
|
const t = `${this.baseUrl}/${this.trackId}?referenceName=na&class=header`, n = await fetch(t, e);
|
1328
1298
|
if (!n.ok)
|
1329
1299
|
throw new Error(`HTTP ${n.status} fetching ${t}: ${await n.text()}`);
|
1330
|
-
const r = await n.json(), s = await
|
1331
|
-
if (s.readInt32LE(0) !==
|
1300
|
+
const r = await n.json(), s = await U(r.htsget.urls, e);
|
1301
|
+
if (s.readInt32LE(0) !== V)
|
1332
1302
|
throw new Error("Not a BAM file");
|
1333
|
-
const i = s.readInt32LE(4), c = s.toString("utf8", 8, 8 + i),
|
1334
|
-
for (const [
|
1303
|
+
const i = s.readInt32LE(4), c = s.toString("utf8", 8, 8 + i), a = j(c), d = [], f = {}, h = a.filter((l) => l.tag === "SQ");
|
1304
|
+
for (const [l, x] of h.entries()) {
|
1335
1305
|
let m = "", b = 0;
|
1336
|
-
for (const u of
|
1306
|
+
for (const u of x.data)
|
1337
1307
|
u.tag === "SN" ? m = u.value : u.tag === "LN" && (b = +u.value);
|
1338
|
-
|
1308
|
+
f[m] = l, d[l] = { refName: m, length: b };
|
1339
1309
|
}
|
1340
|
-
return this.chrToIndex =
|
1310
|
+
return this.chrToIndex = f, this.indexToChr = d, a;
|
1341
1311
|
}
|
1342
1312
|
}
|
1343
1313
|
export {
|
1344
1314
|
v as BAI,
|
1345
1315
|
ue as BamFile,
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1316
|
+
R as BamRecord,
|
1317
|
+
T as CSI,
|
1318
|
+
_e as HtsgetFile
|
1349
1319
|
};
|