Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start of logic that assembles messes of files into store definitions
- Loading branch information
Showing
6 changed files
with
239 additions
and
15 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
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
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,47 @@ | ||
define(['dojo/_base/declare', | ||
'dojo/_base/array', | ||
'./TrackList/BAMDriver'], | ||
function(declare, array, BAMDriver ) { | ||
|
||
return declare( null, { | ||
|
||
constructor: function( args ) { | ||
this.fileDialog = args.dialog; | ||
this.domNode = dojo.create('div', { className: 'trackList', innerHTML: 'track list!' }); | ||
this.types = [ BAMDriver ]; | ||
}, | ||
|
||
// offer a given resource record (either a file or a URL) to the | ||
// driver for a given store type. returns true if that driver will | ||
// make use of that resource | ||
_offerResource: function( resource, typeDriver ) { | ||
return typeDriver.tryResource( this.storeConfs, resource ); | ||
}, | ||
|
||
update: function() { | ||
// when called, rebuild the store and track configurations that we are going to add | ||
this.storeConfs = this.storeConfs || {}; | ||
|
||
// anneal the given resources into a set of data store | ||
// configurations by offering each file to each type driver in | ||
// turn until no more are being accepted | ||
var resources = this.fileDialog.filesToOpen().concat( this.fileDialog.urlsToOpen() ); | ||
var lastLength = 0; | ||
while( resources.length && resources.length != lastLength ) { | ||
resources = array.filter( resources, function( rec ) { | ||
return ! array.some( this.types, function( typeDriver ) { | ||
return this._offerResource( rec, typeDriver ); | ||
},this); | ||
},this); | ||
|
||
lastLength = resources.length; | ||
} | ||
if( resources.length ) | ||
console.warn("warning: not all resources could be used", resources ); | ||
|
||
console.log( this.storeConfs ); | ||
} | ||
|
||
}); | ||
}); | ||
|
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,106 @@ | ||
define([ | ||
'JBrowse/Util', | ||
'JBrowse/Model/FileBlob', | ||
'JBrowse/Model/XHRBlob' | ||
], | ||
function( Util, FileBlob, XHRBlob ) { | ||
var uniqCounter = 0; | ||
return { | ||
|
||
storeType: 'JBrowse/Store/SeqFeature/BAM', | ||
|
||
tryResource: function( configs, resource ) { | ||
if( resource.type == 'bam' ) { | ||
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 with a BAI that seems to match | ||
for( var n in configs ) { | ||
var c = configs[n]; | ||
if( Util.basename( c.bai ? c.bai.blob.name : c.baiUrlTemplate, '.bai' ) == basename ) { | ||
// it's a match, put it in | ||
c.bam = this._makeBlob( resource ); | ||
return true; | ||
} | ||
} | ||
// go through again and look for BAIs that don't have .bam on them | ||
basename = Util.basename( basename, '.bam' ); | ||
for( var n in configs ) { | ||
var c = configs[n]; | ||
if( Util.basename( c.bai ? c.bai.blob.name : c.baiUrlTemplate, '.bai' ) == basename ) { | ||
// it's a match, put it in | ||
c.bam = this._makeBlob( resource ); | ||
return true; | ||
} | ||
} | ||
|
||
// otherwise make a new store config for it | ||
var newName = 'bam_'+uniqCounter++; | ||
configs[newName] = { | ||
type: this.storeType, | ||
bam: this._makeBlob( resource ), | ||
name: newName | ||
}; | ||
return true; | ||
} else if( resource.type == 'bai' ) { | ||
var basename = Util.basename( | ||
resource.file ? resource.file.name : | ||
resource.url ? resource.url : | ||
'' | ||
, '.bai' | ||
); | ||
if( !basename ) | ||
return false; | ||
|
||
// go through the configs and look for BAMs that match like zee.bam -> zee.bam.bai | ||
for( var n in configs ) { | ||
var c = configs[n]; | ||
if( Util.basename( c.bam ? c.bam.blob.name : c.urlTemplate ) == basename ) { | ||
// it's a match, put it in | ||
c.bai = this._makeBlob( resource ); | ||
return true; | ||
} | ||
} | ||
// go through again and look for BAMs that match like zee.bam -> zee.bai | ||
for( var n in configs ) { | ||
var c = configs[n]; | ||
if( Util.basename( c.bam ? c.bam.blob.name : c.urlTemplate, '.bam' ) == basename ) { | ||
// it's a match, put it in | ||
c.bai = this._makeBlob( resource ); | ||
return true; | ||
} | ||
} | ||
|
||
// otherwise make a new store | ||
var newName = 'bam_'+uniqCounter++; | ||
configs[newName] = { | ||
bai: this._makeBlob( resource ), | ||
name: newName, | ||
type: this.storeType | ||
}; | ||
return true; | ||
} | ||
else | ||
return false; | ||
}, | ||
|
||
_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 ) { | ||
return (conf.bam || conf.urlTemplate) && ( conf.bai || conf.baiUrlTemplate || conf.urlTemplate ); | ||
} | ||
}; | ||
}); |
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
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,39 @@ | ||
require([ | ||
'JBrowse/View/FileDialog/TrackList/BAMDriver' | ||
], function( BAMDriver ) { | ||
|
||
describe( 'BAM driver', function() { | ||
it( 'can match a simple BAM URL with its BAI URL', function( ) { | ||
var confs = { foo: { baiUrlTemplate: 'zee.bam.bai' } }; | ||
expect( BAMDriver.tryResource( confs, { type: 'bam', url: 'zee.bam' } ) ) | ||
.toBeTruthy(); | ||
expect( confs.foo.bam.url ).toEqual( 'zee.bam' ); | ||
}); | ||
|
||
it( 'can match a simple BAM file with its BAI URL', function( ) { | ||
var confs = { foo: { baiUrlTemplate: 'zee.bam.bai' } }; | ||
expect( BAMDriver.tryResource( confs, { type: 'bam', file: { name: 'zee.bam'} } ) ) | ||
.toBeTruthy(); | ||
expect( confs.foo.bam.blob.name ).toEqual( 'zee.bam' ); | ||
}); | ||
|
||
it( 'matches a BAI file like zee.bai -> zee.bam', function( ) { | ||
var confs = { foo: { urlTemplate: '/zee.bam' } }; | ||
expect( BAMDriver.tryResource( confs, { type: 'bai', file: { name: 'zee.bai'} } ) ) | ||
.toBeTruthy(); | ||
expect( confs.foo.bai.blob.name ).toEqual( 'zee.bai' ); | ||
}); | ||
|
||
it( 'matches a BAM file like zee.bam -> zee.bai', function( ) { | ||
var confs = { foo: { baiUrlTemplate: '/zee.bai' } }; | ||
expect( BAMDriver.tryResource( confs, { type: 'bam', file: { name: 'zee.bam'} } ) ) | ||
.toBeTruthy(); | ||
expect( confs.foo.bam.blob.name ).toEqual( 'zee.bam' ); | ||
}); | ||
|
||
|
||
}); | ||
|
||
|
||
}); | ||
|