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).
The input query consists in a text line with all the conditions grouped by parenthesis.
An election 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.
The query is the basic element in the tree. When processed, will produce a list of samples that meet the query.
It consists in a list of filters joined by "AND" operators.
QUERY | ( <FILTER> [AND <FILTER> ]* ) |
---|
Each filter contains a param, the operator, and the value.
Standard variant query filters can be used to filter. Can be combined with sample and individual catalog queries pre-pending the query params with "sample.
<sample-param>" or "individual.
<individual-param>" respectively.
FILTER | [sample.|individual.]?<QUERY_PARAM><OPERATOR><VALUE> |
---|
{ "type" : QUERY, "query" : { "<query param 1>" : "<operator><value>", "<query param 2>" : "<operator><value>", ... "<query param n>" : "<operator><value>", } } |
A complement node will inverse the selection of the samples selected by the node.
COMPLEMENT | ( NOT <NODE> ) |
---|
{ "type" : COMPLEMENT "nodes" : [ <node> ] } |
A union node will join all samples selected by the sub-nodes, returning them all.
UNION | ( <NODE> [OR <NODE> ]* ) |
---|
{ "type" : UNION "nodes" : [ <node1>, <node2>, ... ] } |
A intersect node will return only samples selected by all sub-nodes.
INTERSECTION | ( <NODE> [AND <NODE> ]* ) |
---|
{ "type" : INTERSECTION "nodes" : [ <node1>, <node2>, ... ] } |
Get all samples that have (a lof
mutation in gene A and with disorder X) or ((a missense_variant mutation on gene B) and (a missense_variant on gene C) but not (variant rs12345))
To build the election query, the natural language query can be divided into 4 queries:
These queries are combined with AND/OR like this:
(Q1 OR (Q2 AND Q3 AND (NOT Q4)))
All together, the query can be expressed like this:
( |
This can be expressed in a JSON query like this:
{ "type" : UNION "nodes" : [ { "type" : QUERY, "query" : Q1 } , { "type" : INTERSECTION "nodes" : [ { "type" : QUERY "query" : Q2 }, { { "type" : QUERY "query" : Q3 }, { "type" : COMPLEMENT "nodes" : [{ "type" : QUERY "query" : Q4 }] }, ] } ] } |
Implementation details at opencga#1474.
Table of Contents: