Querying the food web
To get the complete network, we can run the query below. Notice the LIMIT statement; when we have networks with thousands of nodes, it is crucial to limit the number of returned items to prevent the Neo4j Browser from crashing. In this case, the LIMIT is higher than the total number of items, so we simply get the complete network.
MATCH (n) RETURN n LIMIT 50
You should get a graph in the Neo4j Browser that contains the entire food web. When you mouse over the relationships, you can see the values; when you drag and drop nodes, you can even rearrange the entire network so it looks like Figure 1! You can see an example of the Neo4j network below (Figure 5).
Since the relationships are directed, there is not even truly a need to specify that some species are predators and others are prey. We can simply use the directionality to find species that interact in a certain direction. The first of these queries returns all predators, the second returns all prey! Finally, the third query filters on the relationships so that only prey are returned that make up over 20% of a predator’s calories.
MATCH (a)-->(b) RETURN a
MATCH (a)-->(b) RETURN b
MATCH (a)-[r]->(b) WHERE r.calories > 0.20 RETURN b LIMIT 50
Explaining the full potential of Cypher is not within the scope of this short guide. Note that many other clauses have not been addressed here, such as CREATE. For a complete overview of Cypher, we refer to the Neo4j manual. For explanations of the mako data schema and related queries, please visit <a href=“https://ramellose.github.io/mako_docs/cypher/introduction/intro/“the Cypher page of this website.