From d98d58f07136bfcfa8dd8854df8ac43a2e23da53 Mon Sep 17 00:00:00 2001 From: Petr Danecek Date: Tue, 3 Dec 2024 14:47:34 +0100 Subject: [PATCH] Fix BCF output The command `convert --gvcf2vcf` was not filling the REF allele when BCF was output because VCF API was not used, the alleles were rewritten directly. That works for VCF, but not BCF output. Fixes #243, finally --- NEWS | 4 ++++ test/test.pl | 1 + vcfconvert.c | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index e0a725cc..46793eec 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,10 @@ Changes affecting specific commands: - New experimental plugin for scoring variants and assess site noisiness (allelic frequency profiles) from a large number of unaffected parental samples +* bcftools convert + + - The command `convert --gvcf2vcf` was not filling the REF allele when BCF was output (#243) + * bcftools query - The functions used in -i/-e filtering expressions (such as SUM, MEDIAN, etc) can be diff --git a/test/test.pl b/test/test.pl index 96105ff8..6609d04a 100755 --- a/test/test.pl +++ b/test/test.pl @@ -1541,6 +1541,7 @@ sub test_vcf_convert_gvcf my ($opts,%args) = @_; bgzip_tabix_vcf($opts,$args{in}); test_cmd($opts,%args,cmd=>"$$opts{bin}/bcftools convert --no-version $args{args} -f $$opts{path}/$args{fa} $$opts{tmp}/$args{in}.vcf.gz"); + test_cmd($opts,%args,cmd=>"$$opts{bin}/bcftools convert --no-version $args{args} -f $$opts{path}/$args{fa} $$opts{tmp}/$args{in}.vcf.gz -Ou | $$opts{bin}/bcftools view --no-version"); test_cmd($opts,%args,cmd=>"$$opts{bin}/bcftools view -Ob $$opts{tmp}/$args{in}.vcf.gz | $$opts{bin}/bcftools convert $args{args} -f $$opts{path}/$args{fa} | grep -v ^##bcftools"); } sub test_vcf_convert_tsv2vcf diff --git a/vcfconvert.c b/vcfconvert.c index f75085aa..32764401 100644 --- a/vcfconvert.c +++ b/vcfconvert.c @@ -1,6 +1,6 @@ /* vcfconvert.c -- convert between VCF/BCF and related formats. - Copyright (C) 2013-2023 Genome Research Ltd. + Copyright (C) 2013-2024 Genome Research Ltd. Author: Petr Danecek @@ -1583,6 +1583,7 @@ static void gvcf_to_vcf(args_t *args) char *ref = faidx_fetch_seq(args->ref, (char*)bcf_hdr_id2name(hdr,line->rid), line->pos, line->pos, &len); if ( !ref ) error("faidx_fetch_seq failed at %s:%"PRId64"\n", bcf_hdr_id2name(hdr,line->rid),(int64_t) line->pos+1); strncpy(line->d.allele[0],ref,len); + bcf_update_alleles(hdr,line,(const char**)line->d.allele,line->n_allele); if ( bcf_write(out_fh,hdr,line)!=0 ) error("[%s] Error: cannot write to %s\n", __func__,args->outfname); free(ref); }