Commit 47b4117e authored by Yoann Dufresne's avatar Yoann Dufresne
Browse files

remove execuption variability

parent 9fde8e34
data/ data/
real_data/
art/ art/
**/__pycache__/ **/__pycache__/
.pytest_cache/ .pytest_cache/
.idea/ .idea/
.snakemake/ .snakemake/
snake_tests/
**/*.tmp
...@@ -56,6 +56,7 @@ class D2Graph(nx.Graph): ...@@ -56,6 +56,7 @@ class D2Graph(nx.Graph):
def construct_from_barcodes(self, index_size=3, verbose=True, debug=False): def construct_from_barcodes(self, index_size=3, verbose=True, debug=False):
import debug_disct as dd
# Compute all the d-graphs # Compute all the d-graphs
if verbose: if verbose:
print("Compute the unit d-graphs") print("Compute the unit d-graphs")
...@@ -228,19 +229,6 @@ class D2Graph(nx.Graph): ...@@ -228,19 +229,6 @@ class D2Graph(nx.Graph):
print() print()
print("\tDmer removal") print("\tDmer removal")
# # Remove dominated in global list
# for r_idx, r_dg in enumerate(to_remove):
#
# self.all_d_graphs.remove(r_dg)
# self.d_graphs_per_node[r_dg.center].remove(r_dg)
#
# Remove from index
# for idx, dmer in enumerate(itertools.combinations(r_dg.to_sorted_list(), tuple_size)):
# if dmer in self.index[dmer]:
# self.index[dmer].remove(r_dg)
# if len(self.index[dmer]) == 0:
# del self.index[dmer]
removable_dmers = set() removable_dmers = set()
for r_idx, r_dg in enumerate(to_remove): for r_idx, r_dg in enumerate(to_remove):
if verbose: if verbose:
......
import networkx as nx import networkx as nx
import math
from functools import total_ordering from functools import total_ordering
...@@ -19,6 +18,8 @@ class Dgraph(object): ...@@ -19,6 +18,8 @@ class Dgraph(object):
self.ordered_list = None self.ordered_list = None
self.sorted_list = None self.sorted_list = None
self.marked = False
""" Static method to load a dgraph from a text """ Static method to load a dgraph from a text
@param text the saved d-graph @param text the saved d-graph
...@@ -56,11 +57,13 @@ class Dgraph(object): ...@@ -56,11 +57,13 @@ class Dgraph(object):
self.halves[0] = h1 self.halves[0] = h1
for node in h1: for node in h1:
self.node_set.add(node) self.node_set.add(node)
self.nodes.append(node)
self.halves[1] = h2 self.halves[1] = h2
for node in h2: for node in h2:
self.node_set.add(node) self.node_set.add(node)
self.nodes.append(node)
self.nodes = sorted([self.center] + self.halves[0] + self.halves[1]) # self.nodes = sorted([self.center] + self.halves[0] + self.halves[1])
self.connexity[0] = {key: 0 for key in self.halves[0]} self.connexity[0] = {key: 0 for key in self.halves[0]}
self.connexity[1] = {key: 0 for key in self.halves[1]} self.connexity[1] = {key: 0 for key in self.halves[1]}
self.edges = [] self.edges = []
...@@ -174,7 +177,7 @@ class Dgraph(object): ...@@ -174,7 +177,7 @@ class Dgraph(object):
if other is None: if other is None:
return False return False
if self.idx == other.idx: if self.idx != -1 and self.idx == other.idx:
return True return True
if self.node_set != other.node_set: if self.node_set != other.node_set:
...@@ -218,6 +221,11 @@ class Dgraph(object): ...@@ -218,6 +221,11 @@ class Dgraph(object):
representation += "[" + ", ".join([f"{node} {self.connexity[1][node]}" for node in self.halves[1]]) + "]" representation += "[" + ", ".join([f"{node} {self.connexity[1][node]}" for node in self.halves[1]]) + "]"
return representation return representation
def _to_str_nodes(self):
str_nodes = [str(x) for x in self.nodes]
str_nodes.sort()
return str(str_nodes)
""" From a barcode graph, compute all the possible max d-graphs by node. """ From a barcode graph, compute all the possible max d-graphs by node.
@param graph A barcode graph @param graph A barcode graph
...@@ -243,15 +251,11 @@ def compute_all_max_d_graphs(graph, debug=False): ...@@ -243,15 +251,11 @@ def compute_all_max_d_graphs(graph, debug=False):
d_graph = Dgraph(node) d_graph = Dgraph(node)
d_graph.put_halves(clq1, clq2, neighbors_graph) d_graph.put_halves(clq1, clq2, neighbors_graph)
if d_graph.get_link_divergence() > d_graph.get_optimal_score() / 2: if d_graph.get_link_divergence() <= d_graph.get_optimal_score() / 2:
continue node_d_graphs.add(d_graph)
node_d_graphs.add(d_graph)
# Cut the the distribution queue
d_graphs[node] = sorted(node_d_graphs) d_graphs[node] = sorted(node_d_graphs)
# print(node_d_graphs)
return d_graphs return d_graphs
...@@ -278,7 +282,6 @@ def add_new_dg_regarding_domination(dg, undominated_dgs_list): ...@@ -278,7 +282,6 @@ def add_new_dg_regarding_domination(dg, undominated_dgs_list):
size = len(undominated_dgs_list) size = len(undominated_dgs_list)
for dg2 in to_remove: for dg2 in to_remove:
undominated_dgs_list.remove(dg2) undominated_dgs_list.remove(dg2)
#print(size, len(to_remove), len(undominated_dgs_list))
# Add the new dg # Add the new dg
if not dominated: if not dominated:
...@@ -296,9 +299,7 @@ def filter_dominated(d_graphs, overall=False, in_place=True): ...@@ -296,9 +299,7 @@ def filter_dominated(d_graphs, overall=False, in_place=True):
for dgs in d_graphs.values(): for dgs in d_graphs.values():
all_d_graphs.extend(dgs) all_d_graphs.extend(dgs)
# print(len(all_d_graphs))
all_d_graphs = list_domination_filter(all_d_graphs) all_d_graphs = list_domination_filter(all_d_graphs)
# print(len(all_d_graphs))
return d_graphs return d_graphs
...@@ -316,8 +317,8 @@ def local_domination_filter(d_graphs, in_place=True): ...@@ -316,8 +317,8 @@ def local_domination_filter(d_graphs, in_place=True):
# Filter node by node # Filter node by node
for node, d_graph_list in d_graphs.items(): for node, d_graph_list in d_graphs.items():
# Add the non filtered d-graph to the output lst = str(sorted([str(x) for x in d_graph_list]))
filtered[node] = brutal_list_domination_filter(d_graph_list) filtered[node] = brutal_list_domination_filter(d_graph_list, node_name=str(node))
return filtered return filtered
...@@ -337,13 +338,14 @@ def list_domination_filter(d_graphs): ...@@ -337,13 +338,14 @@ def list_domination_filter(d_graphs):
return set(filtered) return set(filtered)
def brutal_list_domination_filter(d_graphs): def brutal_list_domination_filter(d_graphs, node_name=""):
undominated = set(d_graphs) undominated = set(d_graphs)
to_remove = set()
for dg1 in d_graphs: for dg1 in d_graphs:
for dg2 in d_graphs: for dg2 in d_graphs:
if dg1.is_dominated(dg2): if dg1.is_dominated(dg2):
undominated.remove(dg1) to_remove.add(dg1)
break break
return undominated return undominated - to_remove
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