UNPKG

taxonium-component

Version:

React component for exploring large phylogenetic trees in the browser

111 lines (110 loc) 3.54 kB
import { I as y } from "./main-D1zX1xg0.js"; import { V as F, a as M } from "./index-DYYPI5hS.js"; import { B as T } from "./index-BnQfM3Nw.js"; import { a4 as v, u as w } from "./JBrowsePanel-uJIA-L6s.js"; import { r as C } from "./rxjs-BnZkaVAs.js"; class L extends T.BaseFeatureDataAdapter { constructor() { super(...arguments), this.calculatedIntervalTreeMap = {}; } async getHeader() { const { header: t } = await this.setup(); return t; } async getMetadata() { const { parser: t } = await this.setup(); return t.getMetadata(); } async setupP(t) { const { statusCallback: n = () => { } } = t || {}, s = v.openLocation(this.getConf("vcfLocation"), this.pluginManager), a = await w.fetchAndMaybeUnzip(s, t), o = [], c = {}; let e = 0; const l = new TextDecoder("utf8"); let u = 0; for (; e < a.length; ) { const i = a.indexOf(10, e), h = i === -1 ? a.subarray(e) : a.subarray(e, i), r = l.decode(h).trim(); if (r) if (r.startsWith("#")) o.push(r); else { const m = r.indexOf(" "), p = r.slice(0, m); c[p] || (c[p] = []), c[p].push(r); } u++ % 1e4 === 0 && n(`Loading ${w.getProgressDisplayStr(e, a.length)}`), e = i + 1; } const f = o.join(` `), d = new F({ header: f }), x = Object.fromEntries(Object.entries(c).map(([i, h]) => [ i, (r) => { if (!this.calculatedIntervalTreeMap[i]) { r == null || r("Parsing VCF data"); let m = 0; const p = new y(); for (const b of h) { const g = new M({ variant: d.parseLine(b), parser: d, id: `${this.id}-${i}-${m++}` }); p.insert([g.get("start"), g.get("end")], g); } this.calculatedIntervalTreeMap[i] = p; } return this.calculatedIntervalTreeMap[i]; } ])); return { header: f, parser: d, intervalTreeMap: x }; } async setup() { return this.vcfFeatures || (this.vcfFeatures = this.setupP().catch((t) => { throw this.vcfFeatures = void 0, t; })), this.vcfFeatures; } async getRefNames(t = {}) { const { intervalTreeMap: n } = await this.setup(); return Object.keys(n); } getFeatures(t, n = {}) { return C.ObservableCreate(async (s) => { var a; try { const { start: o, end: c, refName: e } = t, { intervalTreeMap: l } = await this.setup(); for (const u of ((a = l[e]) === null || a === void 0 ? void 0 : a.call(l, n.statusCallback).search([ o, c ])) || []) s.next(u); s.complete(); } catch (o) { s.error(o); } }, n.stopToken); } async getSources() { const t = this.getConf("samplesTsvLocation"); if (t.uri === "" || t.uri === "/path/to/samples.tsv") { const { parser: n } = await this.setup(); return n.samples.map((s) => ({ name: s })); } else { const s = (await v.openLocation(t).readFile("utf8")).split(/\n|\r\n|\r/), a = s[0].split(" "), { parser: o } = await this.setup(), c = new Set(o.samples); return s.slice(1).map((e) => { const l = e.split(" "); return { name: l[0], ...Object.fromEntries(l.slice(1).map((u, f) => [a[f + 1], u])) }; }).filter((e) => c.has(e.name)); } } } L.capabilities = ["getFeatures", "getRefNames"]; export { L as default }; //# sourceMappingURL=VcfAdapter-D41_2-cN.js.map