Skip to content

Commit

Permalink
port NCList_v0 backcompat stuff to AMD
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuels committed Jul 2, 2012
1 parent b659a63 commit 10000f3
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 92 deletions.
2 changes: 2 additions & 0 deletions src/JBrowse/GenomeView.js
Expand Up @@ -1572,6 +1572,8 @@ GenomeView.prototype.renderTrack = function( /**Object*/ trackConfig ) {
seqHeight: this.seqHeight,
store: store
});
if( store.setTrack )
store.setTrack( track );

// tell the track to get its data, since we're going to display it.
track.load();
Expand Down
4 changes: 2 additions & 2 deletions src/JBrowse/Store/NCList_v0.js
@@ -1,5 +1,5 @@
define([],
function() {
define([ 'JBrowse/Finisher', 'JBrowse/Util'],
function( Finisher, Util ) {

/**
* Legacy-compatible NCList for 1.2.1 backward compatibility.
Expand Down
190 changes: 100 additions & 90 deletions src/JBrowse/Store/SeqFeature/NCList_v0.js
@@ -1,101 +1,110 @@
var SeqFeatureStore; if( !SeqFeatureStore) SeqFeatureStore = function() {};
define([
'dojo/_base/declare',
'JBrowse/Store/SeqFeature/NCList',
'JBrowse/Store/NCList_v0'
], function( declare, SFNCList, GenericNCList ) {
return declare( SFNCList,

/**
* Feature storage backend for backward-compatibility with JBrowse 1.2.1 stores.
* @class
* @extends SeqFeatureStore.NCList
* @lends JBrowse.Store.SeqFeature.NCList_v0
*/
{

SeqFeatureStore.NCList_v0 = function(args) {
SeqFeatureStore.NCList.call( this, args );
/**
* Feature storage backend for backward-compatibility with JBrowse 1.2.1 stores.
* @extends SeqFeatureStore.NCList
* @constructs
*/
constructor: function(args) {
SFNCList.call( this, args );

this.fields = {};
this.track = args.track;
};

SeqFeatureStore.NCList_v0.prototype = new SeqFeatureStore.NCList('');


/**
* Delete an object member and return the deleted value.
* @private
*/
SeqFeatureStore.NCList_v0.prototype._del = function( obj, old ) {
var x = obj[old];
delete obj[old];
return x;
};

SeqFeatureStore.NCList_v0.prototype.loadSuccess = function( trackInfo, url ) {

if( trackInfo ) {

// munge the trackInfo to make the histogram stuff work with v1 code
dojo.forEach( trackInfo.histogramMeta, function(m) {
m.arrayParams.urlTemplate = m.arrayParams.urlTemplate.replace(/\{chunk\}/,'{Chunk}');
});
trackInfo.histograms = {
meta: this._del( trackInfo, 'histogramMeta' ),
stats: this._del( trackInfo, 'histStats' )
};
// rename stats.bases to stats.basesPerBin
dojo.forEach( trackInfo.histograms.stats, function(s) {
s.basesPerBin = this._del( s, 'bases' );
},this);

// since the old format had style information inside the
// trackdata file, yuckily push it up to the track's config.style
var renameVar = {
urlTemplate: "linkTemplate"
};
dojo.forEach(
['className','arrowheadClass','subfeatureClasses','urlTemplate','clientConfig'],
function(varname) {
if( !this.track.config.style ) this.track.config.style = {};
var dest_varname = renameVar[varname] || varname;
if( varname in trackInfo )
this.track.config.style[dest_varname] = trackInfo[varname];
},this);

// also need to merge Ye Olde clientConfig values into the style object
if( this.track.config.style.clientConfig ) {
this.track.config.style = dojo.mixin( this.track.config.style, this.track.config.style.clientConfig );
delete this.track.config.style.clientConfig;
}

// remember the field offsets from the old-style trackinfo headers
this.fields = {};
var i;
for (i = 0; i < trackInfo.headers.length; i++) {
this.fields[trackInfo.headers[i]] = i;
}
this.subFields = {};
if (trackInfo.subfeatureHeaders) {
for (i = 0; i < trackInfo.subfeatureHeaders.length; i++) {
this.subFields[trackInfo.subfeatureHeaders[i]] = i;
this.track = args.track;
},

setTrack: function(t) {
this.track = t;
},

/**
* Delete an object member and return the deleted value.
* @private
*/
_del: function( obj, old ) {
var x = obj[old];
delete obj[old];
return x;
},

loadSuccess: function( trackInfo, url ) {

if( trackInfo ) {

// munge the trackInfo to make the histogram stuff work with v1 code
dojo.forEach( trackInfo.histogramMeta, function(m) {
m.arrayParams.urlTemplate = m.arrayParams.urlTemplate.replace(/\{chunk\}/,'{Chunk}');
});
trackInfo.histograms = {
meta: this._del( trackInfo, 'histogramMeta' ),
stats: this._del( trackInfo, 'histStats' )
};
// rename stats.bases to stats.basesPerBin
dojo.forEach( trackInfo.histograms.stats, function(s) {
s.basesPerBin = this._del( s, 'bases' );
},this);

// since the old format had style information inside the
// trackdata file, yuckily push it up to the track's config.style
var renameVar = {
urlTemplate: "linkTemplate"
};
dojo.forEach(
['className','arrowheadClass','subfeatureClasses','urlTemplate','clientConfig'],
function(varname) {
if( !this.track.config.style ) this.track.config.style = {};
var dest_varname = renameVar[varname] || varname;
if( varname in trackInfo )
this.track.config.style[dest_varname] = trackInfo[varname];
},this);

// also need to merge Ye Olde clientConfig values into the style object
if( this.track.config.style.clientConfig ) {
this.track.config.style = dojo.mixin( this.track.config.style, this.track.config.style.clientConfig );
delete this.track.config.style.clientConfig;
}
}

}
// remember the field offsets from the old-style trackinfo headers
this.fields = {};
var i;
for (i = 0; i < trackInfo.headers.length; i++) {
this.fields[trackInfo.headers[i]] = i;
}
this.subFields = {};
if (trackInfo.subfeatureHeaders) {
for (i = 0; i < trackInfo.subfeatureHeaders.length; i++) {
this.subFields[trackInfo.subfeatureHeaders[i]] = i;
}
}

return SeqFeatureStore.NCList.prototype.loadSuccess.call( this, trackInfo, url );
};
}

SeqFeatureStore.NCList_v0.prototype.makeNCList = function() {
return new NCList_v0();
};
return SFNCList.prototype.loadSuccess.call( this, trackInfo, url );
},

SeqFeatureStore.NCList_v0.prototype.loadNCList = function( trackInfo, url ) {
this.nclist.importExisting(trackInfo.featureNCList,
trackInfo.sublistIndex,
trackInfo.lazyIndex,
url,
trackInfo.lazyfeatureUrlTemplate);
};
makeNCList: function() {
return new GenericNCList();
},

loadNCList: function( trackInfo, url ) {
this.nclist.importExisting(trackInfo.featureNCList,
trackInfo.sublistIndex,
trackInfo.lazyIndex,
url,
trackInfo.lazyfeatureUrlTemplate);
},

SeqFeatureStore.NCList_v0.prototype.iterate = function( startBase, endBase, origFeatCallback, finishCallback ) {
var that = this,
iterate: function( startBase, endBase, origFeatCallback, finishCallback ) {
var that = this,
fields = this.fields,
subFields = this.subFields,
get = function(fieldname) {
Expand All @@ -115,11 +124,12 @@ SeqFeatureStore.NCList_v0.prototype.iterate = function( startBase, endBase, orig
featCallBack = function( feature, path ) {
feature.get = get;
dojo.forEach( feature.get('subfeatures'), function(f) {
f.get = subget;
});
f.get = subget;
});
return origFeatCallback( feature, path );
};

return this.nclist.iterate.call( this.nclist, startBase, endBase, featCallBack, finishCallback );
};

return this.nclist.iterate.call( this.nclist, startBase, endBase, featCallBack, finishCallback );
}
});
});

0 comments on commit 10000f3

Please sign in to comment.