X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bcftools%2Fbcfutils.c;h=ae7ec0f0256f2bff77ad12d31f8c05ece2f518a0;hb=27eec65490fb3461f0af054868d9a0949e1843ed;hp=fb70d81ae8c1c50d765176860c55719388f5b260;hpb=f0b7a686f0f6581bc524353d7e783abbe9a94316;p=samtools.git diff --git a/bcftools/bcfutils.c b/bcftools/bcfutils.c index fb70d81..ae7ec0f 100644 --- a/bcftools/bcfutils.c +++ b/bcftools/bcfutils.c @@ -29,6 +29,16 @@ void bcf_str2id_destroy(void *_hash) if (hash) kh_destroy(str2id, hash); // Note that strings are not freed. } +void bcf_str2id_thorough_destroy(void *_hash) +{ + khash_t(str2id) *hash = (khash_t(str2id)*)_hash; + khint_t k; + if (hash == 0) return; + for (k = 0; k < kh_end(hash); ++k) + if (kh_exist(hash, k)) free((char*)kh_key(hash, k)); + kh_destroy(str2id, hash); +} + int bcf_str2id(void *_hash, const char *str) { khash_t(str2id) *hash = (khash_t(str2id)*)_hash; @@ -53,8 +63,9 @@ int bcf_str2id_add(void *_hash, const char *str) int bcf_shrink_alt(bcf1_t *b, int n) { char *p; - int i, j, k, *z, n_smpl = b->n_smpl; + int i, j, k, n_smpl = b->n_smpl; if (b->n_alleles <= n) return -1; + // update ALT if (n > 1) { for (p = b->alt, k = 1; *p; ++p) if (*p == ',' && ++k == n) break; @@ -63,10 +74,7 @@ int bcf_shrink_alt(bcf1_t *b, int n) ++p; memmove(p, b->flt, b->str + b->l_str - b->flt); b->l_str -= b->flt - p; - z = alloca(sizeof(int) / 2 * n * (n+1)); - for (i = k = 0; i < n; ++i) - for (j = 0; j < n - i; ++j) - z[k++] = i * b->n_alleles + j; + // update PL for (i = 0; i < b->n_gi; ++i) { bcf_ginfo_t *g = b->gi + i; if (g->fmt == bcf_str2int("PL", 2)) { @@ -75,7 +83,7 @@ int bcf_shrink_alt(bcf1_t *b, int n) g->len = n * (n + 1) / 2; for (l = k = 0; l < n_smpl; ++l) { uint8_t *dl = d + l * x; - for (j = 0; j < g->len; ++j) d[k++] = dl[z[j]]; + for (j = 0; j < g->len; ++j) d[k++] = dl[j]; } } // FIXME: to add GL } @@ -147,7 +155,8 @@ int bcf_anno_max(bcf1_t *b) { int k, max_gq, max_sp, n_het; kstring_t str; - uint8_t *gt, *gq, *sp; + uint8_t *gt, *gq; + int32_t *sp; max_gq = max_sp = n_het = 0; gt = locate_field(b, "GT", 2); if (gt == 0) return -1;