-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from tripal/tv4-renderJBrowseFromURL
Integration with JBrowse2 by providing a config.json via URL
- Loading branch information
Showing
5 changed files
with
65 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,42 @@ | ||
// This is derived from JBrowse2 documentation for embedding a JBrowse: | ||
// https://jbrowse.org/jb2/docs/tutorials/embed_linear_genome_view/06_creating_the_view/ | ||
// @TODO: We want to make fields for the assembly and tracks files | ||
// and pull those variables in | ||
import assembly from '/assembly.js' | ||
import tracks from '/tracks.js' | ||
const { createViewState, JBrowseLinearGenomeView } = | ||
JBrowseReactLinearGenomeView | ||
const { createElement } = React | ||
const { render } = ReactDOM | ||
const state = new createViewState({ | ||
assembly, | ||
tracks, | ||
location: '1:100,987,269..100,987,368', | ||
}) | ||
render( | ||
createElement(JBrowseLinearGenomeView, { viewState: state }), | ||
document.getElementById('jbrowse_linear_genome_view'), | ||
) | ||
|
||
Drupal.behaviors.embedJBrowse = { | ||
attach: function (context, settings) { | ||
// Use context to filter the DOM to only the elements of interest, | ||
// and use once() to guarantee that our callback function processes | ||
// any given element one time at most, regardless of how many times | ||
// the behaviour itself is called (it is not sufficient in general | ||
// to assume an element will only ever appear in a single context). | ||
once('embedJBrowse', '#jbrowse_linear_genome_view', context).forEach( | ||
function (element) { | ||
Drupal.ajax({ | ||
headers: { "Content-Type": "application/json" }, | ||
url: drupalSettings.jbrowseUrl, | ||
method: "GET", | ||
success: function (data, status, xhr) { | ||
const { createViewState, JBrowseLinearGenomeView } = | ||
JBrowseReactLinearGenomeView | ||
const { createElement } = React | ||
const { render } = ReactDOM | ||
const params = { | ||
assembly: data['assemblies'][0], | ||
tracks: data['tracks'], | ||
} | ||
// If a starting location was not set, then the default behavior | ||
// is to prompt the user to select a chromosome | ||
if (drupalSettings.location) { | ||
params.location = drupalSettings.location | ||
} | ||
const state = new createViewState(params) | ||
render( | ||
createElement(JBrowseLinearGenomeView, { viewState: state }), | ||
document.getElementById('jbrowse_linear_genome_view'), | ||
) | ||
} | ||
}).execute(); | ||
} | ||
); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters