UNPKG

taxonium-component

Version:

React component for exploring large phylogenetic trees in the browser

117 lines (116 loc) 3.73 kB
import { aX as m, a4 as h } from "./JBrowsePanel-uJIA-L6s.js"; import { u as x, c as _ } from "./unzip-ASAuJ12U.js"; import { I as b, a as y } from "./IndexedFastaAdapter-3PsrnaWp.js"; const g = 65536, B = g * g; function u(i, e = 0) { const t = i[e] | i[e + 1] << 8 | i[e + 2] << 16 | i[e + 3] << 24; return ((i[e + 4] | i[e + 5] << 8 | i[e + 6] << 16 | i[e + 7] << 24) >>> 0) * B + (t >>> 0); } const d = 1; function p(i, e, t) { const s = e[d], n = t ? t[d] : 1 / 0; return s <= i && n > i ? 0 : s < i ? -1 : 1; } class I { constructor({ filehandle: e, path: t }) { if (e) this.filehandle = e; else if (t) this.filehandle = new m(t); else throw new TypeError("either filehandle or path must be defined"); } _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 = 8 * 2 * t; if (n > Number.MAX_SAFE_INTEGER) throw new TypeError("integer overflow"); const o = await this.filehandle.read(n, 8); for (let r = 0; r < t; r += 1) { const c = u(o, r * 16), a = u(o, r * 16 + 8); s[r + 1] = [c, a]; } 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(), o = []; let r = 0, c = n.length - 1, a = Math.floor(n.length / 2), l = p(t, n[a], n[a + 1]); for (; l !== 0; ) l > 0 ? c = a - 1 : l < 0 && (r = a + 1), a = Math.ceil((c - r) / 2) + r, l = p(t, n[a], n[a + 1]); o.push(n[a]); let f = a + 1; for (; f < n.length && (o.push(n[f]), !(n[f][d] >= s)); f += 1) ; return o[o.length - 1][d] < s && o.push([]), o; } } class w { constructor({ filehandle: e, path: t, gziFilehandle: s, gziPath: n }) { if (e) this.filehandle = e; else if (t) this.filehandle = new m(t); else throw new TypeError("either filehandle or path must be defined"); if (!s && !n && !t) throw new TypeError("either gziFilehandle or gziPath must be defined"); this.gzi = new I({ filehandle: s, path: !s && !n && t ? n : `${t}.gzi` }); } async _readAndUncompressBlock(e, t) { let s = t; s || (s = (await this.filehandle.stat()).size); const n = s - e, o = await this.filehandle.read(n, e); return x(o); } async read(e, t) { const s = await this.gzi.getRelevantBlocksForRead(e, t), n = []; for (let o = 0; o < s.length - 1; o += 1) { const r = await this._readAndUncompressBlock(s[o][0], s[o + 1][0]), [, c] = s[o], a = c >= t ? 0 : t - c, l = Math.min(t + e, c + r.length) - c; a >= 0 && a < r.length && n.push(r.subarray(a, l)); } return _(n); } } class L extends b { constructor({ fasta: e, path: t, fai: s, faiPath: n, gzi: o, gziPath: r }) { super({ fasta: e, path: t, fai: s, faiPath: n }), e && o ? this.fasta = new w({ filehandle: e, gziFilehandle: o }) : t && r && (this.fasta = new w({ path: t, gziPath: r })); } } class F extends y { 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 L(n) }; } } export { F as default }; //# sourceMappingURL=BgzipFastaAdapter-CewYltRn.js.map