diff --git a/filter.c b/filter.c index c9ddb6f2a..a2288788b 100644 --- a/filter.c +++ b/filter.c @@ -83,7 +83,7 @@ typedef struct _token_t char *tag; // for debugging and printout only, VCF tag name double threshold; // filtering threshold int is_constant; // the threshold is set - int hdr_id, type; // BCF header lookup ID and one of BCF_HT_* types + int hdr_id, tag_type; // BCF header lookup ID and one of BCF_HL_* types int idx; // 0-based index to VCF vectors, // -2: list (e.g. [0,1,2] or [1..3] or [1..] or any field[*], which is equivalent to [0..]) int *idxs; // set indexes to 0 to exclude, to 1 to include, and last element negative if unlimited @@ -2139,6 +2139,7 @@ static int max_ac_an_unpack(bcf_hdr_t *hdr) } static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) { + tok->tag_type = -1; tok->tok_type = TOK_VAL; tok->hdr_id = -1; tok->pass_site = -1; @@ -2209,6 +2210,7 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) tok->comparator = filters_cmp_filter; tok->tag = strdup("FILTER"); filter->max_unpack |= BCF_UN_FLT; + tok->tag_type = BCF_HL_FLT; return 0; } else if ( !strncasecmp(str,"ID",len) || !strncasecmp(str,"%ID",len) /* for backward compatibility */ ) @@ -2306,7 +2308,7 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) for (i=0; insamples; i++) tok->usmpl[i] = 1; } - tok->type = is_fmt ? BCF_HL_FMT : BCF_HL_INFO; + tok->tag_type = is_fmt ? BCF_HL_FMT : BCF_HL_INFO; if ( is_fmt ) filter->max_unpack |= BCF_UN_FMT; if ( tok->hdr_id>=0 ) { @@ -2807,7 +2809,7 @@ filter_t *filter_init(bcf_hdr_t *hdr, const char *str) int set_missing = 0; if ( out[k].hdr_id>0 ) { - int type = bcf_hdr_id2type(filter->hdr,out[k].type,out[k].hdr_id); + int type = bcf_hdr_id2type(filter->hdr,out[k].tag_type,out[k].hdr_id); if ( type==BCF_HT_INT ) set_missing = 1; else if ( type==BCF_HT_REAL ) set_missing = 1; } @@ -2881,7 +2883,7 @@ filter_t *filter_init(bcf_hdr_t *hdr, const char *str) else if ( !strcasecmp(out[ival].key,"r") ) { out[i].setter = filters_set_genotype2; out[ival].key[0]='r'; out[ival].key[1]=0; } // r continue; } - if ( !strcmp(out[i].tag,"FILTER") ) + if ( out[i].tag_type==BCF_HL_FLT ) { if ( i+1==nout ) error("Could not parse the expression: %s\n", filter->str); int itok = i, ival; diff --git a/test/test.pl b/test/test.pl index 59ac14b6f..817dc99aa 100755 --- a/test/test.pl +++ b/test/test.pl @@ -212,6 +212,7 @@ test_vcf_filter($opts,in=>'view.filter',out=>'view.filter.9.out',args=>q[-S. -e'FMT/FGS[*:1]="BBB"'],reg=>''); test_vcf_filter($opts,in=>'view.filter',out=>'view.filter.10.out',args=>q[-S. -e'FMT/FGS[*:4]="EE"'],reg=>''); test_vcf_filter($opts,in=>'view.filter',out=>'view.filter.11.out',args=>q[-S. -e'FMT/STR="XX"'],reg=>''); +test_vcf_filter($opts,in=>'view.filter.2',out=>'view.filter.12.out',args=>q[-S. -e'FMT/FILTER="aaa"'],reg=>''); test_vcf_view($opts,in=>'view.minmaxac',out=>'view.minmaxac.1.out',args=>q[-H -C5:nonmajor],reg=>''); test_vcf_view($opts,in=>'view.minmaxac',out=>'view.minmaxac.2.out',args=>q[-H -c6:nonmajor],reg=>''); test_vcf_view($opts,in=>'view.minmaxac',out=>'view.minmaxac.1.out',args=>q[-H -q0.3:major],reg=>''); diff --git a/test/view.filter.12.out b/test/view.filter.12.out new file mode 100644 index 000000000..fa868d135 --- /dev/null +++ b/test/view.filter.12.out @@ -0,0 +1,9 @@ +##fileformat=VCFv4.2 +##FILTER= +##FORMAT= +##FORMAT= +##reference=file:///lustre/scratch105/projects/g1k/ref/main_project/human_g1k_v37.fasta +##contig= +#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT A B +1 3162006 . G CA 238 PASS . GT:FILTER ./.:aaa 0/1:bbbb +1 3162007 . G CA 238 PASS . GT:FILTER 0/1:cc 0/1:d diff --git a/test/view.filter.2.vcf b/test/view.filter.2.vcf new file mode 100644 index 000000000..88fa17af4 --- /dev/null +++ b/test/view.filter.2.vcf @@ -0,0 +1,8 @@ +##fileformat=VCFv4.2 +##FORMAT= +##FORMAT= +##reference=file:///lustre/scratch105/projects/g1k/ref/main_project/human_g1k_v37.fasta +##contig= +#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT A B +1 3162006 . G CA 238 PASS . GT:FILTER 0/1:aaa 0/1:bbbb +1 3162007 . G CA 238 PASS . GT:FILTER 0/1:cc 0/1:d