]> git.donarmstrong.com Git - samtools.git/commitdiff
* the code base is stablized again.
authorHeng Li <lh3@live.co.uk>
Thu, 5 Aug 2010 20:17:58 +0000 (20:17 +0000)
committerHeng Li <lh3@live.co.uk>
Thu, 5 Aug 2010 20:17:58 +0000 (20:17 +0000)
 * I will delay the vcf parser, which is quite complicated but with little value for now

bam_plcmd.c
bcftools/bcf.c
bcftools/main.c

index 2c3178c23874c27750bbaa3c3296d2bace171b4a..0cf081d046a0614303957723a94061069545cc86 100644 (file)
@@ -499,6 +499,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn)
        bcf_callret1_t *bcr = 0;
        bcf_call_t bc;
        bcf_t *bp = 0;
+       bcf_hdr_t *bh = 0;
 
        memset(&bc, 0, sizeof(bcf_call_t));
        data = calloc(n, sizeof(void*));
@@ -538,15 +539,16 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn)
        // write the VCF header
        if (conf->flag & MPLP_GLF) {
                kstring_t s;
+               bh = calloc(1, sizeof(bcf_hdr_t));
                s.l = s.m = 0; s.s = 0;
                bp = bcf_open("-", (conf->flag&MPLP_NO_COMP)? "wu" : "w");
                for (i = 0; i < h->n_targets; ++i) {
                        kputs(h->target_name[i], &s);
                        kputc('\0', &s);
                }
-               bp->h.l_nm = s.l;
-               bp->h.name = malloc(s.l);
-               memcpy(bp->h.name, s.s, s.l);
+               bh->l_nm = s.l;
+               bh->name = malloc(s.l);
+               memcpy(bh->name, s.s, s.l);
                s.l = 0;
                for (i = 0; i < n; ++i) {
                        const char *p;
@@ -555,13 +557,13 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn)
                        else kputs(fn[i], &s);
                        kputc('\0', &s);
                }
-               bp->h.l_smpl = s.l;
-               bp->h.sname = malloc(s.l);
-               memcpy(bp->h.sname, s.s, s.l);
-               bp->h.l_txt = 0;
+               bh->l_smpl = s.l;
+               bh->sname = malloc(s.l);
+               memcpy(bh->sname, s.s, s.l);
+               bh->l_txt = 0;
                free(s.s);
-               bcf_hdr_sync(&bp->h);
-               bcf_hdr_write(bp);
+               bcf_hdr_sync(bh);
+               bcf_hdr_write(bp, bh);
        } else if (conf->flag & MPLP_VCF) {
                kstring_t s;
                s.l = s.m = 0; s.s = 0;
@@ -613,7 +615,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn)
                                bcf_call_glfgen(n_plp[i], plp[i], ref16, bca, bcr + i);
                        bcf_call_combine(n, bcr, ref16, &bc);
                        bcf_call2bcf(tid, pos, &bc, b);
-                       bcf_write(bp, b);
+                       bcf_write(bp, bh, b);
                        //fprintf(stderr, "%d,%d,%d\n", b->tid, b->pos, b->l_str);
                        bcf_destroy(b);
                } else if (conf->flag & MPLP_VCF) {
@@ -696,7 +698,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn)
                        if (kh_exist(hash, k)) free(kh_val(hash, k));
                kh_destroy(64, hash);
        }
-       bcf_call_destroy(bca); free(bc.PL); free(bcr);
+       bcf_hdr_destroy(bh); bcf_call_destroy(bca); free(bc.PL); free(bcr);
        mc_destroy(ma);
        bam_mplp_destroy(iter);
        bam_header_destroy(h);
index aa1bb03d8ee2bbcc035f486a9ba2cc2fcc474a6e..2cd6423558c6e3e15459f8beeeb56acc40d6be54 100644 (file)
@@ -25,8 +25,11 @@ bcf_t *bcf_open(const char *fn, const char *mode)
 
 int bcf_close(bcf_t *b)
 {
+       int ret;
        if (b == 0) return 0;
-       return bgzf_close(b->fp);
+       ret = bgzf_close(b->fp);
+       free(b);
+       return ret;
 }
 
 int bcf_hdr_write(bcf_t *b, const bcf_hdr_t *h)
index 017ac437cd29ca1dfe16f39cb83cf60c060a8bb3..21d9eec29f58f4561967c85af0ee7a39edc4f374 100644 (file)
@@ -4,6 +4,7 @@
 
 int bcfview(int argc, char *argv[]);
 int bcf_main_index(int argc, char *argv[]);
+int vcf_test(int argc, char *argv[]);
 
 int main(int argc, char *argv[])
 {