brentp / slivar

genetic variant expressions, annotation, and filtering for great good.
MIT License
248 stars 23 forks source link

filter for presence/absence of a flag tag in the INFO field #93

Closed edg1983 closed 3 years ago

edg1983 commented 3 years ago

Hi Brent,

I want to use slivar for segregation analysis and I want to add a filter based on the INFO field using the --info option. However, it is not clear to me how to set up the expression in case of a flag tag. In my case, I have 2 tags LowComplexity and SegDup that are present and I want to remove variants annotated with any of these 2 flags from my results. So I've tried using --info 'INFO.LowComplexity == false && INFO.SegDup == false' --info 'INFO.LowComplexity == 0 && INFO.SegDup == 0' --info '!INFO.LowComplexity && !INFO.SegDup'

However, with all the above I get a lot of errors like this

[slivar] error evaluating info expression (this can happen if a field is missing):
error from duktape: unknown attribute:LowComplexity for expression:INFO.LowComplexity == false && INFO.SegDup == false

I suppose this can be fine since the flags are missing for many vars. Maybe better to not have this error repeated a lot of times when a flag tag is involved. However, even if the output VCF is generated correctly, only the first (LowComplexity) of the 2 tags is actually removed. What I mean is that if I change the order in the above expression and use --info 'INFO.SegDup == false && INFO.LowComplexity == false' I get this error

[slivar] error evaluating info expression (this can happen if a field is missing):
error from duktape: unknown attribute:SegDup for expression:INFO.SegDup == false && INFO.LowComplexity == false

And now only the SegDup tag is removed from the output.

Can you suggest the best way to filter for flag tags?

brentp commented 3 years ago

for flags, you need:

--info '!(("SegDup" in INFO') || ("LowComplexity" in INFO))'
edg1983 commented 3 years ago

Great thanks! It worked perfectly and no errors reported. I got confused because using any of the expressions reported above the output VCF was created correctly, but only the first tag in the expression got removed.

brentp commented 3 years ago

Yeah. I think you might need parenthesis. It could work how you expected as that's how javascript would work, but I have checks in place so that accessing an absent attribute triggers a warning. This generally helps avoid problems, but in cases like this it's more of a PITA.