コード例 #1
0
ファイル: getting_leaves.py プロジェクト: MikeTrizna/ete
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
0
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=[])
コード例 #3
0
ファイル: getting_leaves.py プロジェクト: tarah28/ete
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"
コード例 #4
0
ファイル: label_nodes.py プロジェクト: MikeTrizna/ete
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=[])