UNPKG

taxonium-component

Version:

React component for exploring large phylogenetic trees in the browser

103 lines (102 loc) 3.5 kB
import { I as D } from "./main-D1zX1xg0.js"; import { B as F, f as x } from "./util-X8nqr6IJ.js"; import { B as E } from "./index-BnQfM3Nw.js"; import { u as b, a4 as S } from "./JBrowsePanel-uJIA-L6s.js"; import { r as I } from "./rxjs-BnZkaVAs.js"; class B extends E.BaseFeatureDataAdapter { constructor() { super(...arguments), this.intervalTrees = {}; } async loadDataP(e) { const { statusCallback: t = () => { } } = e || {}, i = this.getConf("bedLocation"), s = await b.fetchAndMaybeUnzip(S.openLocation(i, this.pluginManager), e), n = [], r = {}; let a = 0, o = 0; const d = new TextDecoder("utf8"); for (; a < s.length; ) { const m = s.indexOf(10, a), y = m === -1 ? s.subarray(a) : s.subarray(a, m), c = d.decode(y).trim(); if (c) if (c.startsWith("#")) n.push(c); else { if (c.startsWith(">")) break; { const C = c.indexOf(" "), g = c.slice(0, C); r[g] || (r[g] = []), r[g].push(c); } } o++ % 1e4 === 0 && t(`Loading ${b.getProgressDisplayStr(a, s.length)}`), a = m + 1; } const f = n.join(` `), l = this.getConf("autoSql"), h = new F({ autoSql: l }), p = this.getConf("columnNames"), u = this.getConf("scoreColumn"), v = this.getConf("colRef"), w = this.getConf("colStart"), T = this.getConf("colEnd"); return { header: f, features: r, parser: h, columnNames: p, scoreColumn: u, colRef: v, colStart: w, colEnd: T }; } async loadData(e = {}) { return this.bedFeatures || (this.bedFeatures = this.loadDataP(e).catch((t) => { throw this.bedFeatures = void 0, t; })), this.bedFeatures; } async getRefNames(e = {}) { const { features: t } = await this.loadData(e); return Object.keys(t); } async getHeader(e = {}) { const { header: t } = await this.loadData(e); return t; } async getNames() { const { header: e, columnNames: t } = await this.loadData(); if (t.length) return t; const s = e.split(/\n|\r\n|\r/).filter((n) => !!n).at(-1); return s != null && s.includes(" ") ? s.slice(1).split(" ").map((n) => n.trim()) : void 0; } async loadFeatureIntervalTreeHelper(e) { const { colRef: t, colStart: i, colEnd: s, features: n, parser: r, scoreColumn: a } = await this.loadData(), o = n[e]; if (!o) return; const d = await this.getNames(), f = new D(); for (let l = 0; l < o.length; l++) { const h = o[l], p = `${this.id}-${e}-${l}`, u = new b.SimpleFeature(x({ line: h, colRef: t, colStart: i, colEnd: s, scoreColumn: a, parser: r, uniqueId: p, names: d })); f.insert([u.get("start"), u.get("end")], u); } return f; } async loadFeatureIntervalTree(e) { return this.intervalTrees[e] || (this.intervalTrees[e] = this.loadFeatureIntervalTreeHelper(e).catch((t) => { throw this.intervalTrees[e] = void 0, t; })), this.intervalTrees[e]; } getFeatures(e, t = {}) { return I.ObservableCreate(async (i) => { const { start: s, end: n, refName: r } = e, a = await this.loadFeatureIntervalTree(r), o = a == null ? void 0 : a.search([s, n]); if (o) for (const d of o) i.next(d); i.complete(); }, t.stopToken); } } B.capabilities = ["getFeatures", "getRefNames"]; export { B as default }; //# sourceMappingURL=BedAdapter-oacR54Nt.js.map