-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to launch breakpoint split view from alignments feature d…
…etails (#4215)
- Loading branch information
Showing
30 changed files
with
1,245 additions
and
723 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
plugins/alignments/src/AlignmentsFeatureDetail/BreakendOptionDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import React, { useState } from 'react' | ||
import { observer } from 'mobx-react' | ||
import { | ||
Button, | ||
Checkbox, | ||
DialogActions, | ||
DialogContent, | ||
FormControlLabel, | ||
} from '@mui/material' | ||
import { makeStyles } from 'tss-react/mui' | ||
import { getSession } from '@jbrowse/core/util' | ||
import { Dialog } from '@jbrowse/core/ui' | ||
import { ViewType } from '@jbrowse/core/pluggableElementTypes' | ||
|
||
// locals | ||
import { AlignmentFeatureWidgetModel } from './stateModelFactory' | ||
import { getBreakpointSplitView } from './launchBreakpointSplitView' | ||
import { getSnapshot } from 'mobx-state-tree' | ||
import { ReducedFeature } from './getSAFeatures' | ||
|
||
const useStyles = makeStyles()({ | ||
block: { | ||
display: 'block', | ||
}, | ||
}) | ||
|
||
interface Track { | ||
id: string | ||
displays: { id: string; [key: string]: unknown }[] | ||
[key: string]: unknown | ||
} | ||
|
||
function stripIds(arr: Track[]) { | ||
return arr.map(({ id, displays, ...rest }) => ({ | ||
...rest, | ||
displays: displays.map(({ id, ...rest }) => rest), | ||
})) | ||
} | ||
|
||
function Checkbox2({ | ||
checked, | ||
label, | ||
onChange, | ||
}: { | ||
checked: boolean | ||
label: string | ||
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void | ||
}) { | ||
const { classes } = useStyles() | ||
return ( | ||
<FormControlLabel | ||
className={classes.block} | ||
control={<Checkbox checked={checked} onChange={onChange} />} | ||
label={label} | ||
/> | ||
) | ||
} | ||
|
||
const BreakendOptionDialog = observer(function ({ | ||
model, | ||
handleClose, | ||
f1, | ||
f2, | ||
}: { | ||
model: AlignmentFeatureWidgetModel | ||
handleClose: () => void | ||
f1: ReducedFeature | ||
f2: ReducedFeature | ||
viewType: ViewType | ||
}) { | ||
const [copyTracks, setCopyTracks] = useState(true) | ||
const [mirror, setMirror] = useState(true) | ||
|
||
return ( | ||
<Dialog open onClose={handleClose} title="Breakpoint split view options"> | ||
<DialogContent> | ||
<Checkbox2 | ||
checked={copyTracks} | ||
onChange={event => setCopyTracks(event.target.checked)} | ||
label="Copy tracks into the new view" | ||
/> | ||
<Checkbox2 | ||
checked={mirror} | ||
onChange={event => setMirror(event.target.checked)} | ||
label="Mirror tracks vertically in vertically stacked view" | ||
/> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button | ||
onClick={() => { | ||
const { view } = model | ||
const session = getSession(model) | ||
try { | ||
const viewSnapshot = getBreakpointSplitView({ view, f1, f2 }) | ||
const [view1, view2] = viewSnapshot.views | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion | ||
const viewTracks = getSnapshot(view.tracks) as Track[] | ||
|
||
session.addView('BreakpointSplitView', { | ||
...viewSnapshot, | ||
views: [ | ||
{ | ||
...view1, | ||
tracks: stripIds(viewTracks), | ||
offsetPx: view1.offsetPx - view.width / 2 + 100, | ||
}, | ||
{ | ||
...view2, | ||
tracks: stripIds( | ||
mirror ? [...viewTracks].reverse() : viewTracks, | ||
), | ||
offsetPx: view2.offsetPx - view.width / 2 + 100, | ||
}, | ||
], | ||
}) | ||
} catch (e) { | ||
console.error(e) | ||
session.notify(`${e}`) | ||
} | ||
handleClose() | ||
}} | ||
variant="contained" | ||
color="primary" | ||
autoFocus | ||
> | ||
OK | ||
</Button> | ||
<Button | ||
onClick={() => handleClose()} | ||
color="secondary" | ||
variant="contained" | ||
> | ||
Cancel | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
) | ||
}) | ||
|
||
export default BreakendOptionDialog |
File renamed without changes.
31 changes: 31 additions & 0 deletions
31
plugins/alignments/src/AlignmentsFeatureDetail/Formatter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React, { useState } from 'react' | ||
import copy from 'copy-to-clipboard' | ||
|
||
// this 'show more...' used specifically as a formatter on alignments feature | ||
// details because long SEQ or CRAM files, even a single div full of a ton of | ||
// data from a long read, can slow down the rest of the app | ||
export default function Formatter({ value }: { value: unknown }) { | ||
const [show, setShow] = useState(false) | ||
const [copied, setCopied] = useState(false) | ||
const display = String(value) | ||
return display.length > 100 ? ( | ||
<> | ||
<button | ||
type="button" | ||
onClick={() => { | ||
copy(display) | ||
setCopied(true) | ||
setTimeout(() => setCopied(false), 700) | ||
}} | ||
> | ||
{copied ? 'Copied to clipboard' : 'Copy'} | ||
</button> | ||
<button type="button" onClick={() => setShow(val => !val)}> | ||
{show ? 'Show less' : 'Show more'} | ||
</button> | ||
<div>{show ? display : `${display.slice(0, 100)}...`}</div> | ||
</> | ||
) : ( | ||
<div>{display}</div> | ||
) | ||
} |
Oops, something went wrong.