Skip to content

Commit

Permalink
tweak TabixIndexedFile interface, rename fetch to getLines, add a…
Browse files Browse the repository at this point in the history
…n `indexLoaded` property the gives access to the index-loading promise
  • Loading branch information
rbuels committed Mar 7, 2013
1 parent 61431e5 commit 01f2e87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions src/JBrowse/Store/TabixIndexedFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ return declare( null, {
constructor: function( args ) {
this.index = new TabixIndex( new BGZBlob( args.tbi ) );
this.data = new BGZBlob( args.file );
this.indexLoaded = this.index.load();
},

fetch: function() {
getLines: function() {
var thisB = this;
var args = Array.prototype.slice.call(arguments);
this.index.load().then(function() {
this.indexLoaded.then(function() {
thisB._fetch.apply( thisB, args );
});
},

_fetch: function( ref, min, max, itemCallback, finishCallback, errorCallback ) {

errorCallback = errorCallback || dojo.hitch( console, 'error' );
Expand Down Expand Up @@ -143,7 +145,7 @@ return declare( null, {
// later, avoiding blocking any UI stuff that needs to be done
else {
window.setTimeout( function() {
that.parseItems( parseState.data, parseState.offset, itemCallback, finishCallback );
that.parseItems( data, parseState.offset, itemCallback, finishCallback );
}, 1);
return;
}
Expand All @@ -162,12 +164,21 @@ return declare( null, {
if( !line )
return null;

var fields = line.split("\t");
// function extractColumn( colNum ) {
// var skips = '';
// while( colNum-- > 1 )
// skips += '^[^\t]*\t';
// var match = (new Regexp( skips+'([^\t]*)' )).exec( line );
// if( ! match )
// return null;
// return match[1];
// }
var fields = line.split( "\t" );
var item = { // note: index column numbers are 1-based
ref: fields[this.index.columnNumbers.ref-1],
start: fields[this.index.columnNumbers.start-1],
end: fields[this.index.columnNumbers.end-1],
_fields: fields
fields: fields
};
return item;
},
Expand Down
2 changes: 1 addition & 1 deletion tests/js_tests/spec/TabixIndexedFile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe( "tabix-indexed file", function() {

it( 'can read ctgA:1000..4000', function() {
var items = [];
f.fetch( 'ctgA', 1000, 4000,
f.getLines( 'ctgA', 1000, 4000,
function(i) {
items.push(i);
},
Expand Down

0 comments on commit 01f2e87

Please sign in to comment.