我试图找到有向图上两个顶点之间的路径。我有一个igraph对象,它是有向图;我有一个父节点,以及具有我想要的属性的节点的顶点序列列表。我希望在这个有向图中找到从父节点到这些具有属性的节点的路径。在
igraph中唯一相关的命令似乎是“所有的简单路径”(如果我使用内置函数来提高效率,而不是编写自己的函数)。我就得想办法解决方向性问题了。在
然而,即使作为初步的方法,我也不能从igraph得到所有的简单路径!在
因此,错误是:
Traceback (most recent call last): File "/homes/jlada/Documents/omnipath_folder/full_network/vss.py", line 3, in from igraph import all_simple_paths ImportError: cannot import name 'all_simple_paths' from 'igraph' (/nfs/software/software/Linux_x86_64/opt/stow/anaconda3/envs/pypath/lib/python3.7/site-packages/igraph/init.py)
注意:我已经检查了是否安装了正确版本的igraph,即pythonigraph
我正在运行代码:
from pypath import main, data_formats
import igraph
from igraph import all_simple_paths
import time
protein = 'BMP7'
max_order= 3
pa = main.PyPath()
pa.init_network(pfile = '/homes/jlada/Documents/omnipath_folder/mynetwork.pickle')
pa.set_transcription_factors()
#network_graph = pa.gs_neighborhood(protein, order = max_order)
sub_bmp7_2 = pa.get_directed(
pa.graph.induced_subgraph(
list(pa.gs_neighborhood(protein, order = max_order).vs()
)
))
vsparent = [v for v in sub_bmp7_2.vs() if v['name']== protein]
#neighboraffects=set(pa.up_affects('BMP7').up())
tfs_ind=[v for v in sub_bmp7_2.vs() if v['tf']]
print(tfs_ind)
j = all_simple_paths(sub_bmp7_2, vsparent, tfs_ind[1], mode= "out")
print(j)
我想我应该检查一下函数all\u simple\u paths是否在igraph中,因此尝试了:
^{pr2}$输出很长。不幸的是,我不知道如何查询输出以查看它是否包含all-unu-simple-chants路径。我确实是手动的,而且据我所知,没有函数都是简单路径。在
有没有人有过igraph不包含所有简单路径的经验?这是版本吗?在
Python的igraph不包含
all_simple_paths
,但是igraph for R does。你可能把两者搞混了。在根据this answer,一个简单的解决方案可以相当容易地配制出来(注意,这可能需要稍作调整才能与igraph一起使用):
相关问题 更多 >
编程相关推荐