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