-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
factor stats estimation out of BAM store into GlobalStatsEstimationMixin
- Loading branch information
Showing
2 changed files
with
80 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/JBrowse/Store/SeqFeature/GlobalStatsEstimationMixin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Mixin that adds _estimateGlobalStats method to a store, which | ||
* samples a section of the features in the store and uses those to | ||
* esimate the statistics of the whole data set. | ||
*/ | ||
|
||
define([ | ||
'dojo/_base/declare', | ||
'dojo/_base/array' | ||
], | ||
function( declare, array ) { | ||
|
||
return declare( null, { | ||
|
||
/** | ||
* Fetch a region of the current reference sequence and use it to | ||
* estimate the feature density of the store. | ||
* @private | ||
*/ | ||
_estimateGlobalStats: function( finishCallback ) { | ||
|
||
var statsFromInterval = function( refSeq, length, callback ) { | ||
var sampleCenter = refSeq.start*0.75 + refSeq.end*0.25; | ||
var start = Math.max( 0, Math.round( sampleCenter - length/2 ) ); | ||
var end = Math.min( Math.round( sampleCenter + length/2 ), refSeq.end ); | ||
this.bam.fetch( refSeq.name, start, end, dojo.hitch( this, function( features, error) { | ||
if ( error ) { | ||
console.error( error ); | ||
callback.call( this, length, null, error ); | ||
} | ||
else if( features ) { | ||
features = array.filter( features, function(f) { return f.get('start') >= start && f.get('end') <= end; } ); | ||
callback.call( this, length, | ||
{ | ||
featureDensity: features.length / length, | ||
_statsSampleFeatures: features.length, | ||
_statsSampleInterval: { ref: refSeq.name, start: start, end: end, length: length } | ||
}); | ||
} | ||
})); | ||
}; | ||
|
||
var maybeRecordStats = function( interval, stats, error ) { | ||
if( error ) { | ||
finishCallback( null, error ); | ||
} else { | ||
var refLen = this.refSeq.end - this.refSeq.start; | ||
if( stats._statsSampleFeatures >= 300 || interval * 2 > refLen || error ) { | ||
console.log( 'Store statistics: '+(this.source||this.name), stats ); | ||
finishCallback( stats ); | ||
} else { | ||
statsFromInterval.call( this, this.refSeq, interval * 2, maybeRecordStats ); | ||
} | ||
} | ||
}; | ||
|
||
statsFromInterval.call( this, this.refSeq, 100, maybeRecordStats ); | ||
} | ||
|
||
}); | ||
}); |