UNPKG

taxonium-component

Version:

React component for exploring large phylogenetic trees in the browser

87 lines (86 loc) 2.84 kB
import { I as T } from "./main-D1zX1xg0.js"; import { B as y } from "./index-CpJXUZUB.js"; import { u as m, a1 as F } from "./JBrowsePanel-BNE3gNW1.js"; import { p as w } from "./parseLineByLine-u4wRqQjK.js"; import { r as x } from "./rxjs-L4bS73F7.js"; class $ extends y.BaseFeatureDataAdapter { constructor() { super(...arguments), this.intervalTrees = {}; } async getNames() { const { header: e, columnNames: t } = await this.loadData(); if (t.length) return t; const s = e.split(/\n|\r\n|\r/).filter((a) => !!a).at(-1); return s != null && s.includes(" ") ? s.slice(1).split(" ").map((a) => a.trim()) : void 0; } async loadFeatureIntervalTreeHelper(e) { var t; const { features: i } = await this.loadData(), s = i[e]; if (!s) return; const a = ((t = await this.getNames()) === null || t === void 0 ? void 0 : t.slice(3)) || [], o = new T(); for (let r = 0; r < s.length; r++) { const n = s[r], [d, l, v, ...u] = n.split(" "); for (let c = 0; c < u.length; c++) { const b = `${this.id}-${d}-${r}-${c}`, h = +l, f = +v, p = +u[c], g = a[c] || `col${c}`; p && o.insert([h, f], new m.SimpleFeature({ id: b, data: { refName: d, start: h, end: f, score: p, source: g } })); } } return o; } async getRefNames(e = {}) { const { features: t } = await this.loadData(e); return Object.keys(t); } async loadDataP(e = {}) { const t = this.pluginManager, i = this.getConf("bedGraphLocation"), s = await m.fetchAndMaybeUnzip(F.openLocation(i, t), e), a = {}, o = []; w.parseLineByLine(s, (n) => { if (n.startsWith("#")) o.push(n); else { const d = n.indexOf(" "), l = n.slice(0, d); a[l] || (a[l] = []), a[l].push(n); } return !0; }, e.statusCallback); const r = this.getConf("columnNames"); return { header: o.join(` `), features: a, columnNames: r }; } 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]; } async loadData(e = {}) { return this.bedFeatures || (this.bedFeatures = this.loadDataP(e).catch((t) => { throw this.bedFeatures = void 0, t; })), this.bedFeatures; } getFeatures(e, t = {}) { return x.ObservableCreate(async (i) => { const { start: s, end: a, refName: o } = e, r = await this.loadFeatureIntervalTree(o); for (const n of (r == null ? void 0 : r.search([s, a])) || []) i.next(n); i.complete(); }); } } export { $ as default }; //# sourceMappingURL=BedGraphAdapter-n8izSG8z.js.map