本文整理汇总了Python中ete_dev.Tree.get_leaves方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.get_leaves方法的具体用法?Python Tree.get_leaves怎么用?Python Tree.get_leaves使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ete_dev.Tree
的用法示例。
在下文中一共展示了Tree.get_leaves方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Tree
# 需要导入模块: from ete_dev import Tree [as 别名]
# 或者: from ete_dev.Tree import get_leaves [as 别名]
from ete_dev import Tree
# Loads a basic tree
t = Tree( '(A:0.2,(B:0.4,(C:1.1,D:0.45):0.5):0.1);' )
print t
# /-A
#---------|
# | /-B
# \--------|
# | /-C
# \--------|
# \-D
# Counts leaves within the tree
nleaves = 0
for leaf in t.get_leaves():
nleaves += 1
print "This tree has", nleaves, "terminal nodes"
# But, like this is much simpler :)
nleaves = len(t)
print "This tree has", nleaves, "terminal nodes [proper way: len(tree) ]"
# Counts leaves within the tree
ninternal = 0
for node in t.get_descendants():
if not node.is_leaf():
ninternal +=1
print "This tree has", ninternal, "internal nodes"
# Counts nodes with whose distance is higher than 0.3
nnodes = 0
for node in t.get_descendants():
if node.dist > 0.3:
nnodes +=1
# or, translated into a better pythonic
示例2: Tree
# 需要导入模块: from ete_dev import Tree [as 别名]
# 或者: from ete_dev.Tree import get_leaves [as 别名]
import time
from ete_dev import Tree
# Creates a random tree with 10,000 leaf nodes
tree = Tree()
tree.populate(10000)
# This code should be faster
t1 = time.time()
for leaf in tree.iter_leaves():
if "aw" in leaf.name:
print "found a match:", leaf.name,
break
print "Iterating: ellapsed time:", time.time()-t1
# This slower
t1 = time.time()
for leaf in tree.get_leaves():
if "aw" in leaf.name:
print "found a match:", leaf.name,
break
print "Getting: ellapsed time:", time.time()-t1
# Results in something like:
# found a match: guoaw Iterating: ellapsed time: 0.00436091423035 secs
# found a match: guoaw Getting: ellapsed time: 0.124316930771 secs