Skip to content

Commit

Permalink
Add MultiIndexedFileDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Jul 11, 2018
1 parent 5d9c538 commit 35e7f2f
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 16 deletions.
11 changes: 9 additions & 2 deletions src/JBrowse/View/FileDialog/ResourceList.js
Expand Up @@ -106,7 +106,11 @@ return declare( null, {
{ label: "GFF3+bgzip", value: "gff3.gz"},
{ label: "Tabix index", value: "vcf.gz.tbi" },
{ label: "Tabix index", value: "gff3.gz.tbi" },
{ label: "Tabix index", value: "bed.gz.tbi" }
{ label: "Tabix index", value: "bed.gz.tbi" },
{ label: "CSI index", value: "bed.gz.csi" },
{ label: "CSI index", value: "vcf.gz.csi" },
{ label: "CSI index", value: "gff3.gz.csi" },
{ label: "CSI index", value: "bam.csi" }
],
value: this.guessType( name ),
onChange: function() {
Expand Down Expand Up @@ -171,7 +175,10 @@ return declare( null, {
/\.gff3?\.gz$/i.test( name ) ? 'gff3.gz':
/\.gff3?\.gz.tbi$/i.test( name )? 'gff3.gz.tbi' :
/\.vcf.gz.tbi$/i.test( name ) ? 'vcf.gz.tbi' :
/\.bed.gz.tbi$/i.test( name ) ? 'bed.gz.tbi' :
/\.bed.gz.tbi$/i.test( name ) ? 'bed.gz.csi' :
/\.gff3?\.gz.csi$/i.test( name )? 'gff3.gz.csi' :
/\.vcf.gz.csi$/i.test( name ) ? 'vcf.gz.csi' :
/\.bam.csi$/i.test( name ) ? 'bam.csi' :
null
);
}
Expand Down
20 changes: 12 additions & 8 deletions src/JBrowse/View/FileDialog/TrackList/GFF3TabixDriver.js
@@ -1,21 +1,25 @@
define([
'dojo/_base/declare',
'./_IndexedFileDriver'
'./_MultiIndexedFileDriver'
],
function( declare, IndexedFileDriver ) {
return declare( IndexedFileDriver, {
function( declare, MultiIndexedFileDriver ) {
return declare( MultiIndexedFileDriver, {
name: 'GFF3+Tabix',
storeType: 'JBrowse/Store/SeqFeature/GFF3Tabix',

fileExtension: 'gff3.gz',
fileConfKey: 'file',
fileUrlConfKey: 'urlTemplate',

indexExtension: 'gff3.gz.tbi',
indexConfKey: 'tbi',
indexUrlConfKey: 'tbiUrlTemplate'


indexType: [{
ext: 'gff3.gz.tbi',
confKey: 'tbi',
urlConfKey: 'tbiUrlTemplate'
}, {
ext: 'gff3.gz.csi',
confKey: 'csi',
urlConfKey: 'csiUrlTemplate'
}]
});

});
18 changes: 12 additions & 6 deletions src/JBrowse/View/FileDialog/TrackList/VCFTabixDriver.js
@@ -1,19 +1,25 @@
define([
'dojo/_base/declare',
'./_IndexedFileDriver'
'./_MultiIndexedFileDriver'
],
function( declare, IndexedFileDriver ) {
return declare( IndexedFileDriver, {
function( declare, MultiIndexedFileDriver ) {
return declare( MultiIndexedFileDriver, {
name: 'VCF+Tabix',
storeType: 'JBrowse/Store/SeqFeature/VCFTabix',

fileExtension: 'vcf.gz',
fileConfKey: 'file',
fileUrlConfKey: 'urlTemplate',

indexExtension: 'vcf.gz.tbi',
indexConfKey: 'tbi',
indexUrlConfKey: 'tbiUrlTemplate'
indexTypes: [{
ext: 'vcf.gz.tbi',
confKey: 'tbi',
urlConfKey: 'tbiUrlTemplate'
}, {
ext: 'vcf.gz.csi',
confKey: 'csi',
urlConfKey: 'csiUrlTemplate'
}]
});

});
125 changes: 125 additions & 0 deletions src/JBrowse/View/FileDialog/TrackList/_MultiIndexedFileDriver.js
@@ -0,0 +1,125 @@
define([
'dojo/_base/declare',
'JBrowse/Util',
'JBrowse/Model/FileBlob',
'JBrowse/Model/XHRBlob'
],
function( declare, Util, FileBlob, XHRBlob ) {
var uniqCounter = 0;
return declare( null, {

tryResource: function( configs, resource ) {
if( resource.type == this.fileExtension ) {
var basename = Util.basename(
resource.file ? resource.file.name :
resource.url ? resource.url :
''
);
if( !basename )
return false;

// go through the configs and see if there is one for an index that seems to match
for( var n in configs ) {
var c = configs[n];
for(const index in this.indexTypes) {
if( Util.basename( c[index.indexConfKey] ? c[index.indexConfKey ].url || c[index.indexConfKey].blob.name : c[index.indexUrlConfKey], '.'+index.indexExtension ) == basename ) {
// it's a match, put it in
c[this.fileConfKey] = this._makeBlob( resource );
return true;
}
}
}
// go through again and look for index files that don't have the base extension in them
basename = Util.basename( basename, '.'+this.fileExtension );
for( var n in configs ) {
var c = configs[n];
for(const index in this.indexTypes) {
if( Util.basename( c[index.indexConfKey] ? c[index.indexConfKey].url || c[index.indexConfKey].blob.name : c[index.indexUrlConfKey], '.'+index.indexExtension ) == basename ) {
// it's a match, put it in
c[this.fileConfKey] = this._makeBlob( resource );
return true;
}
}

}

// otherwise make a new store config for it
var newName = this.name+'_'+basename+'_'+uniqCounter++;
configs[newName] = {
type: this.storeType,
name: newName,
fileBasename: basename
};
configs[newName][this.fileConfKey] = this._makeBlob( resource );

return true;
} else {
for(const index in this.indexTypes) {
if( resource.type == index.indexExtension ) {
var basename = Util.basename(
resource.file ? resource.file.name :
resource.url ? resource.url :
''
, '.'+index.indexExtension
);
if( !basename )
return false;

// go through the configs and look for data files that match like zee.bam -> zee.bam.bai
for( var n in configs ) {
var c = configs[n];
if( Util.basename( c[this.fileConfKey] ? c[this.fileConfKey].url || c[this.fileConfKey].blob.name : c[this.fileUrlConfKey] ) == basename ) {
// it's a match, put it in
c[index.indexConfKey] = this._makeBlob( resource );
return true;
}
}
// go through again and look for data files that match like zee.bam -> zee.bai
for( var n in configs ) {
var c = configs[n];
if( Util.basename( c[this.fileConfKey] ? c[this.fileConfKey].url || c[this.fileConfKey].blob.name : c[this.fileUrlConfKey], '.'+this.fileExtension ) == basename ) {
// it's a match, put it in
c[index.indexConfKey] = this._makeBlob( resource );
return true;
}
}

// otherwise make a new store
var newName = this.name+'_'+Util.basename(basename,'.'+this.fileExtension)+'_'+uniqCounter++;
configs[newName] = {
name: newName,
type: this.storeType
};

configs[newName][index.indexConfKey] = this._makeBlob( resource );
return true;
}
}
}
return false;
},

// try to merge any singleton file and index stores. currently can only do this if there is one of each
finalizeConfiguration: function( configs ) {

},

_makeBlob: function( resource ) {
var r = resource.file ? new FileBlob( resource.file ) :
resource.url ? new XHRBlob( resource.url ) :
null;
if( ! r )
throw 'unknown resource type';
return r;

},

confIsValid: function( conf ) {
var valid = false;
for(var i in this.indexTypes) {
valid |= (conf[this.fileConfKey] || conf[this.fileUrlConfKey]) && ( conf[index.indexConfKey] || conf[index.indexUrlConfKey] || conf[this.fileUrlConfKey] );
}
return valid;
}
});
});

0 comments on commit 35e7f2f

Please sign in to comment.