Skip to content

Commit 44192ea

Browse files
committed
Add test for samtools#871. Make F_MISSING and F_PASS aware of the necessacity to keep the FORMAT fields.
1 parent eded7db commit 44192ea

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

filter.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,6 @@ static int func_npass(filter_t *flt, bcf1_t *line, token_t *rtok, token_t **stac
10281028
rtok->nvalues = 1;
10291029
rtok->values[0] = rtok->tag[0]=='N' ? npass : (line->n_sample ? 1.0*npass/line->n_sample : 0);
10301030
rtok->nsamples = 0;
1031-
10321031
return 1;
10331032
}
10341033
static void filters_set_nalt(filter_t *flt, bcf1_t *line, token_t *tok)
@@ -2127,12 +2126,14 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok)
21272126
}
21282127
else if ( !strncasecmp(str,"N_MISSING",len) )
21292128
{
2129+
filter->max_unpack |= BCF_UN_FMT;
21302130
tok->setter = &filters_set_nmissing;
21312131
tok->tag = strdup("N_MISSING");
21322132
return 0;
21332133
}
21342134
else if ( !strncasecmp(str,"F_MISSING",len) )
21352135
{
2136+
filter->max_unpack |= BCF_UN_FMT;
21362137
tok->setter = &filters_set_nmissing;
21372138
tok->tag = strdup("F_MISSING");
21382139
return 0;
@@ -2519,8 +2520,18 @@ filter_t *filter_init(bcf_hdr_t *hdr, const char *str)
25192520
tok->hdr_id = -1;
25202521
tok->pass_site = -1;
25212522
tok->threshold = -1.0;
2522-
if ( !strncasecmp(tmp-len,"N_PASS",6) ) { tok->func = func_npass; tok->tag = strdup("N_PASS"); }
2523-
else if ( !strncasecmp(tmp-len,"F_PASS",6) ) { tok->func = func_npass; tok->tag = strdup("F_PASS"); }
2523+
if ( !strncasecmp(tmp-len,"N_PASS",6) )
2524+
{
2525+
filter->max_unpack |= BCF_UN_FMT;
2526+
tok->func = func_npass;
2527+
tok->tag = strdup("N_PASS");
2528+
}
2529+
else if ( !strncasecmp(tmp-len,"F_PASS",6) )
2530+
{
2531+
filter->max_unpack |= BCF_UN_FMT;
2532+
tok->func = func_npass;
2533+
tok->tag = strdup("F_PASS");
2534+
}
25242535
else error("The function \"%s\" is not supported\n", tmp-len);
25252536
continue;
25262537
}

test/filter.28.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3162007

test/filter.6.vcf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
##fileformat=VCFv4.2
2+
##FORMAT=<ID=GT,Number=1,Type=String,Description="genotype">
3+
##contig=<ID=1,assembly=b37,length=249250621>
4+
##reference=file:///lustre/scratch105/projects/g1k/ref/main_project/human_g1k_v37.fasta
5+
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT A B C D E
6+
1 3162007 . A C . . . GT 0/0 ./. 0/1 0/0 0/0

test/test.pl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@
240240
test_vcf_filter($opts,in=>'filter.5',out=>'filter.26.out',args=>q[-i'QUAL=="."'],fmt=>'%POS\\t%QUAL\\n');
241241
test_vcf_filter($opts,in=>'filter.2',out=>'filter.27.out',args=>q[-i'N_PASS(DP>32)=1'],fmt=>'[%POS\\t%SAMPLE\\t%DP\\n]');
242242
test_vcf_filter($opts,in=>'filter.2',out=>'filter.27.out',args=>q[-i'F_PASS(DP>32)=0.5'],fmt=>'[%POS\\t%SAMPLE\\t%DP\\n]');
243+
test_vcf_filter($opts,in=>'filter.6',out=>'filter.28.out',args=>q[-i'F_MISSING>=1/5'],fmt=>'%POS\\n');
244+
test_vcf_filter($opts,in=>'filter.6',out=>'filter.28.out',args=>q[-i'F_MISSING>=0.2'],fmt=>'%POS\\n');
245+
test_vcf_filter($opts,in=>'filter.6',out=>'filter.28.out',args=>q[-i'F_PASS(GT=="mis")>=1/5'],fmt=>'%POS\\n');
246+
test_vcf_filter($opts,in=>'filter.6',out=>'filter.28.out',args=>q[-i'F_PASS(GT=="mis")>=0.2'],fmt=>'%POS\\n');
243247
test_vcf_sort($opts,in=>'sort',out=>'sort.out',args=>q[-m 0],fmt=>'%CHROM\\t%POS\\t%REF,%ALT\\n');
244248
test_vcf_sort($opts,in=>'sort',out=>'sort.out',args=>q[-m 1000],fmt=>'%CHROM\\t%POS\\t%REF,%ALT\\n');
245249
test_vcf_regions($opts,in=>'regions');

0 commit comments

Comments
 (0)