Skip to content

Commit

Permalink
Fix behavior of --merge none
Browse files Browse the repository at this point in the history
The option `--merge none` is expected to create no new multiallelic sites,
but it should allow to merge, say, A>C with A>C,AT

Fixes #2333
  • Loading branch information
pd3 committed Jan 2, 2025
1 parent c58d522 commit 7427402
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Changes affecting specific commands:

- Preserve phasing in half-missing genotypes (#2331)

- The option `--merge none` is expected to create no new multiallelic sites, but it should
allow to merge, say, A>C with A>C,AT (#2333)

* bcftools query

- The functions used in -i/-e filtering expressions (such as SUM, MEDIAN, etc) can be
Expand Down
4 changes: 3 additions & 1 deletion test/test.pl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env perl
#
# Copyright (C) 2012-2024 Genome Research Ltd.
# Copyright (C) 2012-2025 Genome Research Ltd.
#
# Author: Petr Danecek <[email protected]>
#
Expand Down Expand Up @@ -61,6 +61,8 @@
run_test(\&test_vcf_isec,$opts,in=>['isec-miss.1.1','isec-miss.1.2','isec-miss.1.3'],out=>'isec-miss.1.1.out',args=>'-R {PATH}/isec-miss.1.regs.txt -n +1');
run_test(\&test_vcf_isec,$opts,in=>['isec-miss.2.1','isec-miss.2.2','isec-miss.2.3'],out=>'isec-miss.2.1.out',args=>'-n +1 -r 20:100,20:140,12:55,20:140,20:100');
run_test(\&test_vcf_isec,$opts,in=>['isec-miss.2.1','isec-miss.2.2','isec-miss.2.3'],out=>'isec-miss.2.1.out',args=>'-R {PATH}/isec-miss.1.regs.txt -n +1');
run_test(\&test_vcf_merge,$opts,in=>['merge.12.a','merge.12.b'],out=>'merge.12.1.out',args=>'--merge none');
run_test(\&test_vcf_merge,$opts,in=>['merge.12.a','merge.12.b'],out=>'merge.12.1.out',args=>'--merge both');
run_test(\&test_vcf_merge,$opts,in=>['merge.phased.1.a','merge.phased.1.b'],out=>'merge.phased.1.1.out',args=>'');
run_test(\&test_vcf_merge,$opts,in=>['merge.11.a','merge.11.b'],out=>'merge.11.1.out',args=>'');
run_test(\&test_vcf_merge,$opts,in=>['merge.join.a','merge.join.b'],out=>'merge.join.1.out',args=>'-i AF:join');
Expand Down
10 changes: 5 additions & 5 deletions vcfmerge.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* vcfmerge.c -- Merge multiple VCF/BCF files to create one multi-sample file.
Copyright (C) 2012-2024 Genome Research Ltd.
Copyright (C) 2012-2025 Genome Research Ltd.
Author: Petr Danecek <[email protected]>
Expand Down Expand Up @@ -2968,10 +2968,10 @@ static inline int types_compatible(args_t *args, int selected_types, buffer_t *b

// The -m none mode or exact matching requested
// Simple test first: are the variants of the same type?
int x = selected_types >> 1; // remove REF
int y = rec_types >> 1; // remove REF
while ( x && y ) { x>>=1; y>>=1; }
if ( x || y ) return 0; // the types differ
int x = selected_types;
int y = rec_types;
if ( !(x&y) ) return 0; // no matching type
if ( (x&y)!=x && (x&y)!=y ) return 0; // not a subset

if ( vcmp_set_ref(args->vcmp,maux->als[0],rec->d.allele[0]) < 0 ) return 0; // refs are not compatible
for (k=1; k<rec->n_allele; k++)
Expand Down

0 comments on commit 7427402

Please sign in to comment.