Skip to content

Commit

Permalink
Actually fix reading of bigWig files with > 256 chromosomes. Thanks t…
Browse files Browse the repository at this point in the history
…o Marcelinus Rocky for pointing out the bug.
  • Loading branch information
dpryan79 committed Mar 29, 2016
1 parent 290e1e3 commit b36da5a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bigWig.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/*!
* The library version number
*/
#define LIBBIGWIG_VERSION 0.1.6
#define LIBBIGWIG_VERSION 0.1.7

/*!
* The magic number of a bigWig file.
Expand Down
17 changes: 11 additions & 6 deletions bwRead.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,21 @@ static uint64_t readChromLeaf(bigWigFile_t *bw, chromList_t *cl, uint32_t valueS
}

static uint64_t readChromNonLeaf(bigWigFile_t *bw, chromList_t *cl, uint32_t keySize) {
uint64_t offset;
uint16_t nVals;
uint64_t offset , rv = 0, previous;
uint16_t nVals, i;

if(bwRead((void*) &nVals, sizeof(uint16_t), 1, bw) != 1) return -1;

//These aren't actually used for anything, we just skip to the next block...
offset = nVals * (keySize + 8) + bwTell(bw);
previous = bwTell(bw) + keySize;
for(i=0; i<nVals; i++) {
if(bwSetPos(bw, previous)) return -1;
if(bwRead((void*) &offset, sizeof(uint64_t), 1, bw) != 1) return -1;
if(bwSetPos(bw, offset)) return -1;
rv += readChromBlock(bw, cl, keySize);
previous += 8 + keySize;
}

if(bwSetPos(bw, offset)) return -1;
return readChromBlock(bw, cl, keySize);
return rv;
}

static uint64_t readChromBlock(bigWigFile_t *bw, chromList_t *cl, uint32_t keySize) {
Expand Down

0 comments on commit b36da5a

Please sign in to comment.