當前位置: 首頁>>代碼示例>>Python>>正文


Python Tree.get_leaves方法代碼示例

本文整理匯總了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
開發者ID:MikeTrizna,項目名稱:ete,代碼行數:33,代碼來源:getting_leaves.py

示例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
開發者ID:MikeTrizna,項目名稱:ete,代碼行數:24,代碼來源:iterators.py


注:本文中的ete_dev.Tree.get_leaves方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。