Skip to content

Commit

Permalink
fix vcf header parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuels committed Mar 7, 2013
1 parent b345c74 commit 330d555
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/JBrowse/Store/SeqFeature/VCFTabix.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ return declare( [SeqFeatureStore,DeferredStatsMixin,DeferredFeaturesMixin,Global

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

thisB.indexedData.data.read(
0,
maxFetch,
function( bytes ) {

var headerLines = String.fromCharCode( Array.prototype.slice.call( Array, bytes ) ).split("\n");
thisB.header = thisB._parseHeader( headerLines );
thisB.header = thisB._parseHeader( new Uint8Array( bytes ) );
console.log( thisB.header );

d.resolve({ success:true});
},
Expand All @@ -86,24 +86,43 @@ return declare( [SeqFeatureStore,DeferredStatsMixin,DeferredFeaturesMixin,Global
}.call();
},

_parseHeader: function( headerLines ) {
_newlineCode: "\n".charCodeAt(0),

_getlineFromBytes: function( parseState ) {
if( ! parseState.offset )
parseState.offset = 0;

var newlineIndex = array.indexOf( parseState.data, this._newlineCode, parseState.offset );

if( newlineIndex == -1 ) // no more lines
return null;

var line = String.fromCharCode.apply( String, Array.prototype.slice.call( parseState.data, parseState.offset, newlineIndex ));
parseState.offset = newlineIndex+1;
return line;
},

_parseHeader: function( headerBytes ) {

// parse the header lines
var headData = {};
array.forEach( headerLines, function( line ) {
var parseState = { data: headerBytes, offset: 0 };
var line;
while(( line = this._getlineFromBytes( parseState ))) {
var match = /^##([^\s#=]+)=(.+)/.exec( line);
if( ! match || !match[1] )
return;
continue;

var metaField = match[1].toLowerCase();
var metaData = (match[2]||'').toLowerCase().trim();
var metaData = (match[2]||'');

// TODO: do further parsing for some fields

if( ! headData[metaField] )
headData[metaField] = [];

headData[metaField].push( metaData );
});
}
return headData;
},

Expand Down

0 comments on commit 330d555

Please sign in to comment.