So I am trying to find paths between a pair of nodes, of different types. The code is shown below. The graph is pretty large and have many different types of relationships, some of which I would like to exclude/blacklisted from the path, since they are extremely redundant/uninteresting.
From what I can see apoc.path.expandConfig
does not allow for that natively. Is there are a way I can achieve this?
MATCH (sourceNode:SourceLabel {symbol: "<source node>"})
MATCH (targetNode:TargetLabel {name:"<target node>"})
CALL apoc.path.expandConfig(g, {
labelFilter: "IntermediaryLabel1, IL2a|IL2b|IL2c, >TargetLabel",
minLevel: 1,
maxLevel: 3,
terminatorNodes: [targetNode],
uniqueness: "NODE_PATH",
limit: 50
})
YIELD path
RETURN path, length(path) AS hops
ORDER BY hops
I've run into this but never sat down to solve it until today when I saw your question. If you have a LOT of relationships like I do, I feel your pain. Ideally they will eventually add a subtract for rels, but for now it is not hard to DIY.
Steps
// get all relationships
CALL db.relationshipTypes() yield relationshipType WITH collect(relationshipType) as rt
// remove unwanted relationships
WITH [n IN rt WHERE NOT n IN ['PERTURBS','CAUSES_SIDE_EFFECT','TREATS','REPURPOSED_INDICATION','SUBSET_OF','GENE_EC','GENE_GENE']] as rt2
// format for use in apoc call
WITH REDUCE(ms = "",word IN rt2 | ms+word+'|') as js
// remove trailing pipe
WITH LEFT(js, SIZE(js)-1) as relationshipWhiteList
// your cypher here (and use the variable relationshipWhiteList)
References used to piece this together