Skip to content

Commit 0857383

Browse files
author
hextraza
committed
Implement RefNameAutocomplete view of the current session
1 parent 3a031cf commit 0857383

File tree

5 files changed

+137
-4
lines changed

5 files changed

+137
-4
lines changed

jbrowse/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"assert": "^2.0.0",
2020
"browserify-zlib": "^0.2.0",
2121
"buffer": "^6.0.3",
22+
"mobx": "^5.0.0",
23+
"mobx-react": "^6.0.0",
24+
"mobx-state-tree": "3.14.1",
2225
"node-polyfill-webpack-plugin": "1.1.0",
2326
"path-browserify": "^1.0.1",
2427
"pkg": "^5.3.2",
@@ -30,7 +33,6 @@
3033
"vm-browserify": "^1.1.2"
3134
},
3235
"devDependencies": {
33-
"rimraf": "~3.0.2",
3436
"@labkey/build": "^4.0.1",
3537
"@types/enzyme": "^3.10.9",
3638
"@types/jest": "^27.0.1",
@@ -40,9 +42,10 @@
4042
"enzyme-adapter-react-16": "^1.15.6",
4143
"enzyme-to-json": "^3.6.2",
4244
"jest": "^27.2.0",
43-
"jest-teamcity-reporter": "^0.9.0",
4445
"jest-cli": "^27.2.0",
46+
"jest-teamcity-reporter": "^0.9.0",
4547
"react-test-renderer": "^17.0.2",
48+
"rimraf": "~3.0.2",
4649
"ts-jest": "^27.0.5"
4750
},
4851
"browser": {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, { useState } from 'react'
2+
import { observer } from 'mobx-react'
3+
import { getSession } from '@jbrowse/core/util'
4+
import { RefNameAutocomplete } from '@jbrowse/plugin-linear-genome-view'
5+
import { ViewModel } from '@jbrowse/react-linear-genome-view'
6+
import BaseResult, { RefSequenceResult }from '@jbrowse/core/TextSearch/BaseResults'
7+
8+
const RefNameAutocompleteWrapper = observer(({ viewState }: { viewState: ViewModel }) => {
9+
const { session } = viewState
10+
const { view } = session
11+
12+
const { assemblyNames, assemblyManager } = getSession(view)
13+
14+
const [selectedAsm, setSelectedAsm] = useState(assemblyNames[0])
15+
const [op, setOption] = useState<BaseResult | undefined>()
16+
17+
const assembly = assemblyManager.get(selectedAsm)
18+
const regions = assembly?.regions || []
19+
20+
const selectedRegion = op?.getLocation()
21+
const message = !assemblyNames.length ? 'No configured assemblies' : ''
22+
23+
return (
24+
<RefNameAutocomplete
25+
model={view}
26+
assemblyName={message ? undefined : selectedAsm}
27+
value={selectedRegion}
28+
onSelect={option => {
29+
setOption(option)
30+
}}
31+
TextFieldProps={{
32+
margin: 'normal',
33+
variant: 'outlined',
34+
helperText: 'Enter a sequence or location',
35+
}}
36+
/>
37+
)
38+
})
39+
40+
export default RefNameAutocompleteWrapper
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import React, {useState, useEffect} from 'react'
2+
//import 'fontsource-roboto'
3+
import {
4+
createViewState,
5+
createJBrowseTheme,
6+
JBrowseLinearGenomeView,
7+
loadPlugins,
8+
ThemeProvider,
9+
} from '@jbrowse/react-linear-genome-view'
10+
11+
import { PluginConstructor } from '@jbrowse/core/Plugin'
12+
import { Ajax, Utils, ActionURL } from '@labkey/api'
13+
import MyProjectPlugin from "./plugins/MyProjectPlugin/index"
14+
import LogSession from "./plugins/LogSession/index"
15+
import ExtendedVariantPlugin from "./plugins/ExtendedVariantPlugin/index"
16+
import RefNameAutocompleteWrapper from "./RefNameAutocompleteWrapper"
17+
18+
const theme = createJBrowseTheme()
19+
const nativePlugins = [MyProjectPlugin, ExtendedVariantPlugin, LogSession]
20+
21+
function generateViewState(genome, plugins){
22+
return createViewState({
23+
assembly: genome.assembly ?? genome.assemblies,
24+
tracks: genome.tracks,
25+
configuration: genome.configuration,
26+
plugins: plugins.concat(nativePlugins),
27+
location: genome.location,
28+
defaultSession: genome.defaultSession,
29+
onChange: genome.onChange
30+
})
31+
}
32+
33+
function Search(){
34+
// Grab session + location information from URL params
35+
const queryParam = new URLSearchParams(window.location.search);
36+
const session = queryParam.get('session')
37+
const location = queryParam.get('location')
38+
39+
const [state, setState] = useState(null);
40+
const [plugins, setPlugins] = useState<PluginConstructor[]>();
41+
42+
// Get the LinearGenomeViewModel from the API, providing the session as a parameter
43+
useEffect(() => {
44+
Ajax.request({
45+
url: ActionURL.buildURL('jbrowse', 'getSession.api'),
46+
method: 'GET',
47+
success: async function(res){
48+
let jsonRes = JSON.parse(res.response);
49+
if (location) {
50+
jsonRes.location = location;
51+
}
52+
53+
var loadedPlugins = null
54+
if (jsonRes.plugins != null){
55+
try {
56+
loadedPlugins = await loadPlugins(jsonRes.plugins);
57+
} catch (error) {
58+
console.error("Error: ", error)
59+
}
60+
setPlugins(loadedPlugins);
61+
} else {
62+
loadedPlugins = []
63+
}
64+
setState(generateViewState(jsonRes, loadedPlugins));
65+
},
66+
failure: function(res){
67+
setState("invalid");
68+
console.log(res);
69+
},
70+
params: {session: session}
71+
});
72+
}, []);
73+
74+
// Error handle and then render the component
75+
if(session === null){
76+
return(<p>Error - no session provided.</p>)
77+
}
78+
else if (state === null){
79+
return (<p>Loading...</p>)
80+
}
81+
else if (state == "invalid") {
82+
return (<p>Error fetching config. See console for more details</p>)
83+
}
84+
return (
85+
<RefNameAutocompleteWrapper viewState={state} />
86+
)
87+
}
88+
89+
export default Search
90+

jbrowse/src/client/JBrowse/Browser/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ const session = queryParam.get('session')
1111
// Need to wait for container element to be available in labkey wrapper before render
1212
window.addEventListener('DOMContentLoaded', (event) => {
1313
ReactDOM.render(<View />, document.getElementById('app'))
14-
});
14+
});

jbrowse/src/client/entryPoints.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ module.exports = {
1111
template: 'app',
1212
path: './src/client/JBrowse/Browser'
1313
}]
14-
};
14+
};

0 commit comments

Comments
 (0)