taxonium-component
Version:
React component for exploring large phylogenetic trees in the browser
105 lines (104 loc) • 4.34 kB
JavaScript
import { jsx as t, jsxs as b } from "react/jsx-runtime";
import { useState as u, useEffect as O } from "react";
import { U as T, u as E, s as D, o as I, m as j, a as w, D as G, c as _, F as z, T as B, d as H, B as x, bu as P, aN as W, aM as U } from "./JBrowsePanel-BNE3gNW1.js";
import { F as R } from "./FormControlLabel-CfHqydvH.js";
import { C as $ } from "./Checkbox-D7_LksK2.js";
var f = {}, L;
function V() {
if (L) return f;
L = 1, Object.defineProperty(f, "__esModule", { value: !0 }), f.formatFastaLines = s, f.formatSeqFasta = a;
function s(n) {
return n.replaceAll(/(.{1,80})/g, `$1
`).trimEnd();
}
function a(n) {
return n.map((o) => `>${o.header}
${s(o.seq)}`).join(`
`);
}
return f;
}
var J = V();
const K = T(/* @__PURE__ */ t("path", {
d: "M19 9h-4V3H9v6H5l7 7zM5 18v2h14v-2z"
}), "GetApp");
async function Q(s, a) {
const n = E.getSession(s), { leftOffset: o, rightOffset: m } = s;
if (!o || !m)
throw new Error("no offsets on model to use for range");
if (new Set(a.map((C) => C.assemblyName)).size > 1)
throw new Error("not able to fetch sequences from multiple assemblies currently");
const { rpcManager: y, assemblyManager: c } = n, p = o.assemblyName || m.assemblyName || "", g = c.get(p);
if (!g)
throw new Error(`assembly ${p} not found`);
const h = D.getConf(g, ["sequence", "adapter"]), l = "getSequence";
return y.call(l, "CoreGetFeatures", {
adapterConfig: h,
regions: a,
sessionId: l
});
}
const X = j()({
dialogContent: {
width: "80em"
},
textAreaFont: {
fontFamily: "Courier New"
},
ml: {
marginLeft: 10
}
}), oe = I(function({ model: s, handleClose: a }) {
const { classes: n } = X(), [o, m] = u(), [d, y] = u(), [c, p] = u(!1), [g, h] = u(!1), [l, C] = u(!1), { leftOffset: A, rightOffset: N } = s, v = d === void 0;
O(() => {
const r = new AbortController();
return (async () => {
try {
const e = s.getSelectedRegions(A, N);
if (e.length === 0)
throw new Error("Selected region is out of bounds");
y(await Q(s, e));
} catch (e) {
console.error(e), m(e);
}
})(), () => {
r.abort();
};
}, [s, A, N]);
const i = d ? J.formatSeqFasta(d.map((r) => {
let e = r.get("seq");
const M = r.get("refName"), q = r.get("start") + 1, F = r.get("end"), k = `${M}:${q}-${F}`;
if ((e == null ? void 0 : e.length) !== F - q + 1)
throw new Error(`${k} returned ${e.length.toLocaleString()} bases, but should have returned ${(F - q).toLocaleString()}`);
return c && (e = E.reverse(e)), l && (e = E.complement(e)), {
header: k + (c ? "-rev" : "") + (l ? "-comp" : ""),
seq: e
};
})) : "", S = i ? i.length > 1e6 : !1;
return b(w.Dialog, { maxWidth: "xl", open: !0, onClose: () => {
a(), s.setOffsets();
}, title: "Reference sequence", children: [b(G, { children: [o ? t(w.ErrorMessage, { error: o }) : v ? t(w.LoadingEllipses, { message: "Retrieving sequences" }) : null, t(_, { "data-testid": "rubberband-sequence", variant: "outlined", multiline: !0, minRows: 5, maxRows: 10, disabled: S, className: n.dialogContent, fullWidth: !0, value: S ? "Reference sequence too large to display, use the download FASTA button" : i, slotProps: {
input: {
readOnly: !0,
classes: {
input: n.textAreaFont
}
}
} }), b(z, { children: [t(R, { control: t($, { value: c, onChange: (r) => {
p(r.target.checked);
} }), label: "Reverse sequence" }), t(R, { control: t($, { value: l, onChange: (r) => {
C(r.target.checked);
} }), label: "Complement sequence" })] }), t(B, { style: { margin: 10 }, children: 'Note: Check both boxes for the "reverse complement"' })] }), b(H, { children: [t(x, { onClick: () => {
W(i), h(!0), setTimeout(() => {
h(!1);
}, 500);
}, disabled: v || !!o || S, color: "primary", startIcon: t(P, {}), children: g ? "Copied" : "Copy to clipboard" }), t(x, { onClick: () => {
U.saveAs(new Blob([i || ""], {
type: "text/x-fasta;charset=utf-8"
}), "jbrowse_ref_seq.fa");
}, disabled: v || !!o, color: "primary", startIcon: t(K, {}), children: "Download FASTA" }), t(x, { onClick: a, variant: "contained", children: "Close" })] })] });
});
export {
oe as default
};
//# sourceMappingURL=GetSequenceDialog-DE1yIJwk.js.map