Skip to content

Commit

Permalink
update gff3 and vcf tabix stores to use @gmod/tabix
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuels committed Sep 8, 2018
1 parent b9e3e18 commit 781cb82
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 281 deletions.
2 changes: 1 addition & 1 deletion src/JBrowse/Model/BGZip/BGZBlob.js
Expand Up @@ -135,4 +135,4 @@ var BGZBlob = declare( null,
});

return BGZBlob;
});
});
31 changes: 3 additions & 28 deletions src/JBrowse/Store/SeqFeature/GFF3Tabix.js
Expand Up @@ -71,9 +71,9 @@ return declare( [ SeqFeatureStore, DeferredStatsMixin, DeferredFeaturesMixin, In
})

// start our global stats estimation
this.getHeader()
this.indexedData.featureCount('nonexistent')
.then(
header => {
() => {
this._deferred.features.resolve({ success: true })
this._estimateGlobalStats()
.then(
Expand All @@ -88,33 +88,8 @@ return declare( [ SeqFeatureStore, DeferredStatsMixin, DeferredFeaturesMixin, In
)
},

getHeader() {
if (this._parsedHeader) return this._parsedHeader

this._parsedHeader = new Deferred()
const reject = this._parsedHeader.reject.bind(this._parsedHeader)

this.indexedData.indexLoaded
.then( () => {
const maxFetch = this.indexedData.index.firstDataLine
? this.indexedData.index.firstDataLine.block + this.indexedData.data.blockSize - 1
: null

this.indexedData.data.read(
0,
maxFetch,
bytes => this._parsedHeader.resolve( this.header ),
reject
);
},
reject
)

return this._parsedHeader
},

_getFeatures(query, featureCallback, finishedCallback, errorCallback, allowRedispatch = true) {
this.getHeader().then(
this.indexedData.featureCount('nonexistent').then(
() => {
const lines = []
this.indexedData.getLines(
Expand Down
29 changes: 13 additions & 16 deletions src/JBrowse/Store/SeqFeature/IndexedStatsEstimationMixin.js
Expand Up @@ -20,24 +20,21 @@ return declare( GlobalStats, {
* estimate the feature density of the store.
* @private
*/
_estimateGlobalStats: function( refseq ) {
refseq = refseq || this.refSeq;
var featCount;
if(this.indexedData) {
featCount = this.indexedData.featureCount(refseq.name);
} else if(this.bam) {
var chr = refseq.name;
chr = this.browser.regularizeReferenceName( chr );
var chrId = this.bam.chrToIndex && this.bam.chrToIndex[chr];
featCount = this.bam.index.featureCount(chrId, true);
async _estimateGlobalStats(refseq) {
refseq = refseq || this.refSeq
let featCount
if (this.indexedData) {
featCount = await this.indexedData.featureCount(refseq.name)
} else if (this.bam) {
const chr = this.browser.regularizeReferenceName(refseq.name)
const chrId = this.bam.chrToIndex && this.bam.chrToIndex[chr]
featCount = await this.bam.index.featureCount(chrId, true)
}
if(featCount == -1) {
return this.inherited(arguments);
if (featCount == -1) {
return this.inherited('_estimateGlobalStats', arguments)
}
var density = featCount / (refseq.end - refseq.start);
var deferred = new Deferred();
deferred.resolve({ featureDensity: density });
return deferred;
const featureDensity = featCount / (refseq.end - refseq.start)
return { featureDensity }
}

});
Expand Down
48 changes: 17 additions & 31 deletions src/JBrowse/Store/SeqFeature/VCFTabix.js
@@ -1,3 +1,7 @@
const promisify = cjsRequire('util.promisify')
const zlib = cjsRequire('zlib')
const gunzip = promisify(zlib.gunzip)

define([
'dojo/_base/declare',
'dojo/_base/lang',
Expand Down Expand Up @@ -29,7 +33,7 @@ define([
// files don't actually have an end coordinate, so we have to make it
// here. also convert coordinates to interbase.
var VCFIndexedFile = declare( TabixIndexedFile, {
parseLine: function() {
parseLine() {
var i = this.inherited( arguments );
if( i ) {
var ret = i.fields[7].match(/^END=(\d+)|;END=(\d+)/);
Expand All @@ -43,7 +47,7 @@ var VCFIndexedFile = declare( TabixIndexedFile, {
return declare( [ SeqFeatureStore, DeferredStatsMixin, DeferredFeaturesMixin, IndexedStatsEstimationMixin, VCFParser ],
{

constructor: function( args ) {
constructor( args ) {
var thisB = this;
var csiBlob, tbiBlob;

Expand All @@ -69,6 +73,8 @@ return declare( [ SeqFeatureStore, DeferredStatsMixin, DeferredFeaturesMixin, In
{ expectRanges: true }
);

this.fileBlob = fileBlob

this.indexedData = new VCFIndexedFile(
{
tbi: tbiBlob,
Expand Down Expand Up @@ -97,35 +103,15 @@ return declare( [ SeqFeatureStore, DeferredStatsMixin, DeferredFeaturesMixin, In
},

/** fetch and parse the VCF header lines */
getVCFHeader: function() {
var thisB = this;
return this._parsedHeader || ( this._parsedHeader = function() {
var d = new Deferred();
var reject = lang.hitch( d, 'reject' );

thisB.indexedData.indexLoaded.then( function() {
var maxFetch = thisB.indexedData.index.firstDataLine
? thisB.indexedData.index.firstDataLine.block + thisB.indexedData.data.blockSize - 1
: null;

thisB.indexedData.data.read(
0,
maxFetch,
function( bytes ) {
thisB.parseHeader( new Uint8Array( bytes ) );
d.resolve( thisB.header );
},
reject
);
},
reject
);

return d;
}.call(this));
getVCFHeader() {
if (!this._parsedHeader) {
this._parsedHeader = this.indexedData.getHeader()
.then(headerBytes => this.parseHeader(headerBytes))
}
return this._parsedHeader
},

_getFeatures: function( query, featureCallback, finishedCallback, errorCallback ) {
_getFeatures( query, featureCallback, finishedCallback, errorCallback ) {
var thisB = this;
thisB.getVCFHeader().then( function() {
thisB.indexedData.getLines(
Expand All @@ -152,12 +138,12 @@ return declare( [ SeqFeatureStore, DeferredStatsMixin, DeferredFeaturesMixin, In
* smart enough to regularize reference sequence names, while
* others are not.
*/
hasRefSeq: function( seqName, callback, errorCallback ) {
hasRefSeq( seqName, callback, errorCallback ) {
return this.indexedData.index.hasRefSeq( seqName, callback, errorCallback );
},


saveStore: function() {
saveStore() {
return {
urlTemplate: this.config.file.url,
tbiUrlTemplate: ((this.config.tbi)||{}).url,
Expand Down

0 comments on commit 781cb82

Please sign in to comment.