Skip to content

Instantly share code, notes, and snippets.

@jhpoelen
Last active February 22, 2019 13:35
Show Gist options
  • Save jhpoelen/192f1e8af5723d3d73c5 to your computer and use it in GitHub Desktop.
Save jhpoelen/192f1e8af5723d3d73c5 to your computer and use it in GitHub Desktop.
Global Biotic Interactions - Getting Started with Cypher Queries

What do great white sharks (Carcharodon carcharias) eat?

Global Biotic Interactions (GloBI, http://globalbioticinteractions.org) uses neo4j to capture recorded interactions between living organisms on our planet. This page give an introduction into how the interactions are currently captured and how to make queries to retrieve specific information.

This page not only serves as a getting started guide, but also as a way to solicit feedback on the way the data is modeled. So . . . please don’t hesitate to share comments or ask questions.

A simplified species interaction model

For sake of simplicity, only a part of the species interaction model is shown below. For a more complete version of the model, please see Figure 1 in Poelen et al. 2014. The complete version includes relationships to habitat, environment, time, location and more.

CREATE (specimenA:Specimen {externalId: "Specimen A"})
CREATE (specimenA)-[r:ATE]->(specimenB:Specimen {externalId: "Specimen B"})
CREATE (specimenA)-[r2:ATE]->(specimenC:Specimen {externalId: "Specimen C"})
CREATE (specimenA)-[:CLASSIFIED_AS]->(greatWhite:Taxon {name: "Carcharodon carcharias", externalId:"http://eol.org/pages/213726"})
CREATE (specimenB)-[:CLASSIFIED_AS]->(seaOtter:Taxon {name: "Enhudra lutris", externalId:"http://eol.org/pages/328583"})
CREATE (specimenC)-[:CLASSIFIED_AS]->(seaLion:Taxon {name: "Zalophus californianus", externalId:"http://eol.org/pages/328615"})
CREATE (study:Study {title: "an existing interaction study"})-[:COLLECTED]->specimenA
RETURN specimenA, r, specimenB

And render as a graph.

Now create a query to retrieve all prey of the great white shark (Carcharodon carcharias).

MATCH (greatWhite)<-[:CLASSIFIED_AS]-(predator)-[rel:ATE]->(prey)-[:CLASSIFIED_AS]->(preyTaxon)
RETURN greatWhite.name, greatWhite.externalId, type(rel), preyTaxon.name, preyTaxon.externalId

and render the results as a table.

Finally query to retrieve all prey of the great white shark using the full GloBI dataset.

Now try to execute the same query with the full GloBI dataset using http://tinyurl.com/q5og9vb .

Want to learn more?

Come visit us at http://globalbioticinteractions.org, or read our blog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment