skbio.tree.TreeNode(name=None, length=None, parent=None, children=None)[source]¶Representation of a node within a tree
A TreeNode instance stores links to its parent and optional children nodes. In addition, the TreeNode can represent a length (e.g., a branch length) between itself and its parent. Within this object, the use of “children” and “descendants” is frequent in the documentation. A child is a direct descendant of a node, while descendants are all nodes that are below a given node (e.g., grand-children, etc).
| Parameters: | name : str or None
length : float, int, or None
parent : TreeNode or None
children : list of TreeNode or None
|
|---|
Attributes
| name | |
| length | |
| parent | |
| children | |
| id |
Methods
copy.copy(tree) |
Returns a copy of self using an iterative approach |
copy.deepcopy(tree) |
Returns a copy of self using an iterative approach |
tree[x] |
Node delegates slicing to children. |
iter(tree) |
Node iter iterates over the children. |
len(tree) |
State: Experimental as of 0.4.0. |
str(tree) |
Returns string version of self, with names and distances |
accumulate_to_ancestor(ancestor) |
Return the sum of the distance between self and ancestor |
ancestors() |
Returns all ancestors back to the root |
append(node) |
Appends a node to children, in-place, cleaning up refs |
ascii_art([show_internal, compact]) |
Returns a string containing an ascii drawing of the tree |
assign_ids() |
Assign topologically stable unique ids to self |
bifurcate([insert_length]) |
Reorders the tree into a bifurcating tree. |
cache_attr(func, cache_attrname[, cache_type]) |
Cache attributes on internal nodes of the tree |
compare_rfd(other[, proportion]) |
Calculates the Robinson and Foulds symmetric difference |
compare_subsets(other[, exclude_absent_taxa]) |
Returns fraction of overlapping subsets where self and other differ. |
compare_tip_distances(other[, sample, …]) |
Compares self to other using tip-to-tip distance matrices. |
copy() |
Returns a copy of self using an iterative approach |
count([tips]) |
Get the count of nodes in the tree |
create_caches() |
Construct an internal lookups to facilitate searching by name |
deepcopy() |
Returns a copy of self using an iterative approach |
descending_branch_length([tip_subset]) |
Find total descending branch length from self or subset of self tips |
distance(other) |
Return the distance between self and other |
extend(nodes) |
Append a list of TreeNode to self. |
find(name) |
Find a node by name. |
find_all(name) |
Find all nodes that match name |
find_by_func(func) |
Find all nodes given a function |
find_by_id(node_id) |
Find a node by id. |
from_linkage_matrix(linkage_matrix, id_list) |
Return tree from SciPy linkage matrix. |
from_taxonomy(lineage_map) |
Construct a tree from a taxonomy |
get_max_distance() |
Returns the max tip tip distance between any pair of tips |
has_children() |
Returns True if the node has children. |
index_tree() |
Index a tree for rapid lookups within a tree array |
invalidate_caches([attr]) |
Delete lookup and attribute caches |
is_root() |
Returns True if the current is a root, i.e. |
is_tip() |
Returns True if the current node has no children. |
lca(tipnames) |
Lowest common ancestor for a list of tips |
levelorder([include_self]) |
Performs levelorder iteration over tree |
lowest_common_ancestor(tipnames) |
Lowest common ancestor for a list of tips |
neighbors([ignore]) |
Returns all nodes that are connected to self |
non_tips([include_self]) |
Iterates over nontips descended from self |
observed_node_counts(tip_counts) |
Returns counts of node observations from counts of tip observations |
pop([index]) |
Remove a TreeNode from self. |
postorder([include_self]) |
Performs postorder iteration over tree. |
pre_and_postorder([include_self]) |
Performs iteration over tree, visiting node before and after |
preorder([include_self]) |
Performs preorder iteration over tree |
prune() |
Reconstructs correct topology after nodes have been removed. |
read(file[, format]) |
Create a new TreeNode instance from a file. |
remove(node) |
Remove a node from self |
remove_deleted(func) |
Delete nodes in which func(node) evaluates True. |
root() |
Returns root of the tree self is in |
root_at(node) |
Return a new tree rooted at the provided node. |
root_at_midpoint() |
Return a new tree rooted at midpoint of the two tips farthest apart |
shear(names) |
Lop off tips until the tree just has the desired tip names. |
shuffle([k, names, shuffle_f, n]) |
Yield trees with shuffled tip names |
siblings() |
Returns all nodes that are children of self parent. |
subset() |
Returns set of names that descend from specified node |
subsets() |
Return all sets of names that come from self and its descendants |
subtree([tip_list]) |
Make a copy of the subtree |
tip_tip_distances([endpoints]) |
Returns distance matrix between pairs of tips, and a tip order. |
tips([include_self]) |
Iterates over tips descended from self. |
to_array([attrs, nan_length_value]) |
Return an array representation of self |
to_taxonomy([allow_empty, filter_f]) |
Returns a taxonomy representation of self |
traverse([self_before, self_after, include_self]) |
Returns iterator over descendants |
unrooted_copy([parent]) |
Walks the tree unrooted-style and returns a copy |
unrooted_deepcopy([parent]) |
Walks the tree unrooted-style and returns a new copy |
write(file[, format]) |
Write an instance of TreeNode to a file. |