正如标题所暗示的那样,我正在尝试编写一个函数来计算任何输入节点所属的周期数。我发现了一个有用的video,它解释了查找循环的算法背后的理论,但我无法理解如何使用networkX而不是网站使用的数据结构来实现它。我无法理解白色/灰色/等设置概念以及遍历网络和查找周期。
我的功能参数/结构:
def feedback_loop_counter(G, node):
c = 0
calculate all cycles in the network
for every cycle node is in, increment c by 1
return c
网络也有输入和输出节点,我不清楚它们如何用于计算周期
这是我的输入网络:
import networkx as nx
import matplotlib.pyplot as plt
G=nx.DiGraph()
molecules = ["CD40L", "CD40", "NF-kB", "XBP1", "Pax5", "Bach2", "Irf4", "IL-4", "IL-4R", "STAT6", "AID", "Blimp1", "Bcl6", "ERK", "BCR", "STAT3", "Ag", "STAT5", "IL-21R", "IL-21", "IL-2", "IL-2R"]
Bcl6 = [("Bcl6", "Bcl6"), ("Bcl6", "Blimp1"), ("Bcl6", "Irf4")]
STAT5 = [("STAT5", "Bcl6")]
IL_2R = [("IL-2R", "STAT5")]
IL_2 = [("IL-22", "IL-2R")]
BCR = [("BCR", "ERK")]
Ag = [("Ag", "BCR")]
CD40L = [("CD40L", "CD40")]
CD40 = [("CD40", "NF-B")]
NF_B = [("NF-B", "Irf4"), ("NF-B", "AID")]
Irf4 = [("Irf4", "Bcl6"), ("Irf4", "Pax5"), ("Irf4", "Irf4"), ("Irf4", "Blimp1")]
ERK = [("ERK", "Bcl6"), ("ERK", "Blimp1"), ("ERK", "Pax5")]
STAT3 = [("STAT3", "Blimp1")]
IL_21 = [("IL-21", "IL-21R")]
IL_21R = [("IL-21R", "STAT3")]
IL_4R = [("IL-4R", "STAT6")]
STAT6 = [("STAT6", "AID"), ("STAT6", "Bcl6")]
Bach2 = [("Bach2", "Blimp1")]
IL_4 = [("IL-4", "IL-4R")]
Blimp1 = [("Blimp1", "Bcl6"), ("Blimp1", "Bach2"), ("Blimp1", "Pax5"), ("Blimp1", "AID"), ("Blimp1", "Irf4")]
Pax5 = [("Pax5", "Pax5"), ("Pax5", "AID"), ("Pax5", "Bcl6"), ("Pax5", "Bach2"), ("Pax5", "XBP1"), ("Pax5", "ERK"), ("Pax5", "Blimp1")]
edges = Bcl6 + STAT5 + IL_2R + IL_2 + BCR + Ag + CD40L + CD40 + NF_B + Irf4 +
ERK + STAT3 + IL_21 + IL_21R + IL_4R + STAT6 + Bach2 + IL_4 + Blimp1 + Pax5
G.add_nodes_from(molecules)
G.add_edges_from(edges)
sources = ["Ag", "CD40L", "IL-2", "IL-21", "IL-4"]
targets = ["XBP1", "AID"]
答案 0 :(得分:1)
找到周期的想法是做Depth-first search,当你这样做时,记住你已经看过哪些节点以及它们的路径。如果您碰巧访问了您已经看过的节点,那么就有一个循环,您可以通过连接路径找到它。
尝试编写一些代码来执行此操作,如果遇到问题,请使用该代码打开一个新问题
答案 1 :(得分:1)
我将根据您感兴趣的假设编写我的答案"简单循环",即仅重复节点是第一个/最后一个节点的循环。
将具有边的节点带到节点u
("输入节点")。然后使用networkx命令all_simple_paths查找从u
到每个输入节点的所有简单路径。这些都变成了一个简单的循环。