我正在尝试将Cytoscape Json(* cyjs)读入NetworkX图表。到目前为止没有成功,我也尝试了其他格式。下面是一个示例输入:
{
"format_version" : "1.0",
"generated_by" : "cytoscape-3.8.2",
"target_cytoscapejs_version" : "~2.1",
"data" : {
"shared_name" : "Network",
"name" : "Network",
"SUID" : 172,
"__Annotations" : [ ],
"selected" : true
},
"elements" : {
"nodes" : [ {
"data" : {
"id" : "187",
"shared_name" : "Node 3",
"name" : "Node 3",
"SUID" : 187,
"selected" : false
},
"position" : {
"x" : -387.81580333030377,
"y" : 6.552640965689666
},
"selected" : false
}, {
"data" : {
"id" : "185",
"shared_name" : "Node 2",
"name" : "Node 2",
"SUID" : 185,
"selected" : false
},
"position" : {
"x" : -236.0,
"y" : -66.0
},
"selected" : false
}, {
"data" : {
"id" : "183",
"shared_name" : "Node 1",
"name" : "Node 1",
"SUID" : 183,
"selected" : false
},
"position" : {
"x" : -392.0,
"y" : -89.0
},
"selected" : false
} ],
"edges" : [ {
"data" : {
"id" : "189",
"source" : "187",
"target" : "185",
"shared_name" : "Node 3 (interacts with) Node 2",
"shared_interaction" : "interacts with",
"name" : "Node 3 (interacts with) Node 2",
"interaction" : "interacts with",
"SUID" : 189,
"selected" : false
},
"selected" : false
}, {
"data" : {
"id" : "191",
"source" : "183",
"target" : "185",
"shared_name" : "Node 1 (interacts with) Node 2",
"shared_interaction" : "interacts with",
"name" : "Node 1 (interacts with) Node 2",
"interaction" : "interacts with",
"SUID" : 191,
"selected" : false
},
"selected" : false
} ]
}
}
这是一个简单的有向图:
当我试图用Netorkx读取它时
import json
from networkx.readwrite.json_graph import cytoscape_data, cytoscape_graph
cyjs = json.load(open("Network.cyjs"))
graph = cytoscape_graph(cyjs)
我得到了以下结果:
...
graph = cytoscape_graph(cyjs)
File "/$HOMEDIR/.local/lib/python3.8/site-packages/networkx/readwrite/json_graph/cytoscape.py", line 89, in cytoscape_graph
node = d["data"]["value"]
KeyError: 'value'
有人有从Cytoscape成功输入到NetworkX的工作示例吗?
任何帮助或见解将不胜感激。
2条答案
按热度按时间oprakyz71#
使用JSON编写自己的解析器,提取边列表,从边列表中构建图形。沿着(确保这里的名称是唯一的)
gjmwrych2#
根据前面的答案,我测试了下面的代码,添加“stringdb_score”作为权重,添加“display_name”作为节点名称。