Skip to content

Commit

Permalink
Create new config schema for ReferenceSequenceTrack based on the base…
Browse files Browse the repository at this point in the history
… track, but without assemblyNames, etc. (#1434)

* Create refSeq track config

* Add comment about duplication

* Fix comment

* Fix getting track name
  • Loading branch information
elliothershberg authored Nov 14, 2020
1 parent 4dae5ba commit 56dbcaf
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/core/util/tracks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function getTrackAssemblyNames(
) {
const trackConf = track.configuration
const trackAssemblyNames = readConfObject(trackConf, 'assemblyNames')
if (trackAssemblyNames[0] === 'assemblyName') {
if (!trackAssemblyNames) {
// Check if it's an assembly sequence track
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const parent = getParent<any>(track.configuration)
Expand Down
17 changes: 4 additions & 13 deletions plugins/sequence/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { ConfigurationSchema } from '@jbrowse/core/configuration'
import AdapterType from '@jbrowse/core/pluggableElementTypes/AdapterType'
import {
createBaseTrackConfig,
createBaseTrackModel,
} from '@jbrowse/core/pluggableElementTypes/models'
import { createBaseTrackModel } from '@jbrowse/core/pluggableElementTypes/models'
import ServerSideRendererType from '@jbrowse/core/pluggableElementTypes/renderers/ServerSideRendererType'
import TrackType from '@jbrowse/core/pluggableElementTypes/TrackType'
import Plugin from '@jbrowse/core/Plugin'
Expand Down Expand Up @@ -33,6 +29,7 @@ import {
AdapterClass as TwoBitAdapterClass,
configSchema as twoBitAdapterConfigSchema,
} from './TwoBitAdapter'
import { createReferenceSeqTrackConfig } from './referenceSeqTrackConfig'

export default class SequencePlugin extends Plugin {
name = 'SequencePlugin'
Expand Down Expand Up @@ -75,14 +72,8 @@ export default class SequencePlugin extends Plugin {
)

pluginManager.addTrackType(() => {
const configSchema = ConfigurationSchema(
'ReferenceSequenceTrack',
{},
{
baseConfiguration: createBaseTrackConfig(pluginManager),
explicitIdentifier: 'trackId',
},
)
const configSchema = createReferenceSeqTrackConfig(pluginManager)

return new TrackType({
name: 'ReferenceSequenceTrack',
configSchema,
Expand Down
63 changes: 63 additions & 0 deletions plugins/sequence/src/referenceSeqTrackConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { types } from 'mobx-state-tree'
import { ConfigurationSchema } from '@jbrowse/core/configuration'
import PluginManager from '@jbrowse/core/PluginManager'

/*
Note: this is primarily a copy of createBaseTrackConfig, except with a subset
of the config slots, to avoid including fields that don't make sense for the
ReferenceSequenceTrack
*/
export function createReferenceSeqTrackConfig(pluginManager: PluginManager) {
return ConfigurationSchema(
'ReferenceSequenceTrack',
{
adapter: pluginManager.pluggableConfigSchemaType('adapter'),
displays: types.array(pluginManager.pluggableConfigSchemaType('display')),
metadata: {
type: 'frozen',
description: 'anything to add about this track',
defaultValue: {},
},
},
{
preProcessSnapshot: s => {
const snap = JSON.parse(JSON.stringify(s))
const displayTypes = new Set()
const { displays = [] } = snap
if (snap.trackId !== 'placeholderId') {
// Gets the displays on the track snapshot and the possible displays
// from the track type and adds any missing possible displays to the
// snapshot
displays.forEach((d: any) => d && displayTypes.add(d.type))
const trackType = pluginManager.getTrackType(snap.type)
trackType.displayTypes.forEach(displayType => {
if (!displayTypes.has(displayType.name)) {
displays.push({
displayId: `${snap.trackId}-${displayType.name}`,
type: displayType.name,
})
}
})
}
return { ...snap, displays }
},
explicitIdentifier: 'trackId',
explicitlyTyped: true,
actions: (self: any) => ({
addDisplayConf(displayConf: { type: string; displayId: string }) {
const { type } = displayConf
if (!type) throw new Error(`unknown display type ${type}`)
const display = self.displays.find(
(d: any) => d && d.displayId === displayConf.displayId,
)
if (display) {
return display
}
const length = self.displays.push(displayConf)
return self.displays[length - 1]
},
}),
},
)
}

0 comments on commit 56dbcaf

Please sign in to comment.