taxonium-component
Version:
React component for exploring large phylogenetic trees in the browser
157 lines (156 loc) • 7.35 kB
JavaScript
import { jsxs as r, Fragment as L, jsx as e } from "react/jsx-runtime";
import { useState as a, useEffect as _ } from "react";
import { o as j, D as $, B as d, R as E, a as A, d as O, u as h, t as P, j as G, m as J, P as N, a$ as B, b0 as U, T, c as K } from "./JBrowsePanel-uJIA-L6s.js";
import { R as I } from "./RadioGroup-CXR2ISZ8.js";
import { F as V } from "./FormControlLabel-CwjOxa71.js";
import { R as W } from "./Radio-D7as17u0.js";
const Q = j(function({ model: n, children: s, handleClose: i }) {
const [p, g] = a(""), [f, c] = a(!1), [m, y] = a(), [v, x] = a("");
return r(L, { children: [r($, { children: [s, r("div", { children: [f ? r("div", { style: { padding: 50 }, children: [e("span", { children: p || "Loading..." }), e(d, { onClick: () => {
E.stopStopToken(v);
}, children: "Stop" })] }) : null, m ? e(A.ErrorMessage, { error: m }) : null] })] }), r(O, { children: [e(d, { variant: "contained", disabled: f, onClick: async () => {
try {
y(void 0), g("Initializing"), c(!0);
const l = h.getContainingView(n);
if (!l.initialized)
return;
const { rpcManager: C } = h.getSession(n), { sourcesWithoutLayout: w, minorAlleleFrequencyFilter: k, lengthCutoffFilter: R, adapterConfig: b } = n;
if (w) {
const M = P.getRpcSessionId(n), t = E.createStopToken();
x(t);
const o = await C.call(M, "MultiVariantClusterGenotypeMatrix", {
regions: l.dynamicBlocks.contentBlocks,
sources: w,
minorAlleleFrequencyFilter: k,
lengthCutoffFilter: R,
sessionId: M,
adapterConfig: b,
stopToken: t,
statusCallback: (u) => {
g(u);
}
});
n.setLayout(o.order.map((u) => {
const S = w[u];
if (!S)
throw new Error(`out of bounds at ${u}`);
return S;
}));
}
i();
} catch (l) {
!h.isAbortException(l) && G(n) && (console.error(l), y(l));
} finally {
c(!1), g(""), x("");
}
}, children: "Run clustering" }), e(d, { variant: "contained", color: "secondary", onClick: () => {
i(), v && E.stopStopToken(v);
}, children: "Cancel" })] })] });
}), X = J()((n) => ({
textAreaFont: {
fontFamily: "Courier New"
},
mgap: {
display: "flex",
flexDirection: "column",
gap: n.spacing(4)
}
})), Y = j(function({ model: n, handleClose: s, children: i }) {
const { classes: p } = X(), [g, f] = a(""), [c, m] = a(), [y, v] = a(), [x, l] = a(!1), [C, w] = h.useLocalStorage("cluster-showAdvanced", !1), [k, R] = a("single");
_(() => {
(async () => {
try {
v(void 0), m(void 0), l(!0);
const t = h.getContainingView(n);
if (!t.initialized)
return;
const { rpcManager: o } = h.getSession(n), { sourcesWithoutLayout: u, minorAlleleFrequencyFilter: S, lengthCutoffFilter: q, adapterConfig: z } = n, F = P.getRpcSessionId(n), H = await o.call(F, "MultiVariantGetGenotypeMatrix", {
regions: t.dynamicBlocks.contentBlocks,
sources: u,
minorAlleleFrequencyFilter: S,
lengthCutoffFilter: q,
sessionId: F,
adapterConfig: z
});
m(H);
} catch (t) {
!h.isAbortException(t) && G(n) && (console.error(t), v(t));
} finally {
l(!1);
}
})();
}, [n]);
const b = c ? `inputMatrix<-matrix(c(${Object.values(c).map((t) => t.join(",")).join(`,
`)}
),nrow=${Object.values(c).length},byrow=TRUE)
rownames(inputMatrix)<-c(${Object.keys(c).map((t) => `'${t}'`).join(",")})
resultClusters<-hclust(dist(inputMatrix), method='${k}')
cat(resultClusters$order,sep='\\n')` : void 0, M = c ? Object.entries(c).map(([t, o]) => [t, ...o].join(" ")).join(`
`) : void 0;
return r(L, { children: [r($, { children: [i, r(N, { style: { padding: 16 }, children: [r("div", { children: [r("div", { style: {
display: "flex",
gap: "8px",
flexWrap: "wrap",
marginBottom: "16px"
}, children: [e(d, { variant: "contained", onClick: () => {
B.saveAs(new Blob([b || ""], {
type: "text/plain;charset=utf-8"
}), "cluster.R");
}, children: "Download Rscript" }), " ", "or", " ", e(d, { variant: "contained", onClick: () => {
U(b || "");
}, children: "Copy Rscript to clipboard" }), " ", "or", " ", e(d, { variant: "contained", onClick: () => {
B.saveAs(new Blob([M || ""], {
type: "text/plain;charset=utf-8"
}), "genotypes.tsv");
}, children: "Download TSV" }), e("div", { children: e(d, { variant: "contained", onClick: () => {
w(!C);
}, children: C ? "Hide advanced options" : "Show advanced options" }) })] }), C ? r("div", { children: [e(T, { variant: "h6", children: "Advanced options" }), e(I, { children: Object.entries({
single: "Single",
complete: "Complete"
}).map(([t, o]) => e(V, { control: e(W, { checked: k === t, onChange: () => {
R(t);
} }), label: o }, t)) })] }) : null, b ? e("div", {}) : x ? e(A.LoadingEllipses, { variant: "h6", title: "Generating genotype matrix" }) : y ? e(A.ErrorMessage, { error: y }) : null] }), r("div", { children: [e(T, { variant: "subtitle2", gutterBottom: !0, style: { marginTop: "16px" }, children: "Clustering Results:" }), e(K, { 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) => {
f(t.target.value);
}, slotProps: {
input: {
classes: {
input: p.textAreaFont
}
}
} })] })] })] }), r(O, { children: [e(d, { variant: "contained", onClick: () => {
const { sourcesWithoutLayout: t } = n;
if (t)
try {
n.setLayout(g.split(`
`).map((o) => o.trim()).filter((o) => !!o).map((o) => +o).map((o) => {
const u = t[o - 1];
if (!u)
throw new Error(`out of bounds at ${o}`);
return u;
}));
} catch (o) {
console.error(o), h.getSession(n).notifyError(`${o}`, o);
}
s();
}, children: "Apply clustering" }), e(d, { variant: "contained", color: "secondary", onClick: () => {
s();
}, children: "Cancel" })] })] });
});
function D({ activeMode: n, setActiveMode: s }) {
return r("div", { children: [e(T, { style: { marginBottom: 30 }, children: "This procedure will cluster the visible genotype data using hierarchical clustering" }), e(I, { 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(([i, p]) => e(V, { control: e(W, { checked: n === i, onChange: () => {
s(i);
} }), label: p }, i)) })] });
}
const ie = j(function({ model: n, handleClose: s }) {
const [i, p] = a("auto");
return e(A.Dialog, { open: !0, title: "Cluster by genotype", onClose: (g, f) => {
f !== "backdropClick" && s();
}, children: i === "auto" ? e(Q, { model: n, handleClose: s, children: e(D, { activeMode: i, setActiveMode: p }) }) : e(Y, { model: n, handleClose: s, children: e(D, { activeMode: i, setActiveMode: p }) }) });
});
export {
ie as default
};
//# sourceMappingURL=ClusterDialog-Dw2CwgW1.js.map