问题描述
在复杂的基因网络中,我们如何找到拓扑重叠.
In a complex gene network how can we find a topological overlap.
输入数据如下
code code weight
3423 3455 3453
2344 2353 45
3432 3453 456
3235 4566 34532
2345 8687 356
2466 6467 3567
3423 2344 564
3455 2353 4564
3432 3423 456
节点列为col [0]和col [1],花费的连接时间为col [2]
The node columns are col[0] and col[1] and the time spent connected is col[2]
代码:
import networkx as nx
import numpy as np
data = np.loadtxt("USC_Test.txt")
col = []
edge_list = zip[col[0],col[1]]
G = nx.Graph()
G.add_edges_from(edge_list)
components = nx.connected_components(G)
print components
错误
edge_list = zip[col[0],col[1]]
IndexError: list index out of range
推荐答案
我必须承认我不熟悉术语拓扑重叠,所以我不得不查找它:
I must confess that I wasn't familiar with the term topological overlap so I had to look it up:
NetworkX似乎没有内置的方法,该方法可以让您查找具有拓扑重叠的节点对,但可以轻松地找到牢固连接的组件.例如:
NetworkX doesn't seem to have a builtin method which lets you find pairs of nodes with topological overlap but it can easily find strongly connected components. For example:
In [1]: import networkx as nx
In [2]: edge_list = [(1, 2), (2, 1), (3, 1), (1, 3), (2, 4), (1, 4), (5, 6)]
In [3]: G = nx.DiGraph()
In [4]: G.add_edges_from(edge_list)
In [5]: components = nx.strongly_connected_components(G)
In [6]: components
Out[6]: [[1, 3, 2], [4], [6], [5]]
如果您有无向图,则可以改用nx.connected_components
.
If you have an undirected graph you can use nx.connected_components
instead.
现在有了组件,可以轻松找到拓扑重叠的所有对对列表.例如,从components
:
Now you have components, it is straightforward to find all lists of pairs with toplogical overlap. For example, generate all pairs of nodes from lists in components
:
In [7]: from itertools import combinations
In [8]: top_overlap = [list(combinations(c, 2)) for c in components if len(c) > 1]
In [9]: top_overlap = [item for sublist in top_overlap for item in sublist]
In [10]: top_overlap
Out[10]: [(1, 3), (1, 2), (3, 2)]
这篇关于基因网络拓扑重叠Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!