diff --git a/products/jbrowse-web/src/__snapshots__/jbrowseModel.test.ts.snap b/products/jbrowse-web/src/__snapshots__/jbrowseModel.test.ts.snap index 4febd03643..7dc03e9433 100644 --- a/products/jbrowse-web/src/__snapshots__/jbrowseModel.test.ts.snap +++ b/products/jbrowse-web/src/__snapshots__/jbrowseModel.test.ts.snap @@ -470,34 +470,26 @@ exports[`JBrowse model creates with non-empty snapshot 1`] = ` }, "connections": [], "defaultSession": { - "activeWidgets": { - "hierarchicalTrackSelector": "hierarchicalTrackSelector", - }, - "name": "Integration test example", + "name": "Session", + "type": "spec", "views": [ { - "bpPerPx": 0.05, - "displayedRegions": [ - { - "assemblyName": "volvox", - "end": 50001, - "refName": "ctgA", - "start": 0, - }, + "assembly": "volvox", + "loc": "ctgA:1-100", + "tracks": [ + "volvox_cram_pileup", ], - "id": "integration_test", - "offsetPx": 2000, "type": "LinearGenomeView", }, - ], - "widgets": { - "hierarchicalTrackSelector": { - "filterText": "", - "id": "hierarchicalTrackSelector", - "type": "HierarchicalTrackSelectorWidget", - "view": "integration_test", + { + "assembly": "volvox", + "loc": "ctgB:1-100", + "tracks": [ + "volvox_cram_pileup", + ], + "type": "LinearGenomeView", }, - }, + ], }, "internetAccounts": [], "plugins": [ diff --git a/products/jbrowse-web/src/components/NoConfigMessage.tsx b/products/jbrowse-web/src/components/NoConfigMessage.tsx index 208d278e55..acff3050b2 100644 --- a/products/jbrowse-web/src/components/NoConfigMessage.tsx +++ b/products/jbrowse-web/src/components/NoConfigMessage.tsx @@ -23,6 +23,7 @@ export default function NoConfigMessage() { ['test_data/volvox/config_auth_main.json', 'Volvox (auth, mainthreadrpc)'], ['test_data/volvox/config_auth.json', 'Volvox (auth)'], ['test_data/volvoxhub/config.json', 'Volvox (with ucsc-hub)'], + ['test_data/volvox/spec.json', 'Volvox (with spec defaultsession)'], ] const { href, search } = window.location const { config, ...rest } = Object.fromEntries(new URLSearchParams(search)) diff --git a/products/jbrowse-web/src/createPluginManager.ts b/products/jbrowse-web/src/createPluginManager.ts index 0f12ec234d..bdc90825cd 100644 --- a/products/jbrowse-web/src/createPluginManager.ts +++ b/products/jbrowse-web/src/createPluginManager.ts @@ -8,9 +8,9 @@ import corePlugins from './corePlugins' import { SessionLoaderModel, loadSessionSpec } from './SessionLoader' export function createPluginManager(self: SessionLoaderModel) { - // it is ready when a session has loaded and when there is no config - // error Assuming that the query changes self.sessionError or - // self.sessionSnapshot or self.blankSession + // it is ready when a session has loaded and when there is no config error + // Assuming that the query changes self.sessionError or self.sessionSnapshot + // or self.blankSession const pluginManager = new PluginManager([ ...corePlugins.map(P => ({ plugin: new P(), @@ -50,36 +50,35 @@ export function createPluginManager(self: SessionLoaderModel) { rootModel.jbrowse.configuration.rpc.defaultDriver.set('WebWorkerRpcDriver') } - let afterInitializedCb = () => {} + let afterInitializedCallback = () => {} - // in order: saves the previous autosave for recovery, tries to - // load the local session if session in query, or loads the default - // session + // in order: saves the previous autosave for recovery, tries to load the + // local session if session in query, or loads the default session try { - if (self.sessionError) { + const { defaultSession } = rootModel.jbrowse + const { sessionError, sessionSnapshot, sessionSpec } = self + if (sessionError) { rootModel.setDefaultSession() rootModel.session.notify( `Error loading session: ${self.sessionError}. If you received this URL from another user, request that they send you a session generated with the "Share" button instead of copying and pasting their URL`, ) - } else if (self.sessionSnapshot) { - rootModel.setSession(self.sessionSnapshot) - } else if (self.sessionSpec) { + } else if (sessionSnapshot) { + rootModel.setSession(sessionSnapshot) + } else if (sessionSpec) { // @ts-expect-error - afterInitializedCb = loadSessionSpec(self.sessionSpec, pluginManager) - } else if (rootModel.jbrowse.defaultSession?.views?.length) { + afterInitializedCallback = loadSessionSpec(sessionSpec, pluginManager) + } else if (defaultSession?.type === 'spec') { + afterInitializedCallback = loadSessionSpec(defaultSession, pluginManager) + } else if (defaultSession?.views?.length) { rootModel.setDefaultSession() } } catch (e) { rootModel.setDefaultSession() const str = `${e}` - const errorMessage = str - .replace('[mobx-state-tree] ', '') - .replace(/\(.+/, '') + const err = str.replace('[mobx-state-tree] ', '').replace(/\(.+/, '') rootModel.session?.notify( `Session could not be loaded. ${ - errorMessage.length > 1000 - ? `${errorMessage.slice(0, 1000)}...see more in console` - : errorMessage + err.length > 1000 ? `${err.slice(0, 1000)}...see more in console` : err }`, ) console.error(e) @@ -90,6 +89,6 @@ export function createPluginManager(self: SessionLoaderModel) { pluginManager.setRootModel(rootModel) pluginManager.configure() - afterInitializedCb() + afterInitializedCallback() return pluginManager } diff --git a/products/jbrowse-web/src/rootModel/rootModel.ts b/products/jbrowse-web/src/rootModel/rootModel.ts index e7be402141..48579e1b4c 100644 --- a/products/jbrowse-web/src/rootModel/rootModel.ts +++ b/products/jbrowse-web/src/rootModel/rootModel.ts @@ -278,6 +278,7 @@ export default function RootModel({ this.setSession(newSession) }, + /** * #action */ diff --git a/test_data/volvox/spec.json b/test_data/volvox/spec.json new file mode 100644 index 0000000000..62ba62edf6 --- /dev/null +++ b/test_data/volvox/spec.json @@ -0,0 +1,63 @@ +{ + "assemblies": [ + { + "name": "volvox", + "aliases": ["vvx"], + "sequence": { + "type": "ReferenceSequenceTrack", + "trackId": "volvox_refseq", + "adapter": { + "type": "TwoBitAdapter", + "twoBitLocation": { + "uri": "volvox.2bit", + "locationType": "UriLocation" + } + } + } + } + ], + "connections": [], + "defaultSession": { + "name": "Session", + "type": "spec", + "views": [ + { + "type": "LinearGenomeView", + "tracks": ["volvox_cram_pileup"], + "loc": "ctgA:1-100", + "assembly": "volvox" + }, + { + "type": "LinearGenomeView", + "tracks": ["volvox_cram_pileup"], + "loc": "ctgB:1-100", + "assembly": "volvox" + } + ] + }, + "tracks": [ + { + "type": "AlignmentsTrack", + "trackId": "volvox_cram_pileup", + "name": "volvox-sorted.cram", + "category": ["Integration test"], + "assemblyNames": ["volvox"], + "adapter": { + "type": "CramAdapter", + "cramLocation": { + "uri": "volvox-sorted-altname.cram" + }, + "craiLocation": { + "uri": "volvox-sorted-altname.cram.crai" + }, + "sequenceAdapter": { + "type": "TwoBitAdapter", + "twoBitLocation": { + "uri": "volvox.2bit" + } + }, + "fetchSizeLimit": 1000 + } + } + ] +}