Neo4j密码查询X染色体祖先 [英] Neo4j cypher query for X-chromosome ancestors

查看:129
本文介绍了Neo4j密码查询X染色体祖先的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在遗传家谱中,X染色体数据可用于链接某些祖先.在以下位置对此进行了很好的说明: X-DNA继承图

In genetic genealogy X-chromosome data is useful linking to certain ancestors. This is well illustrated at: X-DNA Inheritance Chart

我的Neo4j数据库具有每个人"的节点以及将父亲和母亲连接起来的关系.每个节点都有一个属性性别(针对人"的性别; M或F).一位女性有两个X染色体,一个来自父母双方.男性有一个X染色体,通常来自母亲.

My Neo4j database has nodes for each Person and relationships connecting them of father and mother. Each node has a property sex (for the Person's gender; M or F). A female has two X-chromosomes, one from either parent. A male has one X-chromosome, always from the mother.

您可以使用reduce来查看祖先继承所涉及的性别:

You can use reduce to see the genders involved in the inheritance from ancestors:

match p=(n:Person{RN:1})-[:father|mother*..20]->m 
return m.fullname as FullName
,reduce(status ='', q IN nodes(p)| status + q.sex) AS c 
order by length(p), c

因此,从男性(RN:1)开始,c的结果是父亲的MM和母亲的MF,祖父的MMM和外公的祖父的MFM,等等.该模式表明,当c包含MM(顺序在一起的两个M),它们对起始Person的X染色体没有贡献.

So, starting with a male (RN:1), the result for c is MM for his father and MF for his mother, MMM for the paternal grandfather and MFM for the maternal grandfather, etc. This pattern shows that when c contains MM (two Ms together in sequence) that these are NOT contributing to the X-chromosome of the start Person.

我想删除所有具有MM模式的节点.使用外部代码很容易做到这一点,但是我无法弄清楚如何在密码查询中做到这一点.

I want to remove any node that has the MM pattern. It's easy to do this with external code, but I cannot figure out how to do it within the cypher query.

推荐答案

这应该对您有用:

MATCH p=(n:Person { RN:1 })-[:father|mother*..20]->m
WITH m, NODES(p) AS a
WITH m, REDUCE(c = "", i IN RANGE(0, SIZE(a)-1)| CASE
  WHEN c IS NULL OR (i > 0 AND (a[i-1]).sex = "M" AND (a[i]).sex = "M") THEN
    NULL
  ELSE
    c + (a[i]).sex
  END ) AS c
WHERE c IS NOT NULL
RETURN m.fullName AS fullName, c
ORDER BY LENGTH(c);

这是一个演示结果的控制台.

这篇关于Neo4j密码查询X染色体祖先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