Skip to content

Commit c3b7d7e

Browse files
committed
Numerical functions, such as SUM(INFO/DP), in formatting expressions of query
would previously return the value 0 when executed on missing values. This was incorrect, newly a missing value is printed.
1 parent 8d73103 commit c3b7d7e

File tree

6 files changed

+14
-13
lines changed

6 files changed

+14
-13
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ Changes affecting specific commands:
5353
- Make the -i/-e filtering option work for all options, such as line merging and
5454
duplication removal (#2415)
5555

56+
* bcftools query
57+
58+
- Numerical functions, such as SUM(INFO/DP), would previously return the value 0 when
59+
executed on missing values. This was incorrect, newly a missing value is printed.
60+
5661
* bcftools reheader
5762

5863
- Add options `--samples-list` and `--samples-file` to allow renaming samples from a list of

convert.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ static void process_filter_expr(convert_t *convert, bcf1_t *line, fmt_t *fmt, in
11831183
val = filter_get_doubles(dat->filter,&nval,&nval1);
11841184
if ( fmt->is_gt_field )
11851185
{
1186-
if ( !dat->nval )
1186+
if ( nval && !dat->nval )
11871187
{
11881188
dat->nval = nval;
11891189
dat->val = malloc(nval*sizeof(double));
@@ -1204,7 +1204,8 @@ static void process_filter_expr(convert_t *convert, bcf1_t *line, fmt_t *fmt, in
12041204
}
12051205
if ( isample<0 ) isample = 0;
12061206
if ( isample>=nval ) isample = 0;
1207-
kputd(val[isample], str);
1207+
if ( nval ) kputd(val[isample], str);
1208+
else kputc('.', str);
12081209
}
12091210
static void destroy_filter_expr(void *usr)
12101211
{

filter.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4379,15 +4379,10 @@ const double *filter_get_doubles(filter_t *filter, int *nval, int *nval1)
43794379
{
43804380
*nval = tok->nvalues;
43814381
*nval1 = tok->nval1;
4382+
return tok->values;
43824383
}
4383-
else
4384-
{
4385-
if ( !tok->values ) error("fixme in filter_get_doubles(): %s\n", filter->str);
4386-
*nval = 1;
4387-
*nval1 = 1;
4388-
tok->values[0] = filter->flt_stack[0]->pass_site;
4389-
}
4390-
return tok->values;
4384+
*nval = *nval1 = 0;
4385+
return NULL;
43914386
}
43924387

43934388
void filter_set_samples(filter_t *filter, const uint8_t *samples)

test/fill-tags.5.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
##INFO=<ID=DP_BC,Number=1,Type=Integer,Description="Added by +fill-tags expression DP:1=int(sum(FORMAT/DP)) in BC">
3434
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT NA00001 NA00002 NA00003
3535
11 2343543 . A . 999 PASS DP=586;DP_AB=404;DP_BC=393 GT:PL:DP:GQ 0/0:0:193:99 0/0:0:211:99 0/0:0:182:99
36-
11 5464562 . C T 999 PASS DP=0;DP_AB=0;DP_BC=0 GT:PL:DP:GQ ./.:0,0,0:.:. ./.:0,0,0:.:. ./.:0,0,0:.:.
36+
11 5464562 . C T 999 PASS DP=.;DP_AB=.;DP_BC=. GT:PL:DP:GQ ./.:0,0,0:.:. ./.:0,0,0:.:. ./.:0,0,0:.:.
3737
20 76962 rs6111385 T C 999 PASS DP4=110138,70822,421911,262673;DP=586;Dels=0;FS=21.447;HWE=0.491006;ICF=-0.01062;MQ0=1;MQ=46;PV4=2.5e-09,0,0,1;QD=22.31;DP_AB=404;DP_BC=393 GT:PL:DP:GQ 0/1:255,0,255:193:99 1/1:255,255,0:211:99 1/1:255,255,0:182:99
3838
20 126310 . ACC A 999 StrandBias;EndDistBias DP4=125718,95950,113812,80890;DP=306;HWE=0.24036;ICF=0.01738;INDEL;IS=374,0.937343;MQ=49;PV4=9e-30,1,0,3.8e-13;QD=0.0172;AN=6;AC=4;DP_AB=228;DP_BC=189 GT:DP:GQ:PL 0/1:117:99:255,0,132 0/1:111:99:255,0,139 1/1:78:99:255,213,0
3939
20 138125 rs2298108 G T 999 PASS DP4=174391,20849,82080,4950;DP=203;Dels=0;FS=3200;HWE=0.199462;ICF=0.01858;MQ0=0;MQ=46;PV4=0,0,0,1;QD=17.22;AN=6;AC=4;DP_AB=137;DP_BC=137 GT:PL:DP:GQ 0/1:135,0,163:66:99 0/1:140,0,255:71:99 1/1:255,199,0:66:99

test/query.func.1.2.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1:150 . . 0
1+
1:150 . . .
22
1:153 .,.,. 0,0,210 210
33
1:154 30,13,0 300,13,0 356
44
1:155 20,0,10 200,0,10 240

test/query.func.1.3.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1:150 . . 0 0
1+
1:150 . . . .
22
1:153 .,.,. 0,0,210 210 210
33
1:154 30,13,0 300,13,0 356 356
44
1:155 20,0,10 200,0,10 240 240

0 commit comments

Comments
 (0)