Commit 7afe3bfb authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

PEP8 review

parent 1d66c04c
......@@ -254,7 +254,7 @@ def main():
"While there will be 1 process per line (per logical formula "
"on each line)")
parser_input_file.add_argument('--output', action=ReadableDir, nargs='?',
default='result/', help="Output directory.")
default='result/', help="Output directory.")
# default: False
parser_input_file.add_argument('--combinations', action='store_true',
......@@ -335,8 +335,7 @@ def main():
'json_2_interaction_graph',
help=json_2_interaction_graph.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser_json_2_interaction_graph.add_argument('molecules_of_interest',
nargs='+',
parser_json_2_interaction_graph.add_argument('molecules_of_interest', nargs='+',
help="One or multiple molecule of interest to search in the trajectories"
" of every solutions")
parser_json_2_interaction_graph.add_argument('--path',
......
......@@ -99,10 +99,10 @@ def get_solutions_and_related_places_from_file(file_path):
yield (
tuple(solution['solution'].split(' ')),
set(it.chain(*((transition['ext'],transition['ori'])
for step in solution['steps']
for event in step
for transition in event['transitions']))))
set(it.chain(*((transition['ext'], transition['ori'])
for step in solution['steps']
for event in step
for transition in event['transitions']))))
def get_solutions_and_related_places(path):
......@@ -152,9 +152,6 @@ def filter_trajectories(trajectories, molecules_of_interest):
"""Get solutions and count frontier places related to the given molecules
of interest.
binary_interactions: binary_interactions[searched_molec] += Counter(sol)
compteur avec pour clés les entités des solutions liées à 1 molec d'intéret et avec leurs occurences pour valeurs
:param trajectories: A generator of tuples with tuple of frontier places as
keys and set of places involved in transitions as values.
......@@ -165,7 +162,8 @@ def filter_trajectories(trajectories, molecules_of_interest):
:type trajectories: <generator <tuple <tuple>, <set>>>
:type molecules_of_interest: <tuple>
:return: A tuple of all solutions related to the molecules of interest,
and a dictionary of related frontier places.
and a dictionary of related frontier places and their occurences for
each molecule of interest.
.. code-block:: python
......@@ -357,10 +355,10 @@ def build_interactions(filtered_macs, binary_interactions):
molecule_stimuli_interactions
def build_graph(output_dir, all_genes, all_stimuli, unique_genes_interactions,
unique_stimulis_interactions,
unique_genes_stimuli_interactions,
unique_molecule_stimuli_interactions):
def build_graph(output_dir, all_genes, all_stimuli, genes_interactions,
stimulis_interactions,
genes_stimuli_interactions,
molecule_stimuli_interactions):
"""Make an interaction weighted graph based on the search of molecules of interest
:Edges:
......@@ -407,13 +405,14 @@ def build_graph(output_dir, all_genes, all_stimuli, unique_genes_interactions,
LOGGER.info("Building graph...")
# Count all nodes
nodes_count = Counter(it.chain(*unique_genes_interactions.keys()))
nodes_count.update(it.chain(*unique_stimulis_interactions.keys()))
nodes_count.update(it.chain(*unique_genes_stimuli_interactions.keys()))
nodes_count.update(it.chain(*unique_molecule_stimuli_interactions.keys()))
nodes_count = Counter(it.chain(*genes_interactions.keys()))
nodes_count.update(it.chain(*stimulis_interactions.keys()))
nodes_count.update(it.chain(*genes_stimuli_interactions.keys()))
nodes_count.update(it.chain(*molecule_stimuli_interactions.keys()))
# Make Graph ###############################################################
def colormap(node):
"""Get color assigned to the given node depending on its group"""
if node in all_genes:
return 'red'
elif node in all_stimuli:
......@@ -428,21 +427,23 @@ def build_graph(output_dir, all_genes, all_stimuli, unique_genes_interactions,
for node, weight in nodes_count.iteritems()]
def build_edge_data(edges):
"""Build edge tuple for networkx API"""
return [(node1, node2, weight) for (node1, node2), weight in edges.iteritems()]
# Add all edges
# PS Syntax: G.add_weighted_edges_from([(0,1,3.0),(1,2,7.5)],color='red')
# Interactions between genes in the same solution
G.add_weighted_edges_from(
build_edge_data(unique_genes_interactions), color='red')
build_edge_data(genes_interactions), color='red')
# Interactions between stimuli in the same solution
#G.add_weighted_edges_from(build_edge_data(unique_stimulis_interactions), color='blue')
#G.add_weighted_edges_from(build_edge_data(stimulis_interactions), color='blue')
# Interactions between genes and stimulis in the same solution
G.add_weighted_edges_from(
build_edge_data(unique_genes_stimuli_interactions), color='red')
# Interactions between molecules of interest and frontier places that are not genes in trajectories
build_edge_data(genes_stimuli_interactions), color='red')
# Interactions between molecules of interest and frontier places
# that are not genes in trajectories
G.add_weighted_edges_from(
build_edge_data(unique_molecule_stimuli_interactions), color='yellow')
build_edge_data(molecule_stimuli_interactions), color='yellow')
# Write graph
nx.write_graphml(G, output_dir + "interaction_graph.graphml")
......
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