From: Heng Li Date: Tue, 3 Aug 2010 19:06:45 +0000 (+0000) Subject: * samtools-0.1.8-10 (r658) X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=b443abe3fd2559d16fa3c65879398bc67d7609bb;hp=6ff460feabc1b7f09c6ddbcf602bb4bcba6256d2;p=samtools.git * samtools-0.1.8-10 (r658) * fixed a bug in bam2bcf when the reference is N --- diff --git a/bamtk.c b/bamtk.c index e3b71fe..863ba33 100644 --- a/bamtk.c +++ b/bamtk.c @@ -9,7 +9,7 @@ #endif #ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "0.1.8-9 (r649)" +#define PACKAGE_VERSION "0.1.8-10 (r658)" #endif int bam_taf2baf(int argc, char *argv[]); diff --git a/bcf.c b/bcf.c index 7286aca..f8b55c2 100644 --- a/bcf.c +++ b/bcf.c @@ -52,6 +52,19 @@ int bcf_hdr_write(bcf_t *b) return 16 + h->l_nm + h->l_smpl + h->l_txt; } +int bcf_hdr_cpy(bcf_hdr_t *h, const bcf_hdr_t *h0) +{ + *h = *h0; + h->name = malloc(h->l_nm); + h->sname = malloc(h->l_smpl); + h->txt = malloc(h->l_txt); + memcpy(h->name, h0->name, h->l_nm); + memcpy(h->sname, h0->sname, h->l_smpl); + memcpy(h->txt, h0->txt, h->l_txt); + bcf_hdr_sync(h); + return 0; +} + int bcf_hdr_read(bcf_t *b) { uint8_t magic[4]; @@ -102,7 +115,7 @@ int bcf_hdr_sync(bcf_hdr_t *b) int bcf_sync(int n_smpl, bcf1_t *b) { char *p, *tmp[5], *s; - int i, n, c; + int i, n; // set ref, alt, flt, info, fmt b->ref = b->alt = b->flt = b->info = b->fmt = 0; for (p = b->str, n = 0; p < b->str + b->l_str; ++p) @@ -112,10 +125,7 @@ int bcf_sync(int n_smpl, bcf1_t *b) // set n_alleles for (p = b->alt, n = 1; *p; ++p) if (*p == ',') ++n; - b->n_alleles = n; - c = toupper(*b->ref); - if (b->alt - b->ref == 2 && (c == 'A' || c == 'C' || c == 'G' || c == 'T')) - ++b->n_alleles; + b->n_alleles = n + 1; // set n_gi and gi[i].fmt for (p = b->fmt, n = 1; *p; ++p) if (*p == ':') ++n; @@ -223,8 +233,11 @@ char *bcf_fmt(bcf_t *bp, bcf1_t *b) fmt_str(b->alt, &s); kputc('\t', &s); kputw(b->qual, &s); kputc('\t', &s); fmt_str(b->flt, &s); kputc('\t', &s); - fmt_str(b->info, &s); kputc('\t', &s); - fmt_str(b->fmt, &s); + fmt_str(b->info, &s); + if (b->fmt[0]) { + kputc('\t', &s); + fmt_str(b->fmt, &s); + } x = b->n_alleles * (b->n_alleles + 1) / 2; for (j = 0; j < bp->h.n_smpl; ++j) { kputc('\t', &s);