UNPKG

@jbrowse/plugin-wiggle

Version:

JBrowse 2 wiggle adapters, tracks, etc.

88 lines (87 loc) 4.46 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useState } from 'react'; import { getSession, isElectron, isSessionModelWithWidgets, isSessionWithAddTracks, } from '@jbrowse/core/util'; import { storeBlobLocation } from '@jbrowse/core/util/tracks'; import { Button, Paper, TextField } from '@mui/material'; import { observer } from 'mobx-react'; import { makeStyles } from 'tss-react/mui'; const useStyles = makeStyles()(theme => ({ paper: { margin: theme.spacing(), padding: theme.spacing(), }, submit: { marginTop: 25, marginBottom: 100, display: 'block', }, })); function makeFileLocation(file) { return isElectron ? { localPath: window.require('electron').webUtils.getPathForFile(file), locationType: 'LocalPathLocation', } : storeBlobLocation({ blob: file }); } function doSubmit({ trackName, val, model, }) { var _a; const session = 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 (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 (isSessionModelWithWidgets(session)) { session.hideWidget(model); } } catch (e) { console.error(e); session.notifyError(`${e}`, e); } } const MultiWiggleAddTrackWorkflow = observer(function ({ model, }) { const { classes } = useStyles(); const [val, setVal] = useState(''); const [trackName, setTrackName] = useState(`MultiWiggle${+Date.now()}`); return (_jsxs(Paper, { className: classes.paper, children: [_jsxs("ul", { children: [_jsx("li", { children: "Enter list of URLs for bigwig files in the textbox" }), _jsx("li", { children: "Or, use the button below the text box to select files from your computer" })] }), _jsx(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); } }), _jsxs(Button, { variant: "outlined", component: "label", children: ["Choose Files from your computer", _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)); } })] }), _jsx(TextField, { value: trackName, helperText: "Track name", onChange: event => { setTrackName(event.target.value); } }), _jsx(Button, { variant: "contained", className: classes.submit, onClick: () => { doSubmit({ trackName, val, model }); }, children: "Submit" }), _jsx("p", { children: "Additional notes: " }), _jsxs("ul", { children: [_jsxs("li", { children: ["The list of bigwig files in the text box can be a list of URLs, or a list of elements like", ' ', _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"] }), _jsx("li", { children: "Adding local files will update the textbox with JSON contents that are ready to submit with the \"Submit\" button" })] })] })); }); export default MultiWiggleAddTrackWorkflow;