One of the first steps on clinical trials is the selection of the eligible individuals for the study. The rules that an individual must match in order to be elected as a candidate usually involve complex queries combining clinical metadata and variants data, expressed as a list of filters with intersections (AND), unions (OR) and complement (NOT).
Complex query
A complex query can be defined as a tree where each node is either a query or the intersection or union of a list of queries
To solve the query, the tree has to be explored, solve the leaves from the tree, and then join the results.
Query leaf node
Standard variant query.
Can be combined with sample and individual catalog queries pre-pending the query params with "sample.<sample-param>" or "individual.<individual-param>" respectively.
Get all samples that have (a lof mutation in gene A and with HPO X) or ((a missense_variant mutation on gene B) and (a missense_variant on gene C) but not (a missense_variant on gene D))
This can be divided into 3 queries:
Q1
gene : A
ct : lof
hpo : X
Q2
gene : B
ct : missense_variant
Q3
gene : C
ct : missense_variant
Q4
gene : D
ct : missense_variant
These queries are combined with AND/OR like this: Q1 OR (Q2 AND Q3 AND (NOT Q4))