def construct_network(comb): left, right = comb h_left = cluster_hard(left) h_right = cluster_hard(right) clusters = {cl for cl in itertools.chain(h_left, h_right)} g = construct(clusters) return g
def test_one(self): text = "(1, 2);" enewick_graph = enewick_to_digraph(text) clusters = [('1', '2'),] gold = construct(clusters) GM = GraphMatcher(enewick_graph, gold) self.assertTrue(GM.is_isomorphic())
def test_two(self): text = "((1, 2), 3);" enewick_graph = enewick_to_digraph(text) clusters = [(1, 2), (3,)] gold = construct(clusters) GM = GraphMatcher(enewick_graph, gold) self.assertTrue(GM.is_isomorphic())
def test_three(self): cluster = [(6, 8), (4, 7), (2, 6), (7, 10), (6, 10), (2, 3, 7, 9, 10), (1, 4, 7, 9, 10), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,)] result = hybrid_nodes(construct(cluster)) gold = "2h 10h 7h 9h 6h 10,7h".split() self.assertItemsEqual(result, gold)
def test_five(self): text = "((1, (2)h#H1)x,(h#H1,3)y)r;" clusters = [(1, 2), (2, 3)] enewick_graph = enewick_to_digraph(text) self.assertEqual(len(enewick_graph.nodes()), 7) gold = construct(clusters) GM = GraphMatcher(enewick_graph, gold) self.assertTrue(GM.is_isomorphic())
def test_random_0(self): clusters = [(3, 8), (2, 6), (3, 4), (1, 7), (2, 3, 5, 7), (1, 4, 7, 8), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,)] gold = ("1 2 3 4 5 6 7 8 1,2,3,4,5,6,7,8 " "1,4,7,8 2,3,5,7 2,6 3,8 1,7 3,4 1,4 1,8 2,5 3,5 5,7 " "1,4,7 1,4,8 1,7,8 2,3,5 2,5,7 3,5,7 ").split() result = cluster_soft(construct(clusters)) self.assertItemsEqual(result, gold)
def test_complex_6(self): """ 8 nodes emparellats, 8 híbrids, 196 crides, .25 segons""" clusters = [ (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 1), ] G = construct(clusters) gold = ("1 2 3 4 5 6 7 8 1,2,3,4,5,6,7,8 " "7,8 5,6 2,3 1,2 6,7 1,8 4,5 3,4 ").split() self.assertItemsEqual(self.soft(G), gold)
def test_complex_4(self): clusters = [(2, 3), (1, 3), (3, 4), (1, 2, 3), (1, 3, 4), ] G = construct(clusters) gold = [(1,), (2,), (3,), (4,), (1, 2), (1, 3), (1, 4), (2, 3), (3, 4), (1, 3, 4), (1, 2, 3), (1, 2, 3, 4)] gold = ("1 2 3 4 1,2,3,4 " "1,2 1,3 1,4 2,3 3,4 1,3,4 1,2,3 ").split() self.assertItemsEqual(self.soft(G), gold)
def test_complex_2(self): clusters = [ (1, 2), (3, 4), (4, 5), (3, 4, 5), (1, 2, 3, 4) ] G = construct(clusters) gold = ("1 2 3 4 5 1,2,3,4,5 " "1,2,3,4 " "3,4,5 1,2,3 " "4,5 1,2 3,4 ").split() self.assertItemsEqual(self.soft(G), gold)
def test_random_2(self): clusters = [ (3, 5), (2, 5), (5, 9), (4, 10), (1, 2), (3, 4, 6, 7, 8), (2, 5, 8, 9, 10), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,)] gold = ("1 2 3 4 5 6 7 8 9 10 1,10,2,3,4,5,6,7,8,9 " "5,9 10,2,5,8,9 2,5,8,9 8,9 2,5,9 2,5 10,2,8,9 1,2 6,7 " "10,5,8,9 4,6,7,8 2,8,9 3,6,7 10,4 10,5,9 6,7,8 10,9 2,9 " "10,2,5,9 3,5 10,8,9 5,8,9 10,2,9 3,6,7,8 3,4,6,7 4,6,7 3,4,6,7,8 " "").split() result = cluster_soft(construct(clusters)) self.assertItemsEqual(result, gold)
def test_complex_5(self): clusters = [(1, 2), (3, 4), (4, 5), (1, 2, 3, 4), (3, 4, 5), ] G = construct(clusters) gold = [(1,), (2,), (3,), (4,), (5, ), (1, 2), (3, 4), (4, 5), (1, 2, 3), (3, 4, 5), (1, 2, 3, 4), (1, 2, 3, 4, 5)] gold = ("1 2 3 4 5 1,2,3,4,5 " "1,2,3,4 " "1,2 3,4 4,5 1,2,3 3,4,5 ").split() self.assertItemsEqual(self.soft(G), gold)
def test_three(self): text = "((4, 5#1)2, (#1, 6)3);" enewick_graph = enewick_to_digraph(text) self.assertEqual(len(enewick_graph.nodes()), 6) enewick_graph = calc_hybrid(enewick_graph) leafs = get_leaf_nodes(enewick_graph) gold_leafs = ['1', '4', '6', ] self.assertItemsEqual(leafs, gold_leafs) clusters = ["1,2", "2,3"] gold = construct(clusters) g = enewick_to_phylonet(text) GM = GraphMatcher(g, gold) self.assertTrue(GM.is_isomorphic())
def test_two(self): text = "((4, 5#1)2, (#1, 6)3);" enewick_graph = enewick_to_digraph(text) self.assertEqual(len(enewick_graph.nodes()), 6) enewick_phylo = enewick_to_phylonet(text) gold_hard = "1,4 1,4,6 1,6 4 6".split() hard = cluster_hard(enewick_graph) self.assertItemsEqual(hard, gold_hard) self.assertEqual(len(enewick_phylo.nodes()), 7) clusters = [(1, 2), (2, 3),] gold = construct(clusters) GM = GraphMatcher(enewick_phylo, gold) self.assertTrue(GM.is_isomorphic())
def test_one(self): text = "((MOUSE,(HUMAN,RAT)),CIOIN);" enewick_graph = enewick_to_digraph(text) self.assertEqual(len(enewick_graph.nodes()), 7) enewick_graph = enewick_to_phylonet(text) self.assertEqual(len(enewick_graph.nodes()), 7) clusters = [(1, 2, 3), (2, 3), (4,)] gold = construct(clusters) GM = GraphMatcher(enewick_graph, gold) self.assertTrue(GM.is_isomorphic()) gold_hard = [ 'CIOIN,HUMAN,MOUSE,RAT', 'CIOIN', 'HUMAN', 'MOUSE', 'RAT', 'HUMAN,MOUSE,RAT', 'HUMAN,RAT', ] hard = cluster_hard(enewick_graph) self.assertEqual(len(hard), 7) self.assertItemsEqual(hard, gold_hard)
def test_two(self): clusters = [(1, 2), (2, 3), (3, 5), (3, 4, 5) ] result = hybrid_nodes(construct(clusters)) gold = "2h 3h".split() self.assertItemsEqual(result, gold)
def test_one(self): clusters = [(1, 2), (3, 5), (3, 4, 5) ] result = hybrid_nodes(construct(clusters)) gold = [] self.assertItemsEqual(result, gold)
def test_empty(self): clusters = [] result = hybrid_nodes(construct(clusters)) gold = [] self.assertItemsEqual(result, gold)
def test_four(self): clusters = [(1, 2, 3)] G = construct(clusters) gold = "1 2 3 1,2,3".split() self.assertItemsEqual(cluster_hard(G), gold)
def test_two(self): clusters = [(1, 2), (2, 3), (3, 5), (3, 4, 5) ] result = construct(clusters) gold = "1 2 3 4 5 1,2,3,4,5 1,2 2,3 3,5 3,4,5 2h 3h".split() self.assertItemsEqual(result, gold)
def test_empty(self): clusters = [] result = construct(clusters) gold = [] self.assertItemsEqual(result, gold)
def test_one(self): clusters = [(1, 2), (3, 5), (3, 4, 5) ] result = construct(clusters) gold = "1 2 3 4 5 1,2 3,5 3,4,5 1,2,3,4,5".split() self.assertItemsEqual(result, gold)
def test_none(self): clusters = [(1, 2), (3, 4)] G = construct(clusters) self.assertItemsEqual(hybrid_nodes(G), [])
def test_empty(self): clusters = [[]] G = construct(clusters) self.assertItemsEqual(hybrid_nodes(G), [])
def test_one(self): clusters = [(1, 2)] G = construct(clusters) gold = "1 2 1,2".split() self.assertItemsEqual(cluster_hard(G), gold)
def test_two(self): clusters = [(1, 2), (1, 3), (2, 3)] G = construct(clusters) self.assertItemsEqual(hybrid_nodes(G), ['1h','2h','3h',])
def true_hybrid(self): "The fact to have hybrids does not mean you can't be tree-child" clusters = [(1, 2), (1, 3)] G = construct(clusters) self.assertTrue(is_treechild(G))
def test_three(self): clusters = [(1, 2), (3, 4)] G = construct(clusters) gold = "1 2 3 4 1,2,3,4 1,2 3,4".split() self.assertItemsEqual(cluster_hard(G), gold)
def test_complex_false(self): clusters = [(1, 2), (1, 3), (2, 3)] G = construct(clusters) self.assertFalse(is_treechild(G))
def setUp(self): clusters = [(1, 2), (2, 3), (3, 4), (3, 4, 5), (1, 2, 3), (2, 3, 4, 5)] self.root = "1,2,3,4,5" self.G = construct(clusters)
def test_true(self): clusters = [(1, 2), (3, 4)] G = construct(clusters) self.assertTrue(is_treechild(G))