Skip to content

Commit

Permalink
Add text searching to desktop and allow it to reload after installing…
Browse files Browse the repository at this point in the history
… plugins
  • Loading branch information
cmdcolin committed Sep 13, 2021
1 parent 37ed77b commit d178fed
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 25 deletions.
13 changes: 7 additions & 6 deletions products/jbrowse-desktop/public/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,13 @@ ipcMain.handle('listSessions', async () => {
)
})

ipcMain.handle('loadExternalConfig', (_event: unknown, sessionPath) =>
readFile(sessionPath, 'utf8'),
)
ipcMain.handle('loadSession', (_event: unknown, sessionName: string) =>
readFile(getPath(sessionName), 'utf8'),
)
ipcMain.handle('loadExternalConfig', (_event: unknown, sessionPath) => {
return readFile(sessionPath, 'utf8')
})

ipcMain.handle('loadSession', (_event: unknown, sessionName: string) => {
return readFile(getPath(sessionName), 'utf8')
})

ipcMain.on('saveSession', async (_event: unknown, snap: SessionSnap) => {
const page = await mainWindow?.capturePage()
Expand Down
55 changes: 47 additions & 8 deletions products/jbrowse-desktop/src/Loader.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,62 @@
import React, { useState } from 'react'
import PluginManager from '@jbrowse/core/PluginManager'
import { CssBaseline, ThemeProvider } from '@material-ui/core'
import React, { useState, useEffect } from 'react'
import { observer } from 'mobx-react'
import PluginManager from '@jbrowse/core/PluginManager'
import { CssBaseline, ThemeProvider, Typography } from '@material-ui/core'
import { createJBrowseTheme } from '@jbrowse/core/ui'
import {
StringParam,
QueryParamProvider,
useQueryParam,
} from 'use-query-params'
import { ipcRenderer } from 'electron'

import { createPluginManager } from './StartScreen/util'

import JBrowse from './JBrowse'
import StartScreen from './StartScreen'
import { createJBrowseTheme } from '@jbrowse/core/ui'

function Loader() {
const Loader = observer(() => {
const [pluginManager, setPluginManager] = useState<PluginManager>()
const [config, setConfig] = useQueryParam('config', StringParam)
const [error, setError] = useState<Error>()

useEffect(() => {
;(async () => {
if (config) {
try {
const data = await ipcRenderer.invoke('loadSession', config)
const pm = await createPluginManager(JSON.parse(data))
setPluginManager(pm)
setConfig('')
} catch (e) {
console.error(e)
setError(e)
}
}
})()
}, [config, setConfig])

return (
<ThemeProvider theme={createJBrowseTheme()}>
<CssBaseline />
{error ? (
<Typography variant="h6" color="error">{`${error}`}</Typography>
) : null}
{pluginManager?.rootModel?.session ? (
<JBrowse pluginManager={pluginManager} />
) : (
) : !config || error ? (
<StartScreen setPluginManager={setPluginManager} />
)}
) : null}
</ThemeProvider>
)
})

function Wrapper() {
return (
<QueryParamProvider>
<Loader />
</QueryParamProvider>
)
}

export default observer(Loader)
export default Wrapper
77 changes: 77 additions & 0 deletions products/jbrowse-desktop/src/StartScreen/data/preloadedConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,47 @@ const preloadedConfigs = {
},
},
},
{
type: 'FeatureTrack',
trackId: 'ncbi_refseq_109_hg38_latest',
name: 'NCBI RefSeq',
assemblyNames: ['hg38'],
category: ['Annotation'],
adapter: {
type: 'Gff3TabixAdapter',
gffGzLocation: {
uri:
'https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GRCh38_latest_genomic.sort.gff.gz',
},
index: {
location: {
uri:
'https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GRCh38_latest_genomic.sort.gff.gz.tbi',
},
},
},
},
],

