0

Currently, I have a query in Neo4j that returns all the nodes in my graph that are pointed to by multiple nodes.

enter image description here

The query to return these nodes (in picture) looks like this:

MATCH (n)-[r:CLINICAL_SIGNIFICANCE]->()
WITH n, count(r) as rel_cnt
WHERE rel_cnt > 1
MATCH (c)-[r:PROTEIN_CHANGE]->(n)
return c, n

Is there a way to loop through the nodes labeled as c (blue nodes) and if they point to the same node labeled as n (yellow nodes), create a relationship between the nodes labeled as c (blue nodes)?

CJ Dennis
  • 4,226
  • 2
  • 40
  • 69
M. Du
  • 1
  • You may want to consider if that's really what you want, since you can always query through the yellow nodes to find the other blue nodes. Can you explain why you need this? Depending on the number of blue nodes connected (n), you can use the combination formula of C(n, 2) to figure out the number of relationships you want created. So for 3 nodes, 3 relationships, for 4 nodes 6 relationships, for 5 nodes 10 relationships, and so on. That's for creating relationships between each pairing of blue nodes. Tell us if you want a single linked list between all blue nodes instead. – InverseFalcon Aug 11 '18 at 05:41
  • Is there a reason why you aren't using labels in your query? I'm assuming you have labels in your graph as otherwise you wouldn't see a color difference. Labels do make a difference in your query, you may want to at least use stand-in labels for this if you aren't comfortable sharing the actual labels here. – InverseFalcon Aug 11 '18 at 05:49

0 Answers0