Commit 4782df1e authored by Rayan Chikhi's avatar Rayan Chikhi

sensitivity random path fix

parent c653160c
......@@ -139,18 +139,38 @@ def evaluate_accuracy_paths(path_len,max_paths_per_node=5):
# ---- sensitivity evaluation
""" given an ordered list of molecules, determine if the graph contains a path of central nodse which have these molecules.
it does that by testing all possible combinations of d-graphs having those molecules in their central nodes """
it does that creating a multipartite graph with a source and a sink
"""
def is_there_path(graph,molecules_to_nodes,sought_path):
possible_central_nodes = []
for mol in sought_path:
MPG = nx.Graph() # a multipartite graph
# construct all levels of the multipartite graph
possible_central_nodes = []
for i,mol in enumerate(sought_path):
possible_central_nodes += [molecules_to_nodes[mol]]
#print(possible_central_nodes)
for mols in itertools.product(*possible_central_nodes):
if nx.is_connected(graph.subgraph(mols)):
#print("found connected path",mols)
return True
#print("found no connected paths",sought_path)
return False
for node in possible_central_nodes:
MPG.add_node("%d-%s" % (i,node))
# construct edges between levels
for i in range(len(sought_path)-1):
pcn_i = molecules_to_nodes[sought_path[i]]
pcn_ip1 = molecules_to_nodes[sought_path[i+1]]
for node_i,node_j in itertools.product(pcn_i,pcn_ip1):
#print(node_i,node_j)
if graph.has_edge(node_i,node_j):
MPG.add_edge("%d-%s" %(i,node_i),"%d-%s" % (i+1,node_j))
# add source/sink
MPG.add_node("source")
MPG.add_node("sink")
pcn_0 = molecules_to_nodes[sought_path[0]]
for node in pcn_0:
MPG.add_edge("source","0-%s" % node)
pcn_end = molecules_to_nodes[sought_path[-1]]
for node in pcn_end:
MPG.add_edge("%d-%s" % (len(sought_path)-1, node), "sink")
return nx.has_path(MPG,"source","sink")
def evaluate_sensitivity_paths(path_len,overlap_length=7000):
all_molecules = set()
......@@ -183,9 +203,14 @@ def main():
p = Pool(12)
#p.map(evaluate_accuracy_paths, [1,2,4,6,8,10,15,20,50,100,200,500])
p.map(evaluate_accuracy_paths, [2,4,10,100])
p.join()
#p.map(evaluate_sensitivity_paths, [1,2,3,4])
p.map(evaluate_sensitivity_paths, [2,4,10,100])
#evaluate_accuracy_paths(100)
#evaluate_sensitivity_paths(1)
#evaluate_sensitivity_paths(3)
#evaluate_sensitivity_paths(10)
p.close()
p.join()
if __name__ == "__main__":
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment