@jbrowse/plugin-wiggle
Version:
JBrowse 2 wiggle adapters, tracks, etc.
90 lines (89 loc) • 4.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const util_1 = require("@jbrowse/core/util");
const tracks_1 = require("@jbrowse/core/util/tracks");
const material_1 = require("@mui/material");
const mobx_react_1 = require("mobx-react");
const mui_1 = require("tss-react/mui");
const useStyles = (0, mui_1.makeStyles)()(theme => ({
paper: {
margin: theme.spacing(),
padding: theme.spacing(),
},
submit: {
marginTop: 25,
marginBottom: 100,
display: 'block',
},
}));
function makeFileLocation(file) {
return util_1.isElectron
? {
localPath: window.require('electron').webUtils.getPathForFile(file),
locationType: 'LocalPathLocation',
}
: (0, tracks_1.storeBlobLocation)({ blob: file });
}
function doSubmit({ trackName, val, model, }) {
var _a;
const session = (0, util_1.getSession)(model);
try {
const trackId = [
`${trackName.toLowerCase().replaceAll(' ', '_')}-${Date.now()}`,
session.adminMode ? '' : '-sessionTrack',
].join('');
let bigWigs;
try {
bigWigs = JSON.parse(val);
}
catch (e) {
bigWigs = val
.split(/\n|\r\n|\r/)
.map(f => f.trim())
.filter(f => !!f);
}
const obj = typeof bigWigs[0] === 'string' ? { bigWigs } : { subadapters: bigWigs };
if ((0, util_1.isSessionWithAddTracks)(session)) {
session.addTrackConf({
trackId,
type: 'MultiQuantitativeTrack',
name: trackName,
assemblyNames: [model.assembly],
adapter: {
type: 'MultiWiggleAdapter',
...obj,
},
});
(_a = model.view) === null || _a === void 0 ? void 0 : _a.showTrack(trackId);
}
model.clearData();
if ((0, util_1.isSessionModelWithWidgets)(session)) {
session.hideWidget(model);
}
}
catch (e) {
console.error(e);
session.notifyError(`${e}`, e);
}
}
const MultiWiggleAddTrackWorkflow = (0, mobx_react_1.observer)(function ({ model, }) {
const { classes } = useStyles();
const [val, setVal] = (0, react_1.useState)('');
const [trackName, setTrackName] = (0, react_1.useState)(`MultiWiggle${+Date.now()}`);
return ((0, jsx_runtime_1.jsxs)(material_1.Paper, { className: classes.paper, children: [(0, jsx_runtime_1.jsxs)("ul", { children: [(0, jsx_runtime_1.jsx)("li", { children: "Enter list of URLs for bigwig files in the textbox" }), (0, jsx_runtime_1.jsx)("li", { children: "Or, use the button below the text box to select files from your computer" })] }), (0, jsx_runtime_1.jsx)(material_1.TextField, { multiline: true, fullWidth: true, rows: 10, value: val, placeholder: "Paste list of URLs here, or use file selector below", variant: "outlined", onChange: event => {
setVal(event.target.value);
} }), (0, jsx_runtime_1.jsxs)(material_1.Button, { variant: "outlined", component: "label", children: ["Choose Files from your computer", (0, jsx_runtime_1.jsx)("input", { type: "file", hidden: true, multiple: true, onChange: ({ target }) => {
setVal(JSON.stringify([...(target.files || [])].map(file => ({
type: 'BigWigAdapter',
bigWigLocation: makeFileLocation(file),
source: file.name,
})), null, 2));
} })] }), (0, jsx_runtime_1.jsx)(material_1.TextField, { value: trackName, helperText: "Track name", onChange: event => {
setTrackName(event.target.value);
} }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", className: classes.submit, onClick: () => {
doSubmit({ trackName, val, model });
}, children: "Submit" }), (0, jsx_runtime_1.jsx)("p", { children: "Additional notes: " }), (0, jsx_runtime_1.jsxs)("ul", { children: [(0, jsx_runtime_1.jsxs)("li", { children: ["The list of bigwig files in the text box can be a list of URLs, or a list of elements like", ' ', (0, jsx_runtime_1.jsx)("code", { children: `[{"type":"BigWigAdapter","bigWigLocation":{"uri":"http://host/file.bw"}, "color":"green","source":"name for subtrack"}]` }), ' ', "to apply e.g. the color attribute to the view"] }), (0, jsx_runtime_1.jsx)("li", { children: "Adding local files will update the textbox with JSON contents that are ready to submit with the \"Submit\" button" })] })] }));
});
exports.default = MultiWiggleAddTrackWorkflow;