Skip to content

Commit

Permalink
Save track data
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Jan 5, 2023
1 parent 45b7d35 commit 37df522
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
16 changes: 16 additions & 0 deletions packages/core/pluggableElementTypes/models/BaseTrackModel.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { lazy } from 'react'
import { transaction } from 'mobx'
import {
getRoot,
Expand All @@ -16,10 +17,14 @@ import {
} from '../../configuration'
import PluginManager from '../../PluginManager'
import { MenuItem } from '../../ui'
import { Save } from '../../ui/Icons'
import { getContainingView, getEnv, getSession } from '../../util'
import { isSessionModelWithConfigEditing } from '../../util/types'
import { ElementId } from '../../util/types/mst'

// lazies
const SaveTrackDataDlg = lazy(() => import('./components/SaveTrackData'))

export function getCompatibleDisplays(self: IAnyStateTreeNode) {
const { pluginManager } = getEnv(self)
const view = getContainingView(self)
Expand Down Expand Up @@ -210,6 +215,17 @@ export function createBaseTrackModel(

return [
...menuItems,
{
label: 'Save track data',
icon: Save,
onClick: () => {
getSession(self).queueDialog(handleClose => [
SaveTrackDataDlg,
// @ts-ignore
{ model: self, handleClose },
])
},
},
...(compatDisp.length > 1
? [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@ import { Dialog, ErrorMessage } from '@jbrowse/core/ui'
import {
getSession,
getContainingView,
getContainingTrack,
Feature,
Region,
} from '@jbrowse/core/util'
import { getConf } from '@jbrowse/core/configuration'
import { makeStyles } from 'tss-react/mui'
import {
BaseDisplayModel,
BaseTrackModel,
} from '@jbrowse/core/pluggableElementTypes'
import { BaseTrackModel } from '@jbrowse/core/pluggableElementTypes'
import { observer } from 'mobx-react'

// locals
import { LinearGenomeViewModel } from '../../LinearGenomeView'
import { stringifyGFF3 } from './util'

const useStyles = makeStyles()(theme => ({
Expand All @@ -32,19 +27,12 @@ const useStyles = makeStyles()(theme => ({
},
}))

type LGV = LinearGenomeViewModel

/**
* Fetches and returns a list features for a given list of regions
*/
async function fetchFeatures(
track: BaseTrackModel,
view: LGV,
regions: Region[],
signal?: AbortSignal,
) {
const session = getSession(view)
const { rpcManager } = session
const { rpcManager } = getSession(track)
const adapterConfig = getConf(track, ['adapter'])
const sessionId = 'getSequence'
return rpcManager.call(sessionId, 'CoreGetFeatures', {
Expand All @@ -59,7 +47,7 @@ function SaveTrackDataDlg({
model,
handleClose,
}: {
model: BaseDisplayModel
model: BaseTrackModel
handleClose: () => void
}) {
const { classes } = useStyles()
Expand All @@ -70,11 +58,11 @@ function SaveTrackDataDlg({
// eslint-disable-next-line @typescript-eslint/no-floating-promises
;(async () => {
try {
const view = getContainingView(model) as LGV
const track = getContainingTrack(model) as BaseTrackModel
const view = getContainingView(model)
const track = model
const regions = view.dynamicBlocks.contentBlocks
setError(undefined)
const feats = await fetchFeatures(track, view, regions)
const feats = await fetchFeatures(track, regions)
const ret = stringifyGFF3(feats)
setFeatures(ret)
} catch (e) {
Expand Down
13 changes: 1 addition & 12 deletions plugins/linear-genome-view/src/LinearBasicDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import VisibilityIcon from '@mui/icons-material/Visibility'

// locals
import { BaseLinearDisplay } from '../BaseLinearDisplay'
import { Save } from '@jbrowse/core/ui/Icons'

const SetMaxHeightDlg = lazy(() => import('./components/SetMaxHeight'))
const SaveTrackDataDlg = lazy(() => import('./components/SaveTrackData'))

/**
* #stateModel LinearBasicDisplay
Expand Down Expand Up @@ -175,16 +173,7 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
checked: self.showLabels,
onClick: () => self.toggleShowLabels(),
},
{
label: 'Save track data',
icon: Save,
onClick: () => {
getSession(self).queueDialog(handleClose => [
SaveTrackDataDlg,
{ model: self, handleClose },
])
},
},

{
label: 'Show descriptions',
icon: VisibilityIcon,
Expand Down

0 comments on commit 37df522

Please sign in to comment.