Skip to content

Commit

Permalink
Unsuccessful attempt to get correct lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Nov 11, 2018
1 parent e4b34cd commit fea8c81
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion htslib/cram/cram_samtools.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ bam_hdr_t *cram_header_to_bam(SAM_hdr *h) {
header->n_targets = h->nref;
header->target_name = (char **)calloc(header->n_targets,
sizeof(char *));
header->target_len = (uint32_t *)calloc(header->n_targets, 4);
header->target_len = (uint64_t *)calloc(header->n_targets, 4);

for (i = 0; i < h->nref; i++) {
header->target_name[i] = strdup(h->ref[i].name);
Expand Down
2 changes: 1 addition & 1 deletion htslib/htslib/sam.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extern "C" {
typedef struct {
int32_t n_targets, ignore_sam_err;
uint32_t l_text;
uint32_t *target_len;
uint64_t *target_len;
int8_t *cigar_tab;
char **target_name;
char *text;
Expand Down
8 changes: 4 additions & 4 deletions htslib/sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bam_hdr_t *bam_hdr_dup(const bam_hdr_t *h0)
// TODO Check for memory allocation failures
h->text = (char*)calloc(h->l_text + 1, 1);
memcpy(h->text, h0->text, h->l_text);
h->target_len = (uint32_t*)calloc(h->n_targets, sizeof(uint32_t));
h->target_len = (uint64_t*)calloc(h->n_targets, sizeof(uint64_t));
h->target_name = (char**)calloc(h->n_targets, sizeof(char*));
int i;
for (i = 0; i < h->n_targets; ++i) {
Expand All @@ -106,12 +106,12 @@ static bam_hdr_t *hdr_from_dict(sdict_t *d)
h->sdict = d;
h->n_targets = kh_size(d);
// TODO Check for memory allocation failures
h->target_len = (uint32_t*)malloc(sizeof(uint32_t) * h->n_targets);
h->target_len = (uint64_t*)malloc(sizeof(uint64_t) * h->n_targets);
h->target_name = (char**)malloc(sizeof(char*) * h->n_targets);
for (k = kh_begin(d); k != kh_end(d); ++k) {
if (!kh_exist(d, k)) continue;
h->target_name[kh_val(d, k)>>32] = (char*)kh_key(d, k);
h->target_len[kh_val(d, k)>>32] = kh_val(d, k) & 0xffffffffUL;
h->target_len[kh_val(d, k)>>64] = kh_val(d, k) & 0xffffffffffffffffUL;
kh_val(d, k) >>= 32;
}
return h;
Expand Down Expand Up @@ -164,7 +164,7 @@ bam_hdr_t *bam_hdr_read(BGZF *fp)
if (h->n_targets > 0) {
h->target_name = (char**)calloc(h->n_targets, sizeof(char*));
if (!h->target_name) goto nomem;
h->target_len = (uint32_t*)calloc(h->n_targets, sizeof(uint32_t));
h->target_len = (uint64_t*)calloc(h->n_targets, sizeof(uint64_t));
if (!h->target_len) goto nomem;
}
else {
Expand Down
2 changes: 1 addition & 1 deletion pysam/libcalignmentfile.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ cdef class AlignmentHeader(object):
if self.ptr.target_name == NULL:
raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *)))

self.ptr.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
self.ptr.target_len = <uint64_t*>calloc(n, sizeof(uint64_t))
if self.ptr.target_len == NULL:
raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t)))

Expand Down
2 changes: 1 addition & 1 deletion pysam/libchtslib.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ cdef extern from "htslib/sam.h" nogil:
ctypedef struct bam_hdr_t:
int32_t n_targets, ignore_sam_err
uint32_t l_text
uint32_t *target_len
uint64_t *target_len
uint8_t *cigar_tab
char **target_name
char *text
Expand Down
4 changes: 2 additions & 2 deletions samtools/test/merge/test_trans_tbl_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bam_hdr_t * setup_test(const char *bam0_header_text,
bam0->l_text = strlen(bam0_header_text);
bam0->n_targets = 1;
bam0->target_name = (char**)calloc(bam0_n_refseqs, sizeof(char*));
bam0->target_len = (uint32_t*)calloc(bam0_n_refseqs, sizeof(uint32_t));
bam0->target_len = (uint64_t*)calloc(bam0_n_refseqs, sizeof(uint64_t));
for (i = 0; i < bam0_n_refseqs; i++) {
bam0->target_name[i] = strdup(bam0_refseqs[i].name);
if (!bam0->target_name[i]) goto fail;
Expand All @@ -92,7 +92,7 @@ bam_hdr_t * setup_test(const char *bam0_header_text,
bam1->l_text = strlen(bam1_header_text);
bam1->n_targets = bam1_n_refseqs;
bam1->target_name = (char**)calloc(bam1_n_refseqs, sizeof(char*));
bam1->target_len = (uint32_t*)calloc(bam1_n_refseqs, sizeof(uint32_t));
bam1->target_len = (uint64_t*)calloc(bam1_n_refseqs, sizeof(uint64_t));
for (i = 0; i < bam1_n_refseqs; i++) {
bam1->target_name[i] = strdup(bam1_refseqs[i].name);
if (!bam1->target_name[i]) goto fail;
Expand Down
4 changes: 2 additions & 2 deletions samtools/test/merge/test_trans_tbl_init.c.pysam.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bam_hdr_t * setup_test(const char *bam0_header_text,
bam0->l_text = strlen(bam0_header_text);
bam0->n_targets = 1;
bam0->target_name = (char**)calloc(bam0_n_refseqs, sizeof(char*));
bam0->target_len = (uint32_t*)calloc(bam0_n_refseqs, sizeof(uint32_t));
bam0->target_len = (uint64_t*)calloc(bam0_n_refseqs, sizeof(uint64_t));
for (i = 0; i < bam0_n_refseqs; i++) {
bam0->target_name[i] = strdup(bam0_refseqs[i].name);
if (!bam0->target_name[i]) goto fail;
Expand All @@ -94,7 +94,7 @@ bam_hdr_t * setup_test(const char *bam0_header_text,
bam1->l_text = strlen(bam1_header_text);
bam1->n_targets = bam1_n_refseqs;
bam1->target_name = (char**)calloc(bam1_n_refseqs, sizeof(char*));
bam1->target_len = (uint32_t*)calloc(bam1_n_refseqs, sizeof(uint32_t));
bam1->target_len = (uint64_t*)calloc(bam1_n_refseqs, sizeof(uint64_t));
for (i = 0; i < bam1_n_refseqs; i++) {
bam1->target_name[i] = strdup(bam1_refseqs[i].name);
if (!bam1->target_name[i]) goto fail;
Expand Down

0 comments on commit fea8c81

Please sign in to comment.