Skip to content

Commit

Permalink
WIP on true datasource objects
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuels committed Mar 15, 2012
1 parent 56df0e6 commit 87f0304
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 67 deletions.
25 changes: 16 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,26 @@
var queryParams = dojo.queryToObject( window.location.search.slice(1) );
var dataRoot = queryParams.data || 'data';
var b = new Browser({
containerID: "GenomeBrowser",
refSeqs: dataRoot + "/seq/refSeqs.json",
include: [
dataRoot + "/trackList.json",
],
nameUrl: dataRoot + "/names/root.json",
defaultTracks: "DNA,gene,mRNA,noncodingRNA",
queryParams: queryParams,
location: queryParams.loc,
forceTracks: queryParams.tracks,
show_nav: queryParams.nav,

datasources: {
main: {
refSeqs: dataRoot + "/seq/refSeqs.json",
baseUrl: dataRoot,
nameUrl: dataRoot + "/names/root.json",
}
},

containerID: "GenomeBrowser",
defaultTracks: "DNA,gene,mRNA,noncodingRNA",
queryParams: queryParams,
location: queryParams.loc,
forceTracks: queryParams.tracks,
show_nav: queryParams.nav,
show_tracklist: queryParams.tracklist,
show_overview: queryParams.overview
show_overview: queryParams.overview
});
/* ]]> */
</script>
Expand Down
54 changes: 47 additions & 7 deletions js/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,27 @@ var Browser = function(params) {
var browser = this;
dojo.addOnLoad( function() { browser.loadConfig(); } );

dojo.connect( this, 'onConfigLoaded', this, 'loadRefSeqs' );
dojo.connect( this, 'onConfigLoaded', this, 'openDataSources' );
dojo.connect( this, 'onConfigLoaded', this, 'loadNames' );
dojo.connect( this, 'onRefSeqsLoaded', this, 'initView' );
dojo.connect( this, 'onDataSourcesLoaded', this, 'initView' );
};

Browser.prototype.loadRefSeqs = function() {
// load our ref seqs
/**
* Open handles for all the configured data sources.
*/
Browser.prototype.openDataSources = function() {
var source_def, source_name;

this.datasources = {};
for( source_name in this.config.datasources ) {
if( !this.config.datasource.hasOwnProperty(source_name))
continue;

source_def = this.config.datasources[source_name];
this.datasources[source_name] = this.openDataSource( source_name, source_def );
}

// load our ref seqs from data sources
var that = this;
if( typeof this.config.refSeqs == 'string' )
this.config.refSeqs = { url: this.config.refSeqs };
Expand All @@ -66,6 +80,27 @@ Browser.prototype.loadRefSeqs = function() {
});
};

/**
* Open a single datasource based on a datasource definition.
* @return {Object} the object handle for the datasource
*/
Browser.prototype.openDataSource = function( name, def ) {
var adaptor_name = def.adaptor || 'SeqFeatureStore.NCList';
var adaptor_class = eval( ''+adaptor );
if( !adaptor_class ) {
console.error("Unable to find the "+adaptor_name+" adaptor for data source "+name+". Is "+adaptor_name+" the correct adaptor name?" );
return null;
}
var adaptor = new adaptor_class(def);
if( !adaptor ) {
console.error("Unable to open data source "+name+".");
return null;
}

return adaptor;
};


