[英]Neo4j cypher query with differing relationship based on gender
In genealogy we use DNA to find matches. 在家谱学中,我们使用DNA查找匹配项。 Y-DNA finds patrilineal matches.
Y-DNA找到父系匹配。 A neo4j query (where RN is a unique identifier for a person) that does this is:
执行此操作的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
or we use mitochondrial DNA for matrilineal matches: 或者我们将线粒体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`
MY QUESTION is related to X-chromosome DNA. 我的问题与X染色体DNA有关。 A father gives an X-chromosome to only his daughters and a mother gives one to all her children.
父亲只给女儿一个X染色体,母亲给所有孩子一个。 Thus, I need a cypher query that gets all mother's but only father's when there is a daughter in the immediate more recent temporal generation.
因此,我需要一个密码查询,当最近的临时世代中有一个女儿时,该查询可以获取所有母亲的父亲,而只有父亲的。 If there is a son in the later generation then I exclude the father.
如果后代有儿子,那么我会排除父亲。 I have a property 'sex' in the nodes with a value of either M or F. the birth date is not always known, so it cannot be used to determine directionality
我的节点中有一个属性“ sex”,其值为M或F。生日并非总是已知的,因此不能用于确定方向性
I tried this, but get an error: 我尝试了这个,但是得到一个错误:
`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`
[UPDATED] [更新]
The [r:mother*..22|father*..1]
syntax is illegal. [r:mother*..22|father*..1]
语法是非法的。 A relationship in a Cypher query can have at most a single variable length specification, and it must come after the relationship type(s). Cypher查询中的关系最多可以具有单个可变长度说明,并且必须位于关系类型之后 。 (Aside: note also that
[:father*..1]
is the same as [:father]
). (除了:还请注意
[:father*..1]
与[:father]
相同)。
Does this query, which seems to be logically equivalent, work for you? 这个查询在逻辑上是等效的,对您有用吗?
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.