Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:samtools/bcftools into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
pd3 committed May 3, 2019
2 parents 6fc13bf + 44c86bb commit f24ccc9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
10 changes: 6 additions & 4 deletions filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */ )
Expand Down Expand Up @@ -2306,7 +2308,7 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok)
for (i=0; i<tok->nsamples; 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 )
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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=>'');
Expand Down
9 changes: 9 additions & 0 deletions test/view.filter.12.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
##fileformat=VCFv4.2
##FILTER=<ID=PASS,Description="All filters passed">
##FORMAT=<ID=FILTER,Number=1,Type=String,Description="Test">
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
##reference=file:///lustre/scratch105/projects/g1k/ref/main_project/human_g1k_v37.fasta
##contig=<ID=1,length=249250621>
#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
8 changes: 8 additions & 0 deletions test/view.filter.2.vcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
##fileformat=VCFv4.2
##FORMAT=<ID=FILTER,Number=1,Type=String,Description="Test">
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
##reference=file:///lustre/scratch105/projects/g1k/ref/main_project/human_g1k_v37.fasta
##contig=<ID=1,length=249250621>
#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

0 comments on commit f24ccc9

Please sign in to comment.