Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-24-2020 11:08 AM
I've been having quite a bit of trouble with a query I'm building today. To me it seems like it should be quite straightforward, but I'm not seeing the expected results. And for reference, I am testing out the queries in the browser for viz purposes, but I get the same results when using py2neo
.
So I first match a set of nodes based upon some indexed IDs I have for them. This gives me 20 nodes and I can return the nodes, but not the relationships displayed in the Neo4j browser:
MATCH (node1:Protein)
WHERE node1.dbID IN ['7375Prot', '7967Prot', '8873Prot', '8352Prot', '12809Prot', '6980Prot', '2529Prot', '15524Prot', '9875Prot', '7418Prot', '1639Prot', '12813Prot', '6010Prot', '1497Prot', '12821Prot', '8998Prot', '13991Prot', '14166Prot', '12950Prot', '14733Prot']
RETURN node1
Great, but now what if I want to return those nodes and all of those relationships depicted in the browser? When I try doing a path query and return the path I am only getting around 20 relationships and 7/20 nodes. Similarly, if I do a path query and try returning the relationships I only get 9 relationships.
MATCH (node1:Protein)
WHERE node1.dbID IN ['7375Prot', '7967Prot', '8873Prot', '8352Prot', '12809Prot', '6980Prot', '2529Prot', '15524Prot', '9875Prot', '7418Prot', '1639Prot', '12813Prot', '6010Prot', '1497Prot', '12821Prot', '8998Prot', '13991Prot', '14166Prot', '12950Prot', '14733Prot']
MATCH p=(node1)-[rels]-(node1)
RETURN p
I saw a suggestion to use CALL apoc.algo.cover(node1) YIELD rel
but it only returns 9 relationships.
MATCH (node1:Protein)
WHERE node1.dbID IN ['7375Prot', '7967Prot', '8873Prot', '8352Prot', '12809Prot', '6980Prot', '2529Prot', '15524Prot', '9875Prot', '7418Prot', '1639Prot', '12813Prot', '6010Prot', '1497Prot', '12821Prot', '8998Prot', '13991Prot', '14166Prot', '12950Prot', '14733Prot']
CALL apoc.algo.cover(node1) YIELD rel
RETURN rel
Can someone please help me or explain why I'm having so much difficulty? I've also tried chaining together a MATCH
and returning all the relationships between node1
, but again, that only returns a subset.
09-24-2020 11:45 AM
I think I have found a preliminary solution to the above, but it looks very messy. Any suggestions for a more concise query?
MATCH (node1:Gene) WHERE node1.dbID IN ['9403', '12950Prot', '30672', '19285', '7418Prot', '18515', '14166Prot', '8352Prot', '15524Prot', '1002', '1497Prot', '6357', '1035', '4060', '43756', '44644', '7375Prot', '6980Prot', '8214', '24126', '9875Prot', '8048', '12813Prot', '42790', '2529Prot', '12821Prot', '18193', '1639Prot', '7967Prot', '16211', '13991Prot', '6010Prot', '28647', '14733Prot', '12809Prot', '5879', '8873Prot', '40267', '4214', '8998Prot']
MATCH (node1)-[:EXPRESSED_BY_PebG]-(prots:Protein)
WITH COLLECT(prots) AS prot
UNWIND prot AS prot1
UNWIND prot AS prot2
MATCH p = (prot1)-[r]-(prot2)
UNWIND r AS rel
RETURN STARTNODE(rel).dbID AS start, type(rel) as edge, ENDNODE(rel).dbID AS end;
09-24-2020 12:46 PM
Try this:
WITH ['7375Prot', '7967Prot', '8873Prot', '8352Prot', '12809Prot', '6980Prot', '2529Prot', '15524Prot', '9875Prot', '7418Prot', '1639Prot', '12813Prot', '6010Prot', '1497Prot', '12821Prot', '8998Prot', '13991Prot', '14166Prot', '12950Prot', '14733Prot'] as dbIds
MATCH (node1:Protein)
WHERE node1.dbID IN dbIds
MATCH (node2:Protein)
WHERE node2.dbID IN dbIds
MATCH p=(node1)-[rels]-(node2)
WHERE node2.dbID <> node1.dbID
RETURN nodes(p), relationships(p)
All the sessions of the conference are now available online