@jbrowse/plugin-wiggle
Version:
JBrowse 2 wiggle adapters, tracks, etc.
78 lines (77 loc) • 5.43 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useState } from 'react';
import { ErrorMessage } from '@jbrowse/core/ui';
import { getContainingView, getSession, isAbortException, useLocalStorage, } from '@jbrowse/core/util';
import { createStopToken, stopStopToken } from '@jbrowse/core/util/stopToken';
import { getRpcSessionId } from '@jbrowse/core/util/tracks';
import { Button, DialogActions, DialogContent, TextField, Typography, } from '@mui/material';
import { observer } from 'mobx-react';
import { isAlive } from 'mobx-state-tree';
const WiggleClusterDialogAuto = observer(function ({ model, children, handleClose, }) {
const [progress, setProgress] = useState('');
const [error, setError] = useState();
const [loading, setLoading] = useState(false);
const [stopToken, setStopToken] = useState('');
const [showAdvanced, setShowAdvanced] = useState(false);
const [samplesPerPixel, setSamplesPerPixel] = useLocalStorage('cluster-samplesPerPixel', '1');
return (_jsxs(_Fragment, { children: [_jsxs(DialogContent, { children: [children, _jsxs("div", { style: { marginTop: 50 }, children: [_jsx(Button, { variant: "contained", onClick: () => {
setShowAdvanced(!showAdvanced);
}, children: showAdvanced ? 'Hide advanced options' : 'Show advanced options' }), showAdvanced ? (_jsxs("div", { style: { marginTop: 20 }, children: [_jsx(Typography, { children: "This procedure samples the data at each 'pixel' across the visible by default" }), _jsx(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] }), _jsxs("div", { children: [loading ? (_jsxs("div", { style: { padding: 50 }, children: [_jsx("span", { children: progress || 'Loading...' }), _jsx(Button, { onClick: () => {
stopStopToken(stopToken);
}, children: "Stop" })] })) : null, error ? _jsx(ErrorMessage, { error: error }) : null] })] }), _jsxs(DialogActions, { children: [_jsx(Button, { variant: "contained", disabled: loading, onClick: async () => {
try {
setError(undefined);
setProgress('Initializing');
setLoading(true);
const view = getContainingView(model);
if (!view.initialized) {
return;
}
const { rpcManager } = getSession(model);
const { sourcesWithoutLayout, adapterConfig } = model;
if (sourcesWithoutLayout) {
const sessionId = getRpcSessionId(model);
const stopToken = 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 (!isAbortException(e) && isAlive(model)) {
console.error(e);
setError(e);
}
}
finally {
setLoading(false);
setProgress('');
setStopToken('');
}
}, children: "Run clustering" }), _jsx(Button, { variant: "contained", color: "secondary", onClick: () => {
handleClose();
if (stopToken) {
stopStopToken(stopToken);
}
}, children: "Cancel" })] })] }));
});
export default WiggleClusterDialogAuto;