diff --git a/lib2bit/2bit.c b/lib2bit/2bit.c index cfdf771..4364f2a 100644 --- a/lib2bit/2bit.c +++ b/lib2bit/2bit.c @@ -212,7 +212,7 @@ char *twobitSequence(TwoBit *tb, char *chrom, uint32_t start, uint32_t end) { break; } } - if(tid == 0 && strcmp(tb->cl->chrom[i], chrom) != 0) return NULL; + if(tid == 0 && strcmp(tb->cl->chrom[tid], chrom) != 0) return NULL; //Get the start/end if not specified if(start == end && end == 0) { @@ -406,7 +406,7 @@ void *twobitBases(TwoBit *tb, char *chrom, uint32_t start, uint32_t end, int fra } } - if(tid == 0 && strcmp(tb->cl->chrom[i], chrom) != 0) return NULL; + if(tid == 0 && strcmp(tb->cl->chrom[tid], chrom) != 0) return NULL; //Get the start/end if not specified if(start == end && end == 0) { @@ -517,7 +517,7 @@ void twobitIndexRead(TwoBit *tb, int storeMasked) { for(i=0; ihdr->nChroms; i++) { if(idx->nBlockSizes[i]) free(idx->nBlockSizes[i]); } - free(idx->nBlockSizes[i]); + free(idx->nBlockSizes); } if(idx->maskBlockCount) free(idx->maskBlockCount); @@ -587,13 +587,15 @@ void twobitChromListRead(TwoBit *tb) { TwoBitCL *cl = calloc(1, sizeof(TwoBitCL)); uint8_t useLong = tb->hdr->version == 1; size_t offsetSz = (useLong) ? sizeof(uint64_t) : sizeof(uint32_t); + void *offset = calloc(1, offsetSz); //Allocate cl and do error checking if(!cl) goto error; cl->chrom = calloc(tb->hdr->nChroms, sizeof(char*)); - cl->offset = calloc(tb->hdr->nChroms, offsetSz); + cl->offset = calloc(tb->hdr->nChroms, sizeof(uint64_t)); if(!cl->chrom) goto error; if(!cl->offset) goto error; + if(!offset) goto error; for(i=0; ihdr->nChroms; i++) { //Get the string size (not null terminated!) @@ -607,8 +609,14 @@ void twobitChromListRead(TwoBit *tb) { str = NULL; //Read in the size - if(twobitRead(cl->offset + i, offsetSz, 1, tb) != 1) goto error; + if(twobitRead(offset, offsetSz, 1, tb) != 1) goto error; + if(useLong) { + cl->offset[i] = *((uint64_t*) offset); + } else { + cl->offset[i] = *((uint32_t*) offset); + } } + free(offset); tb->cl = cl; return; @@ -625,6 +633,7 @@ void twobitChromListRead(TwoBit *tb) { } free(cl); } + if(offset) free(offset); } void twobitChromListDestroy(TwoBit *tb) { diff --git a/py2bit.h b/py2bit.h index a3dfdd1..d816a99 100644 --- a/py2bit.h +++ b/py2bit.h @@ -1,7 +1,7 @@ #include #include "2bit.h" -#define pyTwoBitVersion "1.0.0" +#define pyTwoBitVersion "1.0.1" typedef struct { PyObject_HEAD diff --git a/pyproject.toml b/pyproject.toml index 017b1d7..00d68d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "py2bit" -version = "1.0.0" +version = "1.0.1" description = "A package for accessing 2bit files using lib2bit" authors = [ { name = "Devon P. Ryan", email = "dpryan79@gmail.com" }