Skip to content

Commit da315c5

Browse files
committed
Allow annotation of Number=A,R INFO tags from tab-delimited files when alleles are split across multiple records
1 parent c9224d0 commit da315c5

File tree

7 files changed

+47
-5
lines changed

7 files changed

+47
-5
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Changes affecting specific commands:
1111
- Fix a bug in annotation renaming via `--rename-annots` and `-c NEW:=OLD`,
1212
where renaming INFO/TAG would simultaneously rename also FORMAT/TAG (#2489)
1313

14+
- Allow annotation of Number=A,R INFO tags from tab-delimited files when alleles
15+
are split across multiple records.
16+
1417
* bcftools cnv
1518

1619
- Fix off-by-one error in reporting HMM qualities

test/annotate.AR.1.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
##fileformat=VCFv4.2
2+
##FILTER=<ID=PASS,Description="All filters passed">
3+
##contig=<ID=1>
4+
##INFO=<ID=IR,Number=R,Type=Integer,Description="">
5+
##INFO=<ID=FR,Number=R,Type=Float,Description="">
6+
##INFO=<ID=IA,Number=A,Type=Integer,Description="">
7+
##INFO=<ID=FA,Number=A,Type=Float,Description="">
8+
#CHROM POS ID REF ALT QUAL FILTER INFO
9+
1 100 . A C,G . . IA=10,20;FA=1.1,2.2;IR=11,22,44;FR=1.1,2.2,4.4

test/annotate.AR.2.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
##fileformat=VCFv4.2
2+
##FILTER=<ID=PASS,Description="All filters passed">
3+
##contig=<ID=1>
4+
##INFO=<ID=IR,Number=R,Type=Integer,Description="">
5+
##INFO=<ID=FR,Number=R,Type=Float,Description="">
6+
##INFO=<ID=IA,Number=A,Type=Integer,Description="">
7+
##INFO=<ID=FA,Number=A,Type=Float,Description="">
8+
#CHROM POS ID REF ALT QUAL FILTER INFO
9+
1 100 . A C,G . . IA=10,20;FA=1.1,2.2;IR=33,22,44;FR=3.3,2.2,4.4

test/annotate.AR.tab

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1 100 A C 10 1.1 11,22 1.1,2.2
2+
1 100 A G 20 2.2 33,44 3.3,4.4

test/annotate.AR.vcf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
##fileformat=VCFv4.2
2+
##FILTER=<ID=PASS,Description="All filters passed">
3+
##contig=<ID=1>
4+
##INFO=<ID=IR,Number=R,Type=Integer,Description="">
5+
##INFO=<ID=FR,Number=R,Type=Float,Description="">
6+
##INFO=<ID=IA,Number=A,Type=Integer,Description="">
7+
##INFO=<ID=FA,Number=A,Type=Float,Description="">
8+
#CHROM POS ID REF ALT QUAL FILTER INFO
9+
1 100 . A C,G . . .

test/test.pl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,9 @@
565565
run_test(\&test_vcf_sort,$opts,in=>'sort',out=>'sort.out',args=>q[-m 0],fmt=>'%CHROM\\t%POS\\t%REF,%ALT\\n');
566566
run_test(\&test_vcf_sort,$opts,in=>'sort',out=>'sort.out',args=>q[-m 1000],fmt=>'%CHROM\\t%POS\\t%REF,%ALT\\n');
567567
run_test(\&test_vcf_regions,$opts,in=>'regions');
568-
+run_test(\&test_vcf_annotate,$opts,in=>'annotate.int.dst',vcf=>'annotate.int.src',out=>'annotate.int.1.out',args=>q[-c +INFO/IA,+INFO/IR]);
568+
run_test(\&test_vcf_annotate,$opts,in=>'annotate.AR',tab=>'annotate.AR',out=>'annotate.AR.1.out',args=>q[-c CHROM,POS,REF,ALT,+INFO/IA,+INFO/FA,+INFO/IR,+INFO/FR]);
569+
run_test(\&test_vcf_annotate,$opts,in=>'annotate.AR',tab=>'annotate.AR',out=>'annotate.AR.2.out',args=>q[-c CHROM,POS,REF,ALT,INFO/IA,INFO/FA,INFO/IR,INFO/FR]);
570+
run_test(\&test_vcf_annotate,$opts,in=>'annotate.int.dst',vcf=>'annotate.int.src',out=>'annotate.int.1.out',args=>q[-c +INFO/IA,+INFO/IR]);
569571
run_test(\&test_vcf_annotate,$opts,in=>'annotate.rename',out=>'annotate.rename.1.out',args=>q[-c INFO/ii:=INFO/XX]);
570572
run_test(\&test_vcf_annotate,$opts,in=>'annotate.rename',out=>'annotate.rename.2.out',args=>q[-c FORMAT/ff:=FORMAT/XX]);
571573
run_test(\&test_vcf_annotate,$opts,in=>'annotate36',bed=>'annots36',out=>'annotate36.1.out',args=>q[-c CHROM,POS,-,~X,-,AF,-,-,- -i'SVTYPE={X}' -k]);

vcfannotate.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,8 @@ static int setter_ARinfo_int32(args_t *args, bcf1_t *line, annot_col_t *col, int
810810

811811
args->tmpi2[i] = args->tmpi[ map[i] ];
812812
}
813-
return bcf_update_info_int32(args->hdr_out,line,col->hdr_key_dst,args->tmpi2,ndst);
813+
int ret = bcf_update_info_int32(args->hdr_out,line,col->hdr_key_dst,args->tmpi2,ndst);
814+
return ret<0 ? ret : 1;
814815
}
815816
static int setter_info_int(args_t *args, bcf1_t *line, annot_col_t *col, void *data)
816817
{
@@ -919,7 +920,10 @@ static int setter_info_int(args_t *args, bcf1_t *line, annot_col_t *col, void *d
919920
}
920921

921922
if ( col->number==BCF_VL_A || col->number==BCF_VL_R )
923+
{
924+
assert(tab);
922925
return setter_ARinfo_int32(args,line,col,tab->nals,tab->als,ntmpi);
926+
}
923927

924928
if ( col->replace & REPLACE_MISSING )
925929
{
@@ -975,7 +979,8 @@ static int setter_ARinfo_real(args_t *args, bcf1_t *line, annot_col_t *col, int
975979

976980
args->tmpf2[i] = args->tmpf[ map[i] ];
977981
}
978-
return bcf_update_info_float(args->hdr_out,line,col->hdr_key_dst,args->tmpf2,ndst);
982+
int ret = bcf_update_info_float(args->hdr_out,line,col->hdr_key_dst,args->tmpf2,ndst);
983+
return ret<0 ? ret : 1;
979984
}
980985
static int setter_info_real(args_t *args, bcf1_t *line, annot_col_t *col, void *data)
981986
{
@@ -1103,7 +1108,10 @@ static int setter_info_real(args_t *args, bcf1_t *line, annot_col_t *col, void *
11031108
}
11041109

11051110
if ( col->number==BCF_VL_A || col->number==BCF_VL_R )
1111+
{
1112+
assert(tab);
11061113
return setter_ARinfo_real(args,line,col,tab->nals,tab->als,ntmpf);
1114+
}
11071115

11081116
if ( col->replace & REPLACE_MISSING )
11091117
{
@@ -3789,7 +3797,7 @@ static int annotate_from_vcf(args_t *args, bcf1_t *line)
37893797
for (j=0; j<args->ncols; j++)
37903798
{
37913799
if ( !args->cols[j].setter ) continue;
3792-
if ( args->cols[j].setter(args,line,&args->cols[j],aline) )
3800+
if ( args->cols[j].setter(args,line,&args->cols[j],aline) < 0 )
37933801
error("fixme: Could not set %s at %s:%"PRId64"\n", args->cols[j].hdr_key_src,bcf_seqname(args->hdr,line),(int64_t) line->pos+1);
37943802
}
37953803
return 1;
@@ -3800,7 +3808,7 @@ static int annotate_from_self(args_t *args, bcf1_t *line)
38003808
for (j=0; j<args->ncols; j++)
38013809
{
38023810
if ( !args->cols[j].setter ) continue;
3803-
if ( args->cols[j].setter(args,line,&args->cols[j],NULL) )
3811+
if ( args->cols[j].setter(args,line,&args->cols[j],NULL) < 0 )
38043812
error("fixme: Could not set %s at %s:%"PRId64"\n", args->cols[j].hdr_key_src,bcf_seqname(args->hdr,line),(int64_t) line->pos+1);
38053813
}
38063814
return 0;

0 commit comments

Comments
 (0)