Commit 4c84978d by Yoann Dufresne

### d2 reloaded completed and tested

parent 96a90ed9
 ... ... @@ -10,6 +10,17 @@ class D2Graph(object): def __init__(self, graph): super(D2Graph, self).__init__() self.graph = graph # Number the edges from original graph self.edge_idxs = {} self.nb_uniq_edge = 0 for idx, edge in enumerate(self.graph.edges()): if edge == (edge[1], edge[0]): self.nb_uniq_edge += 1 if edge in self.edge_idxs: print("Edge already present") self.edge_idxs[edge] = idx self.edge_idxs[(edge[1], edge[0])] = idx def construct_from_barcodes(self, index_size=3, verbose=True, debug=False): ... ... @@ -28,17 +39,6 @@ class D2Graph(object): 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 = {} self.nb_uniq_edge = 0 for idx, edge in enumerate(self.graph.edges()): if edge == (edge[1], edge[0]): self.nb_uniq_edge += 1 if edge in self.edge_idxs: print("Edge already present") self.edge_idxs[edge] = idx self.edge_idxs[(edge[1], edge[0])] = idx # Index all the d-graphes if verbose: ... ... @@ -75,8 +75,31 @@ class D2Graph(object): # Extract d-graphs from nx graph self.all_d_graphs = [] for node in self.nx_graph.nodes(): self.all_d_graphs.append(Dgraph.load(node, self.graph)) self.node_by_idx = {} for idx, node in enumerate(self.nx_graph.nodes()): dg = Dgraph.load(node, self.graph) self.all_d_graphs.append(dg) if dg.idx == -1: dg.idx = idx self.node_by_idx[dg.idx] = dg # Extract edges and re-compute distances self.distances = {} for edge in self.nx_graph.edges(): # Get the dg pair idx1 = int(edge[0].split(' ')[0]) idx2 = int(edge[1].split(' ')[0]) dg1 = self.node_by_idx[idx1] dg2 = self.node_by_idx[idx2] # Compute and save the distance dist = dg1.distance_to(dg2) if not idx1 in self.distances: self.distances[idx1] = {} self.distances[idx1][idx2] = dist if not idx2 in self.distances: self.distances[idx2] = {} self.distances[idx2][idx1] = dist def create_index_from_tuples(self, tuple_size=3): ... ...
 ... ... @@ -29,10 +29,15 @@ class Dgraph(object): # Head parsing head = head.split(' ') dg = Dgraph(head[-3]) dg = Dgraph(int(head[-3])) if len(head) == 4: dg.idx = int(head[0]) # Reload halves h1 = [int(x.split(' ')[-2]) for x in h1.split(',')] h2 = [int(x.split(' ')[-2]) for x in h2.split(',')] dg.put_halves(h1, h2, barcode_graph) return dg ... ...
 ... ... @@ -113,6 +113,15 @@ class TestD2Graph(unittest.TestCase): for dg in d2.all_d_graphs: self.assertTrue(dg.idx in reloaded_idxs) # Verify distances self.assertEquals(len(d2.distances), len(d2_reloaded.distances)) for idx1 in d2.distances: self.assertTrue(idx1 in d2_reloaded.distances) self.assertEquals(len(d2.distances[idx1]), len(d2_reloaded.distances[idx1])) for idx2 in d2.distances[idx1]: self.assertTrue(idx2 in d2_reloaded.distances[idx1]) self.assertEquals(d2.distances[idx1][idx2], d2_reloaded.distances[idx1][idx2]) if __name__ == "__main__": unittest.main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!