Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
VIGNET Pierre
cadbiom
Commits
7afe3bfb
Commit
7afe3bfb
authored
Oct 28, 2018
by
VIGNET Pierre
Browse files
PEP8 review
parent
1d66c04c
Changes
2
Hide whitespace changes
Inline
Side-by-side
command_line/cadbiom_cmd/cadbiom_cmd.py
View file @
7afe3bfb
...
...
@@ -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'
,
...
...
command_line/cadbiom_cmd/interaction_graph.py
View file @
7afe3bfb
...
...
@@ -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"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment