1 var SeqFeatureStore; if( !SeqFeatureStore) SeqFeatureStore = function() {}; 2 3 /** 4 * Implementation of SeqFeatureStore using nested containment 5 * lists held in static files that are lazily fetched from the web 6 * server. 7 * 8 * @class 9 * @extends SeqFeatureStore 10 */ 11 12 SeqFeatureStore.NCList = function(args) { 13 SeqFeatureStore.call( this, args ); 14 if( !args ) 15 return; 16 17 this.nclist = this.makeNCList(); 18 19 this.baseUrl = args.baseUrl; 20 this.urlTemplates = { tracklist: args.urlTemplate }; 21 this.refSeq = args.refSeq; 22 }; 23 24 SeqFeatureStore.NCList.prototype = new SeqFeatureStore(); 25 26 SeqFeatureStore.NCList.prototype.makeNCList = function() { 27 return new NCList(); 28 }; 29 30 SeqFeatureStore.NCList.prototype.load = function() { 31 var url = Util.resolveUrl( 32 this.baseUrl, 33 Util.fillTemplate( this.urlTemplates.tracklist, 34 {'refseq': this.refSeq.name} 35 ) 36 ); 37 // fetch the trackdata 38 dojo.xhrGet({ url: url, 39 handleAs: "json", 40 load: dojo.hitch( this, function(o) { this.loadSuccess(o, url); }), 41 error: dojo.hitch( this, function(e) { console.error(''+e); this.loadFail(e, url); } ) 42 }); 43 }; 44 45 SeqFeatureStore.NCList.prototype.loadSuccess = function( trackInfo, url ) { 46 47 this.count = trackInfo.featureCount; 48 // average feature density per base 49 this.density = trackInfo.featureCount / this.refSeq.length; 50 51 this.loadNCList( trackInfo, url ); 52 53 if (trackInfo.histograms) { 54 this.histograms = trackInfo.histograms; 55 for (var i = 0; i < this.histograms.meta.length; i++) { 56 this.histograms.meta[i].lazyArray = 57 new LazyArray(this.histograms.meta[i].arrayParams, url); 58 } 59 } 60 }; 61 62 SeqFeatureStore.NCList.prototype.loadNCList = function( trackInfo, url ) { 63 this.attrs = new ArrayRepr(trackInfo.intervals.classes); 64 this.nclist.importExisting( trackInfo.intervals.nclist, 65 this.attrs, 66 url, 67 trackInfo.intervals.urlTemplate, 68 trackInfo.intervals.lazyClass 69 ); 70 }; 71 72 73 SeqFeatureStore.NCList.prototype.loadFail = function(trackInfo,url) { 74 this.empty = true; 75 this.setLoaded(); 76 }; 77 78 // just forward histogram() and iterate() to our encapsulate nclist 79 SeqFeatureStore.NCList.prototype.histogram = function() { 80 return this.nclist.histogram.apply( this.nclist, arguments ); 81 }; 82 83 84 SeqFeatureStore.NCList.prototype.iterate = function( startBase, endBase, origFeatCallback, finishCallback ) { 85 var that = this; 86 var accessors = this.attrs.accessors(), 87 /** @inner */ 88 featCallBack = function( feature, path ) { 89 that._add_getters( accessors.get, feature ); 90 return origFeatCallback( feature, path ); 91 }; 92 93 return this.nclist.iterate.call( this.nclist, startBase, endBase, featCallBack, finishCallback ); 94 }; 95 96 // helper method to recursively add a .get method to a feature and its 97 // subfeatures 98 SeqFeatureStore.NCList.prototype._add_getters = function(getter,feature) { 99 var that = this; 100 feature.get = getter; 101 dojo.forEach( feature.get('subfeatures'), function(f) { that._add_getters( getter, f ); } ); 102 }; 103 104