Skip to content

Commit 40a418b

Browse files
author
Devon Ryan
committed
Fix #24, properly handle 32-bit files
1 parent ff9df9d commit 40a418b

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

lib2bit/2bit.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ char *twobitSequence(TwoBit *tb, char *chrom, uint32_t start, uint32_t end) {
212212
break;
213213
}
214214
}
215-
if(tid == 0 && strcmp(tb->cl->chrom[i], chrom) != 0) return NULL;
215+
if(tid == 0 && strcmp(tb->cl->chrom[tid], chrom) != 0) return NULL;
216216

217217
//Get the start/end if not specified
218218
if(start == end && end == 0) {
@@ -406,7 +406,7 @@ void *twobitBases(TwoBit *tb, char *chrom, uint32_t start, uint32_t end, int fra
406406
}
407407
}
408408

409-
if(tid == 0 && strcmp(tb->cl->chrom[i], chrom) != 0) return NULL;
409+
if(tid == 0 && strcmp(tb->cl->chrom[tid], chrom) != 0) return NULL;
410410

411411
//Get the start/end if not specified
412412
if(start == end && end == 0) {
@@ -517,7 +517,7 @@ void twobitIndexRead(TwoBit *tb, int storeMasked) {
517517
for(i=0; i<tb->hdr->nChroms; i++) {
518518
if(idx->nBlockSizes[i]) free(idx->nBlockSizes[i]);
519519
}
520-
free(idx->nBlockSizes[i]);
520+
free(idx->nBlockSizes);
521521
}
522522

523523
if(idx->maskBlockCount) free(idx->maskBlockCount);
@@ -587,13 +587,15 @@ void twobitChromListRead(TwoBit *tb) {
587587
TwoBitCL *cl = calloc(1, sizeof(TwoBitCL));
588588
uint8_t useLong = tb->hdr->version == 1;
589589
size_t offsetSz = (useLong) ? sizeof(uint64_t) : sizeof(uint32_t);
590+
void *offset = calloc(1, offsetSz);
590591

591592
//Allocate cl and do error checking
592593
if(!cl) goto error;
593594
cl->chrom = calloc(tb->hdr->nChroms, sizeof(char*));
594-
cl->offset = calloc(tb->hdr->nChroms, offsetSz);
595+
cl->offset = calloc(tb->hdr->nChroms, sizeof(uint64_t));
595596
if(!cl->chrom) goto error;
596597
if(!cl->offset) goto error;
598+
if(!offset) goto error;
597599

598600
for(i=0; i<tb->hdr->nChroms; i++) {
599601
//Get the string size (not null terminated!)
@@ -607,8 +609,14 @@ void twobitChromListRead(TwoBit *tb) {
607609
str = NULL;
608610

609611
//Read in the size
610-
if(twobitRead(cl->offset + i, offsetSz, 1, tb) != 1) goto error;
612+
if(twobitRead(offset, offsetSz, 1, tb) != 1) goto error;
613+
if(useLong) {
614+
cl->offset[i] = *((uint64_t*) offset);
615+
} else {
616+
cl->offset[i] = *((uint32_t*) offset);
617+
}
611618
}
619+
free(offset);
612620

613621
tb->cl = cl;
614622
return;
@@ -625,6 +633,7 @@ void twobitChromListRead(TwoBit *tb) {
625633
}
626634
free(cl);
627635
}
636+
if(offset) free(offset);
628637
}
629638

630639
void twobitChromListDestroy(TwoBit *tb) {

py2bit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <Python.h>
22
#include "2bit.h"
33

4-
#define pyTwoBitVersion "1.0.0"
4+
#define pyTwoBitVersion "1.0.1"
55

66
typedef struct {
77
PyObject_HEAD

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "py2bit"
7-
version = "1.0.0"
7+
version = "1.0.1"
88
description = "A package for accessing 2bit files using lib2bit"
99
authors = [
1010
{ name = "Devon P. Ryan", email = "dpryan79@gmail.com" }

0 commit comments

Comments
 (0)