def test_edge_list(self): ntags, nsinks, iedges = graph.iedge_from_annotations(self.annots) self.assertEqual(6, ntags) self.assertEqual(5, nsinks) edges = set(e for e in iedges) outgo_edges = [(0, 1), (0, 3), (0, 4), (0, 5), (1, 3), (1, 4), (4, 3)] #Inverse edges expected = [] + outgo_edges #Copy expected.extend((v, k) for k, v in outgo_edges) #Edges to items expected.extend([(0, 6), (0, 8), (1, 6), (1, 9), (1, 10), (2, 7), (3, 6), (4, 6), (5, 8)]) self.assertEquals(edges, set(expected))
def test_graph(self): edges = [e for e in graph.iedge_from_annotations(self.annots)[2]] g = graph.create_nxgraph(edges) paths = nx.shortest_path_length(g, source=0) self.assertEquals(paths, { 0: 0, 1: 1, 3: 1, 4: 1, 5: 1, 6: 1, 8: 1, 9: 2, 10: 2 })
def create_graph(annotation_it, out_folder): ntags, nsinks, iedges = \ graph.iedge_from_annotations(annotation_it, 1, False) tmp_fname = tempfile.mktemp() n_edges = 0 with io.open(tmp_fname, 'w') as tmp: for source, dest in sorted(iedges): tmp.write(u'%d %d\n' % (source, dest)) n_edges += 1 with io.open(tmp_fname) as tmp: out_graph = os.path.join(out_folder, 'navi.graph') with io.open(out_graph, 'w') as out: out.write(u'#Nodes: %d\n'%ntags) out.write(u'#Edges: %d\n'%n_edges) out.write(u'#Directed\n') for line in tmp: out.write(line)
def real_main(database, table, out_file, use): with AnnotReader(database) as reader: reader.change_table(table) ntags, nsinks, iedges = \ graph.iedge_from_annotations(reader.iterate(), use) n_nodes = ntags + nsinks tmp_fname = tempfile.mktemp() n_edges = 0 with open(tmp_fname, 'w') as tmp: for source, dest in sorted(iedges): print(source, dest, file=tmp) n_edges += 1 with open(tmp_fname) as tmp: with open(out_file, 'w') as out: print('#Nodes: %d'%n_nodes, file=out) print('#Edges: %d'%n_edges, file=out) print('#Directed', file=out) for line in tmp: print(line[:-1], file=out)
def test_graph(self): edges = [e for e in graph.iedge_from_annotations(self.annots)[2]] g = graph.create_nxgraph(edges) paths = nx.shortest_path_length(g, source = 0) self.assertEquals(paths, {0: 0, 1: 1, 3: 1, 4: 1, 5: 1, 6: 1, 8: 1, 9: 2, 10: 2})