Skip to content

Instantly share code, notes, and snippets.

@cmdcolin
Last active November 7, 2017 00:38
Show Gist options
  • Save cmdcolin/d7c849083164510d4f0a93a280b0a92f to your computer and use it in GitHub Desktop.
Save cmdcolin/d7c849083164510d4f0a93a280b0a92f to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>JBrowse - Retrieve data outside of browser</title>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<link rel="stylesheet" type="text/css" href="css/genome.css">
<script type="text/javascript" src="src/dojo/dojo.js" data-dojo-config="async: 1, baseUrl: './src'"></script>
<script type="text/javascript" src="src/JBrowse/init.js"></script>
<style>
pre {
white-space: pre-wrap;
word-wrap: break-word;
}
</style>
<script>
// Require bare bones jbrowse components without using the main browser object
require([
'JBrowse/Browser',
'JBrowse/Store/SeqFeature/GFF3Tabix',
'JBrowse/Store/SeqFeature/NCList',
'JBrowse/Model/SimpleFeature',
'JBrowse/Store/Sequence/StaticChunked',
'JBrowse/View/Export',
'JBrowse/View/Export/GFF3',
'JBrowse/View/Export/FASTA'
],
function(
Browser,
GFF3Tabix,
NCList,
SimpleFeature,
StaticChunkedSequence,
ExportMixin,
GFF3Mixin,
FastaMixin
) {
var getSequence = function(conf, region, callback) {
var conf = dojo.mixin({
storeClass: 'JBrowse/Store/Sequence/StaticChunked',
chunkSize: 20000,
}, conf);
var store = new StaticChunkedSequence(conf);
store.refSeq = { name: region.refseq };
var exp = new dojo.declare([ExportMixin, FastaMixin])({ store: store });
exp.refSeq = store.refSeq;
exp.exportRegion({ ref: region.refseq, start: region.start, end: region.end }, callback);
};
var getGFF = function(conf, region, callback) {
var conf = dojo.mixin({
storeClass: 'JBrowse/Store/SeqFeature/NCList'
}, conf);
var store = new NCList(conf);
store.refSeq = {};
store.refSeq.name = region.refseq;
var exp = new dojo.declare([ExportMixin, GFF3Mixin])({ store: store });
exp.exportRegion({ ref: region.refseq, start: region.start, end: region.end }, callback);
};
// Initialize jbrowse instance in unittestmode so that it doesn't actually draw the browser to screen
var browser = new Browser({unitTestMode: true});
var region = { start: 1, end: 3000, refseq: 'ctgA' };
getSequence({
urlTemplate: 'jbrowse/sample_data/json/volvox/seq/{refseq_dirpath}/{refseq}-',
label: 'DNA',
browser: browser
}, region, function(seq) {
document.getElementById('sequence').innerHTML = seq;
});
getGFF({
urlTemplate: 'jbrowse/sample_data/json/volvox/tracks/Genes/{refseq}/trackData.json',
label: 'Genes',
browser: browser
}, region, function(features) {
document.getElementById('gff').innerHTML = features;
});
});
</script>
</head>
<body>
<h1>JBrowse sequence store access outside of browser</h1>
<pre id="sequence"></pre>
<h1>JBrowse gff store access outside of browser</h1>
<pre id="gff"></pre>
</body>
</html>
@cmdcolin
Copy link
Author

cmdcolin commented Jan 30, 2017

Note that the machinery to figure out where the data directory is sort of messed up so the urlTemplate argument should be specialized for this

Basically, the urlTemplate to the track should include even the jbrowse folder name and the data directory path, so this sample assumes jbrowse is running at 'http://localhost/jbrowse/' and that this HTML file is in the jbrowse folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment