I am attempting to create the glycolytic pathway shown in the image at the bottom of this question, in Neo4j, using these data:
glycolysis_bioentities.csv>
@cybersam's answer is excellent, providing the most elegant solution (once again: thank you!) -- please upvote that accepted answer.
Since this question/answer/topic is likely to be of interest to others, I wanted to mention that my code (based on this SO thread, How to specify relationship type in CSV?, and modified per the hints provided by @cybersam) now works, and show the result:
Solution 1 (my original post, updated):
LOAD CSV WITH HEADERS FROM "file:/glycolysis_relations.csv" AS row
MERGE (s:Glycolysis {name:row.source})
MERGE (t:Glycolysis {name:row.target})
FOREACH (x in case row.relation when "substrate_of" then [1] else [] end |
MERGE (s)-[r:substrate_of]->(t)
)
FOREACH (x in case row.relation when "yields" then [1] else [] end |
MERGE (s)-[r:yields]->(t)
);
Solution 2 (cybersam's, updated):
LOAD CSV WITH HEADERS FROM "file:/glycolysis_relations.csv" AS row
MERGE (s:Metabolism:Glycolysis {name: row.source})
MERGE (t:Metabolism:Glycolysis {name: row.target})
WITH s, t, row
// "Bug" -- additional duplicate relations with each iteration of this statement/script:
// CALL apoc.create.relationship(s, row.relation, {}, t) YIELD rel
// Solution:
// https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/271
// https://stackoverflow.com/questions/47808421/neo4j-load-csv-to-create-dynamic-relationship-types
CALL apoc.merge.relationship(s, row.relation, {}, {}, t) YIELD rel
RETURN COUNT(*);
Both solutions generate the identical graph, below. :-D