taxonium-component
Version:
React component for exploring large phylogenetic trees in the browser
158 lines (157 loc) • 7.96 kB
JavaScript
import { jsxs as s, Fragment as F, jsx as e } from "react/jsx-runtime";
import { useState as i, useEffect as U } from "react";
import { o as D, u, D as O, B as c, T as E, c as L, O as j, a as R, d as I, t as z, j as G, m as K, aM as B, aN as Q } from "./JBrowsePanel-BNE3gNW1.js";
import { R as H } from "./RadioGroup-VjVK5G6V.js";
import { F as V } from "./FormControlLabel-CfHqydvH.js";
import { R as N } from "./Radio-Bf0n3fp_.js";
const X = D(function({ model: n, children: l, handleClose: o }) {
const [h, g] = i(""), [v, d] = i(), [x, y] = i(!1), [f, k] = i(""), [m, b] = i(!1), [P, M] = u.useLocalStorage("cluster-samplesPerPixel", "1");
return s(F, { children: [s(O, { children: [l, s("div", { style: { marginTop: 50 }, children: [e(c, { variant: "contained", onClick: () => {
b(!m);
}, children: m ? "Hide advanced options" : "Show advanced options" }), m ? s("div", { style: { marginTop: 20 }, children: [e(E, { children: "This procedure samples the data at each 'pixel' across the visible by default" }), e(L, { label: "Samples per pixel (>1 for denser sampling, between 0-1 for sparser sampling)", variant: "outlined", size: "small", value: P, onChange: (a) => {
M(a.target.value);
} })] }) : null] }), s("div", { children: [x ? s("div", { style: { padding: 50 }, children: [e("span", { children: h || "Loading..." }), e(c, { onClick: () => {
j.stopStopToken(f);
}, children: "Stop" })] }) : null, v ? e(R.ErrorMessage, { error: v }) : null] })] }), s(I, { children: [e(c, { variant: "contained", disabled: x, onClick: async () => {
try {
d(void 0), g("Initializing"), y(!0);
const a = u.getContainingView(n);
if (!a.initialized)
return;
const { rpcManager: C } = u.getSession(n), { sourcesWithoutLayout: w, adapterConfig: S } = n;
if (w) {
const T = z.getRpcSessionId(n), t = j.createStopToken();
k(t);
const r = await C.call(T, "MultiWiggleClusterScoreMatrix", {
regions: a.dynamicBlocks.contentBlocks,
sources: w,
sessionId: T,
adapterConfig: S,
stopToken: t,
bpPerPx: a.bpPerPx / +P,
statusCallback: (p) => {
g(p);
}
});
n.setLayout(r.order.map((p) => {
const A = w[p];
if (!A)
throw new Error(`out of bounds at ${p}`);
return A;
}));
}
o();
} catch (a) {
!u.isAbortException(a) && G(n) && (console.error(a), d(a));
} finally {
y(!1), g(""), k("");
}
}, children: "Run clustering" }), e(c, { variant: "contained", color: "secondary", onClick: () => {
o(), f && j.stopStopToken(f);
}, children: "Cancel" })] })] });
}), Y = K()((n) => ({
textAreaFont: {
fontFamily: "Courier New"
},
mgap: {
display: "flex",
flexDirection: "column",
gap: n.spacing(4)
}
})), Z = D(function({ model: n, handleClose: l, children: o }) {
const { classes: h } = Y(), [g, v] = i(""), [d, x] = i(), [y, f] = i(), [k, m] = i(!1), [b, P] = u.useLocalStorage("cluster-showAdvanced", !1), [M, a] = i("single"), [C, w] = i("1");
U(() => {
(async () => {
try {
f(void 0), x(void 0), m(!0);
const t = u.getContainingView(n), { dynamicBlocks: r, bpPerPx: p } = t, { rpcManager: A } = u.getSession(n), { sourcesWithoutLayout: _, adapterConfig: q } = n, W = z.getRpcSessionId(n), J = await A.call(W, "MultiWiggleGetScoreMatrix", {
regions: r.contentBlocks,
sources: _,
sessionId: W,
adapterConfig: q,
bpPerPx: p / +C
});
x(J);
} catch (t) {
!u.isAbortException(t) && G(n) && (console.error(t), f(t));
} finally {
m(!1);
}
})();
}, [n, C]);
const S = d ? `inputMatrix<-matrix(c(${Object.values(d).map((t) => t.join(",")).join(`,
`)}
),nrow=${Object.values(d).length},byrow=TRUE)
rownames(inputMatrix)<-c(${Object.keys(d).map((t) => `'${t}'`).join(",")})
resultClusters<-hclust(dist(inputMatrix), method='${M}')
cat(resultClusters$order,sep='\\n')` : void 0, T = d ? Object.entries(d).map(([t, r]) => [t, ...r].join(" ")).join(`
`) : void 0;
return s(F, { children: [s(O, { children: [o, s("div", { style: { marginTop: 50 }, children: [s("div", { children: [s("div", { style: {
display: "flex",
gap: "8px",
flexWrap: "wrap",
marginBottom: "16px"
}, children: [e(c, { variant: "contained", onClick: () => {
B.saveAs(new Blob([S || ""], {
type: "text/plain;charset=utf-8"
}), "cluster.R");
}, children: "Download Rscript" }), " ", "or", " ", e(c, { variant: "contained", onClick: () => {
Q(S || "");
}, children: "Copy Rscript to clipboard" }), " ", "or", " ", e(c, { variant: "contained", onClick: () => {
B.saveAs(new Blob([T || ""], {
type: "text/plain;charset=utf-8"
}), "scores.tsv");
}, children: "Download TSV" })] }), e("div", { children: e(c, { variant: "contained", onClick: () => {
P(!b);
}, children: b ? "Hide advanced options" : "Show advanced options" }) }), b ? s("div", { children: [e(E, { variant: "h6", children: "Advanced options" }), e(H, { children: Object.entries({
single: "Single",
complete: "Complete"
}).map(([t, r]) => e(V, { control: e(N, { checked: M === t, onChange: () => {
a(t);
} }), label: r }, t)) }), s("div", { style: { marginTop: 20 }, children: [e(E, { children: "This procedure samples the data at each 'pixel' across the visible by default" }), e(L, { label: "Samples per pixel (>1 for denser sampling, between 0-1 for sparser sampling)", variant: "outlined", size: "small", value: C, onChange: (t) => {
w(t.target.value);
} })] })] }) : null, S ? e("div", {}) : k ? e(R.LoadingEllipses, { variant: "h6", title: "Generating score matrix" }) : y ? e(R.ErrorMessage, { error: y }) : null] }), s("div", { children: [e(E, { variant: "subtitle2", gutterBottom: !0, style: { marginTop: "16px" }, children: "Clustering Results:" }), e(L, { multiline: !0, fullWidth: !0, variant: "outlined", placeholder: "Paste results from Rscript here (sequence of numbers, one per line, specifying the new ordering)", rows: 10, value: g, onChange: (t) => {
v(t.target.value);
}, slotProps: {
input: {
classes: {
input: h.textAreaFont
}
}
} })] })] })] }), s(I, { children: [e(c, { variant: "contained", onClick: () => {
const { sourcesWithoutLayout: t } = n;
if (t)
try {
n.setLayout(g.split(`
`).map((r) => r.trim()).filter((r) => !!r).map((r) => +r).map((r) => {
const p = t[r - 1];
if (!p)
throw new Error(`out of bounds at ${r}`);
return p;
}));
} catch (r) {
console.error(r), u.getSession(n).notifyError(`${r}`, r);
}
l();
}, children: "Apply clustering" }), e(c, { variant: "contained", color: "secondary", onClick: () => {
l();
}, children: "Cancel" })] })] });
});
function $({ activeMode: n, setActiveMode: l }) {
return e("div", { children: e(H, { children: Object.entries({
auto: e("div", { children: "Run in-app clustering (slower, particularly for large numbers of samples, uses JS implementation of hclust)" }),
manual: e("div", { children: "Download R script to run clustering (faster, uses R implementation of hclust)" })
}).map(([o, h]) => e(V, { control: e(N, { checked: n === o, onChange: () => {
l(o);
} }), label: h }, o)) }) });
}
const ie = D(function({ model: n, handleClose: l }) {
const [o, h] = i("auto");
return e(R.Dialog, { open: !0, title: "Cluster by score", maxWidth: "xl", onClose: (g, v) => {
v !== "backdropClick" && l();
}, children: o === "auto" ? e(X, { model: n, handleClose: l, children: e($, { activeMode: o, setActiveMode: h }) }) : e(Z, { model: n, handleClose: l, children: e($, { activeMode: o, setActiveMode: h }) }) });
});
export {
ie as default
};
//# sourceMappingURL=WiggleClusterDialog-D_xrwA7d.js.map