brentp / slivar

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

extract shared variant #125

Closed luceamso closed 2 years ago

luceamso commented 2 years ago

Hi, thanks again for this useful tool.

I wanted to extract variants shared by all patients, so I tried several times, but didn't get the results I wanted. This is the code that produced similar results.

--family-expr 'aff:fam.every(function(s) {return (s.het || s.hom_ref) && s.GQ >= 20 }) && fam.some(function(s) {return s.hom_ref != s.affected })'

How can I get the results I want? I would highly appreciate if you could have a look. Thank you so much! Seoon

brentp commented 2 years ago

I wanted to extract variants shared by all patient

I'll assume that "patient" means affected, so you want variants where affected samples are het or hom_alt. in which case, you simply need:

--family-expr 'aff:fam.every(function(s) {return !s.affected || ((s.het || s.hom_alt) && s.affected && s.GQ >= 20) })'
luceamso commented 2 years ago

Thanks for the quick reply. You're right. 'patient' means 'affected' It worked perfectly. Unfortunately I didn't understand how that code works. Could you please explain?

brentp commented 2 years ago

!s.affected means return true for any unaffected sample. so those are ignored. the rest:

(s.het || s.hom_alt) && s.affected && s.GQ >= 20 requires the affected samples to be het or hom_alt and have a GQ >= 20.

luceamso commented 2 years ago

Sorry for all question. Why return if unaffected is ignored?

brentp commented 2 years ago

the function is fam.every that means that it will only pass if the expression returns true for every member in the family. You could also do:

return S.GQ >= 20 \  # all samples have GQ >= 20
    && (
        (!s.affected && s.hom_ref) \  # unaffected samples are hom_ref
        ||   
        ((s.het || s.hom_alt) && s.affected) \ # affected samples are het or hom_alt
   )

(note you must remove the "# ... " if you want to try that expression.

luceamso commented 2 years ago

Thank you for your kindness. It really helped a lot!