taxonium-component
Version:
React component for exploring large phylogenetic trees in the browser
88 lines (87 loc) • 2.99 kB
JavaScript
import { I as T } from "./main-D1zX1xg0.js";
import { B as x } from "./index-BnQfM3Nw.js";
import { u as g, a4 as b } from "./JBrowsePanel-uJIA-L6s.js";
import { r as F } from "./rxjs-BnZkaVAs.js";
class N extends x.BaseFeatureDataAdapter {
constructor() {
super(...arguments), this.intervalTrees = {};
}
async getNames() {
const { header: e, columnNames: t } = await this.loadData();
if (t.length)
return t;
const a = e.split(/\n|\r\n|\r/).filter((o) => !!o).at(-1);
return a != null && a.includes(" ") ? a.slice(1).split(" ").map((o) => o.trim()) : void 0;
}
async loadFeatureIntervalTreeHelper(e) {
var t;
const { features: c } = await this.loadData(), a = c[e];
if (!a)
return;
const o = ((t = await this.getNames()) === null || t === void 0 ? void 0 : t.slice(3)) || [], n = new T();
for (let s = 0; s < a.length; s++) {
const r = a[s], [h, d, f, ...i] = r.split(" ");
for (let l = 0; l < i.length; l++) {
const u = `${this.id}-${h}-${s}-${l}`, p = +d, m = +f, v = +i[l], w = o[l] || `col${l}`;
v && n.insert([p, m], new g.SimpleFeature({
id: u,
data: {
refName: h,
start: p,
end: m,
score: v,
source: w
}
}));
}
}
return n;
}
async getRefNames(e = {}) {
const { features: t } = await this.loadData(e);
return Object.keys(t);
}
async loadDataP(e = {}) {
const t = this.pluginManager, c = this.getConf("bedGraphLocation"), a = await g.fetchAndMaybeUnzip(b.openLocation(c, t), e);
if (a.length > 536870888)
throw new Error("Data exceeds maximum string length (512MB)");
const n = new TextDecoder("utf8", { fatal: !0 }).decode(a).split(/\n|\r\n|\r/).filter((i) => !!i), s = [];
let r = 0;
for (; r < n.length && n[r].startsWith("#"); r++)
s.push(n[r]);
const h = s.join(`
`), d = {};
for (; r < n.length; r++) {
const i = n[r], l = i.indexOf(" "), u = i.slice(0, l);
d[u] || (d[u] = []), d[u].push(i);
}
const f = this.getConf("columnNames");
return {
header: h,
features: d,
columnNames: 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];
}
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 F.ObservableCreate(async (c) => {
const { start: a, end: o, refName: n } = e, s = await this.loadFeatureIntervalTree(n);
for (const r of (s == null ? void 0 : s.search([a, o])) || [])
c.next(r);
c.complete();
});
}
}
export {
N as default
};
//# sourceMappingURL=BedGraphAdapter-DytuIPv3.js.map