UNPKG

taxonium-component

Version:

React component for exploring large phylogenetic trees in the browser

119 lines (118 loc) 3.74 kB
import "./remoteFile-H_6BTCFF.js"; import { u as p } from "./unzip-NIBF0hze.js"; import { B as A, a as I, p as k, c as y, b as x } from "./BamAdapter-lVmrDAGd.js"; async function $(l, e) { const r = await Promise.all(l.map(async (t) => { const { url: a, headers: i } = t; if (a.startsWith("data:")) { const s = await fetch(a); if (!s.ok) throw new Error("failed to decode base64"); const n = await s.arrayBuffer(); return new Uint8Array(n); } else { const { referer: s, ...n } = i, o = await fetch(a, { ...e, headers: { ...e == null ? void 0 : e.headers, ...n } }); if (!o.ok) throw new Error(`HTTP ${o.status} fetching ${a}: ${await o.text()}`); return new Uint8Array(await o.arrayBuffer()); } })); return y(await Promise.all(r.map((t) => p(t)))); } class B extends A { constructor(e) { super({ htsget: !0 }), this.baseUrl = e.baseUrl, this.trackId = e.trackId; } async *streamRecordsForRange(e, r, t, a) { var o; const s = `${`${this.baseUrl}/${this.trackId}`}?referenceName=${e}&start=${r}&end=${t}&format=BAM`, n = (o = this.chrToIndex) == null ? void 0 : o[e]; if (n === void 0) yield []; else { const c = await fetch(s, { ...a }); if (!c.ok) throw new Error(`HTTP ${c.status} fetching ${s}: ${await c.text()}`); const d = await c.json(), f = await $(d.htsget.urls.slice(1), a); yield* this._fetchChunkFeatures([ // fake stuff to pretend to be a Chunk { buffer: f, _fetchedSize: void 0, bin: 0, compareTo() { return 0; }, toUniqueString() { return `${e}_${r}_${t}`; }, fetchedSize() { return 0; }, minv: { dataPosition: 0, blockPosition: 0, compareTo: () => 0 }, maxv: { dataPosition: Number.MAX_SAFE_INTEGER, blockPosition: 0, compareTo: () => 0 }, toString() { return `${e}_${r}_${t}`; } } ], n, r, t, a); } } // @ts-expect-error async _readChunk({ chunk: e }) { if (!e.buffer) throw new Error("expected chunk.buffer in htsget"); return { data: e.buffer, cpositions: [], dpositions: [], chunk: e }; } async getHeader(e = {}) { const r = `${this.baseUrl}/${this.trackId}?referenceName=na&class=header`, t = await fetch(r, e); if (!t.ok) throw new Error(`HTTP ${t.status} fetching ${r}: ${await t.text()}`); const a = await t.json(), i = await $(a.htsget.urls, e), s = new DataView(i.buffer); if (s.getInt32(0, !0) !== I) throw new Error("Not a BAM file"); const n = s.getInt32(4, !0), c = new TextDecoder("utf8").decode(i.subarray(8, 8 + n)), d = k(c), f = [], g = {}, m = d.filter((u) => u.tag === "SQ"); for (const [u, T] of m.entries()) { let w = "", b = 0; for (const h of T.data) h.tag === "SN" ? w = h.value : h.tag === "LN" && (b = +h.value); g[w] = u, f[u] = { refName: w, length: b }; } return this.chrToIndex = g, this.indexToChr = f, d; } } class N extends x { async configurePre() { const e = this.getConf("htsgetBase"), r = this.getConf("htsgetTrackId"), t = new B({ baseUrl: e, trackId: r }), a = this.getConf("sequenceAdapter"); if (a && this.getSubAdapter) { const i = await this.getSubAdapter(a); return { bam: t, sequenceAdapter: i.dataAdapter }; } return { bam: t }; } } export { N as default }; //# sourceMappingURL=HtsgetBamAdapter-BL-voECU.js.map