diff --git a/plugins/arc/src/ArcRenderer/ArcRenderer.tsx b/plugins/arc/src/ArcRenderer/ArcRenderer.ts similarity index 100% rename from plugins/arc/src/ArcRenderer/ArcRenderer.tsx rename to plugins/arc/src/ArcRenderer/ArcRenderer.ts diff --git a/plugins/arc/src/ArcRenderer/configSchema.tsx b/plugins/arc/src/ArcRenderer/configSchema.ts similarity index 100% rename from plugins/arc/src/ArcRenderer/configSchema.tsx rename to plugins/arc/src/ArcRenderer/configSchema.ts diff --git a/plugins/arc/src/ArcRenderer/index.ts b/plugins/arc/src/ArcRenderer/index.ts new file mode 100644 index 0000000000..156bda52f0 --- /dev/null +++ b/plugins/arc/src/ArcRenderer/index.ts @@ -0,0 +1,17 @@ +import PluginManager from '@jbrowse/core/PluginManager' + +import ReactComponent from './ArcRendering' +import configSchema from './configSchema' +import ArcRenderer from './ArcRenderer' + +export default (pluginManager: PluginManager) => { + pluginManager.addRendererType( + () => + new ArcRenderer({ + name: 'ArcRenderer', + ReactComponent, + configSchema, + pluginManager, + }), + ) +} diff --git a/plugins/arc/src/ArcRenderer/index.tsx b/plugins/arc/src/ArcRenderer/index.tsx deleted file mode 100644 index 6b1bd96681..0000000000 --- a/plugins/arc/src/ArcRenderer/index.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export { default as ReactComponent } from './ArcRendering' -export { default as configSchema } from './configSchema' -export { default } from './ArcRenderer' diff --git a/plugins/arc/src/LinearArcDisplay/configSchema.tsx b/plugins/arc/src/LinearArcDisplay/configSchema.ts similarity index 76% rename from plugins/arc/src/LinearArcDisplay/configSchema.tsx rename to plugins/arc/src/LinearArcDisplay/configSchema.ts index 992e9661a5..3b08efb160 100644 --- a/plugins/arc/src/LinearArcDisplay/configSchema.tsx +++ b/plugins/arc/src/LinearArcDisplay/configSchema.ts @@ -1,15 +1,12 @@ import PluginManager from '@jbrowse/core/PluginManager' import { types } from 'mobx-state-tree' import { ConfigurationSchema } from '@jbrowse/core/configuration' +import { baseLinearDisplayConfigSchema } from '@jbrowse/plugin-linear-genome-view' /** * #config LinearArcDisplay */ export function configSchemaFactory(pluginManager: PluginManager) { - const LGVPlugin = pluginManager.getPlugin( - 'LinearGenomeViewPlugin', - ) as import('@jbrowse/plugin-linear-genome-view').default - const { baseLinearDisplayConfigSchema } = LGVPlugin.exports return ConfigurationSchema( 'LinearArcDisplay', { diff --git a/plugins/arc/src/LinearArcDisplay/index.ts b/plugins/arc/src/LinearArcDisplay/index.ts new file mode 100644 index 0000000000..d8ae623505 --- /dev/null +++ b/plugins/arc/src/LinearArcDisplay/index.ts @@ -0,0 +1,20 @@ +import PluginManager from '@jbrowse/core/PluginManager' +import { DisplayType } from '@jbrowse/core/pluggableElementTypes' +import { BaseLinearDisplayComponent } from '@jbrowse/plugin-linear-genome-view' + +import { configSchemaFactory } from './configSchema' +import { stateModelFactory } from './model' + +export default (pluginManager: PluginManager) => { + pluginManager.addDisplayType(() => { + const configSchema = configSchemaFactory(pluginManager) + return new DisplayType({ + name: 'LinearArcDisplay', + configSchema, + stateModel: stateModelFactory(configSchema), + trackType: 'FeatureTrack', + viewType: 'LinearGenomeView', + ReactComponent: BaseLinearDisplayComponent, + }) + }) +} diff --git a/plugins/arc/src/LinearArcDisplay/index.tsx b/plugins/arc/src/LinearArcDisplay/index.tsx deleted file mode 100644 index bb7c3318c0..0000000000 --- a/plugins/arc/src/LinearArcDisplay/index.tsx +++ /dev/null @@ -1,2 +0,0 @@ -export { configSchemaFactory } from './configSchema' -export { stateModelFactory } from './model' diff --git a/plugins/arc/src/LinearArcDisplay/model.tsx b/plugins/arc/src/LinearArcDisplay/model.ts similarity index 71% rename from plugins/arc/src/LinearArcDisplay/model.tsx rename to plugins/arc/src/LinearArcDisplay/model.ts index 71c6afe8ea..b868f3e1fe 100644 --- a/plugins/arc/src/LinearArcDisplay/model.tsx +++ b/plugins/arc/src/LinearArcDisplay/model.ts @@ -2,18 +2,10 @@ import { AnyConfigurationSchemaType, ConfigurationReference, } from '@jbrowse/core/configuration/configurationSchema' -import PluginManager from '@jbrowse/core/PluginManager' import { types } from 'mobx-state-tree' +import { BaseLinearDisplay } from '@jbrowse/plugin-linear-genome-view' -export function stateModelFactory( - configSchema: AnyConfigurationSchemaType, - pluginManager: PluginManager, -) { - const LGVPlugin = pluginManager.getPlugin( - 'LinearGenomeViewPlugin', - ) as import('@jbrowse/plugin-linear-genome-view').default - // @ts-ignore - const { BaseLinearDisplay } = LGVPlugin.exports +export function stateModelFactory(configSchema: AnyConfigurationSchemaType) { return types .compose( 'LinearArcDisplay', diff --git a/plugins/arc/src/index.ts b/plugins/arc/src/index.ts index b43f29c3ca..823154ef13 100644 --- a/plugins/arc/src/index.ts +++ b/plugins/arc/src/index.ts @@ -1,53 +1,18 @@ import Plugin from '@jbrowse/core/Plugin' import PluginManager from '@jbrowse/core/PluginManager' -import DisplayType from '@jbrowse/core/pluggableElementTypes/DisplayType' -import { - configSchemaFactory as linearArcDisplayConfigSchemaFactory, - stateModelFactory as LinearArcDisplayStateModelFactory, -} from './LinearArcDisplay' -import ArcRenderer, { - configSchema as ArcRendererConfigSchema, - ReactComponent as ArcRendererReactComponent, -} from './ArcRenderer' +import LinearArcDisplayF from './LinearArcDisplay' +import ArcRendererF from './ArcRenderer' +import { Feature } from '@jbrowse/core/util' -export default class MyProjectPlugin extends Plugin { +export default class ArcPlugin extends Plugin { name = 'ArcRenderer' install(pluginManager: PluginManager) { - const LGVPlugin = pluginManager.getPlugin( - 'LinearGenomeViewPlugin', - ) as import('@jbrowse/plugin-linear-genome-view').default - // @ts-ignore - const { BaseLinearDisplayComponent } = LGVPlugin.exports - - pluginManager.addRendererType( - () => - // @ts-ignore error "expected 0 arguments, but got 1"? - new ArcRenderer({ - name: 'ArcRenderer', - ReactComponent: ArcRendererReactComponent, - configSchema: ArcRendererConfigSchema, - pluginManager, - }), - ) - pluginManager.addDisplayType(() => { - const configSchema = linearArcDisplayConfigSchemaFactory(pluginManager) - return new DisplayType({ - name: 'LinearArcDisplay', - configSchema, - stateModel: LinearArcDisplayStateModelFactory( - configSchema, - pluginManager, - ), - trackType: 'FeatureTrack', - viewType: 'LinearGenomeView', - ReactComponent: BaseLinearDisplayComponent, - }) - }) + ArcRendererF(pluginManager) + LinearArcDisplayF(pluginManager) pluginManager.jexl.addFunction( 'logThickness', - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (feature: any, attributeName: string) => { + (feature: Feature, attributeName: string) => { return Math.log(feature.get(attributeName) + 1) }, ) diff --git a/plugins/gff3/src/Gff3Adapter/index.ts b/plugins/gff3/src/Gff3Adapter/index.ts index 7703441d29..1fc4b969bd 100644 --- a/plugins/gff3/src/Gff3Adapter/index.ts +++ b/plugins/gff3/src/Gff3Adapter/index.ts @@ -1 +1,14 @@ -export { default as configSchema } from './configSchema' +import { AdapterType } from '@jbrowse/core/pluggableElementTypes' +import PluginManager from '@jbrowse/core/PluginManager' +import configSchema from './configSchema' + +export default (pluginManager: PluginManager) => { + pluginManager.addAdapterType( + () => + new AdapterType({ + name: 'Gff3Adapter', + configSchema, + getAdapterClass: () => import('./Gff3Adapter').then(r => r.default), + }), + ) +} diff --git a/plugins/gff3/src/Gff3TabixAdapter/index.ts b/plugins/gff3/src/Gff3TabixAdapter/index.ts index 7703441d29..b8c5f43224 100644 --- a/plugins/gff3/src/Gff3TabixAdapter/index.ts +++ b/plugins/gff3/src/Gff3TabixAdapter/index.ts @@ -1 +1,15 @@ -export { default as configSchema } from './configSchema' +import { AdapterType } from '@jbrowse/core/pluggableElementTypes' +import PluginManager from '@jbrowse/core/PluginManager' +import configSchema from './configSchema' + +export default (pluginManager: PluginManager) => { + pluginManager.addAdapterType( + () => + new AdapterType({ + name: 'Gff3TabixAdapter', + configSchema, + getAdapterClass: () => + import('./Gff3TabixAdapter').then(r => r.default), + }), + ) +} diff --git a/plugins/gff3/src/GuessGff3/index.ts b/plugins/gff3/src/GuessGff3/index.ts new file mode 100644 index 0000000000..22c8252ceb --- /dev/null +++ b/plugins/gff3/src/GuessGff3/index.ts @@ -0,0 +1,63 @@ +import PluginManager from '@jbrowse/core/PluginManager' +import { FileLocation } from '@jbrowse/core/util/types' +import { + makeIndex, + makeIndexType, + getFileName, + AdapterGuesser, +} from '@jbrowse/core/util/tracks' + +export default (pluginManager: PluginManager) => { + pluginManager.addToExtensionPoint( + 'Core-guessAdapterForLocation', + (adapterGuesser: AdapterGuesser) => { + return ( + file: FileLocation, + index?: FileLocation, + adapterHint?: string, + ) => { + const regexGuess = /\.gff3?\.b?gz$/i + const adapterName = 'Gff3TabixAdapter' + const fileName = getFileName(file) + const indexName = index && getFileName(index) + if (regexGuess.test(fileName) || adapterHint === adapterName) { + return { + type: adapterName, + bamLocation: file, + gffGzLocation: file, + index: { + location: index || makeIndex(file, '.tbi'), + indexType: makeIndexType(indexName, 'CSI', 'TBI'), + }, + } + } + return adapterGuesser(file, index, adapterHint) + } + }, + ) + + pluginManager.addToExtensionPoint( + 'Core-guessAdapterForLocation', + (adapterGuesser: AdapterGuesser) => { + return ( + file: FileLocation, + index?: FileLocation, + adapterHint?: string, + ) => { + const regexGuess = /\.gff3?$/i + const adapterName = 'Gff3Adapter' + const fileName = getFileName(file) + const obj = { + type: adapterName, + gffLocation: file, + } + if (regexGuess.test(fileName) && !adapterHint) { + return obj + } else if (adapterHint === adapterName) { + return obj + } + return adapterGuesser(file, index, adapterHint) + } + }, + ) +} diff --git a/plugins/gff3/src/index.ts b/plugins/gff3/src/index.ts index 905587d028..0c6cdcf7a8 100644 --- a/plugins/gff3/src/index.ts +++ b/plugins/gff3/src/index.ts @@ -1,88 +1,16 @@ -import AdapterType from '@jbrowse/core/pluggableElementTypes/AdapterType' import PluginManager from '@jbrowse/core/PluginManager' import Plugin from '@jbrowse/core/Plugin' -import { configSchema as gff3TabixAdapterConfigSchema } from './Gff3TabixAdapter' -import { FileLocation } from '@jbrowse/core/util/types' -import { - makeIndex, - makeIndexType, - AdapterGuesser, - getFileName, -} from '@jbrowse/core/util/tracks' -import { configSchema as gff3AdapterConfigSchema } from './Gff3Adapter' + +import Gff3TabixAdapterF from './Gff3TabixAdapter' +import Gff3AdapterF from './Gff3Adapter' +import GuessGff3F from './GuessGff3' export default class extends Plugin { name = 'GFF3Plugin' install(pluginManager: PluginManager) { - pluginManager.addAdapterType( - () => - new AdapterType({ - name: 'Gff3TabixAdapter', - configSchema: gff3TabixAdapterConfigSchema, - getAdapterClass: () => - import('./Gff3TabixAdapter/Gff3TabixAdapter').then(r => r.default), - }), - ) - pluginManager.addToExtensionPoint( - 'Core-guessAdapterForLocation', - (adapterGuesser: AdapterGuesser) => { - return ( - file: FileLocation, - index?: FileLocation, - adapterHint?: string, - ) => { - const regexGuess = /\.gff3?\.b?gz$/i - const adapterName = 'Gff3TabixAdapter' - const fileName = getFileName(file) - const indexName = index && getFileName(index) - if (regexGuess.test(fileName) || adapterHint === adapterName) { - return { - type: adapterName, - bamLocation: file, - gffGzLocation: file, - index: { - location: index || makeIndex(file, '.tbi'), - indexType: makeIndexType(indexName, 'CSI', 'TBI'), - }, - } - } - return adapterGuesser(file, index, adapterHint) - } - }, - ) - pluginManager.addAdapterType( - () => - new AdapterType({ - name: 'Gff3Adapter', - configSchema: gff3AdapterConfigSchema, - getAdapterClass: () => - import('./Gff3Adapter/Gff3Adapter').then(r => r.default), - }), - ) - pluginManager.addToExtensionPoint( - 'Core-guessAdapterForLocation', - (adapterGuesser: AdapterGuesser) => { - return ( - file: FileLocation, - index?: FileLocation, - adapterHint?: string, - ) => { - const regexGuess = /\.gff3?$/i - const adapterName = 'Gff3Adapter' - const fileName = getFileName(file) - const obj = { - type: adapterName, - gffLocation: file, - } - if (regexGuess.test(fileName) && !adapterHint) { - return obj - } else if (adapterHint === adapterName) { - return obj - } - return adapterGuesser(file, index, adapterHint) - } - }, - ) + Gff3TabixAdapterF(pluginManager) + Gff3AdapterF(pluginManager) + GuessGff3F(pluginManager) } } diff --git a/plugins/hic/src/HicAdapter/index.ts b/plugins/hic/src/HicAdapter/index.ts new file mode 100644 index 0000000000..483d3685ae --- /dev/null +++ b/plugins/hic/src/HicAdapter/index.ts @@ -0,0 +1,14 @@ +import { AdapterType } from '@jbrowse/core/pluggableElementTypes' +import PluginManager from '@jbrowse/core/PluginManager' +import configSchema from './configSchema' + +export default (pluginManager: PluginManager) => { + pluginManager.addAdapterType( + () => + new AdapterType({ + name: 'HicAdapter', + configSchema, + getAdapterClass: () => import('./HicAdapter').then(r => r.default), + }), + ) +} diff --git a/plugins/hic/src/HicRenderer/index.ts b/plugins/hic/src/HicRenderer/index.ts index 96d44270f6..e575609f26 100644 --- a/plugins/hic/src/HicRenderer/index.ts +++ b/plugins/hic/src/HicRenderer/index.ts @@ -1,3 +1,17 @@ -export { default as ReactComponent } from './components/HicRendering' -export { default as configSchema } from './configSchema' -export { default } from './HicRenderer' +import PluginManager from '@jbrowse/core/PluginManager' + +import ReactComponent from './components/HicRendering' +import configSchema from './configSchema' +import HicRenderer from './HicRenderer' + +export default (pluginManager: PluginManager) => { + pluginManager.addRendererType( + () => + new HicRenderer({ + name: 'HicRenderer', + ReactComponent, + configSchema, + pluginManager, + }), + ) +} diff --git a/plugins/hic/src/configSchema.ts b/plugins/hic/src/HicTrack/configSchema.ts similarity index 100% rename from plugins/hic/src/configSchema.ts rename to plugins/hic/src/HicTrack/configSchema.ts diff --git a/plugins/hic/src/HicTrack/index.ts b/plugins/hic/src/HicTrack/index.ts new file mode 100644 index 0000000000..50ff301780 --- /dev/null +++ b/plugins/hic/src/HicTrack/index.ts @@ -0,0 +1,15 @@ +import PluginManager from '@jbrowse/core/PluginManager' +import TrackType from '@jbrowse/core/pluggableElementTypes/TrackType' +import { createBaseTrackModel } from '@jbrowse/core/pluggableElementTypes/models' +import configSchemaF from './configSchema' + +export default (pluginManager: PluginManager) => { + pluginManager.addTrackType(() => { + const configSchema = configSchemaF(pluginManager) + return new TrackType({ + name: 'HicTrack', + configSchema, + stateModel: createBaseTrackModel(pluginManager, 'HicTrack', configSchema), + }) + }) +} diff --git a/plugins/hic/src/LinearHicDisplay/index.ts b/plugins/hic/src/LinearHicDisplay/index.ts index 8f902e27ec..e275feb753 100644 --- a/plugins/hic/src/LinearHicDisplay/index.ts +++ b/plugins/hic/src/LinearHicDisplay/index.ts @@ -1,2 +1,20 @@ -export { default as configSchemaFactory } from './configSchema' -export { default as modelFactory } from './model' +import { DisplayType } from '@jbrowse/core/pluggableElementTypes' +import PluginManager from '@jbrowse/core/PluginManager' +import { BaseLinearDisplayComponent } from '@jbrowse/plugin-linear-genome-view' + +import configSchemaFactory from './configSchema' +import stateModelFactory from './model' + +export default (pluginManager: PluginManager) => { + pluginManager.addDisplayType(() => { + const configSchema = configSchemaFactory(pluginManager) + return new DisplayType({ + name: 'LinearHicDisplay', + configSchema, + stateModel: stateModelFactory(configSchema), + trackType: 'HicTrack', + viewType: 'LinearGenomeView', + ReactComponent: BaseLinearDisplayComponent, + }) + }) +} diff --git a/plugins/hic/src/index.ts b/plugins/hic/src/index.ts index ddd3f3d7c9..8ef7025f61 100644 --- a/plugins/hic/src/index.ts +++ b/plugins/hic/src/index.ts @@ -1,22 +1,11 @@ -import AdapterType from '@jbrowse/core/pluggableElementTypes/AdapterType' -import DisplayType from '@jbrowse/core/pluggableElementTypes/DisplayType' -import { createBaseTrackModel } from '@jbrowse/core/pluggableElementTypes/models' -import TrackType from '@jbrowse/core/pluggableElementTypes/TrackType' import Plugin from '@jbrowse/core/Plugin' import PluginManager from '@jbrowse/core/PluginManager' -import { BaseLinearDisplayComponent } from '@jbrowse/plugin-linear-genome-view' import { FileLocation } from '@jbrowse/core/util/types' -import configSchemaF from './configSchema' import Color from 'color' -import HicRenderer, { - configSchema as hicRendererConfigSchema, - ReactComponent as HicRendererReactComponent, -} from './HicRenderer' -import { - configSchemaFactory as linearHicdisplayConfigSchemaFactory, - modelFactory as linearHicdisplayModelFactory, -} from './LinearHicDisplay' -import hicAdapterConfigSchema from './HicAdapter/configSchema' +import HicRendererF from './HicRenderer' +import HicTrackF from './HicTrack' +import LinearHicDisplayF from './LinearHicDisplay' +import HicAdapterF from './HicAdapter' import { AdapterGuesser, getFileName, @@ -27,15 +16,11 @@ export default class HicPlugin extends Plugin { name = 'HicPlugin' install(pluginManager: PluginManager) { - pluginManager.addAdapterType( - () => - new AdapterType({ - name: 'HicAdapter', - configSchema: hicAdapterConfigSchema, - getAdapterClass: () => - import('./HicAdapter/HicAdapter').then(r => r.default), - }), - ) + HicAdapterF(pluginManager) + HicRendererF(pluginManager) + HicTrackF(pluginManager) + LinearHicDisplayF(pluginManager) + pluginManager.addToExtensionPoint( 'Core-guessAdapterForLocation', (adapterGuesser: AdapterGuesser) => { @@ -72,38 +57,6 @@ export default class HicPlugin extends Plugin { } }, ) - pluginManager.addRendererType( - () => - new HicRenderer({ - name: 'HicRenderer', - ReactComponent: HicRendererReactComponent, - configSchema: hicRendererConfigSchema, - pluginManager, - }), - ) - pluginManager.addTrackType(() => { - const configSchema = configSchemaF(pluginManager) - return new TrackType({ - name: 'HicTrack', - configSchema, - stateModel: createBaseTrackModel( - pluginManager, - 'HicTrack', - configSchema, - ), - }) - }) - pluginManager.addDisplayType(() => { - const configSchema = linearHicdisplayConfigSchemaFactory(pluginManager) - return new DisplayType({ - name: 'LinearHicDisplay', - configSchema, - stateModel: linearHicdisplayModelFactory(configSchema), - trackType: 'HicTrack', - viewType: 'LinearGenomeView', - ReactComponent: BaseLinearDisplayComponent, - }) - }) } configure(pluginManager: PluginManager) { diff --git a/plugins/linear-genome-view/src/LaunchLinearGenomeView/index.ts b/plugins/linear-genome-view/src/LaunchLinearGenomeView/index.ts new file mode 100644 index 0000000000..428ab39b7c --- /dev/null +++ b/plugins/linear-genome-view/src/LaunchLinearGenomeView/index.ts @@ -0,0 +1,66 @@ +import PluginManager from '@jbrowse/core/PluginManager' +import { AbstractSessionModel, when } from '@jbrowse/core/util' +import { LinearGenomeViewModel } from '../LinearGenomeView' + +type LGV = LinearGenomeViewModel + +export default (pluginManager: PluginManager) => { + pluginManager.addToExtensionPoint( + 'LaunchView-LinearGenomeView', + // @ts-ignore + async ({ + session, + assembly, + loc, + tracks = [], + }: { + session: AbstractSessionModel + assembly?: string + loc: string + tracks?: string[] + }) => { + try { + const { assemblyManager } = session + const view = session.addView('LinearGenomeView', {}) as LGV + + await when(() => !!view.volatileWidth) + + if (!assembly) { + throw new Error( + 'No assembly provided when launching linear genome view', + ) + } + + const asm = await assemblyManager.waitForAssembly(assembly) + if (!asm) { + throw new Error( + `Assembly "${assembly}" not found when launching linear genome view`, + ) + } + + view.navToLocString(loc, assembly) + + const idsNotFound = [] as string[] + tracks.forEach(track => { + try { + view.showTrack(track) + } catch (e) { + if (`${e}`.match('Could not resolve identifier')) { + idsNotFound.push(track) + } else { + throw e + } + } + }) + if (idsNotFound.length) { + throw new Error( + `Could not resolve identifiers: ${idsNotFound.join(',')}`, + ) + } + } catch (e) { + session.notify(`${e}`, 'error') + throw e + } + }, + ) +} diff --git a/plugins/linear-genome-view/src/LinearBareDisplay/index.ts b/plugins/linear-genome-view/src/LinearBareDisplay/index.ts index bb7c3318c0..32f56a4ea3 100644 --- a/plugins/linear-genome-view/src/LinearBareDisplay/index.ts +++ b/plugins/linear-genome-view/src/LinearBareDisplay/index.ts @@ -1,2 +1,21 @@ -export { configSchemaFactory } from './configSchema' -export { stateModelFactory } from './model' +import { DisplayType } from '@jbrowse/core/pluggableElementTypes' +import PluginManager from '@jbrowse/core/PluginManager' +import { BaseLinearDisplayComponent } from '../BaseLinearDisplay' +import { configSchemaFactory } from './configSchema' +import { stateModelFactory } from './model' + +export default (pluginManager: PluginManager) => { + pluginManager.addDisplayType(() => { + const configSchema = configSchemaFactory(pluginManager) + return new DisplayType({ + name: 'LinearBareDisplay', + configSchema, + stateModel: stateModelFactory(configSchema), + trackType: 'BasicTrack', + viewType: 'LinearGenomeView', + ReactComponent: BaseLinearDisplayComponent, + }) + }) +} + +export { configSchemaFactory, stateModelFactory } diff --git a/plugins/linear-genome-view/src/LinearBasicDisplay/index.ts b/plugins/linear-genome-view/src/LinearBasicDisplay/index.ts index 0557262167..1784780622 100644 --- a/plugins/linear-genome-view/src/LinearBasicDisplay/index.ts +++ b/plugins/linear-genome-view/src/LinearBasicDisplay/index.ts @@ -1,2 +1,23 @@ -export { default as modelFactory } from './model' -export { default as configSchema } from './configSchema' +import PluginManager from '@jbrowse/core/PluginManager' +import { DisplayType } from '@jbrowse/core/pluggableElementTypes' +import { BaseLinearDisplayComponent } from '../BaseLinearDisplay' + +// locals +import configSchema from './configSchema' +import modelFactory from './model' + +export default (pluginManager: PluginManager) => { + pluginManager.addDisplayType(() => { + const config = configSchema(pluginManager) + return new DisplayType({ + name: 'LinearBasicDisplay', + configSchema: config, + stateModel: modelFactory(config), + trackType: 'FeatureTrack', + viewType: 'LinearGenomeView', + ReactComponent: BaseLinearDisplayComponent, + }) + }) +} + +export { modelFactory, configSchema } diff --git a/plugins/linear-genome-view/src/LinearBasicDisplay/model.ts b/plugins/linear-genome-view/src/LinearBasicDisplay/model.ts index af641848da..fc91a7df3b 100644 --- a/plugins/linear-genome-view/src/LinearBasicDisplay/model.ts +++ b/plugins/linear-genome-view/src/LinearBasicDisplay/model.ts @@ -18,7 +18,8 @@ const SetMaxHeightDlg = lazy(() => import('./components/SetMaxHeight')) /** * #stateModel LinearBasicDisplay - * used by `FeatureTrack`, has simple settings like "show/hide feature labels", etc. + * used by `FeatureTrack`, has simple settings like "show/hide feature labels", + * etc. */ function stateModelFactory(configSchema: AnyConfigurationSchemaType) { return types diff --git a/plugins/linear-genome-view/src/LinearGenomeView/index.ts b/plugins/linear-genome-view/src/LinearGenomeView/index.ts new file mode 100644 index 0000000000..b9f91e77e3 --- /dev/null +++ b/plugins/linear-genome-view/src/LinearGenomeView/index.ts @@ -0,0 +1,17 @@ +import { lazy } from 'react' +import PluginManager from '@jbrowse/core/PluginManager' +import { ViewType } from '@jbrowse/core/pluggableElementTypes' +import { stateModelFactory } from './model' + +export default (pluginManager: PluginManager) => { + pluginManager.addViewType( + () => + new ViewType({ + name: 'LinearGenomeView', + stateModel: stateModelFactory(pluginManager), + ReactComponent: lazy(() => import('./components/LinearGenomeView')), + }), + ) +} + +export * from './model' diff --git a/plugins/linear-genome-view/src/LinearGenomeView/index.tsx b/plugins/linear-genome-view/src/LinearGenomeView/model.ts similarity index 99% rename from plugins/linear-genome-view/src/LinearGenomeView/index.tsx rename to plugins/linear-genome-view/src/LinearGenomeView/model.ts index bac55ed1b4..c0df2891d5 100644 --- a/plugins/linear-genome-view/src/LinearGenomeView/index.tsx +++ b/plugins/linear-genome-view/src/LinearGenomeView/model.ts @@ -1584,6 +1584,8 @@ export { ZoomControls, LinearGenomeView, } + export type LinearGenomeViewStateModel = ReturnType export type LinearGenomeViewModel = Instance + export { default as ReactComponent } from './components/LinearGenomeView' diff --git a/plugins/linear-genome-view/src/index.ts b/plugins/linear-genome-view/src/index.ts index c401292585..7fb2da1533 100644 --- a/plugins/linear-genome-view/src/index.ts +++ b/plugins/linear-genome-view/src/index.ts @@ -1,42 +1,36 @@ -import { lazy } from 'react' -import { when } from 'mobx' - -import DisplayType from '@jbrowse/core/pluggableElementTypes/DisplayType' -import ViewType from '@jbrowse/core/pluggableElementTypes/ViewType' import Plugin from '@jbrowse/core/Plugin' import PluginManager from '@jbrowse/core/PluginManager' import { AbstractSessionModel, isAbstractMenuManager } from '@jbrowse/core/util' + +// icons import LineStyleIcon from '@mui/icons-material/LineStyle' + import { BaseLinearDisplay, BaseLinearDisplayComponent, - baseLinearDisplayConfigSchema, BlockModel, + baseLinearDisplayConfigSchema, } from './BaseLinearDisplay' -import { +import LinearBareDisplayF, { configSchemaFactory as linearBareDisplayConfigSchemaFactory, - stateModelFactory as LinearBareDisplayStateModelFactory, } from './LinearBareDisplay' -import { +import LinearGenomeViewF, { + renderToSvg, LinearGenomeViewModel, LinearGenomeViewStateModel, - stateModelFactory as linearGenomeViewStateModelFactory, - renderToSvg, RefNameAutocomplete, SearchBox, ZoomControls, LinearGenomeView, } from './LinearGenomeView' - -import { +import LinearBasicDisplayF, { configSchema as linearBasicDisplayConfigSchemaFactory, modelFactory as linearBasicDisplayModelFactory, } from './LinearBasicDisplay' import FeatureTrackF from './FeatureTrack' import BasicTrackF from './BasicTrack' - -type LGV = LinearGenomeViewModel +import LaunchLinearGenomeViewF from './LaunchLinearGenomeView' export default class LinearGenomeViewPlugin extends Plugin { name = 'LinearGenomeViewPlugin' @@ -53,99 +47,10 @@ export default class LinearGenomeViewPlugin extends Plugin { install(pluginManager: PluginManager) { FeatureTrackF(pluginManager) BasicTrackF(pluginManager) - pluginManager.addDisplayType(() => { - const configSchema = linearBareDisplayConfigSchemaFactory(pluginManager) - return new DisplayType({ - name: 'LinearBareDisplay', - configSchema, - stateModel: LinearBareDisplayStateModelFactory(configSchema), - trackType: 'BasicTrack', - viewType: 'LinearGenomeView', - ReactComponent: BaseLinearDisplayComponent, - }) - }) - - pluginManager.addDisplayType(() => { - const configSchema = linearBasicDisplayConfigSchemaFactory(pluginManager) - return new DisplayType({ - name: 'LinearBasicDisplay', - configSchema, - stateModel: linearBasicDisplayModelFactory(configSchema), - trackType: 'FeatureTrack', - viewType: 'LinearGenomeView', - ReactComponent: BaseLinearDisplayComponent, - }) - }) - - pluginManager.addViewType( - () => - new ViewType({ - name: 'LinearGenomeView', - stateModel: linearGenomeViewStateModelFactory(pluginManager), - ReactComponent: lazy( - () => import('./LinearGenomeView/components/LinearGenomeView'), - ), - }), - ) - - pluginManager.addToExtensionPoint( - 'LaunchView-LinearGenomeView', - // @ts-ignore - async ({ - session, - assembly, - loc, - tracks = [], - }: { - session: AbstractSessionModel - assembly?: string - loc: string - tracks?: string[] - }) => { - try { - const { assemblyManager } = session - const view = session.addView('LinearGenomeView', {}) as LGV - - await when(() => !!view.volatileWidth) - - if (!assembly) { - throw new Error( - 'No assembly provided when launching linear genome view', - ) - } - - const asm = await assemblyManager.waitForAssembly(assembly) - if (!asm) { - throw new Error( - `Assembly "${assembly}" not found when launching linear genome view`, - ) - } - - view.navToLocString(loc, assembly) - - const idsNotFound = [] as string[] - tracks.forEach(track => { - try { - view.showTrack(track) - } catch (e) { - if (`${e}`.match('Could not resolve identifier')) { - idsNotFound.push(track) - } else { - throw e - } - } - }) - if (idsNotFound.length) { - throw new Error( - `Could not resolve identifiers: ${idsNotFound.join(',')}`, - ) - } - } catch (e) { - session.notify(`${e}`, 'error') - throw e - } - }, - ) + LinearBasicDisplayF(pluginManager) + LinearGenomeViewF(pluginManager) + LinearBareDisplayF(pluginManager) + LaunchLinearGenomeViewF(pluginManager) } configure(pluginManager: PluginManager) { diff --git a/plugins/spreadsheet-view/src/LaunchSpreadsheetView/index.ts b/plugins/spreadsheet-view/src/LaunchSpreadsheetView/index.ts new file mode 100644 index 0000000000..3ed0c82dd5 --- /dev/null +++ b/plugins/spreadsheet-view/src/LaunchSpreadsheetView/index.ts @@ -0,0 +1,40 @@ +import PluginManager from '@jbrowse/core/PluginManager' +import { AbstractSessionModel } from '@jbrowse/core/util' +import { SpreadsheetViewModel } from '../SpreadsheetView' + +export default (pluginManager: PluginManager) => { + pluginManager.addToExtensionPoint( + 'LaunchView-SpreadsheetView', + // @ts-ignore + async ({ + session, + assembly, + uri, + fileType, + }: { + session: AbstractSessionModel + assembly: string + uri: string + fileType?: string + }) => { + const view = session.addView('SpreadsheetView') as SpreadsheetViewModel + + if (!view) { + throw new Error('Failed to initialize view') + } + 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({ + uri, + locationType: 'UriLocation', + }) + view.importWizard.import(assembly) + }, + ) +} diff --git a/plugins/spreadsheet-view/src/SpreadsheetView/index.ts b/plugins/spreadsheet-view/src/SpreadsheetView/index.ts new file mode 100644 index 0000000000..85f446a47d --- /dev/null +++ b/plugins/spreadsheet-view/src/SpreadsheetView/index.ts @@ -0,0 +1,19 @@ +import { lazy } from 'react' +import { ViewType } from '@jbrowse/core/pluggableElementTypes' +import PluginManager from '@jbrowse/core/PluginManager' +import stateModel, { + SpreadsheetViewModel, + SpreadsheetViewStateModel, +} from './models/SpreadsheetView' + +export default (pluginManager: PluginManager) => { + pluginManager.addViewType(() => { + return new ViewType({ + name: 'SpreadsheetView', + stateModel, + ReactComponent: lazy(() => import('./components/SpreadsheetView')), + }) + }) +} + +export type { SpreadsheetViewStateModel, SpreadsheetViewModel } diff --git a/plugins/spreadsheet-view/src/index.ts b/plugins/spreadsheet-view/src/index.ts index 6bd69e1de7..aabb781e4c 100644 --- a/plugins/spreadsheet-view/src/index.ts +++ b/plugins/spreadsheet-view/src/index.ts @@ -1,62 +1,24 @@ -import { lazy } from 'react' -import { Instance } from 'mobx-state-tree' -import { AbstractSessionModel, isAbstractMenuManager } from '@jbrowse/core/util' import PluginManager from '@jbrowse/core/PluginManager' import Plugin from '@jbrowse/core/Plugin' +import { AbstractSessionModel, isAbstractMenuManager } from '@jbrowse/core/util' + +// icons import ViewComfyIcon from '@mui/icons-material/ViewComfy' -import ViewType from '@jbrowse/core/pluggableElementTypes/ViewType' -import SpreadsheetViewModel from './SpreadsheetView/models/SpreadsheetView' -type SpreadsheetView = Instance +// locals +import SpreadsheetViewF, { + SpreadsheetViewModel, + SpreadsheetViewStateModel, +} from './SpreadsheetView' + +import LaunchSpreadsheetViewF from './LaunchSpreadsheetView' export default class SpreadsheetViewPlugin extends Plugin { name = 'SpreadsheetViewPlugin' install(pluginManager: PluginManager) { - pluginManager.addViewType(() => { - return new ViewType({ - name: 'SpreadsheetView', - stateModel: SpreadsheetViewModel, - ReactComponent: lazy( - () => import('./SpreadsheetView/components/SpreadsheetView'), - ), - }) - }) - - pluginManager.addToExtensionPoint( - 'LaunchView-SpreadsheetView', - // @ts-ignore - async ({ - session, - assembly, - uri, - fileType, - }: { - session: AbstractSessionModel - assembly: string - uri: string - fileType?: string - }) => { - const view = session.addView('SpreadsheetView') as SpreadsheetView - - if (!view) { - throw new Error('Failed to initialize view') - } - 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({ - uri, - locationType: 'UriLocation', - }) - view.importWizard.import(assembly) - }, - ) + SpreadsheetViewF(pluginManager) + LaunchSpreadsheetViewF(pluginManager) } configure(pluginManager: PluginManager) { @@ -73,4 +35,4 @@ export default class SpreadsheetViewPlugin extends Plugin { } } -export type { SpreadsheetViewModel, SpreadsheetView } +export type { SpreadsheetViewStateModel, SpreadsheetViewModel } diff --git a/plugins/sv-inspector/src/LaunchSvInspectorView/index.ts b/plugins/sv-inspector/src/LaunchSvInspectorView/index.ts new file mode 100644 index 0000000000..8b8215e04e --- /dev/null +++ b/plugins/sv-inspector/src/LaunchSvInspectorView/index.ts @@ -0,0 +1,47 @@ +import PluginManager from '@jbrowse/core/PluginManager' +import { AbstractSessionModel } from '@jbrowse/core/util' +import { SvInspectorViewModel } from '../SvInspectorView/models/SvInspectorView' + +export default (pluginManager: PluginManager) => { + pluginManager.addToExtensionPoint( + 'LaunchView-SvInspectorView', + // @ts-ignore + async ({ + session, + assembly, + uri, + fileType, + }: { + session: AbstractSessionModel + assembly: string + uri: string + fileType?: string + }) => { + // add view, make typescript happy with return type + const view = session.addView( + 'SvInspectorView', + ) as unknown as SvInspectorViewModel + + if (!view) { + throw new Error('Failed to initialize view') + } + const exts = uri.split('.') + let ext = exts?.pop()?.toUpperCase() + if (ext === 'GZ') { + ext = exts?.pop()?.toUpperCase() + } + + // @ts-ignore + view.spreadsheetView.importWizard.setFileType(fileType || ext || '') + // @ts-ignore + view.spreadsheetView.importWizard.setSelectedAssemblyName(assembly) + // @ts-ignore + view.spreadsheetView.importWizard.setFileSource({ + uri, + locationType: 'UriLocation', + }) + // @ts-ignore + view.spreadsheetView.importWizard.import(assembly) + }, + ) +} diff --git a/plugins/sv-inspector/src/SvInspectorView/SvInspectorViewType.js b/plugins/sv-inspector/src/SvInspectorView/SvInspectorViewType.js deleted file mode 100644 index 581ff338f1..0000000000 --- a/plugins/sv-inspector/src/SvInspectorView/SvInspectorViewType.js +++ /dev/null @@ -1,11 +0,0 @@ -import ReactComponent from './components/SvInspectorView' -import StateModelFactory from './models/SvInspectorView' -import ViewType from '@jbrowse/core/pluggableElementTypes/ViewType' - -const SvInspectorViewF = ({ jbrequire }) => { - const { stateModel } = jbrequire(StateModelFactory) - - return new ViewType({ name: 'SvInspectorView', stateModel, ReactComponent }) -} - -export default SvInspectorViewF diff --git a/plugins/sv-inspector/src/SvInspectorView/index.ts b/plugins/sv-inspector/src/SvInspectorView/index.ts new file mode 100644 index 0000000000..baacc41ab1 --- /dev/null +++ b/plugins/sv-inspector/src/SvInspectorView/index.ts @@ -0,0 +1,16 @@ +import PluginManager from '@jbrowse/core/PluginManager' +import ViewType from '@jbrowse/core/pluggableElementTypes/ViewType' + +import ReactComponent from './components/SvInspectorView' +import stateModelFactory from './models/SvInspectorView' + +export default (pluginManager: PluginManager) => { + pluginManager.addViewType(() => { + const { stateModel } = stateModelFactory(pluginManager) + return new ViewType({ + name: 'SvInspectorView', + stateModel, + ReactComponent, + }) + }) +} diff --git a/plugins/sv-inspector/src/SvInspectorView/models/SvInspectorView.ts b/plugins/sv-inspector/src/SvInspectorView/models/SvInspectorView.ts index 07154276b9..8ec20c2d76 100644 --- a/plugins/sv-inspector/src/SvInspectorView/models/SvInspectorView.ts +++ b/plugins/sv-inspector/src/SvInspectorView/models/SvInspectorView.ts @@ -20,7 +20,7 @@ import { getSerializedFeatureForRow, } from './breakpointSplitViewFromTableRow' import PluginManager from '@jbrowse/core/PluginManager' -import { SpreadsheetViewModel } from '@jbrowse/plugin-spreadsheet-view' +import { SpreadsheetViewStateModel } from '@jbrowse/plugin-spreadsheet-view' import { CircularViewStateModel } from '@jbrowse/plugin-circular-view' function defaultOnChordClick( @@ -49,7 +49,7 @@ const SvInspectorViewF = (pluginManager: PluginManager) => { const CircularViewType = pluginManager.getViewType('CircularView') const SpreadsheetModel = - SpreadsheetViewType.stateModel as typeof SpreadsheetViewModel + SpreadsheetViewType.stateModel as SpreadsheetViewStateModel const CircularModel = CircularViewType.stateModel as CircularViewStateModel const minHeight = 400 diff --git a/plugins/sv-inspector/src/index.ts b/plugins/sv-inspector/src/index.ts index 95714c4df6..d74d8e251e 100644 --- a/plugins/sv-inspector/src/index.ts +++ b/plugins/sv-inspector/src/index.ts @@ -4,61 +4,20 @@ import { AbstractSessionModel, isAbstractMenuManager, } from '@jbrowse/core/util/types' + +// icons import TableChartIcon from '@mui/icons-material/TableChart' -import SvInspectorViewTypeFactory from './SvInspectorView/SvInspectorViewType' -import SvInspectorViewModel from './SvInspectorView/models/SvInspectorView' -type SvInspectorView = ReturnType['stateModel'] +// locals +import SvInspectorViewF from './SvInspectorView' +import LaunchSvInspectorViewF from './LaunchSvInspectorView' export default class SvInspectorViewPlugin extends Plugin { name = 'SvInspectorViewPlugin' install(pluginManager: PluginManager) { - pluginManager.addViewType(() => - pluginManager.jbrequire(SvInspectorViewTypeFactory), - ) - - pluginManager.addToExtensionPoint( - 'LaunchView-SvInspectorView', - // @ts-ignore - async ({ - session, - assembly, - uri, - fileType, - }: { - session: AbstractSessionModel - assembly: string - uri: string - fileType?: string - }) => { - // add view, make typescript happy with return type - const view = session.addView( - 'SvInspectorView', - ) as unknown as SvInspectorView - - if (!view) { - throw new Error('Failed to initialize view') - } - const exts = uri.split('.') - let ext = exts?.pop()?.toUpperCase() - if (ext === 'GZ') { - ext = exts?.pop()?.toUpperCase() - } - - // @ts-ignore - view.spreadsheetView.importWizard.setFileType(fileType || ext || '') - // @ts-ignore - view.spreadsheetView.importWizard.setSelectedAssemblyName(assembly) - // @ts-ignore - view.spreadsheetView.importWizard.setFileSource({ - uri, - locationType: 'UriLocation', - }) - // @ts-ignore - view.spreadsheetView.importWizard.import(assembly) - }, - ) + SvInspectorViewF(pluginManager) + LaunchSvInspectorViewF(pluginManager) } configure(pluginManager: PluginManager) {