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
Beispiel #2
0
 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())
Beispiel #3
0
 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())
Beispiel #4
0
 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)
Beispiel #5
0
 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)
Beispiel #12
0
    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())
Beispiel #13
0
    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())
Beispiel #14
0
 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)
Beispiel #15
0
 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)
Beispiel #16
0
 def test_one(self):
     clusters = [(1, 2), (3, 5), (3, 4, 5) ]
     result = hybrid_nodes(construct(clusters))
     gold = []
     self.assertItemsEqual(result, gold)
Beispiel #17
0
 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)
Beispiel #19
0
 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)
Beispiel #20
0
 def test_empty(self):
     clusters = []
     result = construct(clusters)
     gold = []
     self.assertItemsEqual(result, gold)
Beispiel #21
0
 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)
Beispiel #22
0
 def test_none(self):
     clusters = [(1, 2), (3, 4)]
     G = construct(clusters)
     self.assertItemsEqual(hybrid_nodes(G), [])
Beispiel #23
0
 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)
Beispiel #25
0
 def test_two(self):
     clusters = [(1, 2), (1, 3), (2, 3)]
     G = construct(clusters)
     self.assertItemsEqual(hybrid_nodes(G), ['1h','2h','3h',])
Beispiel #26
0
 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)
Beispiel #28
0
 def test_complex_false(self):
     clusters = [(1, 2), (1, 3), (2, 3)]
     G = construct(clusters)
     self.assertFalse(is_treechild(G))
Beispiel #29
0
 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)
Beispiel #30
0
 def test_true(self):
     clusters = [(1, 2), (3, 4)]
     G = construct(clusters)
     self.assertTrue(is_treechild(G))