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                   failOk: true,
 41                   load:  Util.debugHandler( this, function(o) { this.loadSuccess(o, url); }),
 42                   error: dojo.hitch( this, function(error) {
 43                                          if( error.status != 404 )
 44                                              console.error(''+error);
 45                                          this.loadFail(error, url);
 46                                      })
 47 	        });
 48 };
 49 
 50 SeqFeatureStore.NCList.prototype.loadSuccess = function( trackInfo, url ) {
 51 
 52     this.count = trackInfo.featureCount;
 53     // average feature density per base
 54     this.density = trackInfo.featureCount / this.refSeq.length;
 55 
 56     this.loadNCList( trackInfo, url );
 57 
 58     if ( trackInfo.histograms && trackInfo.histograms.meta ) {
 59         this.histograms = trackInfo.histograms;
 60         for (var i = 0; i < this.histograms.meta.length; i++) {
 61             this.histograms.meta[i].lazyArray =
 62                 new LazyArray(this.histograms.meta[i].arrayParams, url);
 63         }
 64     }
 65 };
 66 
 67 SeqFeatureStore.NCList.prototype.loadNCList = function( trackInfo, url ) {
 68     this.attrs = new ArrayRepr(trackInfo.intervals.classes);
 69     this.nclist.importExisting( trackInfo.intervals.nclist,
 70                                 this.attrs,
 71                                 url,
 72                                 trackInfo.intervals.urlTemplate,
 73                                 trackInfo.intervals.lazyClass
 74                               );
 75 };
 76 
 77 
 78 SeqFeatureStore.NCList.prototype.loadFail = function(trackInfo,url) {
 79     this.empty = true;
 80     this.setLoaded();
 81 };
 82 
 83 // just forward histogram() and iterate() to our encapsulate nclist
 84 SeqFeatureStore.NCList.prototype.histogram = function() {
 85     return this.nclist.histogram.apply( this.nclist, arguments );
 86 };
 87 
 88 
 89 SeqFeatureStore.NCList.prototype.iterate = function( startBase, endBase, origFeatCallback, finishCallback ) {
 90     var that = this;
 91     var accessors    = this.attrs.accessors(),
 92         /** @inner */
 93         featCallBack = function( feature, path ) {
 94             that._add_getters( accessors.get, feature );
 95             return origFeatCallback( feature, path );
 96         };
 97 
 98     return this.nclist.iterate.call( this.nclist, startBase, endBase, featCallBack, finishCallback );
 99 };
100 
101 // helper method to recursively add a .get method to a feature and its
102 // subfeatures
103 SeqFeatureStore.NCList.prototype._add_getters = function(getter,feature) {
104     var that = this;
105     feature.get = getter;
106     dojo.forEach( feature.get('subfeatures'), function(f) { that._add_getters( getter, f ); } );
107 };
108 
109