Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create defaultSession spec for config.json files to load simplified default sessions #4148

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
39 changes: 19 additions & 20 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 @@ -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)
Expand All @@ -90,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
}
}
]
}