本文整理汇总了Python中cogent.parse.tree.DndParser.getNewick方法的典型用法代码示例。如果您正苦于以下问题:Python DndParser.getNewick方法的具体用法?Python DndParser.getNewick怎么用?Python DndParser.getNewick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cogent.parse.tree.DndParser
的用法示例。
在下文中一共展示了DndParser.getNewick方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_DndParser
# 需要导入模块: from cogent.parse.tree import DndParser [as 别名]
# 或者: from cogent.parse.tree.DndParser import getNewick [as 别名]
def test_DndParser(self):
"""DndParser tests"""
t_str = "(A_a,(B:1.0,C),'D_e':0.5)E;"
tree_unesc = DndParser(t_str, PhyloNode, unescape_name=True)
tree_esc = DndParser(t_str, PhyloNode, unescape_name=False)
self.assertEqual(tree_unesc.Name, 'E')
self.assertEqual(tree_unesc.Children[0].Name, 'A a')
self.assertEqual(tree_unesc.Children[1].Children[0].Name, 'B')
self.assertEqual(tree_unesc.Children[1].Children[0].Length, 1.0)
self.assertEqual(tree_unesc.Children[1].Children[1].Name, 'C')
self.assertEqual(tree_unesc.Children[2].Name, 'D_e')
self.assertEqual(tree_unesc.Children[2].Length, 0.5)
self.assertEqual(tree_esc.Name, 'E')
self.assertEqual(tree_esc.Children[0].Name, 'A_a')
self.assertEqual(tree_esc.Children[1].Children[0].Name, 'B')
self.assertEqual(tree_esc.Children[1].Children[0].Length, 1.0)
self.assertEqual(tree_esc.Children[1].Children[1].Name, 'C')
self.assertEqual(tree_esc.Children[2].Name, "'D_e'")
self.assertEqual(tree_esc.Children[2].Length, 0.5)
reload_test = tree_esc.getNewick(with_distances=True, \
escape_name=False)
obs = DndParser(reload_test, unescape_name=False)
self.assertEqual(obs.getNewick(with_distances=True), \
tree_esc.getNewick(with_distances=True))
reload_test = tree_unesc.getNewick(with_distances=True, \
escape_name=False)
obs = DndParser(reload_test, unescape_name=False)
self.assertEqual(obs.getNewick(with_distances=True), \
tree_unesc.getNewick(with_distances=True))
示例2: test_getsubtree
# 需要导入模块: from cogent.parse.tree import DndParser [as 别名]
# 或者: from cogent.parse.tree.DndParser import getNewick [as 别名]
def test_getsubtree(self):
"""testing getting a subtree
"""
otu_names = ['NineBande', 'Mouse', 'HowlerMon', 'DogFaced']
newick = '(((Human,HowlerMon),Mouse),NineBande,DogFaced);'
newick_reduced = '((Mouse,HowlerMon),NineBande,DogFaced);'
tree = DndParser(newick, constructor = PicrustNode)
subtree = tree.getSubTree(otu_names)
new_tree = DndParser(newick_reduced, constructor = PicrustNode)
# check we get the same names
self.assertEqual(*[len(t.Children) for t in (subtree,new_tree)])
self.assertEqual(subtree.getNewick(), new_tree.getNewick())
示例3: test_join_nodes
# 需要导入模块: from cogent.parse.tree import DndParser [as 别名]
# 或者: from cogent.parse.tree.DndParser import getNewick [as 别名]
def test_join_nodes(self):
"""join them nodes! (((99 + 97) + 94) + 91) + ..."""
parsed = [make_nodes(self.clst_99, 0.01, 99),
make_nodes(self.clst_97, 0.02, 97),
make_nodes(self.clst_94, 0.03, 94)]
exp = """((((3:.005)99_2_3:.01,(8:.005,7:.005)99_3_8:.01)97_0_3:.015)94_0_3,
(((1:.005,6:.005)99_1_1:.01)97_1_1:.015,
((10:.005,20:.005,30:.005)99_0_10:.01)97_2_10:.015)94_1_1);"""
expt = DndParser(exp)
obs = join_nodes(parsed)
self.assertEqual(obs.getNewick(with_distances=True),
expt.getNewick(with_distances=True))
示例4: test_commonname_promotion
# 需要导入模块: from cogent.parse.tree import DndParser [as 别名]
# 或者: from cogent.parse.tree.DndParser import getNewick [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)
示例5: test_make_tree_arb_safe
# 需要导入模块: from cogent.parse.tree import DndParser [as 别名]
# 或者: from cogent.parse.tree.DndParser import getNewick [as 别名]
def test_make_tree_arb_safe(self):
"""ARB can't handle single descendent nodes"""
t = DndParser("(((((a)b)c)d)e)f;", constructor=RangeNode)
exp = "(((((a,X)b,X)c,X)d,X)e,X)f;"
make_tree_arb_safe(t)
self.assertEqual(t.getNewick(), exp)