Exemplo n.º 1
0
    def test_backfill_names_gap(self):
        """correctly backfill names"""
        consensus_tree = DndParser("(((s1,s2)g1,(s3,s4)g2,(s5,s6)g3)f1)o1;")
        rank_lookup = {'s':6,'g':5,'f':4,'o':3,'c':2,'p':1,'k':0}
        for n in consensus_tree.traverse(include_self=True):
            n.Rank = rank_lookup[n.Name[0]]
        input = "((((1)s1,(2)s2),((3)s3,(4)s5)))o1;"
        lookup = dict([(n.Name, n) for n in consensus_tree.traverse(include_self=True)])
        #exp = "((((1)s1,(2)s2)g1,((3)'g2; s3',(4)'g3; s5')))'o1; f1'"
        t = DndParser(input)
        t.Rank = 3
        t.Children[0].Rank = None
        t.Children[0].Children[0].Rank = None
        t.Children[0].Children[1].Rank = None
        t.Children[0].Children[0].Children[0].Rank = 6
        t.Children[0].Children[0].Children[1].Rank = 6
        t.Children[0].Children[1].Children[0].Rank = 6
        t.Children[0].Children[1].Children[1].Rank = 6

        backfill_names_gap(t, lookup)

        self.assertEqual(t.BackFillNames, ['o1'])
        self.assertEqual(t.Children[0].BackFillNames, [])
        self.assertEqual(t.Children[0].Children[0].BackFillNames, [])
        self.assertEqual(t.Children[0].Children[1].BackFillNames, [])
        self.assertEqual(t.Children[0].Children[0].Children[0].BackFillNames, ['f1','g1','s1'])
        self.assertEqual(t.Children[0].Children[0].Children[1].BackFillNames, ['f1','g1','s2'])
        self.assertEqual(t.Children[0].Children[1].Children[0].BackFillNames, ['f1','g2','s3'])
        self.assertEqual(t.Children[0].Children[1].Children[1].BackFillNames, ['f1','g3','s5'])
Exemplo n.º 2
0
 def test_commonname_promotion(self):
     """correctly promote names if possible"""
     consensus_tree = DndParser("(((s1,s2)g1,(s3,s4)g2,(s5,s6)g3)f1)o1;")
     rank_lookup = {'s':6,'g':5,'f':4,'o':3,'c':2,'p':1,'k':0}
     for n in consensus_tree.traverse(include_self=True):
         n.Rank = rank_lookup[n.Name[0]]
     input = "((((1)s1,(2)s2),((3)s3,(4)s5)))o1;"
     lookup = dict([(n.Name, n) for n in consensus_tree.traverse(include_self=True)])
     exp = "((((1)s1,(2)s2)g1,((3)'g2; s3',(4)'g3; s5')))'o1; f1';"
     t = DndParser(input)
     t.Rank = 3
     t.Children[0].Rank = None
     t.Children[0].Children[0].Rank = None
     t.Children[0].Children[1].Rank = None
     t.Children[0].Children[0].Children[0].Rank = 6
     t.Children[0].Children[0].Children[1].Rank = 6
     t.Children[0].Children[1].Children[0].Rank = 6
     t.Children[0].Children[1].Children[1].Rank = 6
     backfill_names_gap(t, lookup)
     commonname_promotion(t)
     self.assertEqual(t.getNewick(with_distances=False), exp)