From: Heng Li Date: Thu, 5 Aug 2010 20:17:58 +0000 (+0000) Subject: * the code base is stablized again. X-Git-Url: https://git.donarmstrong.com/?p=samtools.git;a=commitdiff_plain;h=95882d9fdab78fb90469798141d9308a65415fda * the code base is stablized again. * I will delay the vcf parser, which is quite complicated but with little value for now --- diff --git a/bam_plcmd.c b/bam_plcmd.c index 2c3178c..0cf081d 100644 --- a/bam_plcmd.c +++ b/bam_plcmd.c @@ -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); diff --git a/bcftools/bcf.c b/bcftools/bcf.c index aa1bb03..2cd6423 100644 --- a/bcftools/bcf.c +++ b/bcftools/bcf.c @@ -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) diff --git a/bcftools/main.c b/bcftools/main.c index 017ac43..21d9eec 100644 --- a/bcftools/main.c +++ b/bcftools/main.c @@ -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[]) {