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

remove execuption variability

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