Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spreadsheet view refactor to use @mui/x-data-grid component and volatile storage #4047

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export default tseslint.config(
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-deprecated': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
Expand Down
6 changes: 6 additions & 0 deletions packages/core/assemblyManager/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,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
69 changes: 39 additions & 30 deletions packages/sv-core/src/BreakendMultiLevelOptionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button, DialogActions, DialogContent } from '@mui/material'
import { getSnapshot } from 'mobx-state-tree'
import { Dialog } from '@jbrowse/core/ui'
import { when } from 'mobx'
import { getSession, Feature } from '@jbrowse/core/util'
import { Feature, AbstractSessionModel } from '@jbrowse/core/util'
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
import type { Assembly } from '@jbrowse/core/assemblyManager/assembly'

Expand All @@ -29,17 +29,17 @@ function stripIds(arr: Track[]) {
}

const BreakendMultiLevelOptionDialog = observer(function ({
model,
session,
handleClose,
feature,
assemblyName,
viewType,
view,
}: {
model: unknown
session: AbstractSessionModel
handleClose: () => void
feature: Feature
view: LinearGenomeViewModel
view?: LinearGenomeViewModel
assemblyName: string
viewType: {
getBreakendCoveringRegions: (arg: {
Expand All @@ -63,45 +63,52 @@ const BreakendMultiLevelOptionDialog = observer(function ({
title="Multi-level breakpoint split view options"
>
<DialogContent>
<Checkbox2
checked={copyTracks}
label="Copy tracks into the new view"
onChange={event => {
setCopyTracks(event.target.checked)
}}
/>
<div>Launch multi-level breakpoint split view</div>
{view ? (
<>
<Checkbox2
checked={copyTracks}
label="Copy tracks into the new view"
onChange={event => {
setCopyTracks(event.target.checked)
}}
/>

{copyTracks ? (
<Checkbox2
checked={mirror}
disabled={!copyTracks}
label="Mirror the copied tracks (only available if copying tracks and using two level)"
onChange={event => {
setMirror(event.target.checked)
}}
/>
{copyTracks ? (
<Checkbox2
checked={mirror}
disabled={!copyTracks}
label="Mirror the copied tracks (only available if copying tracks and using two level)"
onChange={event => {
setMirror(event.target.checked)
}}
/>
) : null}
</>
) : null}
</DialogContent>
<DialogActions>
<Button
onClick={() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
;(async () => {
const session = getSession(model)
try {
const asm =
await session.assemblyManager.waitForAssembly(assemblyName)
if (!asm) {
const { assemblyManager } = session
const assembly =
await assemblyManager.waitForAssembly(assemblyName)
if (!assembly) {
throw new Error(`assembly ${assemblyName} not found`)
}

const { refName, pos, mateRefName, matePos } =
viewType.getBreakendCoveringRegions({
feature,
assembly: asm,
assembly: assembly,
})

const viewTracks = getSnapshot(view.tracks) as Track[]
const viewTracks = view
? (getSnapshot(view.tracks) as Track[])
: []
const breakpointSplitView = session.addView(
'BreakpointSplitView',
{
Expand All @@ -114,7 +121,7 @@ const BreakendMultiLevelOptionDialog = observer(function ({
{
type: 'LinearGenomeView',
hideHeader: true,
tracks: stripIds(getSnapshot(view.tracks)),
tracks: stripIds(viewTracks),
},
{
type: 'LinearGenomeView',
Expand All @@ -126,8 +133,10 @@ const BreakendMultiLevelOptionDialog = observer(function ({
],
},
) as unknown as { views: LinearGenomeViewModel[] }
const r1 = asm.regions!.find(r => r.refName === refName)
const r2 = asm.regions!.find(r => r.refName === mateRefName)
const r1 = assembly.regions!.find(r => r.refName === refName)
const r2 = assembly.regions!.find(
r => r.refName === mateRefName,
)
if (!r1 || !r2) {
throw new Error("can't find regions")
}
Expand Down Expand Up @@ -172,7 +181,7 @@ const BreakendMultiLevelOptionDialog = observer(function ({
breakpointSplitView.views[0]!.centerAt(pos, refName)
} catch (e) {
console.error(e)
session.notify(`${e}`)
session.notifyError(`${e}`, e)
}
})()
handleClose()
Expand Down
39 changes: 23 additions & 16 deletions packages/sv-core/src/BreakendSingleLevelOptionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { Button, DialogActions, DialogContent, TextField } from '@mui/material'
import { getSnapshot } from 'mobx-state-tree'
import { Dialog } from '@jbrowse/core/ui'
import {
getSession,
Feature,
gatherOverlaps,
useLocalStorage,
AbstractSessionModel,
} from '@jbrowse/core/util'
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
import type { Assembly } from '@jbrowse/core/assemblyManager/assembly'
Expand All @@ -33,17 +33,17 @@ function stripIds(arr: Track[]) {
}

const BreakendSingleLevelOptionDialog = observer(function ({
model,
session,
handleClose,
feature,
assemblyName,
viewType,
view,
}: {
model: unknown
session: AbstractSessionModel
handleClose: () => void
feature: Feature
view: LinearGenomeViewModel
view?: LinearGenomeViewModel
assemblyName: string
viewType: {
getBreakendCoveringRegions: (arg: {
Expand All @@ -70,13 +70,15 @@ const BreakendSingleLevelOptionDialog = observer(function ({
title="Single-level breakpoint split view options"
>
<DialogContent>
<Checkbox2
checked={copyTracks}
label="Copy tracks into the new view"
onChange={event => {
setCopyTracks(event.target.checked)
}}
/>
{view ? (
<Checkbox2
checked={copyTracks}
label="Copy tracks into the new view"
onChange={event => {
setCopyTracks(event.target.checked)
}}
/>
) : null}

<TextField
label="Window size (bp)"
Expand All @@ -89,17 +91,20 @@ const BreakendSingleLevelOptionDialog = observer(function ({
<DialogActions>
<Button
onClick={() => {
const session = getSession(model)
// eslint-disable-next-line @typescript-eslint/no-floating-promises
;(async () => {
try {
const assembly = session.assemblyManager.get(assemblyName)
const { assemblyManager } = session
const assembly =
await assemblyManager.waitForAssembly(assemblyName)
if (!assembly) {
throw new Error(`assembly ${assemblyName} not found`)
}
const w = +windowSize
if (Number.isNaN(w)) {
throw new Error('windowSize not a number')
}
const { refName, pos, mateRefName, matePos } =
// @ts-expect-error
viewType.getBreakendCoveringRegions({ feature, assembly })

const breakpointSplitView = session.addView(
Expand All @@ -112,7 +117,9 @@ const BreakendSingleLevelOptionDialog = observer(function ({
views: [
{
type: 'LinearGenomeView',
tracks: stripIds(getSnapshot(view.tracks)),
tracks: view?.tracks
? stripIds(getSnapshot(view.tracks))
: [],
},
],
},
Expand All @@ -139,7 +146,7 @@ const BreakendSingleLevelOptionDialog = observer(function ({
)
} catch (e) {
console.error(e)
session.notify(`${e}`)
session.notifyError(`${e}`, e)
}
})()
handleClose()
Expand Down
2 changes: 1 addition & 1 deletion plugins/alignments/src/AlignmentsFeatureDetail/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export async function navToLoc(locString: string, model: IAnyStateTreeNode) {
}
} catch (e) {
console.error(e)
session.notify(`${e}`)
session.notifyError(`${e}`, e)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export function SharedLinearPileupDisplayMixin(
}
} catch (e) {
console.error(e)
session.notify(`${e}`)
session.notifyError(`${e}`, e)
}
},

Expand Down Expand Up @@ -455,7 +455,7 @@ export function SharedLinearPileupDisplayMixin(
}
} catch (e) {
console.error(e)
session.notify(`${e}`)
session.notifyError(`${e}`, e)
}
},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getSession, Feature, Region } from '@jbrowse/core/util'
import { Feature, AbstractSessionModel } from '@jbrowse/core/util'
import ViewType from '@jbrowse/core/pluggableElementTypes/ViewType'
import { parseBreakend } from '@gmod/vcf'
import { IStateTreeNode } from 'mobx-state-tree'
import { Assembly } from '@jbrowse/core/assemblyManager/assembly'

export default class BreakpointSplitViewType extends ViewType {
Expand Down Expand Up @@ -52,22 +51,23 @@ export default class BreakpointSplitViewType extends ViewType {
}
}

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

const { assemblyManager } = session
const assembly = assemblyManager.get(assemblyName)
if (!assembly) {
const assembly = await assemblyManager.waitForAssembly(assemblyName)
if (!assembly?.regions) {
throw new Error(`assembly ${assemblyName} not found`)
}
if (!assembly.regions) {
throw new Error(`assembly ${assemblyName} regions not loaded`)
}

const {
refName,
pos: startPos,
Expand Down Expand Up @@ -103,23 +103,22 @@ export default class BreakpointSplitViewType extends ViewType {
featureData: undefined as unknown,
}
}

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

const { assemblyManager } = session
const assembly = assemblyManager.get(assemblyName)
if (!assembly) {
const assembly = await assemblyManager.waitForAssembly(assemblyName)
if (!assembly?.regions) {
throw new Error(`assembly ${assemblyName} not found`)
}
if (!assembly.regions) {
throw new Error(`assembly ${assemblyName} regions not loaded`)
}

const {
refName,
pos: startPos,
Expand Down
Loading