1 var SeqFeatureStore; if( !SeqFeatureStore) SeqFeatureStore = function() {}; 2 3 /** 4 * Feature storage backend for backward-compatibility with JBrowse 1.2.1 stores. 5 * @class 6 * @extends SeqFeatureStore.NCList 7 */ 8 9 SeqFeatureStore.NCList_v0 = function(args) { 10 SeqFeatureStore.NCList.call( this, args ); 11 12 this.fields = {}; 13 this.track = args.track; 14 }; 15 16 SeqFeatureStore.NCList_v0.prototype = new SeqFeatureStore.NCList(''); 17 18 19 /** 20 * Delete an object member and return the deleted value. 21 * @private 22 */ 23 SeqFeatureStore.NCList_v0.prototype._del = function( obj, old ) { 24 var x = obj[old]; 25 delete obj[old]; 26 return x; 27 }; 28 29 SeqFeatureStore.NCList_v0.prototype.loadSuccess = function( trackInfo, url ) { 30 31 if( trackInfo ) { 32 33 // munge the trackInfo to make the histogram stuff work with v1 code 34 dojo.forEach( trackInfo.histogramMeta, function(m) { 35 m.arrayParams.urlTemplate = m.arrayParams.urlTemplate.replace(/\{chunk\}/,'{Chunk}'); 36 }); 37 trackInfo.histograms = { 38 meta: this._del( trackInfo, 'histogramMeta' ), 39 stats: this._del( trackInfo, 'histStats' ) 40 }; 41 // rename stats.bases to stats.basesPerBin 42 dojo.forEach( trackInfo.histograms.stats, function(s) { 43 s.basesPerBin = this._del( s, 'bases' ); 44 },this); 45 46 // since the old format had style information inside the 47 // trackdata file, yuckily push it up to the track's config.style 48 var renameVar = { 49 urlTemplate: "linkTemplate" 50 }; 51 dojo.forEach( 52 ['className','arrowheadClass','subfeatureClasses','urlTemplate','clientConfig'], 53 function(varname) { 54 if( !this.track.config.style ) this.track.config.style = {}; 55 var dest_varname = renameVar[varname] || varname; 56 if( varname in trackInfo ) 57 this.track.config.style[dest_varname] = trackInfo[varname]; 58 },this); 59 60 // also need to merge Ye Olde clientConfig values into the style object 61 if( this.track.config.style.clientConfig ) { 62 this.track.config.style = dojo.mixin( this.track.config.style, this.track.config.style.clientConfig ); 63 delete this.track.config.style.clientConfig; 64 } 65 66 // remember the field offsets from the old-style trackinfo headers 67 this.fields = {}; 68 var i; 69 for (i = 0; i < trackInfo.headers.length; i++) { 70 this.fields[trackInfo.headers[i]] = i; 71 } 72 this.subFields = {}; 73 if (trackInfo.subfeatureHeaders) { 74 for (i = 0; i < trackInfo.subfeatureHeaders.length; i++) { 75 this.subFields[trackInfo.subfeatureHeaders[i]] = i; 76 } 77 } 78 79 } 80 81 return SeqFeatureStore.NCList.prototype.loadSuccess.call( this, trackInfo, url ); 82 }; 83 84 SeqFeatureStore.NCList_v0.prototype.makeNCList = function() { 85 return new NCList_v0(); 86 }; 87 88 SeqFeatureStore.NCList_v0.prototype.loadNCList = function( trackInfo, url ) { 89 this.nclist.importExisting(trackInfo.featureNCList, 90 trackInfo.sublistIndex, 91 trackInfo.lazyIndex, 92 url, 93 trackInfo.lazyfeatureUrlTemplate); 94 }; 95 96 97 SeqFeatureStore.NCList_v0.prototype.iterate = function( startBase, endBase, origFeatCallback, finishCallback ) { 98 var that = this, 99 fields = this.fields, 100 subFields = this.subFields, 101 get = function(fieldname) { 102 var f = fields[fieldname]; 103 if( f >= 0 ) 104 return this[f]; 105 else 106 return undefined; 107 }, 108 subget = function(fieldname) { 109 var f = subFields[fieldname]; 110 if( f >= 0 ) 111 return this[f]; 112 else 113 return undefined; 114 }, 115 featCallBack = function( feature, path ) { 116 feature.get = get; 117 dojo.forEach( feature.get('subfeatures'), function(f) { 118 f.get = subget; 119 }); 120 return origFeatCallback( feature, path ); 121 }; 122 123 return this.nclist.iterate.call( this.nclist, startBase, endBase, featCallBack, finishCallback ); 124 }; 125 126