Neo4j study - A Tool for Entity-Relationship (Ontology) Data Model

So when talking about data models in the context of data curation, we know there are three main types: relational model, tree model and Entity-Relationship (ER) model.

We’re all familiar with the first two models and tools to deal with them. But not for ER model. It’s easy to understand the concept but rarely you can find as many discussions about tools and applications. This also seems to be a missing part in Data Curation lecture in UIUC.

So in this note We’ll try to take a look at basic graph queries in Neo4j graph database using cypher query language.

As we know, typical graph analysis includes:

  1. path
  2. connectivity
  3. community
  4. centrality

Following hands on will cover above basic analysis.

First, Neo4j Windows installation is straightforward by following instructions on Neo4j website

After that, we’ll create a new project and database, do hands on in Neo4j GUI as following:

Load a sample gene data into Neo4j

LOAD CSV WITH HEADERS FROM “file:///C:/gene_gene_associations_50k.csv” AS line
MERGE (n:Symbol {Name:line.OFFICIAL_SYMBOL_A})
MERGE (m:Symbol {Name:line.OFFICIAL_SYMBOL_B})
MERGE (n) -[:AssociationType {Type:line.EXPERIMENTAL_SYSTEM}]-> (m)

load

Overview of the graph
match (n) -[r] ->(m) return m,n,r limit 100

overview

How many genes in total?

match (n:Symbol) return count(n)

nodes-count

How many total associations between all genes?

match (n:Symbol)-[r]->() return count(r)

edges-count

How many associations that genes point to themselves?

match (n:Symbol)-[r]->(n:Symbol) return count(n)

loops

What is the maximum number of associations between two genes?

match (n)-[r]->(m) where m <> n
return distinct n, m, count(r) as myCount order by myCount desc limit 1

max-r

Which five genes have the most association to other genes?

match (n:Symbol) -[r:AssociationType] ->()
return n.Name, count(r) as AssociationCount order by AssociationCount desc limit 5

list-r

Find the second-neighborhood of gene named ‘BRCA1’

match p=(n {Name:’USP25’})-[:AssociationType*..2]->(m) return p

second-neighborhood

Find all shortest path between two genes

match (n:Symbol) where n.Name=’BRCA1’ or n.Name=’NBR1’ with collect(n) as nodes
unwind nodes as n
unwind nodes as m
with * WHERE id(n) < id(m)
match path = allShortestPaths( (n)-[*..4]-(m) )
return path

shortest-path

Create a gene degree histogram

match (n:Symbol)-[r]-()
with n as nodes, count(distinct r) as degree
return degree, count(nodes) order by degree asc

degree

Written on December 30, 2017