Skip to content

Commit

Permalink
Create notion of defaultSessionSpec for config.json files
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 20, 2023
1 parent d2f38c9 commit 767d8ef
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 48 deletions.
36 changes: 14 additions & 22 deletions products/jbrowse-web/src/__snapshots__/jbrowseModel.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions products/jbrowse-web/src/components/NoConfigMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
47 changes: 21 additions & 26 deletions products/jbrowse-web/src/createPluginManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -47,43 +47,38 @@ export function createPluginManager(self: SessionLoaderModel) {

// @ts-expect-error
if (!self.configSnapshot?.configuration?.rpc?.defaultDriver) {
const { rpc } = rootModel.jbrowse.configuration
rpc.defaultDriver.set('WebWorkerRpcDriver')
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`,
`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)
Expand All @@ -94,6 +89,6 @@ export function createPluginManager(self: SessionLoaderModel) {

pluginManager.setRootModel(rootModel)
pluginManager.configure()
afterInitializedCb()
afterInitializedCallback()
return pluginManager
}
1 change: 1 addition & 0 deletions products/jbrowse-web/src/rootModel/rootModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export default function RootModel({

this.setSession(newSession)
},

/**
* #action
*/
Expand Down
63 changes: 63 additions & 0 deletions test_data/volvox/spec.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
}

0 comments on commit 767d8ef

Please sign in to comment.