Skip to content

Commit 97cfa16

Browse files
committed
Fix a bug when update of INFO/END results in assertion error
When INFO/END is updated from a text annotation file, VCF record that overlaps multiple annotation records could update rlen on the fly and lead to negative overlap length calculation. Fixes #1957
1 parent eda84ab commit 97cfa16

File tree

6 files changed

+35
-1
lines changed

6 files changed

+35
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Changes affecting specific commands:
1414

1515
- Fix a bug where the `-m` function did not respect the `--min-overlap` option (#1869)
1616

17+
- Fix a bug when update of INFO/END results in assertion error (#1957)
18+
1719
* bcftools concat
1820

1921
- New option `--drop-genotypes`

test/annotate34.out

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
##fileformat=VCFv4.2
2+
##FILTER=<ID=PASS,Description="All filters passed">
3+
##contig=<ID=chr21,length=45090682>
4+
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
5+
##FORMAT=<ID=AD,Number=R,Type=Integer,Description="Allelic depths for the ref and alt alleles in the order listed">
6+
##FILTER=<ID=HET1,Description="Heterozygous in the first haplotype">
7+
##FILTER=<ID=HET2,Description="Heterozygous in the second haplotype">
8+
##INFO=<ID=SVTYPE,Number=1,Type=String,Description="SVTYPE">
9+
##INFO=<ID=SVLEN,Number=1,Type=Integer,Description="SVLEN">
10+
##INFO=<ID=END,Number=1,Type=Integer,Description="End coordinate in reference for SV">
11+
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT syndip
12+
chr21 8914240 . gttccattccattccattcaattccattccattgcattccattccattccattcca G 30 HET2 SVTYPE=DEL;SVLEN=55;END=8914295 GT:AD 0|.:3,1
13+
chr21 8914680 . tattccattccattcc TATTCCATTCCATTCCATTCCATTCCATTCCATTCCATTCCATTCTAGTTGATTCCATTCCATTCCATCCCGTTCCATTCCATTCCGTTACTTTCTATTCCATTCCATTCCATTCC 30 HET2 SVTYPE=INS;SVLEN=100;END=8914681 GT:AD 0|.:1,1
14+
chr21 8914690 . c CATTCCATTCCATTCCATTCCATTCTAGTTGATTCCATTCCATTCCATCCCGTTCCATTCCATTCCGTTACTTTCT 30 HET2 SVTYPE=INS;SVLEN=75;END=8914691 GT:AD 0|.:2,1

test/annotate34.vcf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
##fileformat=VCFv4.2
2+
##FILTER=<ID=PASS,Description="All filters passed">
3+
##contig=<ID=chr21,length=45090682>
4+
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
5+
##FORMAT=<ID=AD,Number=R,Type=Integer,Description="Allelic depths for the ref and alt alleles in the order listed">
6+
##FILTER=<ID=HET1,Description="Heterozygous in the first haplotype">
7+
##FILTER=<ID=HET2,Description="Heterozygous in the second haplotype">
8+
##INFO=<ID=SVTYPE,Number=1,Type=String,Description="SVTYPE">
9+
##INFO=<ID=SVLEN,Number=1,Type=Integer,Description="SVLEN">
10+
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT syndip
11+
chr21 8914240 . gttccattccattccattcaattccattccattgcattccattccattccattcca G 30 HET2 SVTYPE=DEL;SVLEN=55 GT:AD 0|.:3,1
12+
chr21 8914680 . tattccattccattcc TATTCCATTCCATTCCATTCCATTCCATTCCATTCCATTCCATTCTAGTTGATTCCATTCCATTCCATCCCGTTCCATTCCATTCCGTTACTTTCTATTCCATTCCATTCCATTCC 30 HET2 SVTYPE=INS;SVLEN=100 GT:AD 0|.:1,1
13+
chr21 8914690 . c CATTCCATTCCATTCCATTCCATTCTAGTTGATTCCATTCCATTCCATCCCGTTCCATTCCATTCCGTTACTTTCT 30 HET2 SVTYPE=INS;SVLEN=75 GT:AD 0|.:2,1

test/annots34.tab

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
chr21 8914240 8914240 8914295
2+
chr21 8914680 8914680 8914681
3+
chr21 8914690 8914690 8914691

test/test.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@
523523
run_test(\&test_vcf_annotate,$opts,in=>'annotate28',tab=>'annots28',out=>'annotate28.3.out',args=>'-c CHROM,POS,REF,ALT,FMT/TEST -s smpl1');
524524
run_test(\&test_vcf_annotate,$opts,in=>'annotate28',tab=>'annots28',out=>'annotate28.4.out',args=>'-c CHROM,POS,REF,ALT,FMT/TEST -s smpl2');
525525
run_test(\&test_vcf_annotate,$opts,in=>'annotate',out=>'annotate.33.out',args=>'-m XXX');
526+
run_test(\&test_vcf_annotate,$opts,in=>'annotate34',tab=>'annots34',out=>'annotate34.out',args=>q[-c CHROM,FROM,TO,INFO/END -H '##INFO=<ID=END,Number=1,Type=Integer,Description="End coordinate in reference for SV">']);
526527
run_test(\&test_vcf_plugin,$opts,in=>'checkploidy',out=>'checkploidy.out',cmd=>'+check-ploidy --no-version');
527528
run_test(\&test_vcf_plugin,$opts,in=>'checkploidy.2',out=>'checkploidy.2.out',cmd=>'+check-ploidy --no-version');
528529
run_test(\&test_vcf_plugin,$opts,in=>'checkploidy.2',out=>'checkploidy.3.out',cmd=>'+check-ploidy --no-version',args=>'-- -m');

vcfannotate.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3094,6 +3094,7 @@ static void annotate(args_t *args, bcf1_t *line)
30943094
for (j=0; j<args->ncols; j++) args->cols[j].done = 0;
30953095
if ( regidx_overlap(args->tgt_idx, bcf_seqname(args->hdr,line),line->pos,line->pos+line->rlen-1, args->tgt_itr) )
30963096
{
3097+
hts_pos_t vcf_end = line->pos + line->rlen - 1;
30973098
while ( regitr_overlap(args->tgt_itr) )
30983099
{
30993100
annot_line_t *tmp = &args->alines[0];
@@ -3104,7 +3105,7 @@ static void annotate(args_t *args, bcf1_t *line)
31043105
// Check min overlap
31053106
int len_ann = tmp->end - tmp->start + 1;
31063107
int len_vcf = line->rlen;
3107-
int isec = (tmp->end < line->pos+line->rlen-1 ? tmp->end : line->pos+line->rlen-1) - (tmp->start > line->pos ? tmp->start : line->pos) + 1;
3108+
int isec = (tmp->end < vcf_end ? tmp->end : vcf_end) - (tmp->start > line->pos ? tmp->start : line->pos) + 1;
31083109
assert( isec > 0 );
31093110
if ( args->min_overlap_ann && args->min_overlap_ann > (float)isec/len_ann ) continue;
31103111
if ( args->min_overlap_vcf && args->min_overlap_vcf > (float)isec/len_vcf ) continue;

0 commit comments

Comments
 (0)