Commit 76239d13 by Yoann Dufresne

### Test and support previously writed code

parent 31633d6a
 ... ... @@ -3,7 +3,6 @@ import sys print(sys.argv) with open(sys.argv[1]) as file: header = file.readline() nb_nodes, nb_variables = [int(x) for x in header.split()] ... ...
 ... ... @@ -2,25 +2,28 @@ import networkx as nx from d2_path import Path, Unitig """ For each node of the d2 graph, construct a node in the reducted graph. Then, for each node, compute the closest neighbors in d2 (with equal scores) and add an edge in the greedy graph. @param d2 Input d2 graph (with distances already computed) @return A greedy constructed graph. """ def greedy_reduct(d2): """ Compute a graph where, for each node, the neighbors are the closest neighbors. """ gG = nx.Graph() for node in d2.nodes: gG.add_node(node) for dgraph, node in d2.nodes.items(): if not dgraph in d2.distances: if not dgraph.idx in d2.distances or len(d2.distances[dgraph.idx]) == 0: continue distances = d2.distances[dgraph] distances = d2.distances[dgraph.idx] min_dist = min(distances.values()) for n_dgraph, dist in distances.items(): for graph_idx, dist in distances.items(): if dist == min_dist: gG.add_edge(node, d2.nodes[n_dgraph]) gG.add_edge(node, d2.nodes[d2.node_by_idx[graph_idx]]) return gG ... ...
 ... ... @@ -2,12 +2,12 @@ import networkx as nx import itertools from bidict import bidict from d_graph import compute_all_max_d_graphs, filter_dominated from d_graph import compute_all_max_d_graphs, filter_dominated, list_domination_filter class D2Graph(object): """D2Graph (read it (d-graph)²)""" def __init__(self, graph, index_size=8, verbose=True, debug=False): def __init__(self, graph, index_size=3, verbose=True, debug=False): super(D2Graph, self).__init__() self.graph = graph ... ... @@ -22,8 +22,10 @@ class D2Graph(object): # Name the d-graphs # Number the d_graphs self.node_by_idx = {} for idx, d_graph in enumerate(self.all_d_graphs): d_graph.idx = idx self.node_by_idx[idx] = d_graph # Number the edges from original graph self.edge_idxs = {} ... ... @@ -40,6 +42,7 @@ class D2Graph(object): if verbose: print("Compute the dmer index") self.index = self.create_index_from_tuples(index_size) self.filter_dominated_in_index() # Compute node distances for pair of dgraphs that share at least 1 dmer. if verbose: print("Compute a subset of distances") ... ... @@ -156,4 +159,39 @@ class D2Graph(object): return G, bidict(nodes) def filter_dominated_in_index(self): to_remove = [] # Find dominated for dmer, dg_list in self.index.items(): undominated = list_domination_filter(dg_list) # Register dominated if len(dg_list) != len(undominated): for dg in dg_list: if not dg in undominated: to_remove.append(dg) self.index[dmer] = undominated to_remove = frozenset(to_remove) # Remove dominated in global list for r_dg in to_remove: self.all_d_graphs.remove(r_dg) self.d_graphs_per_node[r_dg.center].remove(r_dg) # Remove dominated in index removable_dmers = [] for dmer, indexed_list in self.index.items(): for r_dg in to_remove: if r_dg in indexed_list: indexed_list.remove(r_dg) if len(indexed_list) == 0: removable_dmers.append(dmer) # Remove empty dmers for dmer in removable_dmers: del self.index[dmer] \ No newline at end of file