taxonium-component
Version:
React component for exploring large phylogenetic trees in the browser
125 lines (124 loc) • 6.54 kB
JavaScript
import { a as Po, ad as no, ae as so, s as j, u as M, ah as io, ai as Ro } from "./JBrowsePanel-BNE3gNW1.js";
import "react";
import "react/jsx-runtime";
const ro = 7, co = 4.5, jo = 7, ao = {
C: "G",
G: "C",
A: "T",
T: "A"
}, No = 0.6;
async function Wo(o, lo) {
var H;
const { features: F, regions: ho, bpPerPx: E, colorBy: W, displayCrossHatches: fo, visibleModifications: G = {}, scaleOpts: K, height: po, theme: bo, config: I, ticks: yo, stopToken: L } = lo, go = Po.createJBrowseTheme(bo), k = ho[0], mo = (k.end - k.start) / E, O = Ro, S = po - O * 2, Q = { ...K, range: [0, S] }, vo = no(Q), uo = no({
...Q,
range: [0, S / 2],
scaleType: "linear"
}), To = so(K.scaleType), ko = so("linear"), So = j.readConfObject(I, "indicatorThreshold"), Co = j.readConfObject(I, "showInterbaseCounts"), _o = j.readConfObject(I, "showArcs"), Do = j.readConfObject(I, "showInterbaseIndicators"), d = (e) => S - (vo(e) || 0) + O, C = (e) => d(To) - d(e), X = (e) => S - (uo(e) || 0) + O, Z = (e) => X(ko) - X(e), { bases: N, softclip: Mo, hardclip: Eo, insertion: Io } = go.palette, _ = {
A: N.A.main,
C: N.C.main,
G: N.G.main,
T: N.T.main,
insertion: Io,
softclip: Mo,
hardclip: Eo,
total: j.readConfObject(I, "color"),
mod_NONE: "blue",
cpg_meth: "red",
cpg_unmeth: "blue"
};
o.fillStyle = _.total, M.forEachWithStopTokenCheck(F.values(), L, (e) => {
if (e.get("type") === "skip")
return;
const [y, u] = M.featureSpanPx(e, k, E), g = u - y + No, f = e.get("score");
o.fillRect(y, d(f), g, C(f));
});
let x = 0;
const oo = k.reversed ? 1 / E : 0, Oo = W.type === "modifications", wo = W.type === "methylation", B = (H = W.modifications) === null || H === void 0 ? void 0 : H.isolatedModification;
if (M.forEachWithStopTokenCheck(F.values(), L, (e) => {
var y, u, g, f, D, w, A, P, Y;
if (e.get("type") === "skip")
return;
const [m, Ao] = M.featureSpanPx(e, k, E), v = e.get("snpinfo"), R = Math.max(Ao - m, 1), r = e.get("score");
if (Oo) {
let c = 0;
const i = (y = v.refbase) === null || y === void 0 ? void 0 : y.toUpperCase(), { nonmods: h, mods: l, snps: t, ref: n } = v;
for (const a of Object.keys(h).sort().reverse()) {
const s = G[a.replace("nonmod_", "")] || G[a.replace("mod_", "")];
if (!s) {
console.warn(`${a} not known yet`);
continue;
}
if (B && s.type !== B)
continue;
const p = ao[s.base], z = s.base === "N" ? r : (((u = t[s.base]) === null || u === void 0 ? void 0 : u.entryDepth) || 0) + (((g = t[p]) === null || g === void 0 ? void 0 : g.entryDepth) || 0) + (i === s.base ? n[1] : 0) + (i === p ? n[-1] : 0), U = s.base === "N" ? r : (((f = t[s.base]) === null || f === void 0 ? void 0 : f.entryDepth) || 0) + (((D = t[p]) === null || D === void 0 ? void 0 : D.entryDepth) || 0) + (i === s.base ? n.entryDepth : 0) + (i === p ? n.entryDepth : 0), { entryDepth: $, avgProbability: J = 0 } = v.nonmods[a], T = U / r * ($ / z), V = io("blue", J), b = C(r), q = d(r) + b;
o.fillStyle = V, o.fillRect(Math.round(m), q - (c + T * b), R, T * b), c += T * b;
}
for (const a of Object.keys(l).sort().reverse()) {
const s = G[a.replace("mod_", "")];
if (!s) {
console.warn(`${a} not known yet`);
continue;
}
if (B && s.type !== B)
continue;
const p = ao[s.base], z = s.base === "N" ? r : (((w = t[s.base]) === null || w === void 0 ? void 0 : w.entryDepth) || 0) + (((A = t[p]) === null || A === void 0 ? void 0 : A.entryDepth) || 0) + (i === s.base ? n[1] : 0) + (i === p ? n[-1] : 0), U = s.base === "N" ? r : (((P = t[s.base]) === null || P === void 0 ? void 0 : P.entryDepth) || 0) + (((Y = t[p]) === null || Y === void 0 ? void 0 : Y.entryDepth) || 0) + (i === s.base ? n.entryDepth : 0) + (i === p ? n.entryDepth : 0), { entryDepth: $, avgProbability: J = 0 } = l[a], T = U / r * ($ / z), to = s.color || "black", V = io(to, J), b = C(r), q = d(r) + b;
o.fillStyle = V, o.fillRect(Math.round(m), q - (c + T * b), R, T * b), c += T * b;
}
} else if (wo) {
const { depth: c, nonmods: i, mods: h } = v;
let l = 0;
for (const t of Object.keys(h).sort().reverse()) {
const { entryDepth: n } = h[t], a = C(r), s = d(r) + a;
o.fillStyle = _[t] || "black", o.fillRect(Math.round(m), s - (n + l) / c * a, R, n / c * a), l += n;
}
for (const t of Object.keys(i).sort().reverse()) {
const { entryDepth: n } = i[t], a = C(r), s = d(r) + a;
o.fillStyle = _[t] || "black", o.fillRect(Math.round(m), s - (n + l) / c * a, R, n / c * a), l += n;
}
} else {
const { depth: c, snps: i } = v;
let h = 0;
for (const l of Object.keys(i).sort().reverse()) {
const { entryDepth: t } = i[l], n = C(r), a = d(r) + n;
o.fillStyle = _[l] || "black", o.fillRect(Math.round(m), a - (t + h) / c * n, R, t / c * n), h += t;
}
}
const eo = Object.keys(v.noncov);
if (Co) {
let c = 0;
for (const i of eo) {
const { entryDepth: h } = v.noncov[i], l = 0.6;
o.fillStyle = _[i], o.fillRect(m - l + oo, co + Z(c), l * 2, Z(h)), c += h;
}
}
if (Do) {
let c = 0, i = 0, h = "";
for (const t of eo) {
const { entryDepth: n } = v.noncov[t];
c += n, n > i && (i = n, h = t);
}
const l = Math.max(r, x);
if (c > l * So && l > jo) {
o.fillStyle = _[h], o.beginPath();
const t = m + oo;
o.moveTo(t - ro / 2, 0), o.lineTo(t + ro / 2, 0), o.lineTo(t, co), o.fill();
}
}
x = r;
}), _o && M.forEachWithStopTokenCheck(F.values(), L, (e) => {
if (e.get("type") !== "skip")
return;
const y = e.get("start"), u = e.get("end"), [g, f] = M.bpSpanPx(y, u, k, E);
o.beginPath();
const D = e.get("effectiveStrand"), w = "rgba(255,200,200,0.7)", A = "rgba(200,200,255,0.7)", P = "rgba(200,200,200,0.7)";
D === 1 ? o.strokeStyle = w : D === -1 ? o.strokeStyle = A : o.strokeStyle = P, o.lineWidth = Math.log(e.get("score") + 1), o.moveTo(g, S - O * 2), o.bezierCurveTo(g, 0, f, 0, f, S - O * 2), o.stroke();
}), fo) {
o.lineWidth = 1, o.strokeStyle = "rgba(140,140,140,0.8)";
for (const e of yo.values)
o.beginPath(), o.moveTo(0, Math.round(d(e))), o.lineTo(mo, Math.round(d(e))), o.stroke();
}
}
export {
Wo as makeImage
};
//# sourceMappingURL=makeImage-Yl3i1_VI.js.map