如何在密码中找到所有关系

时间:2015-06-30 08:02:45

标签: neo4j cypher

有一个图表,其中分子附着到具有[:substructureOf]关系的共同支架,并且类似的分子通过[:isSimilarTo]关系连接到每个人,是一种返回所有[:isSimilarTo]关系的方法特定的分子子集?

在伪密码中,将m视为一个集合(分子子集),我想评估每个sim关系的m1和m2是m的一部分

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);

是否有适当的密码方式来写这个?下面的示例数据集。

<p:dataTable id="rosterviewtab" var="data" value="#{dtRosterView.rostertab}" >

    <p:columnGroup type="header">

        <p:row>
            <p:column headerText="" />

    <p:column style="display:none">
            <f:facet name="header"> #{dtRosterView.dates}   </f:facet>
    </p:column>

            <ui:repeat value="#{dtRosterView.dates}" var="dates">
               <p:column headerText="#{dates}" exportable="false" />                
            </ui:repeat>
        </p:row>
    </p:columnGroup>   

      <p:column> 
        <h:outputText value="#{data.slot_noresources}" />
      </p:column>    

     <p:column>
        <h:outputText value="#{data.datecol1}" />
    </p:column>     

     <p:column>
        <h:outputText value="#{data.datecol2}" />
    </p:column> 

    </p:dataTable>

    <h:panelGrid columns="2" cellpadding="5">
    <p:commandButton value="Export To Excel" style="font-size:11px;width:120px;height:40px" immediate="true" ajax="false" >          
    <p:dataExporter type="xls" target="rosterviewtab" fileName="RosterView" postProcessor="#{dtRosterView.postProcessXLS}" update="@form"  />
    </p:commandButton>

2 个答案:

答案 0 :(得分:1)

我仍然不完全明白你想要什么,下次网络方案/图纸可能会有所帮助。

但我认为你想要的是类似的分子共享相同的支架。即由Molecule边连接的所有isSimilarTo对,其中 Molecules都链接到已定义的Scaffold

您可以通过匹配完整路径来获得此信息:

(Scaffold)--(Molecule)--(similar Molecule)--(same Scaffold)

在Cypher:

MATCH (s:Scaffold {Name: 'A'})<-[:isbstructureOf]-(m1:Molecule)
       -[sim:isSimilarTo]-(m2:Molecule)-[:isbstructureOf]->(s)
// Return the relationships
RETURN DISTINCT m1.name, sim.value, m2.name
// Return count of relationships
RETURN count(DISTINCT sim)

答案 1 :(得分:0)

替代答案:

MATCH (s:Scaffold {Name: 'A'})-[:substructureOf*]->(m:Molecule) 
WITH collect(m) as mols MATCH p=(:Molecule) -[sim:isSimilarTo]- (:Molecule)    
WHERE startNode(r) IN mols and endNode(r) IN mols
RETURN p

整体路径较短。