Skip to content

Commit ff9df9d

Browse files
authored
Merge pull request #23 from deeptools/issue22
Add support for version 1 2bit files.
2 parents 4ad501c + 795d7a4 commit ff9df9d

4 files changed

Lines changed: 11 additions & 8 deletions

File tree

lib2bit/2bit.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ void twobitIndexRead(TwoBit *tb, int storeMasked) {
452452
if(!idx->nBlockStart) goto error;
453453
if(!idx->nBlockSizes) goto error;
454454
idx->maskBlockCount = calloc(tb->hdr->nChroms, sizeof(uint32_t));
455+
455456
if(!idx->maskBlockCount) goto error;
456457
if(storeMasked) {
457458
idx->maskBlockStart = calloc(tb->hdr->nChroms, sizeof(uint32_t*));
@@ -584,11 +585,13 @@ void twobitChromListRead(TwoBit *tb) {
584585
uint8_t byte;
585586
char *str = NULL;
586587
TwoBitCL *cl = calloc(1, sizeof(TwoBitCL));
588+
uint8_t useLong = tb->hdr->version == 1;
589+
size_t offsetSz = (useLong) ? sizeof(uint64_t) : sizeof(uint32_t);
587590

588591
//Allocate cl and do error checking
589592
if(!cl) goto error;
590593
cl->chrom = calloc(tb->hdr->nChroms, sizeof(char*));
591-
cl->offset = malloc(sizeof(uint32_t) * tb->hdr->nChroms);
594+
cl->offset = calloc(tb->hdr->nChroms, offsetSz);
592595
if(!cl->chrom) goto error;
593596
if(!cl->offset) goto error;
594597

@@ -604,7 +607,7 @@ void twobitChromListRead(TwoBit *tb) {
604607
str = NULL;
605608

606609
//Read in the size
607-
if(twobitRead(cl->offset + i, sizeof(uint32_t), 1, tb) != 1) goto error;
610+
if(twobitRead(cl->offset + i, offsetSz, 1, tb) != 1) goto error;
608611
}
609612

610613
tb->cl = cl;
@@ -657,8 +660,8 @@ void twobitHdrRead(TwoBit *tb) {
657660

658661
//Version
659662
hdr->version = data[1];
660-
if(hdr->version != 0) {
661-
fprintf(stderr, "[twobitHdrRead] The file version is %"PRIu32" while only version 0 is defined!\n", hdr->version);
663+
if(hdr->version != 0 && hdr->version != 1) {
664+
fprintf(stderr, "[twobitHdrRead] The file version is %"PRIu32" while only versions 0 and 1 are defined!\n", hdr->version);
662665
goto error;
663666
}
664667

lib2bit/2bit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <inttypes.h>
22
#include <stdio.h>
33

4-
/*! \mainpage libBigWig
4+
/*! \mainpage lib2bit
55
*
66
* \section Introduction
77
*
@@ -45,7 +45,7 @@ typedef struct {
4545
*/
4646
typedef struct {
4747
char **chrom; /**<A list of null terminated chromosomes */
48-
uint32_t *offset; /**<The file offset for the beginning of each chromosome */
48+
uint64_t *offset; /**<The file offset for the beginning of each chromosome */
4949
} TwoBitCL;
5050

5151
/*!

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 "0.3.3"
4+
#define pyTwoBitVersion "1.0.0"
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 = "0.3.3"
7+
version = "1.0.0"
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)