From ce00ece6e230022e26e4b1edc5feeefcfb3e36e0 Mon Sep 17 00:00:00 2001 From: Heng Li Date: Fri, 10 Dec 2010 15:50:29 +0000 Subject: [PATCH] * fixed a minor issue in printing VCFs * write bcftools specific INFO and FORMAT in the header --- bcftools/call1.c | 33 ++++++++++++++++++++++++++++++++- bcftools/vcf.c | 2 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/bcftools/call1.c b/bcftools/call1.c index b913c9a..adf7a52 100644 --- a/bcftools/call1.c +++ b/bcftools/call1.c @@ -200,6 +200,34 @@ static int update_bcf1(int n_smpl, bcf1_t *b, const bcf_p1aux_t *pa, const bcf_p return is_var; } +static void write_header(bcf_hdr_t *h) +{ + kstring_t str; + str.l = h->l_txt? h->l_txt - 1 : 0; + str.m = str.l + 1; str.s = h->txt; + if (!strstr(str.s, "##INFO=\n", &str); + if (!strstr(str.s, "##INFO=\n", &str); + if (!strstr(str.s, "##INFO=\n", &str); + if (!strstr(str.s, "##INFO=\n", &str); + if (!strstr(str.s, "##INFO=\n", &str); + if (!strstr(str.s, "##INFO=\n", &str); + if (!strstr(str.s, "##INFO=\n", &str); + if (!strstr(str.s, "##FORMAT=\n", &str); + if (!strstr(str.s, "##FORMAT=\n", &str); + if (!strstr(str.s, "##FORMAT=\n", &str); + h->l_txt = str.l + 1; h->txt = str.s; +} + double bcf_ld_freq(const bcf1_t *b0, const bcf1_t *b1, double f[4]); int bcfview(int argc, char *argv[]) @@ -285,7 +313,10 @@ int bcfview(int argc, char *argv[]) bp = vcf_open(argv[optind], moder); h = vcf_hdr_read(bp); bout = vcf_open("-", modew); - if (!(vc.flag & VC_QCALL)) vcf_hdr_write(bout, h); + if (!(vc.flag & VC_QCALL)) { + if (vc.flag & VC_CALL) write_header(h); + vcf_hdr_write(bout, h); + } if (vc.flag & VC_CALL) { p1 = bcf_p1_init(h->n_smpl); if (vc.prior_file) { diff --git a/bcftools/vcf.c b/bcftools/vcf.c index 9b661ff..b3832e7 100644 --- a/bcftools/vcf.c +++ b/bcftools/vcf.c @@ -101,7 +101,7 @@ int vcf_hdr_write(bcf_t *bp, const bcf_hdr_t *h) fwrite(h->txt, 1, h->l_txt - 1, v->fpout); if (strstr(h->txt, "##SQ=")) has_ref = 1; } - if (has_ver == 0) fprintf(v->fpout, "##fileformat=VCFv4.0\n"); + if (h->l_txt == 0) fprintf(v->fpout, "##fileformat=VCFv4.0\n"); fprintf(v->fpout, "#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT"); for (i = 0; i < h->n_smpl; ++i) fprintf(v->fpout, "\t%s", h->sns[i]); -- 2.39.2