@jbrowse/plugin-wiggle
Version:
JBrowse 2 wiggle adapters, tracks, etc.
80 lines (79 loc) • 5.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const ui_1 = require("@jbrowse/core/ui");
const util_1 = require("@jbrowse/core/util");
const stopToken_1 = require("@jbrowse/core/util/stopToken");
const tracks_1 = require("@jbrowse/core/util/tracks");
const material_1 = require("@mui/material");
const mobx_react_1 = require("mobx-react");
const mobx_state_tree_1 = require("mobx-state-tree");
const WiggleClusterDialogAuto = (0, mobx_react_1.observer)(function ({ model, children, handleClose, }) {
const [progress, setProgress] = (0, react_1.useState)('');
const [error, setError] = (0, react_1.useState)();
const [loading, setLoading] = (0, react_1.useState)(false);
const [stopToken, setStopToken] = (0, react_1.useState)('');
const [showAdvanced, setShowAdvanced] = (0, react_1.useState)(false);
const [samplesPerPixel, setSamplesPerPixel] = (0, util_1.useLocalStorage)('cluster-samplesPerPixel', '1');
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(material_1.DialogContent, { children: [children, (0, jsx_runtime_1.jsxs)("div", { style: { marginTop: 50 }, children: [(0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", onClick: () => {
setShowAdvanced(!showAdvanced);
}, children: showAdvanced ? 'Hide advanced options' : 'Show advanced options' }), showAdvanced ? ((0, jsx_runtime_1.jsxs)("div", { style: { marginTop: 20 }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { children: "This procedure samples the data at each 'pixel' across the visible by default" }), (0, jsx_runtime_1.jsx)(material_1.TextField, { label: "Samples per pixel (>1 for denser sampling, between 0-1 for sparser sampling)", variant: "outlined", size: "small", value: samplesPerPixel, onChange: event => {
setSamplesPerPixel(event.target.value);
} })] })) : null] }), (0, jsx_runtime_1.jsxs)("div", { children: [loading ? ((0, jsx_runtime_1.jsxs)("div", { style: { padding: 50 }, children: [(0, jsx_runtime_1.jsx)("span", { children: progress || 'Loading...' }), (0, jsx_runtime_1.jsx)(material_1.Button, { onClick: () => {
(0, stopToken_1.stopStopToken)(stopToken);
}, children: "Stop" })] })) : null, error ? (0, jsx_runtime_1.jsx)(ui_1.ErrorMessage, { error: error }) : null] })] }), (0, jsx_runtime_1.jsxs)(material_1.DialogActions, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", disabled: loading, onClick: async () => {
try {
setError(undefined);
setProgress('Initializing');
setLoading(true);
const view = (0, util_1.getContainingView)(model);
if (!view.initialized) {
return;
}
const { rpcManager } = (0, util_1.getSession)(model);
const { sourcesWithoutLayout, adapterConfig } = model;
if (sourcesWithoutLayout) {
const sessionId = (0, tracks_1.getRpcSessionId)(model);
const stopToken = (0, stopToken_1.createStopToken)();
setStopToken(stopToken);
const ret = (await rpcManager.call(sessionId, 'MultiWiggleClusterScoreMatrix', {
regions: view.dynamicBlocks.contentBlocks,
sources: sourcesWithoutLayout,
sessionId,
adapterConfig,
stopToken,
bpPerPx: view.bpPerPx / +samplesPerPixel,
statusCallback: (arg) => {
setProgress(arg);
},
}));
model.setLayout(ret.order.map(idx => {
const ret = sourcesWithoutLayout[idx];
if (!ret) {
throw new Error(`out of bounds at ${idx}`);
}
return ret;
}));
}
handleClose();
}
catch (e) {
if (!(0, util_1.isAbortException)(e) && (0, mobx_state_tree_1.isAlive)(model)) {
console.error(e);
setError(e);
}
}
finally {
setLoading(false);
setProgress('');
setStopToken('');
}
}, children: "Run clustering" }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", color: "secondary", onClick: () => {
handleClose();
if (stopToken) {
(0, stopToken_1.stopStopToken)(stopToken);
}
}, children: "Cancel" })] })] }));
});
exports.default = WiggleClusterDialogAuto;