forked from GMOD/jbrowse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
241 lines (200 loc) · 10.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JBrowse</title>
<link rel="stylesheet" type="text/css" href="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>
<script type="text/javascript">
window.onerror=function(msg){
if( document.body )
document.body.setAttribute("JSError",msg);
}
// puts the main Browser object in this for convenience. feel
// free to move it into function scope if you want to keep it
// out of the global namespace
var JBrowse;
require(['JBrowse/Browser', 'dojo/io-query', 'dojo/json' ],
function (Browser,ioQuery,JSON) {
// the initial configuration of this JBrowse
// instance
// NOTE: this initial config is the same as any
// other JBrowse config in any other file. this
// one just sets defaults from URL query params.
// If you are embedding JBrowse in some other app,
// you might as well just set this initial config
// to something like { include: '../my/dynamic/conf.json' },
// or you could put the entire
// dynamically-generated JBrowse config here.
// parse the query vars in the page URL
var queryParams = ioQuery.queryToObject( window.location.search.slice(1) );
var config = {
containerID: "GenomeBrowser",
dataRoot: queryParams.data,
queryParams: queryParams,
location: queryParams.loc,
forceTracks: queryParams.tracks,
initialHighlight: queryParams.highlight,
show_nav: queryParams.nav,
show_tracklist: queryParams.tracklist,
show_overview: queryParams.overview,
show_menu: queryParams.menu,
stores: { url: { type: "JBrowse/Store/SeqFeature/FromConfig", features: [] } },
makeFullViewURL: function( browser ) {
// the URL for the 'Full view' link
// in embedded mode should be the current
// view URL, except with 'nav', 'tracklist',
// and 'overview' parameters forced to 1.
return browser.makeCurrentViewURL({ nav: 1, tracklist: 1, overview: 1 });
},
updateBrowserURL: true
};
//if there is ?addFeatures in the query params,
//define a store for data from the URL
if( queryParams.addFeatures ) {
config.stores.url.features = JSON.parse( queryParams.addFeatures );
}
// if there is ?addTracks in the query params, add
// those track configurations to our initial
// configuration
if( queryParams.addTracks ) {
config.tracks = JSON.parse( queryParams.addTracks );
}
// if there is ?addStores in the query params, add
// those store configurations to our initial
// configuration
if( queryParams.addStores ) {
config.stores = JSON.parse( queryParams.addStores );
}
function start_jbrowse(cfg) {
// create a JBrowse global variable holding the JBrowse instance
JBrowse = new Browser( cfg );
}
if( queryParams.addFeaturesBatch || queryParams.addTracksBatch || queryParams.addStoresBatch || queryParams.addAllBatch) {
console.log("has batch");
if (typeof(queryParams.addFeaturesBatch) == 'undefined' ) {
queryParams.addFeaturesBatch = null;
}
if (typeof(queryParams.addTracksBatch) == 'undefined' ) {
queryParams.addTracksBatch = null;
}
if (typeof(queryParams.addStoresBatch) == 'undefined' ) {
queryParams.addStoresBatch = null;
}
if (typeof(queryParams.addAllBatch) == 'undefined' ) {
queryParams.addAllBatch = null;
}
if (typeof(config.stores.url.features) == 'undefined' ) {
config.stores.url.features = '';
}
if (typeof(config.tracks) == 'undefined' ) {
config.tracks = [];
}
if (typeof(config.stores) == 'undefined' ) {
config.stores = {};
}
load_batches( config, queryParams.addFeaturesBatch, queryParams.addTracksBatch, queryParams.addStoresBatch, queryParams.addAllBatch, function(){ start_jbrowse(config); } )
} else {
console.log("no batch");
start_jbrowse(config);
}
});
function load_batches( config, addFeaturesBatch, addTracksBatch, addStoresBatch, addAllBatch, callback ) {
console.log("config.stores.url.features", config.stores.url.features);
console.log("config.tracks" , config.tracks);
console.log("config.stores" , config.stores);
console.log("loading feature batch", addFeaturesBatch);
load_json( addFeaturesBatch, function(res1){
console.log("loaded feature batch", addFeaturesBatch, "res", res1);
if (res1 != null) {
console.log("parsing feature batch", res1);
config.stores.url.features += res1.join(',');
} else {
console.log("no feature to parse");
}
console.log("loading tracks batch", addTracksBatch);
load_json( addTracksBatch , function(res2){
console.log("loaded tracks batch", addTracksBatch, "res", res2);
if (res2 != null) {
console.log("parsing tracks batch", res2);
for ( var t in res2 ) {
console.log("t", res2[t]);
config.tracks.push(res2[t]);
}
} else {
console.log("no track to parse");
}
console.log("loading stores batch", addStoresBatch);
load_json( addStoresBatch , function(res3){
console.log("loaded stores batch", addStoresBatch, "res", res3);
if (res3 != null) {
console.log("parsing stores batch", res3);
for ( var s in res3 ) {
console.log("s", res3[s]);
config.stores[s] = res3[s];
}
} else {
console.log("no store to parse");
}
console.log("loading all batch", addAllBatch);
load_json( addAllBatch , function(res4){
console.log("loaded all batch", addAllBatch, "res", res4);
if (res4 != null) {
console.log("parsing all batch", res4);
config.stores.url.features += res4['features'].join(',');
for ( var t in res4['tracks'] ) {
console.log("t", res4['tracks'][t]);
config.tracks.push(res4['tracks'][t]);
}
for ( var s in res4['stores'] ) {
console.log("s", res4['stores'][s]);
config.stores[s] = res4['stores'][s];
}
} else {
console.log("no all to parse");
}
console.log("starting JBrowse", "config.stores.url.features", config.stores.url.features, "config.tracks", config.tracks, "config.stores", config.stores);
callback();
} )
} );
} );
} );
}
function load_json( url, clbk ) {
// create a new json handler for dojo.xhrGet (jsoni - insecure json)
dojo.contentHandlers.jsoni = function(xhr) {
// summary: A contentHandler which returns a JavaScript object created from the response data after extra verification on the JSON structure
if (typeof JSON === 'object' && typeof JSON.parse === 'function') {
// if has native JSON.parse, use secure JSON.parse
//fromJson has a second argument which will force extra scrutiny
//on the JSON string
return _d.fromJson(xhr.responseText || null, true);
} else {
// else, do not attempt to parse
return null;
}
}
if ( url == null ) {
console.log("load_json: url is null");
clbk(null);
} else {
console.log("load_json: url is not null");
dojo.xhrGet({ url : url,
handleAs: "jsoni",
failOk : true,
load : clbk,
error : function( url ) { _alert("failed to load url: "+url); clbk(null); }
});
}
}
function _alert( msg ) {
alert(msg);
}
</script>
</head>
<body>
<div id="GenomeBrowser" style="height: 100%; width: 100%; padding: 0; border: 0;"></div>
<div style="display: none">JBrowseDefaultMainPage</div>
</body>
</html>