[英]create relationship between existing nodes in Py4neo
I have a list of gene names genes_list
and a list of genes that target other genes (list of tuples) genes2
, I successfully connected to my local database and created the 20244 nodes labeled GEN
with name
property.我有一个基因名称列表
genes_list
和一个针对其他基因(元组列表) genes2
的基因列表,我成功连接到我的本地数据库并创建了20244 个标记为具有name
属性的GEN
节点。 I am trying to generate a script that automates the creation of relationships for any pair of nodes(usin variables tupla[0]and tupla[1]
) in a Neo4j graph but I can't get the for loop to work for a list of tuples, any advice?我正在尝试生成一个脚本,该脚本可以自动为 Neo4j 图中的任何一对节点(使用变量
tupla[0]and tupla[1]
)创建关系,但我无法让 for 循环为以下列表工作元组,有什么建议吗? Im still learning how to use this library any advices would be great!我还在学习如何使用这个库,任何建议都会很棒! regards!
问候!
from py2neo import Node,Relationship,Graph, database,NodeMatcher
import time
import pandas as pd
genes_list=pd.read_csv("Gen_list.txt",delimiter="\t",header=None)
genes_list=genes_list[0].tolist()
for name in genes_list:
graph.run("CREATE(:GEN{name:$name})",name=name)
genes=pd.read_csv(r"C:\Users\espin\OneDrive\Escritorio\MCI\SCRIPTS\dorothea_final.csv", delimiter="\t",header=None)
genes2=list(genes.to_records(index=False))
for tupla in genes2:
existing_u1 = matcher.match("GEN").where(name=tupla[0]).first()
existing_u2 = matcher.match("GEN").where(name=tupla[1).first()
graph.merge(existing_u1,"REGULATES", existing_u2)
I figured out, For the people that want to try this implementation and is using py2neo V4, try using graph.run()我发现,对于想要尝试此实现并使用 py2neo V4 的人,请尝试使用 graph.run()
for tupla in genes2:
graph.run("MATCH(a:GEN{name:$name}) MATCH(b:GEN{name:$name1}) CREATE (a)-[:REGULATES]->(b)",name=tupla[0],name1=tupla[1])
remember that the query has to be in the first argument and then you declare the $ variables
separated by "," at less this works when you have already created the nodes and does not duplicate the existing ones.请记住,查询必须在第一个参数中,然后声明由“,”分隔的 $
variables
,这在您已经创建节点并且不复制现有节点时有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.