Skip to content

Commit

Permalink
Fix BCF output
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pd3 committed Dec 3, 2024
1 parent 25aff97 commit d98d58f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion vcfconvert.c
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit d98d58f

Please sign in to comment.