Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Yoann DUFRESNE
linked reads molecule ordering
Commits
e8142332
Commit
e8142332
authored
Mar 12, 2019
by
Yoann Dufresne
Browse files
allow nodes to be in both half dgraph
parent
e8a2652e
Changes
1
Hide whitespace changes
Inline
Sidebyside
deconvolve.py
View file @
e8142332
...
...
@@ 12,7 +12,7 @@ def deconvolve(G,node):
# Extract neighbors from the graph
G_neighbors
=
nx
.
Graph
(
G
.
subgraph
(
neighbors
))
communities
=
get_communities
(
G_neighbors
)
communities
=
get_communities
(
G_neighbors
,
node
==
"273:597_148"
)
# Continue only if something need to be splited.
if
len
(
communities
)
==
1
:
...
...
@@ 33,26 +33,30 @@ def deconvolve(G,node):
print
(
"splitted into"
,
len
(
communities
),
"parts
\n
"
)
def
get_communities
(
G
):
def
get_communities
(
G
,
max_overlap
=
2
,
verbose
=
False
):
# Half dgraphs are cliques. So compute max cliques
cliques
=
list
(
nx
.
find_cliques
(
G
))
if
verbose
:
for
clq
in
cliques
:
print
(
clq
,
"
\n
"
)
candidate_d_graphs
=
[]
# dgraphs are composed of 2 cliques related by the current node.
# The overlap
p
between the 2 cliques determine the node order in the dgraph.
# The overlap between the 2 cliques determine the node order in the dgraph.
for
idx
,
clq1
in
enumerate
(
cliques
):
to_compare
=
cliques
[
idx
+
1
:]
for
clq2
in
to_compare
:
# TO REMOVE : Temporary only check for distinct cliques
jump
=
False
# Test if dgraphs only if there are less than max overlapping nodes
# between the two half
overlap
=
0
for
val
in
clq1
:
if
val
in
clq2
:
jump
=
True
break
if
jump
:
continue
# / TO REMOVE
overlap
+=
1
if
overlap
>
max_overlap
:
continue
# Check for dgraph candidates
d_graph
=
compute_d_graph
(
clq1
,
clq2
,
G
)
...
...
@@ 67,13 +71,13 @@ def get_communities(G):
if
len
(
minimal_d_graphes
)
==
0
:
return
[
list
(
G
.
nodes
())]
# TODO : !!! Concatenation not possible if the same node can be in both side
communites
=
[
d_graph
[
0
]
+
d_graph
[
1
]
for
d_graph
in
minimal_d_graphes
]
communites
=
[
list
(
set
(
d_graph
[
0
]
+
d_graph
[
1
]))
for
d_graph
in
minimal_d_graphes
]
return
communites
""" This function take two cliques in the graph G and try to find if they are 2 halfes of a dgraph.
1  The algorithm compute overlapp between nodes from first clique to the second and from the
""" This function take two cliques in the graph G and try to find if they are 2 halfes
of a dgraph.
1  The algorithm compute overlap between nodes from first clique to the second and from the
second to the first.
2  Filter the clique pairs that have less than n*(n1)/2 traversing edges (necessary critera
to be considered as dgraph).
...
...
@@ 83,7 +87,7 @@ def get_communities(G):
@param G the graph of the neighbors of the central node (not present).
@return A pair of lists that are the 2 halves of the dgraph ordered from the center.
"""
def
compute_d_graph
(
clq1
,
clq2
,
G
):
def
compute_d_graph
(
clq1
,
clq2
,
G
,
verbose
=
False
):
# Compute the arities between the cliques
arities1
=
{
name
:
0
for
name
in
clq1
}
arities2
=
{
name
:
0
for
name
in
clq2
}
...
...
@@ 107,19 +111,25 @@ def compute_d_graph(clq1, clq2, G):
arities2
[
node2
]
+=
1
sum_edges
+=
1
if
verbose
:
print
(
clq1
,
clq2
)
print
(
arities1
,
arities2
,
"
\n
"
)
# Reject if not enought edges
if
sum_edges
<
min_clq_size
*
(
min_clq_size

1
)
/
2
:
return
None
# print(clq1, clq2)
# print(arities1, arities2, "\n")
# if verbose:
# print(clq1, clq2)
# print(arities1, arities2, "\n")
# order lists
lst1
=
[
key
for
key
,
value
in
sorted
(
arities1
.
items
(),
key
=
lambda
tup
:

tup
[
1
])]
lst2
=
[
key
for
key
,
value
in
sorted
(
arities2
.
items
(),
key
=
lambda
tup
:

tup
[
1
])]
# print(min_clq_size)
# print(lst1, "\n", lst2, "\n")
if
verbose
:
print
(
min_clq_size
)
print
(
lst1
,
"
\n
"
,
lst2
,
"
\n
"
)
# Return the 2 halves of the dgraph
return
lst1
,
lst2
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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