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

JBrowse2 component integration #1263

Draft
wants to merge 6 commits 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
5 changes: 4 additions & 1 deletion packages/sites/genomics-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@
},
"files": [
"dist"
]
],
"dependencies": {
"@jbrowse/react-linear-genome-view": "^2.16.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { once, debounce } from 'lodash';
import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';
import { httpGet } from '@veupathdb/web-common/lib/util/http';
import { JbrowseIframe } from '@veupathdb/web-common/lib/components/JbrowseIframe';
import JbrowseIframe from './JBrowse2'; // stand-in for iframe component - it's not an iframe any more
import { Loading } from '@veupathdb/wdk-client/lib/Components';
import newFeatureImage from '@veupathdb/wdk-client/lib/Core/Style/images/new-feature.png';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React, { useEffect, useState } from 'react';
import { Loading } from '@veupathdb/wdk-client/lib/Components';
import {
createViewState,
JBrowseLinearGenomeView,
} from '@jbrowse/react-linear-genome-view';

interface JBrowseConfig {
assemblies: { name: string }[];
tracks: any[];
}

interface Props {
jbrowseUrl: string;
height: number;
}

export default function JBrowse2LinearView({
jbrowseUrl,
height = 400,
}: Props) {
// const url = new URL(jbrowseUrl, 'https://example.com');
// const params = url.searchParams;
const assemblyId = 'agamPEST'; // (params.get('data') ?? '').split('/').pop(); // TO DO: better fallback
const location = 'AgamP4_2L'; // params.get('loc');
// const tracks = params.get('tracks'); // comma-delimited track ids

const [config, setConfig] = useState<JBrowseConfig | undefined>();
const [loading, setLoading] = useState(true);

// Could use wdk usePromise? or react-query?
useEffect(() => {
// Fetch the config JSON
fetch('/jbrowse2/config.json')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, this would be a configuration value that gets set in configer. Something like jbrowse2_root_url = /jbrowse2. Then, you can update __SITE_CONFIG__ in EbrcWebsiteCommon/Model/lib/conifer/roles/conifer/templates/EbrcWebsiteCommon/appBase.html.j2 to include that value. Then, update packages/libs/web-common/src/config.ts to export that value. Finally, you can import that here via import { jbrowse2RootUrl } from 'web-common/lib/config';.

.then((response) => {
if (!response.ok) {
throw new Error(`Error: ${response.status}`);
}
return response.json();
})
.then((data) => {
setConfig(data);
setLoading(false);
})
.catch((error) => {
console.error('Failed to load JSON config:', error);
setLoading(false); // Set to false to avoid infinite loading
});
}, []);

if (loading) {
return <Loading />;
}

if (!config) {
return <div>Error loading configuration</div>; // Error handling fallback - TO DO add contact-us etc
}

const assembly = config.assemblies.find(({ name }) => name === assemblyId);

if (!assembly) {
return <div>Error finding assembly '{assemblyId}'</div>;
}
const { tracks } = config;

const viewState = createViewState({
assembly,
tracks,
location,
});

return <JBrowseLinearGenomeView viewState={viewState} />;
}
2 changes: 2 additions & 0 deletions packages/sites/genomics-site/webpack.config.local.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default configure({
...makeCommonDevServerConfig({
rootClientUrl: process.env.ROOT_URL,
proxies: {
[process.env.JBROWSE2_DATA_ENDPOINT]: process.env.JBROWSE2_DATA_URL,
[process.env.JBROWSE2_ENDPOINT]: process.env.JBROWSE2_URL,
[process.env.WDK_SERVICE_ENDPOINT]: process.env.WDK_SERVICE_URL,
[process.env.VDI_SERVICE_ENDPOINT]: process.env.VDI_SERVICE_URL,
[process.env.SITE_SEARCH_SERVICE_ENDPOINT]: process.env.SITE_SEARCH_SERVICE_URL,
Expand Down
Loading
Loading