neo4j cypher - 麻烦制造关系

Posted

技术标签:

【中文标题】neo4j cypher - 麻烦制造关系【英文标题】:neo4j cypher - trouble making relation 【发布时间】:2016-05-03 14:13:58 【问题描述】:

我正在尝试将 mysql 数据库转换为 neo4j,但我不明白如何创建关系(不明白意味着我收到“错误”)

我已将 MySQL 表数据导出到 csv 文件

target_type, target_desc, parent_type
"ADMET","Target is not applicable for an ADMET assay (e.g., physchem property)","UNDEFINED"
"CELL-LINE","Target is a specific cell-line","NON-MOLECULAR"
"CHIMERIC PROTEIN","Target is a fusion of two different proteins, either a synthetic construct or naturally occurring fusion protein","PROTEIN"
"LIPID","Target is a lipid","MOLECULAR"
"MACROMOLECULE","Target is a biological macromolecule (e.g., glycoproteins, hemozoin, hydroxyapatite)","MOLECULAR"
"METAL","Target is a metal e.g., iron","MOLECULAR"
"MOLECULAR","Target has been identified as a defined molecular entity (e.g., protein or nucleic acid)",NULL
"NO TARGET","Target is not applicable for a screening assay (e.g., negative control/counterscreen)","UNDEFINED"
"NON-MOLECULAR","Target has not been defined at a molecular level, only the non-molecular entity which is affected (e.g., organism, cell line etc)",NULL
"NUCLEIC-ACID","Target is DNA, RNA or PNA","MOLECULAR"
"OLIGOSACCHARIDE","Target is an oligosaccharide (e.g., heparin, starch)","MOLECULAR"
"ORGANISM","Target is a complete organism","NON-MOLECULAR"
"PHENOTYPE","Target is a biological phenotype or process","NON-MOLECULAR"
"PROTEIN","Target is a protein or group of proteins","MOLECULAR"
"PROTEIN COMPLEX","Target is a defined protein complex, consisting of multiple subunits","PROTEIN"
"PROTEIN COMPLEX GROUP","Target is a poorly defined protein complex, where subunit composition is unclear (e.g., GABA-A receptor)","PROTEIN"
"PROTEIN FAMILY","Target is a group of closely related proteins","PROTEIN"
"PROTEIN NUCLEIC-ACID COMPLEX","Target is a complex consisting of both protein and nucleic-acid components (e.g., ribosome)","MOLECULAR"
"PROTEIN-PROTEIN INTERACTION","Target is the disruption of a protein-protein interaction","PROTEIN"
"SELECTIVITY GROUP","Target is a pair of proteins for which the selectivity has been assessed","PROTEIN"
"SINGLE PROTEIN","Target is a single protein chain","PROTEIN"
"SMALL MOLECULE","Target is a small molecule such as an amino acid, sugar or metabolite)","MOLECULAR"
"SUBCELLULAR","Target is a subcellular fraction","NON-MOLECULAR"
"TISSUE","Target is a healthy or diseased tissue","NON-MOLECULAR"
"UNCHECKED","Target has not yet been assigned","UNDEFINED"
"UNDEFINED","No target has been defined",NULL
"UNKNOWN","Molecular identity of target is unknown (e.g., pharmacologically defined target)","UNDEFINED"

之后我用代码创建了节点

LOAD CSV WITH HEADERS FROM 'file:///target_type.csv' AS line
CREATE (targetType:TargetType id: line.target_type )
SET targetType.description = line.target_desc
RETURN targetType

问题是当我尝试在类型节点之间创建关系时。以下代码给出消息“(无行)”:

LOAD CSV WITH HEADERS FROM 'file:///target_type.csv' AS line
MATCH (targetType:TargetType id: line.target_type)
MATCH (parentType:TargetType id: line.parent_type)
CREATE (targetType)-[:CHILD_OF]->(parentType)
RETURN targetType, parentType;

我尝试在 csv 文件中重写 NULL 值,以在节点中设置不同的标签(名称而不是 ID),但没有给我结果。

有人可以帮我用这些数据获取图表吗?

【问题讨论】:

【参考方案1】:

[编辑]

您需要删除 CSV 文件标题行中逗号周围的空格。

使用这些空格,LOAD CSV 仅捕获第一列数据 (target_type)。

【讨论】:

怎么样?我从 cvs 创建了 27 个 TargetType 节点。也许我不明白这是如何工作的。我有第二个查询再次加载 csv。在那里,我对所有加载的 TargetType 使用 MATCH 作为 targetType(其中 id 是来自 csv 的 target_type)。第二个 MATCH 也使用加载的 TargetType 节点,只是将它们称为 parentType(将加载的 targetType 的 ID 与 line.parent_type 匹配)。由于所有 parent_type 值都加载到 TargetType 节点中,我不明白“您没有创建(或者,更安全的,合并)任何 ID 为 line.parent_type 的节点”是什么意思? 好的,仔细看看,你的问题有一个非常不同的原因。请参阅我编辑的答案。 有效! :) 我显然没有注意空格。谢谢。

以上是关于neo4j cypher - 麻烦制造关系的主要内容,如果未能解决你的问题,请参考以下文章

Neo4j:如何删除与 cypher 的特定关系?

neo4j cypher 节点可以模糊匹配么

neo4j cypher:如何更改关系类型

知识图谱Neo4j Cypher查询语言详解

CYPHER 语句(Neo4j)

使用 Cypher 在 Neo4j 中通过模式移动与其他节点的关系