1- import React from 'react'
1+ import React , { useState , useEffect } from 'react'
22//import 'fontsource-roboto'
33import {
44 createViewState ,
55 createJBrowseTheme ,
66 JBrowseLinearGenomeView ,
7+ loadPlugins ,
78 ThemeProvider ,
89} from '@jbrowse/react-linear-genome-view'
10+ import { PluginConstructor } from '@jbrowse/core/Plugin'
11+ import { Ajax , Utils , ActionURL } from '@labkey/api'
912
1013const theme = createJBrowseTheme ( )
1114
12- const assembly = {
13- name : 'GRCh38' ,
14- sequence : {
15- type : 'ReferenceSequenceTrack' ,
16- trackId : 'GRCh38-ReferenceSequenceTrack' ,
17- adapter : {
18- type : 'BgzipFastaAdapter' ,
19- fastaLocation : {
20- uri :
21- 'http://ftp.ensembl.org/pub/release-100/fasta/homo_sapiens/dna_index/Homo_sapiens.GRCh38.dna.toplevel.fa.gz' ,
22- } ,
23- faiLocation : {
24- uri :
25- 'http://ftp.ensembl.org/pub/release-100/fasta/homo_sapiens/dna_index/Homo_sapiens.GRCh38.dna.toplevel.fa.gz.fai' ,
26- } ,
27- gziLocation : {
28- uri :
29- 'http://ftp.ensembl.org/pub/release-100/fasta/homo_sapiens/dna_index/Homo_sapiens.GRCh38.dna.toplevel.fa.gz.gzi' ,
30- } ,
31- } ,
32- } ,
33- aliases : [ 'hg38' ] ,
34- refNameAliases : {
35- adapter : {
36- type : 'RefNameAliasAdapter' ,
37- location : {
38- uri :
39- 'https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/hg38_aliases.txt' ,
40- } ,
41- } ,
42- } ,
43- }
4415
45- const tracks = [
46- {
47- type : 'FeatureTrack' ,
48- trackId : 'ncbi_refseq_109_hg38' ,
49- name : 'NCBI RefSeq (GFF3Tabix)' ,
50- assemblyNames : [ 'GRCh38' ] ,
51- category : [ 'Annotation' ] ,
52- adapter : {
53- type : 'Gff3TabixAdapter' ,
54- gffGzLocation : {
55- uri :
56- 'https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GCA_000001405.15_GRCh38_full_analysis_set.refseq_annotation.sorted.gff.gz' ,
57- } ,
58- index : {
59- location : {
60- uri :
61- 'https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GCA_000001405.15_GRCh38_full_analysis_set.refseq_annotation.sorted.gff.gz.tbi' ,
62- } ,
63- } ,
64- } ,
65- } ,
66- ]
6716
68- const defaultSession = {
69- name : 'My session' ,
70- view : {
71- id : 'linearGenomeView' ,
72- type : 'LinearGenomeView' ,
73- tracks : [
74- {
75- type : 'ReferenceSequenceTrack' ,
76- configuration : 'GRCh38-ReferenceSequenceTrack' ,
77- displays : [
78- {
79- type : 'LinearReferenceSequenceDisplay' ,
80- configuration :
81- 'GRCh38-ReferenceSequenceTrack-LinearReferenceSequenceDisplay' ,
82- } ,
83- ] ,
84- } ,
85- {
86- type : 'FeatureTrack' ,
87- configuration : 'ncbi_refseq_109_hg38' ,
88- displays : [
89- {
90- type : 'LinearBasicDisplay' ,
91- configuration : 'ncbi_refseq_109_hg38-LinearBasicDisplay' ,
92- } ,
93- ] ,
94- } ,
95- ] ,
96- } ,
97- }
17+ function generateViewState ( genome ) {
18+ /* TODO - Fix plugin functionality
19+ const [plugins, setPlugins] = useState<PluginConstructor[]>()
9820
99- function View ( ) {
100- const state = createViewState ( {
101- assembly,
102- tracks,
103- location : '10:29,838,737..29,838,819' ,
104- defaultSession,
21+ useEffect(() => {
22+ async function getPlugins() {
23+ const loadedPlugins = await loadPlugins(genome.plugins)
24+ setPlugins(loadedPlugins)
25+ }
26+ getPlugins()
27+ }, [setPlugins])
28+ */
29+ return createViewState ( {
30+ assembly : genome . assembly ?? genome . assemblies ,
31+ tracks : genome . tracks ,
32+ configuration : genome . configuration ,
33+ //plugins: plugins,
34+ location : genome . location ,
35+ defaultSession : genome . defaultSession ,
36+ onChange : genome . onChange
10537 } )
106- return (
107- < ThemeProvider theme = { theme } >
108- < JBrowseLinearGenomeView viewState = { state } />
109- </ ThemeProvider >
110- )
111- }
11238
113- export default View
114- // In components/Browser.js
115- /*
116- import React from 'react'
117- import {
118- createViewState,
119- createJBrowseTheme,
120- JBrowseLinearGenomeView,
121- ThemeProvider,
122- } from '@jbrowse/react-linear-genome-view'
123-
124- const theme = createJBrowseTheme()
125-
126- const assembly = {
127- // configuration
12839}
12940
130- const tracks = [
131- // configuration
132- ]
41+ function View ( ) {
42+ const queryParam = new URLSearchParams ( window . location . search ) ;
43+ const session = queryParam . get ( 'session' )
13344
134- const defaultSession = {
135- // configuration
136- }
45+ const [ state , setState ] = useState ( null ) ;
46+ useEffect ( ( ) => {
47+ Ajax . request ( {
48+ url : ActionURL . buildURL ( 'jbrowse' , 'getSession.api' ) ,
49+ method : 'GET' ,
50+ success : function ( res ) { // TODO - handle empty request better
51+ setState ( generateViewState ( JSON . parse ( res . response ) ) ) ;
52+ console . log ( res ) ;
53+ } ,
54+ failure : function ( res ) {
55+ setState ( "invalid" ) ;
56+ console . log ( res ) ;
57+ } ,
58+ params : { session : session }
59+ } ) ;
60+ } , [ ] ) ;
13761
138- function View() {
139- const state = createViewState({
140- assembly,
141- tracks,
142- location: '10:29,838,737..29,838,819',
143- defaultSession,
144- })
145- return (
146- <ThemeProvider theme={theme}>
147- <JBrowseLinearGenomeView viewState={state} />
148- </ThemeProvider>
149- )
62+ if ( session === null ) {
63+ return ( < p > Error - no session provided.</ p > )
64+ }
65+ else if ( state === null ) {
66+ return ( < p > Loading...</ p > )
67+ }
68+ else if ( state == "invalid" ) {
69+ return ( < p > "Error fetching config. See console for more details"</ p > )
70+ }
71+ return (
72+ < ThemeProvider theme = { theme } >
73+ < JBrowseLinearGenomeView viewState = { state } />
74+ </ ThemeProvider >
75+ )
15076}
15177
15278export default View
153- */
0 commit comments