This is a test version of Biostars. For the public version, visit https://www.biostars.org.
bcftools expression string exact match

Hello, If I execute this in bcftools 1.10.2

clinvar.vcf.gz is https://ftp.ncbi.nlm.nih.gov/pub/clinvar/vcf_GRCh37/clinvar.vcf.gz

bcftools query -i "CLNREVSTAT='criteria_provided,_conflicting_interpretations'"  -f '%CLNREVSTAT\n' clinvar.vcf.gz | sort -u
I get this results:
criteria_provided,_conflicting_interpretations
criteria_provided,_multiple_submitters,_no_conflicts
criteria_provided,_single_submitter

I was expecting to get only criteria_provided,_conflicting_interpretations. Is there anything that I don't understand.

Many thanks

bcftools

1 answer

I supect it's invoked as an OR operator. Can you please try

"CLNREVSTAT='criteria_provided' &&  CLNREVSTAT='_conflicting_interpretations' "

Yes it seems so,

also I execute this:

 bcftools query -i "CLNSIG='Pathogenic'"  -f '%CLNSIG\n' clinvar.vcf.gz | sort -u
The result is
Pathogenic
Pathogenic,_Affects
Pathogenic,_association
Pathogenic,_association,_protective
Pathogenic,_drug_response
Pathogenic,_drug_response,_other
Pathogenic,_other
Pathogenic,_protective
Pathogenic,_risk_factor

I think it is applying the OR also to the results. This is not my desire behavior :(

Thanks for the answer

see the "Notes" section here https://samtools.github.io/bcftools/bcftools.html#expressions

Comma in strings is interpreted as a separator and when multiple values are compared, the OR logic is used.

Seems like this applies to both the value used in the expression and to the contents of the field you are querying.

In one of my cases, I wanted to filter on an INFO tag like TAG=val1,val3,val4 (a field with comma-separated string values), and include variants with certain values but exclude variants with other values. Since you cannot use both -i and -e simultaneously I ended up just | piping the output of the first into the second one ; bcfools filter -i 'TAG="val1,val2"' input.vcf | bcftools filter -e 'TAG="val3,val4"'

Log in to answer this question.