taxonium-component
Version:
React component for exploring large phylogenetic trees in the browser
104 lines (103 loc) • 3.33 kB
JavaScript
import { u as x, c as _ } from "./unzip-NIBF0hze.js";
import { L as g } from "./browser-BpRiKmO-.js";
import { I as B, a as L } from "./IndexedFastaAdapter-CqEccOzJ.js";
import { a1 as h } from "./JBrowsePanel-BNE3gNW1.js";
const p = 65536, I = p * p;
function u(o, e = 0) {
const t = o[e] | o[e + 1] << 8 | o[e + 2] << 16 | o[e + 3] << 24;
return ((o[e + 4] | o[e + 5] << 8 | o[e + 6] << 16 | o[e + 7] << 24) >>> 0) * I + (t >>> 0);
}
const f = 1;
function m(o, e, t) {
const s = e[f], n = t ? t[f] : 1 / 0;
return s <= o && n > o ? 0 : s < o ? -1 : 1;
}
class b {
constructor({ filehandle: e }) {
this.filehandle = e;
}
_getIndex() {
return this.index || (this.index = this._readIndex().catch((e) => {
throw this.index = void 0, e;
})), this.index;
}
async _readIndex() {
const e = await this.filehandle.read(8, 0), t = u(e);
if (!t)
return [[0, 0]];
const s = new Array(t + 1);
s[0] = [0, 0];
const n = 16 * t;
if (n > Number.MAX_SAFE_INTEGER)
throw new TypeError("integer overflow");
const a = await this.filehandle.read(n, 8);
for (let i = 0; i < t; i += 1) {
const c = u(a, i * 16), r = u(a, i * 16 + 8);
s[i + 1] = [c, r];
}
return s;
}
async getLastBlock() {
return (await this._getIndex()).at(-1);
}
async getRelevantBlocksForRead(e, t) {
const s = t + e;
if (e === 0)
return [];
const n = await this._getIndex(), a = [];
let i = 0, c = n.length - 1, r = Math.floor(n.length / 2), l = m(t, n[r], n[r + 1]);
for (; l !== 0; )
l > 0 ? c = r - 1 : l < 0 && (i = r + 1), r = Math.ceil((c - i) / 2) + i, l = m(t, n[r], n[r + 1]);
a.push(n[r]);
let d = r + 1;
for (; d < n.length && (a.push(n[d]), !(n[d][f] >= s)); d += 1)
;
return a[a.length - 1][f] < s && a.push([]), a;
}
}
class w {
constructor({ filehandle: e, gziFilehandle: t }) {
this.filehandle = e, this.gzi = new b({
filehandle: t
});
}
async _readAndUncompressBlock(e, t) {
let s = t;
s || (s = (await this.filehandle.stat()).size);
const n = s - e, a = await this.filehandle.read(n, e);
return x(a);
}
async read(e, t) {
const s = await this.gzi.getRelevantBlocksForRead(e, t), n = [];
for (let a = 0; a < s.length - 1; a += 1) {
const i = await this._readAndUncompressBlock(s[a][0], s[a + 1][0]), [, c] = s[a], r = c >= t ? 0 : t - c, l = Math.min(t + e, c + i.length) - c;
r >= 0 && r < i.length && n.push(i.subarray(r, l));
}
return _(n);
}
}
class y extends B {
constructor({ fasta: e, path: t, fai: s, faiPath: n, gzi: a, gziPath: i }) {
super({ fasta: e, path: t, fai: s, faiPath: n }), e && a ? this.fasta = new w({
filehandle: e,
gziFilehandle: a
}) : t && i && (this.fasta = new w({
filehandle: new g(t),
gziFilehandle: new g(i)
}));
}
}
class A extends L {
async setupPre() {
const e = this.getConf("fastaLocation"), t = this.getConf("faiLocation"), s = this.getConf("gziLocation"), n = {
fasta: h.openLocation(e, this.pluginManager),
fai: h.openLocation(t, this.pluginManager),
gzi: h.openLocation(s, this.pluginManager)
};
return { fasta: new y(n) };
}
}
export {
A as default
};
//# sourceMappingURL=BgzipFastaAdapter-CqBgyTNQ.js.map