首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >基于性别关系不同的Neo4j密码查询

基于性别关系不同的Neo4j密码查询
EN

Stack Overflow用户
提问于 2015-12-14 20:38:45
回答 1查看 222关注 0票数 1

在家谱学中,我们用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来匹配母系:

代码语言:javascript
运行
复制
`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染色体,母亲给她所有的孩子一个染色体。因此,我需要一个密码查询,得到所有母亲的,但只有父亲的,当有一个女儿在最近的时间世代。如果后世有个儿子,我就把父亲排除在外。我在节点中有一个属性“性别”,值为M或F。出生日期并不总是已知的,因此不能用来确定方向性。

我试过了,但有个错误:

代码语言:javascript
运行
复制
`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`
EN

回答 1

Stack Overflow用户

发布于 2015-12-14 21:47:16

已更新

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

这个似乎在逻辑上等价的查询对您有用吗?

代码语言:javascript
运行
复制
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;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34276166

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档