本文整理匯總了Python中ete_dev.Tree.get_descendants方法的典型用法代碼示例。如果您正苦於以下問題:Python Tree.get_descendants方法的具體用法?Python Tree.get_descendants怎麽用?Python Tree.get_descendants使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ete_dev.Tree
的用法示例。
在下文中一共展示了Tree.get_descendants方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: len
# 需要導入模塊: from ete_dev import Tree [as 別名]
# 或者: from ete_dev.Tree import get_descendants [as 別名]
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
nnodes = len([n for n in t.get_descendants() if n.dist>0.3])
print "This tree has", nnodes, "nodes with a branch length > 0.3"
示例2: Tree
# 需要導入模塊: from ete_dev import Tree [as 別名]
# 或者: from ete_dev.Tree import get_descendants [as 別名]
from ete_dev import Tree
tree = Tree( '(A:1,(B:1,(C:1,D:1):0.5):0.5);' )
# Prints the name of every leaf under the tree root
print "Leaf names:"
for leaf in tree.get_leaves():
print leaf.name
# Label nodes as terminal or internal. If internal, saves also the
# number of leaves that it contains.
print "Labeled tree:"
for node in tree.get_descendants():
if node.is_leaf():
node.add_features(ntype="terminal")
else:
node.add_features(ntype="internal", size=len(node))
# Gets the extended newick of the tree including new node features
print tree.write(features=[])