I am trying to create a graph in neo4j and my data which is in CSV file looks like
node1,connection,node2
PPARA,0.5,PPARGC1A
PPARA,0.5,ENSG00000236349
PPARA,0.5,TSPA
I want connection
values to use as labels of relationships in graph which I am not able to do. Following is the exact code I am using to create graph.
LOAD CSV WITH HEADERS FROM "file:///C:/Users/username/Desktop/Cytoscape-friend.csv" AS network
CREATE (:GeneRN2{sourceNode:network.node1, destNode:network.node2})
CREATE (sourceNode) -[:TO {exp:network.connection}] ->(destNode)
My second question is that as there are multiple repeating values in my file, by default neo4j is creating multiple nodes for repeating values. How do I create single node for multiple values and connect all other relating nodes to that single node?
labels
. They have a type
.apoc.create.relationship
from the APOC library
.MERGE
instead of CREATE
.So your query might look like this:
LOAD CSV WITH HEADERS
FROM "file:///C:/Users/username/Desktop/Cytoscape-friend.csv"
AS network
MERGE (sourceNode {id:network.node1})
MERGE (destNode {id:network.node2})
WITH sourceNode,
destNode,
network
CALL apoc.create.relationship(sourceNode, network.connection, {}, destNode) yield rel
RETURN sourceNode,
rel,
destNode