Neo4j cypher查询具有基于性别

时间:2015-12-14 20:38:45

标签: neo4j genetic-algorithm genealogy

在家谱中,我们使用DNA来寻找匹配。 Y-DNA发现了父系匹配。执行此操作的neo4j查询(其中RN是人的唯一标识符)是:

MATCH (n{RN:1}) match p=n-[r:father*..22]->m return m.RN as RN,m.fullname as FullName,m.sex as Sex,m.bd as BD,m.dd as DD,length(p) as generation,case when left(m.bd,4)>'1930' and rtrim(m.dd)='' then 'Y' else 'N' end as mtDNA_Candidate, reduce(srt2 ='|', q IN nodes(p)| srt2 + q.RN + '|') AS PathOrder order by generation desc,PathOrder desc

或我们使用线粒体DNA进行母系匹配:

`MATCH (n{RN:1}) match p=n-[r:mother*..22]->m return m.RN as RN,m.fullname as FullName,m.sex as Sex,m.bd as BD,m.dd as DD,length(p) as generation,case when left(m.bd,4)>'1930' and rtrim(m.dd)='' then 'Y' else 'N' end as mtDNA_Candidate, reduce(srt2 ='|', q IN nodes(p)| srt2 + q.RN + '|') AS PathOrder order by generation desc,PathOrder desc`

我的问题与X染色体DNA有关。父亲只给他的女儿一张X染色体,一位母亲给她所有的孩子一张。因此,我需要一个密码查询,它可以获得所有母亲的信息,但只有父亲才会在最近的一代时间内产生一个女儿。如果在后一代有一个儿子,那么我排除了父亲。我在节点中有一个属性为'sex',其值为M或F.出生日期并不总是已知,因此不能用于确定方向性

我试过这个,但收到错误:

`MATCH (n{RN:1}) match p=n-[r:mother*..22|father*..1]->m return m.RN as RN,m.fullname as FullName,m.sex as Sex,m.bd as BD,m.dd as DD,length(p) as generation,case when left(m.bd,4)>'1930' and rtrim(m.dd)='' then 'Y' else 'N' end as mtDNA_Candidate, reduce(srt2 ='|', q IN nodes(p)| srt2 + q.RN + '|') AS PathOrder order by generation desc,PathOrder desc`

1 个答案:

答案 0 :(得分:1)

[增订]

[r:mother*..22|father*..1]语法是非法的。 Cypher查询中的关系最多只能有一个变量长度规范,并且必须关系类型之后。 (旁白:还请注意[:father*..1][:father])相同。

这个看起来在逻辑上等同的查询对你有用吗?

MATCH pf=(n { RN:1 })-[:father]->()
MATCH pm=n-[:mother*..22]->()
WITH [pf] + COLLECT(pm) AS paths
UNWIND paths AS p
WITH LENGTH(p) AS generation, NODES(p) AS ancestors
WITH generation, ancestors, LAST(ancestors) AS m
RETURN m.RN AS RN, m.fullname AS FullName, m.sex AS Sex, m.bd AS BD, m.dd AS DD, generation,
  CASE WHEN left(m.bd,4)>'1930' AND rtrim(m.dd)='' THEN 'Y' ELSE 'N' END AS mtDNA_Candidate,
  reduce(srt2 ='|', q IN ancestors | srt2 + q.RN + '|' ) AS PathOrder
ORDER BY generation DESC, PathOrder DESC;