From 1745829009c136857b8406d3c514992e3883e7ae Mon Sep 17 00:00:00 2001 From: Petr Danecek Date: Mon, 13 Jun 2022 16:56:39 +0200 Subject: [PATCH] Fix a bug introduced in 1.14 The bug caused that records with INFO/END annotation would incorrectly trigger `-c ~INFO/END` mode of comparison even when not explicitly requested, which would result in not transferring the annotation from a tab-delimited file. Resolves #1733 --- NEWS | 7 +++++++ test/annotate.32.out | 12 ++++++++++++ test/annotate27.tab | 4 ++++ test/annotate27.vcf | 12 ++++++++++++ test/test.pl | 1 + vcfannotate.c | 7 ++++--- 6 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 test/annotate.32.out create mode 100644 test/annotate27.tab create mode 100644 test/annotate27.vcf diff --git a/NEWS b/NEWS index 95ed1736e..0e6dfcb51 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,13 @@ Changes affecting the whole of bcftools, or multiple commands: Changes affecting specific commands: +* bcftools annotate + + - A bug introduced in 1.14 caused that records with INFO/END annotation would + incorrectly trigger `-c ~INFO/END` mode of comparison even when not explicitly + requested, which would result in not transferring the annotation from a tab-delimited + file (#1733) + * bcftools mpileup - New NMBZ annotation for Mann-Whitney U-z test on number of mismatches within diff --git a/test/annotate.32.out b/test/annotate.32.out new file mode 100644 index 000000000..0ad0e990d --- /dev/null +++ b/test/annotate.32.out @@ -0,0 +1,12 @@ +##fileformat=VCFv4.2 +##FILTER= +##ALT= +##ALT= +##INFO= +##INFO= +##contig= +#CHROM POS ID REF ALT QUAL FILTER INFO +chr1 54713 . N . PASS END=54714;EVIDENCE=RD,PE,SR +chr1 66224 . N . PASS END=66275;EVIDENCE=RD,PE,SR +chr1 66242 . N . PASS END=66520;EVIDENCE=RD,PE,SR +chr1 998763 . N . PASS END=998764;EVIDENCE=RD,PE,SR diff --git a/test/annotate27.tab b/test/annotate27.tab new file mode 100644 index 000000000..4e1687d1b --- /dev/null +++ b/test/annotate27.tab @@ -0,0 +1,4 @@ +chr1 54713 N RD,PE,SR +chr1 66224 N RD,PE,SR +chr1 66242 N RD,PE,SR +chr1 998763 N RD,PE,SR diff --git a/test/annotate27.vcf b/test/annotate27.vcf new file mode 100644 index 000000000..b4f3eeb20 --- /dev/null +++ b/test/annotate27.vcf @@ -0,0 +1,12 @@ +##fileformat=VCFv4.2 +##FILTER= +##ALT= +##ALT= +##INFO= +##INFO= +##contig= +#CHROM POS ID REF ALT QUAL FILTER INFO +chr1 54713 . N . PASS END=54714 +chr1 66224 . N . PASS END=66275 +chr1 66242 . N . PASS END=66520 +chr1 998763 . N . PASS END=998764 diff --git a/test/test.pl b/test/test.pl index 5bf6e37af..0c35dee62 100755 --- a/test/test.pl +++ b/test/test.pl @@ -489,6 +489,7 @@ test_vcf_annotate($opts,in=>'annotate.olap',tab=>'annots.olap',out=>'annotate.olap.2.out',args=>'-c CHROM,BEG,END,DB -l DB:unique --min-overlap 0.4:0.5'); test_vcf_annotate($opts,in=>'annotate.id',vcf=>'annots.id',out=>'annotate.id.1.out',args=>'-c ALT'); test_vcf_annotate($opts,in=>'annotate.id',vcf=>'annots.id',out=>'annotate.id.2.out',args=>'-c +ALT'); +test_vcf_annotate($opts,in=>'annotate27',tab=>'annotate27',out=>'annotate.32.out',args=>'-c CHROM,POS,REF,ALT,EVIDENCE'); test_vcf_plugin($opts,in=>'checkploidy',out=>'checkploidy.out',cmd=>'+check-ploidy --no-version'); test_vcf_plugin($opts,in=>'checkploidy.2',out=>'checkploidy.2.out',cmd=>'+check-ploidy --no-version'); test_vcf_plugin($opts,in=>'checkploidy.2',out=>'checkploidy.3.out',cmd=>'+check-ploidy --no-version',args=>'-- -m'); diff --git a/vcfannotate.c b/vcfannotate.c index 4efa77089..bd2dea293 100644 --- a/vcfannotate.c +++ b/vcfannotate.c @@ -140,8 +140,8 @@ typedef struct _args_t int ref_idx, alt_idx, chr_idx, beg_idx, end_idx; // -1 if not present annot_col_t *cols; // column indexes and setters int ncols; - int match_id; // set iff `-c ~ID` given - int match_end; // set iff `-c ~INFO/END` is given + int match_id; // set iff `-c ~ID` given, -1 otherwise + int match_end; // set iff `-c ~INFO/END` is given, -1 otherwise char *set_ids_fmt; convert_t *set_ids; @@ -3145,7 +3145,7 @@ static void annotate(args_t *args, bcf1_t *line) ialt++; } if ( args->match_id>=0 && !strstr_match(line->d.id,args->alines[i].cols[args->match_id]) ) continue; - if ( match_end.l && strcmp(match_end.s,args->alines[i].cols[args->match_end]) ) continue; + if ( args->match_end>=0 && match_end.l && strcmp(match_end.s,args->alines[i].cols[args->match_end]) ) continue; args->srt_alines[args->nsrt_alines++] = (ialt<<16) | i; has_overlap = 1; break; @@ -3335,6 +3335,7 @@ int main_vcfannotate(int argc, char *argv[]) args->ref_idx = args->alt_idx = args->chr_idx = args->beg_idx = args->end_idx = -1; args->set_ids_replace = 1; args->match_id = -1; + args->match_end = -1; args->clevel = -1; args->pair_logic = -1; int regions_is_file = 0;