Complex queries

The following more complex queries use mako’s database schema to carry out more intricate operations that require the use of WHERE and WITH statements.


MATCH (n:Family)--(a:Taxon)--(b:Edge)--(c:Network) 
WITH n, count(c) AS num, collect(distinct(c.name)) AS networks
WHERE num > 2
RETURN n.name, networks

This query finds a pattern that links taxonomic families to network. It then collects the family names and all unique network names and filters the pattern so all results occur in at least two networks.


MATCH p=(a:Order)--()--(x:Edge)--()--(b:Order), 
q=(a:Order)--()--(y:Edge)--()--(b:Order) 
RETURN p, q


This query finds two patterns, which both have the same taxonomic orders but distinct edges. Therefore, these edges contain different taxa but have similar taxonomic composition.


MATCH p=(a:Order)--()--(x:Edge)--()--(b:Order), 
q=(a:Order)--()--(y:Edge)--()--(b:Order) 
WHERE x.weight > 0 AND y.weight < 0 
RETURN p, q LIMIT 1

This query finds the same pattern as bove, but it specifies that one edge should have a positive weight and the other should have a negative weight.

For additional examples of complex queries, take a look at the case studies, where we write queries to answer specific biological questions.