Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
VIGNET Pierre
cadbiom
Commits
e5a1a074
Commit
e5a1a074
authored
Oct 28, 2018
by
VIGNET Pierre
Browse files
build_graph: update doc
parent
3e6571b9
Changes
1
Hide whitespace changes
Inline
Side-by-side
command_line/cadbiom_cmd/interaction_graph.py
View file @
e5a1a074
...
...
@@ -36,6 +36,7 @@ import os
import
glob
import
itertools
as
it
from
collections
import
defaultdict
,
Counter
import
networkx
as
nx
# Library imports
import
cadbiom.commons
as
cm
...
...
@@ -351,17 +352,53 @@ def build_graph(all_genes, all_stimuli, unique_genes_interactions,
unique_stimulis_interactions
,
unique_genes_stimuli_interactions
,
unique_molecule_stimuli_interactions
):
"""
"""Make an interaction weighted graph based on the searched molecule of interest
:Edges:
* gene - gene: Two genes present simultaneously in a solution
* stimulus - stimulus: Two stimuli present simultaneously in a solution
* gene - stimulus: One gene and one stimulus present simultaneously in
a solution (deprecated)
* molecule of interest - stimulus: A molecule of interest in a trajectory
related to a solution that contains a stimulus.
:Legend of the edges:
* gene - gene: red
* stimulus - stimulus: blue (deprecated)
* gene - stimulus: red
* molecule of interest - stimulus: yellow
:Legend of the nodes:
* genes: red
* stimuli: blue
* molecules of interest: yellow
:param all_genes: All genes in all the solutions
:param all_stimuli: All stimulis in all the solutions
:param genes_interactions: Interactions between genes in the same solution
:param stimulis_interactions: Interactions between stimuli in the same solution
:param genes_stimuli_interactions: Interactions between genes and stimulis in
the same solution
:param molecule_stimuli_interactions: Counter interactions between molecules
of interest and frontier places that are not genes (stimuli)
in trajectories (i.e.: ``(molecule, stimulus)``).
:type all_genes: <set>
:type all_stimuli: <set>
:type genes_interactions: <Counter>
:type stimulis_interactions: <Counter>
:type genes_stimuli_interactions: <Counter>
:type molecule_stimuli_interactions: <Counter>
"""
# Count
er update...
# 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
()))
import
networkx
as
nx
# Make Graph ###############################################################
def
colormap
(
node
):
if
node
in
all_genes
:
...
...
@@ -380,6 +417,8 @@ def build_graph(all_genes, all_stimuli, unique_genes_interactions,
def
build_edge_data
(
edges
):
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'
)
...
...
@@ -390,9 +429,11 @@ def build_graph(all_genes, all_stimuli, unique_genes_interactions,
build_edge_data
(
unique_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_filtered_binary_interactions
),
color
=
'yellow'
)
build_edge_data
(
unique_molecule_stimuli_interactions
),
color
=
'yellow'
)
# Write graph
nx
.
write_graphml
(
G
,
"test.graphml"
)
# G.add_weighted_edges_from([(0,1,3.0),(1,2,7.5)],color='red')
nx
.
write_graphml
(
G
,
"test.graphml"
)
Write
Preview
Supports
Markdown
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