当前位置: 首页>>代码示例>>Python>>正文


Python DndParser.Rank方法代码示例

本文整理汇总了Python中cogent.parse.tree.DndParser.Rank方法的典型用法代码示例。如果您正苦于以下问题:Python DndParser.Rank方法的具体用法?Python DndParser.Rank怎么用?Python DndParser.Rank使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cogent.parse.tree.DndParser的用法示例。


在下文中一共展示了DndParser.Rank方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_backfill_names_gap

# 需要导入模块: from cogent.parse.tree import DndParser [as 别名]
# 或者: from cogent.parse.tree.DndParser import Rank [as 别名]
    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'])
开发者ID:teravest,项目名称:tax2tree,代码行数:31,代码来源:test_nlevel.py

示例2: test_commonname_promotion

# 需要导入模块: from cogent.parse.tree import DndParser [as 别名]
# 或者: from cogent.parse.tree.DndParser import Rank [as 别名]
 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)
开发者ID:teravest,项目名称:tax2tree,代码行数:23,代码来源:test_nlevel.py


注:本文中的cogent.parse.tree.DndParser.Rank方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。