Skip to content

Commit

Permalink
BGZip file open functionality working without singleton check
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Aug 31, 2018
1 parent 529f2c8 commit da816bc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 77 deletions.
110 changes: 48 additions & 62 deletions src/JBrowse/View/FileDialog/TrackList/BgzipIndexedFASTADriver.js
Expand Up @@ -7,18 +7,19 @@ define([
function( declare, Util, FileBlob, XHRBlob ) {
var uniqCounter = 0;
return declare( null, {
name: 'BGZFASTA',
storeType: 'JBrowse/Store/SeqFeature/BgzipIndexedFasta',
fileExtension: 'gz',
fileExtension: 'fasta.gz',
fileExtensionMap: ['.fasta.gz', '.fa.gz'],
fileConfKey: 'bgzfa',
fileUrlConfKey: 'urlTemplate',

indexExtension: 'gz.fai',
indexExtension: 'fai',
indexExtensionMap: ['.fasta.gz.fai', '.fa.gz.fai'],
indexConfKey: 'fai',
indexUrlConfKey: 'faiUrlTemplate',

doubleIndexExtension: 'gz.gzi',
doubleIndexExtension: 'gzi',
doubleIndexExtensionMap: ['.fasta.gz.gzi', '.fa.gz.gzi'],
doubleIndexConfKey: 'gzi',
doubleIndexUrlConfKey: 'gziUrlTemplate',
Expand All @@ -32,23 +33,15 @@ return declare( null, {
'',
this.fileExtensionMap
);
console.log(basename)
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];
if( Util.basename( c[this.indexConfKey] ? c[this.indexConfKey ].url || c[this.indexConfKey].blob.name : c[this.indexUrlConfKey], this.indexExtensionMap ) == basename ) {
// it's a match, put it in
c[this.fileConfKey] = this._makeBlob( resource );
return true;
}
}
if( Util.basename( c[this.indexConfKey] ? c[this.indexConfKey ].url || c[this.indexConfKey].blob.name : c[this.indexUrlConfKey], this.indexExtensionMap ) == basename ||
Util.basename( c[this.doubleIndexConfKey] ? c[this.doubleIndexConfKey ].url || c[this.doubleIndexConfKey].blob.name : c[this.doubleIndexUrlConfKey], this.doubleExtensionMap ) == basename ) {

for( var n in configs ) {
var c = configs[n];
if( Util.basename( c[this.doubleIndexConfKey] ? c[this.doubleIndexConfKey ].url || c[this.doubleIndexConfKey].blob.name : c[this.doubleIndexUrlConfKey], this.doubleExtensionMap ) == basename ) {
// it's a match, put it in
c[this.fileConfKey] = this._makeBlob( resource );
return true;
Expand All @@ -68,17 +61,17 @@ return declare( null, {
var basename = Util.basename(
resource.file ? resource.file.name :
resource.url ? resource.url :
''
, this.indexExtensionMap
'',
this.indexExtensionMap
);
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.fileConfKey], this.fileExtensionMap ) == basename ||
Util.basename( c[this.doubleIndexConfKey] ? c[this.doubleIndexConfKey ].url || c[this.doubleIndexConfKey].blob.name : c[this.doubleIndexUrlConfKey], this.doubleExtensionMap ) == basename ) {

if( Util.basename( c[this.fileConfKey] ? c[this.fileConfKey].url || c[this.fileConfKey].blob.name : c[this.fileUrlConfKey], this.fileExtensionMap ) == basename ) {
// it's a match, put it in
c[this.indexConfKey] = this._makeBlob( resource );
return true;
Expand All @@ -98,16 +91,17 @@ return declare( null, {
var basename = Util.basename(
resource.file ? resource.file.name :
resource.url ? resource.url :
''
, this.doubleIndexExtensionMap
'',
this.doubleIndexExtensionMap
);
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], this.fileExtensionMap ) == basename ) {
if( Util.basename( c[this.fileConfKey] ? c[this.fileConfKey ].url || c[this.fileConfKey].blob.name : c[this.fileConfKey], this.fileExtensionMap ) == basename ||
Util.basename( c[this.indexConfKey] ? c[this.indexConfKey ].url || c[this.indexConfKey].blob.name : c[this.indexUrlConfKey], this.indexExtensionMap ) == basename ) {

// it's a match, put it in
c[this.doubleIndexConfKey] = this._makeBlob( resource );
return true;
Expand All @@ -131,52 +125,44 @@ return declare( null, {

// try to merge any singleton file and index stores. currently can only do this if there is one of each
finalizeConfiguration: function( configs ) {
var singletonIndexes = {};
var singletonIndexCount = 0;
var singletonFiles = {};
var singletonFileCount = 0;

for( var n in configs ) {
var conf = configs[n];
if( conf.type === this.storeType ) {
if( (conf[this.indexConfKey] || conf[this.indexUrlConfKey]) && ! ( conf[this.fileConfKey] || conf[this.fileUrlConfKey] ) ) {
// singleton Index
singletonIndexCount++;
singletonIndexes[n] = conf;
}
else if(( conf[this.fileConfKey] || conf[this.fileUrlConfKey] ) && ! ( conf[this.indexConfKey] || conf[this.indexUrlConfKey]) ) {
// singleton File
singletonFileCount++;
singletonFiles[n] = conf;
}
}
}

// if we have a single File and single Index left at the end,
// stick them together and we'll see what happens
if( singletonFileCount == 1 && singletonIndexCount == 1 ) {
for( var indexName in singletonIndexes ) {
for( var fileName in singletonFiles ) {
if( singletonIndexes[indexName][this.indexUrlConfKey] )
singletonFiles[fileName][this.indexUrlConfKey] = singletonIndexes[indexName][this.indexUrlConfKey];
if( singletonIndexes[indexName][this.indexConfKey] )
singletonFiles[fileName][this.indexConfKey] = singletonIndexes[indexName][this.indexConfKey];

delete configs[indexName];
}
var v1 = !!(conf[this.indexConfKey] || conf[this.indexUrlConfKey])
var v2 = !!(conf[this.fileConfKey] || conf[this.fileUrlConfKey])
var v3 = !!(conf[this.doubleIndexConfKey] || conf[this.doubleIndexUrlConfKey])
if(+v1+v2+v3 != 3) {
delete configs[n]
}
}

// delete any remaining singleton Indexes, since they don't have
// a hope of working
for( var indexName in singletonIndexes ) {
delete configs[indexName];
}

// delete any remaining singleton Files, unless they are URLs
for( var fileName in singletonFiles ) {
if( ! configs[fileName][this.fileUrlConfKey] )
delete configs[fileName];
}
// // if we have a single File and single Index left at the end,
// // stick them together and we'll see what happens
// if( singletonFileCount == 1 && singletonIndexCount == 1 ) {
// for( var indexName in singletonIndexes ) {
// for( var fileName in singletonFiles ) {
// if( singletonIndexes[indexName][this.indexUrlConfKey] )
// singletonFiles[fileName][this.indexUrlConfKey] = singletonIndexes[indexName][this.indexUrlConfKey];
// if( singletonIndexes[indexName][this.indexConfKey] )
// singletonFiles[fileName][this.indexConfKey] = singletonIndexes[indexName][this.indexConfKey];

// delete configs[indexName];
// }
// }
// }

// // delete any remaining singleton Indexes, since they don't have
// // a hope of working
// for( var indexName in singletonIndexes ) {
// delete configs[indexName];
// }

// // delete any remaining singleton Files, unless they are URLs
// for( var fileName in singletonFiles ) {
// if( ! configs[fileName][this.fileUrlConfKey] )
// delete configs[fileName];
// }
},

_makeBlob: function( resource ) {
Expand All @@ -190,7 +176,7 @@ return declare( null, {
},

confIsValid: function( conf ) {
return (conf[this.fileConfKey] || conf[this.fileUrlConfKey]) && ( conf[this.indexConfKey] || conf[this.indexUrlConfKey] || conf[this.fileUrlConfKey] );
return (conf[this.fileConfKey] || conf[this.fileUrlConfKey]) && ( conf[this.indexConfKey] || conf[this.indexUrlConfKey] ) && ( conf[this.doubleIndexConfKey] || conf[this.doubleIndexUrlConfKey] );
}
});
});
4 changes: 2 additions & 2 deletions tests/js_tests/spec/AddFiles.spec.js
Expand Up @@ -124,8 +124,8 @@ describe( 'FileDialog drivers', function() {
it( 'BGZIP FASTA file', function( ) {
var confs = { foo: { bgzfa: { blob: { name :'zee.fa.gz'} } } };
var driver = new BgzipIndexedFastaDriver();
expect( driver.tryResource( confs, { type: 'gz.fai', file: { name: 'zee.fa.gz.fai'} } ) ).toBeTruthy();
expect( driver.tryResource( confs, { type: 'gz.gzi', file: { name: 'zee.fa.gz.gzi'} } ) ).toBeTruthy();
expect( driver.tryResource( confs, { type: 'fai', file: { name: 'zee.fa.gz.fai'} } ) ).toBeTruthy();
expect( driver.tryResource( confs, { type: 'gzi', file: { name: 'zee.fa.gz.gzi'} } ) ).toBeTruthy();
driver.finalizeConfiguration(confs);
console.log(confs)
expect( confs.foo.fai.blob.name ).toEqual( 'zee.fa.gz.fai' );
Expand Down
21 changes: 8 additions & 13 deletions yarn.lock
Expand Up @@ -121,8 +121,8 @@
arrify "^1.0.1"

"@gmod/bgzf-filehandle@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@gmod/bgzf-filehandle/-/bgzf-filehandle-1.0.0.tgz#33d0138cdcce02129be202573c072c5e6a44a557"
version "1.1.0"
resolved "https://registry.yarnpkg.com/@gmod/bgzf-filehandle/-/bgzf-filehandle-1.1.0.tgz#0094dee3c634893ece3e68992b9ed0c0d6c20e1e"
dependencies:
binary-parser "^1.3.2"
fs-extra "^7.0.0"
Expand Down Expand Up @@ -151,8 +151,8 @@
typical "^2.6.1"

"@gmod/indexedfasta@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@gmod/indexedfasta/-/indexedfasta-1.0.2.tgz#8f5bcdf60b6f3bb799dd0525b6155b9d0267466d"
version "1.0.5"
resolved "https://registry.yarnpkg.com/@gmod/indexedfasta/-/indexedfasta-1.0.5.tgz#5211a50fa6362f2aee47c0b13101b72c46dc51b9"
dependencies:
"@gmod/bgzf-filehandle" "^1.0.0"
util.promisify "^1.0.0"
Expand Down Expand Up @@ -2131,11 +2131,10 @@ deepmerge@~2.0.1:
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.0.1.tgz#25c1c24f110fb914f80001b925264dd77f3f4312"

define-properties@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.2.tgz#83a73f2fea569898fb737193c8f873caf6d45c94"
version "1.1.3"
resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1"
dependencies:
foreach "^2.0.5"
object-keys "^1.0.8"
object-keys "^1.0.12"

define-property@^0.2.5:
version "0.2.5"
Expand Down Expand Up @@ -3037,10 +3036,6 @@ for-own@^1.0.0:
dependencies:
for-in "^1.0.1"

foreach@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99"

forever-agent@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
Expand Down Expand Up @@ -4915,7 +4910,7 @@ object-copy@^0.1.0:
define-property "^0.2.5"
kind-of "^3.0.3"

object-keys@^1.0.8:
object-keys@^1.0.12:
version "1.0.12"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.12.tgz#09c53855377575310cca62f55bb334abff7b3ed2"

Expand Down

0 comments on commit da816bc

Please sign in to comment.