Having a graph where molecules are attached to a common scaffold with [:substructureOf] relationships and where similar molecules are connected to eachothers with a [:isSimilarTo] relationship, is the a way to return all [:isSimilarTo] relationships for a specific subset of molecules?
In pseudo cypher code, considering m as a collection (subset of molecules), I would like to assess that m1 and m2 of each sim relationship is part of m
MATCH (:Scaffold {Name: 'A'}) <-[:usbstructureOf]- (m:Molecule)
WITH m MATCH (m1:Molecule) -[sim:isSimilarTo]- (m2:Molecule)
WHERE m1 IN m AND m2 IN m
Is there a proper cypher way to write this? Example dataset below.
CREATE (:Scaffold {Name: 'A'});
CREATE (:Scaffold {Name: 'B'});
MATCH (s:Scaffold {Name: 'A'}) MERGE (s) -[:substructureOf]->(:Molecule {Name: 'm1'});
MATCH (s:Scaffold {Name: 'A'}) MERGE (s) -[:substructureOf]->(:Molecule {Name: 'm2'});
MATCH (s:Scaffold {Name: 'A'}) MERGE (s) -[:substructureOf]->(:Molecule {Name: 'm3'});
MATCH (s:Scaffold {Name: 'A'}) MERGE (s) -[:substructureOf]->(:Molecule {Name: 'm4'});
MATCH (s:Scaffold {Name: 'B'}) MERGE (s) -[:substructureOf]->(:Molecule {Name: 'm5'});
MATCH (m:Molecule {Name: 'm1'}), (n:Molecule {Name: 'm2'}) CREATE (m) -[isSimilarTo]-> (n);
MATCH (m:Molecule {Name: 'm1'}), (n:Molecule {Name: 'm3'}) CREATE (m) -[isSimilarTo]-> (n);
MATCH (m:Molecule {Name: 'm2'}), (n:Molecule {Name: 'm3'}) CREATE (m) -[isSimilarTo]-> (n);
MATCH (m:Molecule {Name: 'm3'}), (n:Molecule {Name: 'm4'}) CREATE (m) -[isSimilarTo]-> (n);
MATCH (m:Molecule {Name: 'm4'}), (n:Molecule {Name: 'm5'}) CREATE (m) -[isSimilarTo]-> (n);
MATCH
in the first query? More constraints? Explain. – Martin Preusse