/**
* Event that fires when the reference sequences have been loaded.
*/
Expand Down Expand Up @@ -242,7 +277,11 @@ Browser.prototype.loadConfig = function () {
Browser.prototype.onConfigLoaded = function() {

var initial_config = this.config;
this.config = {};

// start the merging process with the defaults
this.config = {
// no defaults yet
};

// load all the configuration data in order
dojo.forEach( initial_config.include, function( config ) {
Expand All @@ -254,6 +293,7 @@ Browser.prototype.onConfigLoaded = function() {
// it overrides the other config
this.addConfigData( initial_config );


this.validateConfig();
};

Expand All @@ -264,8 +304,8 @@ Browser.prototype.onConfigLoaded = function() {
*/
Browser.prototype.validateConfig = function() {
var c = this.config;
if( ! c.baseUrl ) {
throw "Must provide a baseUrl in config.";
if( ! c.datasources || c.datasources.length == 0 ) {
throw "Must provide at least one datasources in config.";
}
};

Expand Down
54 changes: 23 additions & 31 deletions js/FeatureTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,12 @@ function FeatureTrack( config, refSeq, browserParams ) {
track: this
});

// connect the store and track loadSuccess and loadFailed events
// to eachother
dojo.connect( this.featureStore, 'loadSuccess', this, 'loadSuccess' );
dojo.connect( this.featureStore, 'loadFail', this, 'loadFail' );

this.featureStore.load();

//number of histogram bins per block
this.numBins = 25;
this.histLabel = false;
this.padding = 5;
this.trackPadding = browserParams.trackPadding;

this.config = config;
}

FeatureTrack.prototype = new Track("");

FeatureTrack.prototype.loadSuccess = function(trackInfo, url) {

var defaultConfig = {
style: {
className: "feature2"
Expand Down Expand Up @@ -91,9 +77,7 @@ FeatureTrack.prototype.loadSuccess = function(trackInfo, url) {
};
}

Util.deepUpdate(defaultConfig, this.config);
this.config = defaultConfig;

this.config = Util.deepUpdate(defaultConfig, config);
this.config.hooks.create = this.evalHook(this.config.hooks.create);
this.config.hooks.modify = this.evalHook(this.config.hooks.modify);

Expand All @@ -102,9 +86,9 @@ FeatureTrack.prototype.loadSuccess = function(trackInfo, url) {
this.eventHandlers[event] =
this.wrapHandler(this.evalHook(this.config.events[event]));
}
}

this.setLoaded();
};
FeatureTrack.prototype = new Track("");

FeatureTrack.prototype.evalHook = function(hook) {
if (! ("string" == typeof hook)) return hook;
Expand Down Expand Up @@ -145,11 +129,14 @@ FeatureTrack.prototype.setViewInfo = function(genomeView, numBlocks,
FeatureTrack.prototype.fillHist = function(blockIndex, block,
leftBase, rightBase,
stripeWidth) {

var histograms = this.featureStore.histograms( this.refSeq );

// bases in each histogram bin that we're currently rendering
var bpPerBin = (rightBase - leftBase) / this.numBins;
var pxPerCount = 2;
var logScale = false;
var stats = this.featureStore.histograms.stats;
var stats = histograms( this.refSeq ).stats;
for (var i = 0; i < stats.length; i++) {
if (stats[i].bases >= bpPerBin) {
//console.log("bpPerBin: " + bpPerBin + ", histStats bases: " + this.histStats[i].bases + ", mean/max: " + (this.histStats[i].mean / this.histStats[i].max));
Expand Down Expand Up @@ -201,10 +188,10 @@ FeatureTrack.prototype.fillHist = function(blockIndex, block,
// is at 50,000 bases/bin, and we have server histograms at 20,000
// and 2,000 bases/bin, then we should choose the 2,000 histogramMeta
// rather than the 20,000)
var histogramMeta = this.featureStore.histograms.meta[0];
for (var i = 0; i < this.featureStore.histograms.meta.length; i++) {
if (bpPerBin >= this.featureStore.histograms.meta[i].basesPerBin)
histogramMeta = this.featureStore.histograms.meta[i];
var histogramMeta = histograms.meta[0];
for (var i = 0; i < histograms.meta.length; i++) {
if (bpPerBin >= histograms.meta[i].basesPerBin)
histogramMeta = histograms.meta[i];
}

// number of bins in the server-supplied histogram for each current bin
Expand Down Expand Up @@ -235,7 +222,7 @@ FeatureTrack.prototype.fillHist = function(blockIndex, block,
);
} else {
// make our own counts
this.featureStore.histogram( leftBase, rightBase,
this.featureStore.iterateHistogram( leftBase, rightBase,
this.numBins, makeHistBlock);
}
};
Expand Down Expand Up @@ -370,12 +357,17 @@ FeatureTrack.prototype.fillFeatures = function(blockIndex, block,
var startBase = goLeft ? rightBase : leftBase;
var endBase = goLeft ? leftBase : rightBase;

this.featureStore.iterate(startBase, endBase, featCallback,
function () {
block.style.backgroundColor = "";
curTrack.heightUpdate(layouter.totalHeight,
blockIndex);
});
this.featureStore.iterate({
refseq: this.refSeq,
start: startBase,
end: endBase,
feature: featCallback,
finish: function () {
block.style.backgroundColor = "";
curTrack.heightUpdate(layouter.totalHeight,
blockIndex);
}
);
};

FeatureTrack.prototype.measureStyles = function() {
Expand Down
45 changes: 25 additions & 20 deletions js/SeqFeatureStore/NCList.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ SeqFeatureStore.NCList = function(args) {

this.baseUrl = args.baseUrl;
this.urlTemplates = { tracklist: args.urlTemplate };
this.refSeq = args.refSeq;
};

SeqFeatureStore.NCList.prototype = new SeqFeatureStore();
Expand All @@ -27,20 +26,26 @@ SeqFeatureStore.NCList.prototype.makeNCList = function() {
return new NCList();
};

SeqFeatureStore.NCList.prototype.load = function() {
var that = this,
url = Util.resolveUrl(
this.baseUrl,
Util.fillTemplate( this.urlTemplates.tracklist,
{'refseq': this.refSeq.name}
)
);
// fetch the trackdata
dojo.xhrGet({ url: url,
handleAs: "json",
load: Util.debugHandler(this,function(o) { that.loadSuccess(o, url); }),
error: function(e) { console.error(''+e); that.loadFail(e, url); }
});
SeqFeatureStore.NCList.prototype.forRefSeq = function( refSeqName, callback ) {
if( !(refSeqName in this.nclists )) {
var that = this,
data_root_url = Util.resolveUrl(
this.baseUrl,
Util.fillTemplate( this.urlTemplates.tracklist,
{'refseq': refSeqName }
)
);

this.nclists[refSeqName] = 'loading';
// fetch the trackdata
dojo.xhrGet({ url: url,
handleAs: "json",
load: Util.debugHandler( this, function(o) { that.loadSuccess(o, url); }),
error: function(e) { console.error(''+e); that.loadFail(e, url); }
});
} else {

}
};

SeqFeatureStore.NCList.prototype.loadSuccess = function( trackInfo, url ) {
Expand Down Expand Up @@ -72,12 +77,10 @@ SeqFeatureStore.NCList.prototype.loadNCList = function( trackInfo, url ) {


SeqFeatureStore.NCList.prototype.loadFail = function(trackInfo,url) {
this.empty = true;
this.setLoaded();
};

// just forward histogram() and iterate() to our encapsulate nclist
SeqFeatureStore.NCList.prototype.histogram = function() {
SeqFeatureStore.NCList.prototype.iterateHistogram = function() {
return this.nclist.histogram.apply( this.nclist, arguments );
};

Expand All @@ -94,8 +97,10 @@ SeqFeatureStore.NCList.prototype.iterate = function( startBase, endBase, origFea
return this.nclist.iterate.call( this.nclist, startBase, endBase, featCallBack, finishCallback );
};

// helper method to recursively add a .get method to a feature and its
// subfeatures
/**
* Helper method to recursively add a .get method to a feature and its subfeatures.
* @private
*/
SeqFeatureStore.NCList.prototype._add_getters = function(getter,feature) {
var that = this;
feature.get = getter;
Expand Down

0 comments on commit 87f0304

Please sign in to comment.