File: tree_basis.py

package info (click to toggle)
python-ete3 3.1.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,148 kB
  • sloc: python: 52,375; javascript: 12,959; xml: 4,903; ansic: 69; sql: 65; makefile: 26; sh: 7
file content (21 lines) | stat: -rw-r--r-- 718 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from ete3 import Tree
# Creates an empty tree and populates it with some new
# nodes
t = Tree()
A = t.add_child(name="A")
B = t.add_child(name="B")
C = A.add_child(name="C")
D = A.add_child(name="D")
print(t)
#                    /-C
#          /--------|
#---------|          \-D
#         |
#          \-B
print('is "t" the root?', t.is_root()) # True
print('is "A" a terminal node?', A.is_leaf()) # False
print('is "B" a terminal node?', B.is_leaf()) # True
print('B.get_tree_root() is "t"?', B.get_tree_root() is t) # True
print('Number of leaves in tree:', len(t)) # returns number of leaves under node (3)
print('is C in tree?', C in t) # Returns true
print("All leaf names in tree:", [node.name for node in t])