defaultSession: {
name: 'New Session',
},
aggregateTextSearchAdapters: [
{
type: 'TrixTextSearchAdapter',
textSearchAdapterId: 'hg38-index',
ixFilePath: {
uri: 'https://jbrowse.org/genomes/GRCh38/trix/hg38.ix',
},
ixxFilePath: {
uri: 'https://jbrowse.org/genomes/GRCh38/trix/hg38.ixx',
},
metaFilePath: {
uri: 'https://jbrowse.org/genomes/GRCh38/trix/meta.json',
},
assemblyNames: ['hg38'],
},
],
},
hg19: {
assemblies: [
Expand Down Expand Up @@ -243,6 +279,30 @@ const preloadedConfigs = {
},
],
tracks: [
{
type: 'FeatureTrack',
trackId: 'ncbi_gff_hg19',
name: 'NCBI RefSeq',
assemblyNames: ['hg19'],
category: ['Annotation'],
metadata: {
source: 'https://www.ncbi.nlm.nih.gov/genome/guide/human/',
dateaccessed: '12/03/2020',
},
adapter: {
type: 'Gff3TabixAdapter',
gffGzLocation: {
uri:
'https://s3.amazonaws.com/jbrowse.org/genomes/hg19/ncbi_refseq/GRCh37_latest_genomic.sort.gff.gz',
},
index: {
location: {
uri:
'https://s3.amazonaws.com/jbrowse.org/genomes/hg19/ncbi_refseq/GRCh37_latest_genomic.sort.gff.gz.tbi',
},
},
},
},
{
type: 'FeatureTrack',
trackId: 'repeats_hg19',
Expand Down Expand Up @@ -397,6 +457,23 @@ const preloadedConfigs = {
defaultSession: {
name: 'New Session',
},

aggregateTextSearchAdapters: [
{
type: 'TrixTextSearchAdapter',
textSearchAdapterId: 'hg19-index',
ixFilePath: {
uri: 'https://jbrowse.org/genomes/hg19/trix/hg19.ix',
},
ixxFilePath: {
uri: 'https://jbrowse.org/genomes/hg19/trix/hg19.ixx',
},
metaFilePath: {
uri: 'https://jbrowse.org/genomes/hg19/trix/meta.json',
},
assemblyNames: ['hg19'],
},
],
},
mm10: {
assemblies: [
Expand Down
2 changes: 2 additions & 0 deletions products/jbrowse-desktop/src/corePlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Wiggle from '@jbrowse/plugin-wiggle'
import SpreadsheetViewPlugin from '@jbrowse/plugin-spreadsheet-view'
import SvInspectorPlugin from '@jbrowse/plugin-sv-inspector'
import HicPlugin from '@jbrowse/plugin-hic'
import TrixPlugin from '@jbrowse/plugin-trix'
import GridBookmarkPlugin from '@jbrowse/plugin-grid-bookmark'

const corePlugins = [
Expand All @@ -45,6 +46,7 @@ const corePlugins = [
SvInspectorPlugin,
BreakpointSplitView,
HicPlugin,
TrixPlugin,
GridBookmarkPlugin,
]

Expand Down
3 changes: 3 additions & 0 deletions products/jbrowse-desktop/src/jbrowseModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export default function JBrowseDesktop(
// track configuration is an array of track config schemas. multiple
// instances of a track can exist that use the same configuration
tracks: types.array(pluginManager.pluggableConfigSchemaType('track')),
aggregateTextSearchAdapters: types.array(
pluginManager.pluggableConfigSchemaType('text search adapter'),
),
connections: types.array(
pluginManager.pluggableConfigSchemaType('connection'),
),
Expand Down
20 changes: 9 additions & 11 deletions products/jbrowse-desktop/src/rootModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { autorun } from 'mobx'
import PluginManager from '@jbrowse/core/PluginManager'
import RpcManager from '@jbrowse/core/rpc/RpcManager'
import { MenuItem } from '@jbrowse/core/ui'
import AddIcon from '@material-ui/icons/Add'
import SettingsIcon from '@material-ui/icons/Settings'
import TextSearchManager from '@jbrowse/core/TextSearch/TextSearchManager'
import AppsIcon from '@material-ui/icons/Apps'
import electron from 'electron'
import {
Expand Down Expand Up @@ -58,6 +58,7 @@ export default function rootModelFactory(pluginManager: PluginManager) {
.volatile(() => ({
pluginsUpdated: false,
error: undefined as Error | undefined,
textSearchManager: new TextSearchManager(pluginManager),
}))
.actions(self => ({
setSavedSessionNames(sessionNames: string[]) {
Expand Down Expand Up @@ -109,13 +110,6 @@ export default function rootModelFactory(pluginManager: PluginManager) {
{
label: 'File',
menuItems: [
{
label: 'New Session',
icon: AddIcon,
onClick: (session: { setDefaultSession: () => void }) => {
session.setDefaultSession()
},
},
{
label: 'Return to start screen',
icon: AppsIcon,
Expand Down Expand Up @@ -294,15 +288,19 @@ export default function rootModelFactory(pluginManager: PluginManager) {
self,
autorun(
() => {
// if (self.session) {
// ipcRenderer.send('saveSession', getSnapshot(self.session))
// }
if (self.session) {
ipcRenderer.send('saveSession', {
...getSnapshot(self.jbrowse),
defaultSession: getSnapshot(self.session),
})
}
if (self.pluginsUpdated) {
const url = window.location.href.split('?')[0]

window.location.href = `${url}?config=${encodeURIComponent(
self.session?.name || '',
)}`
}
},
{ delay: 1000 },
),
Expand Down

0 comments on commit d178fed

Please sign in to comment.