本文整理汇总了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'])
示例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)