Skip to content

Commit

Permalink
Volatile-ize spreadsheet view
Browse files Browse the repository at this point in the history
Remove

[skip ci] Volatile

[skip ci] Parse out INFO field

[skip ci] Misc

Misc

Restyling

Refactoring

More misc

Misc

Misc

Misc

Misc

New

Refname renaming fix for breakpoint split view

Breakpoint split view

Misc

[skip ci] Refactors

Use 7.0.0

Updates

Misc

Misc

Misc

SV inspector working
  • Loading branch information
cmdcolin committed Sep 19, 2024
1 parent 03e1d91 commit 5a0b3f7
Show file tree
Hide file tree
Showing 68 changed files with 2,469 additions and 5,066 deletions.
6 changes: 6 additions & 0 deletions packages/core/assemblyManager/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ export default function assemblyFactory(
self.refNameAliases[refName] || self.lowerCaseRefNameAliases[refName]
)
},
/**
* #method
*/
getCanonicalRefNameOrDefault(refName: string) {
return this.getCanonicalRefName(refName) || refName
},
/**
* #method
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/core/configuration/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
* will be sent to each of the slotNames
*/
export function readConfObject<CONFMODEL extends AnyConfigurationModel>(
confObject: CONFMODEL,
confObject: CONFMODEL | Record<string, unknown>,
slotPath?:
| ConfigurationSlotName<ConfigurationSchemaForModel<CONFMODEL>>
| string[],
Expand Down
7 changes: 5 additions & 2 deletions packages/core/ui/ResizeHandle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ const useStyles = makeStyles()({
},
flexbox_verticalHandle: {
cursor: 'col-resize',
alignSelf: 'stretch', // the height: 100% is actually unable to function inside flexbox
alignSelf: 'stretch',
// uses alignSelf:stretch with flexbox as the height: 100% is actually
// unable to function inside flexbox
},
flexbox_horizontalHandle: {
cursor: 'row-resize',
alignSelf: 'stretch', // similar to above
alignSelf: 'stretch',
// similar to above
},
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { getSession, Feature, Region } from '@jbrowse/core/util'
import {
getSession,
Feature,
Region,
AbstractSessionModel,
} from '@jbrowse/core/util'
import ViewType from '@jbrowse/core/pluggableElementTypes/ViewType'
import { parseBreakend } from '@gmod/vcf'
import { IStateTreeNode } from 'mobx-state-tree'
Expand Down Expand Up @@ -103,15 +108,12 @@ export default class BreakpointSplitViewType extends ViewType {
featureData: undefined as unknown,
}
}

snapshotFromBreakendFeature(
async snapshotFromBreakendFeature(
feature: Feature,
view: { displayedRegions: Region[] } & IStateTreeNode,
assemblyName: string,
session: AbstractSessionModel,
) {
const session = getSession(view)
const bpPerPx = 10
const { assemblyName } = view.displayedRegions[0]!

const { assemblyManager } = session
const assembly = assemblyManager.get(assemblyName)
if (!assembly) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,15 @@ const Breakends = observer(function ({
const [mouseoverElt, setMouseoverElt] = useState<string>()
const snap = getSnapshot(model)
useNextFrame(snap)
const assembly = assemblyManager.get(views[0]!.assemblyNames[0]!)

if (!assembly) {
return null
}
const asm = assemblyManager.get(views[0]!.assemblyNames[0]!)

let yoff = 0
if (ref.current) {
const rect = ref.current.getBoundingClientRect()
yoff = rect.top
}

return (
return asm ? (
<g
stroke="green"
strokeWidth={5}
Expand All @@ -71,8 +67,8 @@ const Breakends = observer(function ({
}
const f1origref = f1.get('refName')
const f2origref = f2.get('refName')
const f1ref = assembly.getCanonicalRefName(f1origref)
const f2ref = assembly.getCanonicalRefName(f2origref)
const f1ref = asm.getCanonicalRefName(f1origref)
const f2ref = asm.getCanonicalRefName(f2origref)
if (!f1ref || !f2ref) {
throw new Error(`unable to find ref for ${f1ref || f2ref}`)
}
Expand Down Expand Up @@ -140,7 +136,7 @@ const Breakends = observer(function ({
return ret
})}
</g>
)
) : null
})

export default Breakends
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,17 @@ const PairedFeatures = observer(function ({
const [mouseoverElt, setMouseoverElt] = useState<string>()
const snap = getSnapshot(model)
useNextFrame(snap)
const assembly = assemblyManager.get(views[0]!.assemblyNames[0]!)

if (!assembly) {
return null
}
const assembly = views[0]
? assemblyManager.get(views[0].assemblyNames[0]!)
: undefined

let yoff = 0
if (ref.current) {
const rect = ref.current.getBoundingClientRect()
yoff = rect.top
}

return (
return assembly ? (
<g
stroke="green"
strokeWidth={5}
Expand Down Expand Up @@ -121,7 +119,7 @@ const PairedFeatures = observer(function ({
return ret
})}
</g>
)
) : null
})

export default PairedFeatures
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ const Translocations = observer(function ({
const snap = getSnapshot(model)
useNextFrame(snap)

const assembly = assemblyManager.get(views[0]!.assemblyNames[0]!)
if (!assembly) {
return null
}

const assembly = views[0]
? assemblyManager.get(views[0].assemblyNames[0]!)
: undefined
let yOffset = 0
if (ref.current) {
const rect = ref.current.getBoundingClientRect()
Expand All @@ -64,10 +62,7 @@ const Translocations = observer(function ({
// just return null here note: would need to do processing of the INFO
// CHR2/END and see which view could contain those coordinates to really do
// it properly
if (views.length < 2) {
return null
}
return (
return !assembly || views.length < 2 ? null : (
<g
fill="none"
stroke="green"
Expand All @@ -86,19 +81,18 @@ const Translocations = observer(function ({
}

const info = f1.get('INFO')
const chr1 = f1.get('refName')
const chr2 = info.CHR2[0]
const f1ref = assembly.getCanonicalRefName(chr2) || chr2
const f2ref = assembly.getCanonicalRefName(chr1) || chr2
const end2 = info.END[0]
const res = info.STRANDS?.[0]?.split('') // not all files have STRANDS
const [myDirection, mateDirection] = res ?? ['.', '.']

const r = getPxFromCoordinate(views[level2]!, chr2, end2)
const r = getPxFromCoordinate(views[level2]!, f2ref, end2)
if (r) {
const c2: LayoutRecord = [r, 0, r + 1, 0]
const x1 = getPxFromCoordinate(
views[level1]!,
f1.get('refName'),
c1[LEFT],
)
const x1 = getPxFromCoordinate(views[level1]!, f1ref, c1[LEFT])
const x2 = r
const reversed1 = views[level1]!.pxToBp(x1).reversed
const reversed2 = views[level2]!.pxToBp(x2).reversed
Expand All @@ -118,7 +112,7 @@ const Translocations = observer(function ({
'L', // line to
x1,
y1,
'L', // line to as const
'L', // line to
x2,
y2,
'L', // line to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ export function heightFromSpecificLevel(
}

export function getPxFromCoordinate(view: LGV, refName: string, coord: number) {
return (view.bpToPx({ refName, coord })?.offsetPx || 0) - view.offsetPx
return (
(view.bpToPx({
refName,
coord,
})?.offsetPx || 0) - view.offsetPx
)
}

// get's the yposition of a layout record in a track
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const useStyles = makeStyles()(theme => ({
},
}))

const Slices = observer(({ model }: { model: CircularViewModel }) => {
const Slices = observer(function ({ model }: { model: CircularViewModel }) {
return (
<>
{model.staticSlices.map(slice => (
Expand All @@ -49,7 +49,11 @@ const Slices = observer(({ model }: { model: CircularViewModel }) => {
)
})

const CircularView = observer(({ model }: { model: CircularViewModel }) => {
const CircularView = observer(function ({
model,
}: {
model: CircularViewModel
}) {
const initialized =
!!model.displayedRegions.length &&
!!model.figureWidth &&
Expand Down
56 changes: 20 additions & 36 deletions plugins/circular-view/src/CircularView/components/Controls.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useState } from 'react'
import React, { lazy } from 'react'
import { observer } from 'mobx-react'
import { IconButton } from '@mui/material'
import { makeStyles } from 'tss-react/mui'
import JBrowseMenu from '@jbrowse/core/ui/Menu'
import CascadingMenuButton from '@jbrowse/core/ui/CascadingMenuButton'
import { getSession } from '@jbrowse/core/util'

// icons
import ZoomOutIcon from '@mui/icons-material/ZoomOut'
Expand All @@ -17,8 +18,9 @@ import { TrackSelector as TrackSelectorIcon } from '@jbrowse/core/ui/Icons'

// locals
import { CircularViewModel } from '../models/model'
import { getSession } from '@jbrowse/core/util'
import ExportSvgDialog from './ExportSvgDialog'

// lazies
const ExportSvgDialog = lazy(() => import('./ExportSvgDialog'))

const useStyles = makeStyles()(theme => ({
controls: {
Expand All @@ -32,7 +34,6 @@ const useStyles = makeStyles()(theme => ({

const Controls = observer(function ({ model }: { model: CircularViewModel }) {
const { classes } = useStyles()
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null)
return (
<div className={classes.controls}>
<IconButton
Expand Down Expand Up @@ -77,13 +78,22 @@ const Controls = observer(function ({ model }: { model: CircularViewModel }) {
{model.lockedFitToWindow ? <LockIcon /> : <LockOpenIcon />}
</IconButton>

<IconButton
onClick={event => {
setAnchorEl(event.currentTarget)
}}
<CascadingMenuButton
menuItems={[
{
label: 'Export SVG',
icon: PhotoCamera,
onClick: () => {
getSession(model).queueDialog(handleClose => [
ExportSvgDialog,
{ model, handleClose },
])
},
},
]}
>
<MoreVert />
</IconButton>
</CascadingMenuButton>

{model.hideTrackSelectorButton ? null : (
<IconButton
Expand All @@ -94,32 +104,6 @@ const Controls = observer(function ({ model }: { model: CircularViewModel }) {
<TrackSelectorIcon />
</IconButton>
)}

{anchorEl ? (
<JBrowseMenu
anchorEl={anchorEl}
menuItems={[
{
label: 'Export SVG',
icon: PhotoCamera,
onClick: () => {
getSession(model).queueDialog(handleClose => [
ExportSvgDialog,
{ model, handleClose },
])
},
},
]}
onMenuItemClick={(_event, callback) => {
callback()
setAnchorEl(null)
}}
open={Boolean(anchorEl)}
onClose={() => {
setAnchorEl(null)
}}
/>
) : null}
</div>
)
})
Expand Down
5 changes: 4 additions & 1 deletion plugins/circular-view/src/CircularView/models/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,10 @@ function stateModelFactory(pluginManager: PluginManager) {
/**
* #action
*/
addTrackConf(configuration: AnyConfigurationModel, initialSnapshot = {}) {
addTrackConf(
configuration: AnyConfigurationModel | Record<string, unknown>,
initialSnapshot = {},
) {
const { type } = configuration
const name = readConfObject(configuration, 'name')
const trackType = pluginManager.getTrackType(type)
Expand Down
12 changes: 1 addition & 11 deletions plugins/spreadsheet-view/src/LaunchSpreadsheetView/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,17 @@ export default function LaunchSpreadsheetViewF(pluginManager: PluginManager) {
session,
assembly,
uri,
fileType,
}: {
session: AbstractSessionModel
assembly: string
uri: string
fileType?: string
}) => {
const view = session.addView('SpreadsheetView') as SpreadsheetViewModel
const exts = uri.split('.')
let ext = exts.pop()?.toUpperCase()
if (ext === 'GZ') {
ext = exts.pop()?.toUpperCase()
}

view.importWizard.setFileType(fileType || ext || '')
view.importWizard.setSelectedAssemblyName(assembly)
view.importWizard.setFileSource({
view.importWizard.setSpreadsheetFilehandle({
uri,
locationType: 'UriLocation',
})
await view.importWizard.import(assembly)
},
)
}
Loading

0 comments on commit 5a0b3f7

Please sign in to comment.