Skip to main content
`Ctrl`+`K`

# skbio.tree.TreeNode

class skbio.tree.TreeNode(name=None, length=None, support=None, parent=None, children=None)

  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

      A node can have a name. It is common for tips in particular to have names, for instance, in a phylogenetic tree where the tips correspond to species.

    length float, int, or None

      Length of the branch connecting this node to its parent. Can represent ellapsed time, amount of mutations, or other measures of evolutionary distance.

    support float, int, or None

      Support value of the branch connecting this node to its parent. Can be bootstrap value, posterior probability, or other metrics measuring the confidence or frequency of this branch.

    parent TreeNode or None

      Connect this node to a parent

    children list of TreeNode or None

      Connect this node to existing children

  Attributes

  `default_write_format` |

  Built-ins

  `__copy__`() | Return a shallow copy.
  `__deepcopy__`(memo) | Return a deep copy.
  `__eq__`(value, /) | Return self==value.
  `__ge__`(value, /) | Return self>=value.
  `__getitem__`(i) | Node delegates slicing to children.
  `__getstate__`(/) | Helper for pickle.
  `__gt__`(value, /) | Return self>value.
  `__hash__`(/) | Return hash(self).
  `__iter__`() | Node iter iterates over the children.
  `__le__`(value, /) | Return self<=value.
  `__len__`() |
  `__lt__`(value, /) | Return self<value.
  `__ne__`(value, /) | Return self!=value.
  `__str__`() | Return string version of self, with names and distances.

  Methods

  `accumulate_to_ancestor`(ancestor) | Return the sum of the distance between self and ancestor.
  `ancestors`() | Return all ancestors back to the root.
  `append`(node) | Add a node to self's children.
  `ascii_art`([show_internal, compact]) | Return a string containing an ascii drawing of the tree.
  `assign_ids`() | Assign topologically stable unique ids to self.
  `assign_supports`() | Extract support values from internal node labels of a tree.
  `bifurcate`([insert_length]) | Reorder 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]) | Calculate the Robinson and Foulds symmetric difference.
  `compare_subsets`(other[, exclude_absent_taxa]) | Return fraction of overlapping subsets where self and other differ.
  `compare_tip_distances`(other[, sample, ...]) | Compare self to other using tip-to-tip distance matrices.
  `copy`([deep]) | Return a copy of self using an iterative approach.
  `count`([tips]) | Get the count of nodes in the tree.
  `create_caches`() | Construct an internal lookup table to facilitate searching by name.
  `deepcopy`() | Return a deep 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) | Add a list of nodes to self's children.
  `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_taxdump`(nodes[, names]) | Construct a tree from the NCBI taxonomy database.
  `from_taxonomy`(lineage_map) | Construct a tree from a taxonomy.
  `get_max_distance`() | Return the max tip tip distance between any pair of tips.
  `has_children`() | Return True if the node has children.
  `index_tree`() | Index a tree for rapid lookups within a tree array.
  `insert`(node[, distance, branch_attrs]) | Insert a node into the branch connecting self and its parent.
  `invalidate_caches`([attr]) | Delete lookup and attribute caches.
  `is_root`() | Return True if the current is a root, i.e. has no parent.
  `is_tip`() | Return True if the current node has no children.
  `lca`(tipnames) | Find lowest common ancestor for a list of tips.
  `levelorder`([include_self]) | Perform levelorder iteration over tree.
  `lowest_common_ancestor`(tipnames) | Find lowest common ancestor for a list of tips.
  `neighbors`([ignore]) | Return all nodes that are connected to self.
  `non_tips`([include_self]) | Iterate over nontips descended from self.
  `observed_node_counts`(tip_counts) | Return counts of node observations from counts of tip observations.
  `pop`([index]) | Remove and return a child node by its index position from self.
  `postorder`([include_self]) | Perform postorder iteration over tree.
  `pre_and_postorder`([include_self]) | Perform iteration over tree, visiting node before and after.
  `preorder`([include_self]) | Perform preorder iteration over tree.
  `prune`() | Reconstruct 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`() | Return root of the tree which contains self.
  `root_at`([node, above, reset, branch_attrs, ...]) | Reroot the tree at the provided node.
  `root_at_midpoint`([reset, branch_attrs, ...]) | Reroot the tree at the midpoint of the two tips farthest apart.
  `root_by_outgroup`(outgroup[, above, reset, ...]) | Reroot the tree with a given set of taxa as outgroup.
  `shear`(names) | Remove tips until the tree just has the desired tip names.
  `shuffle`([k, names, shuffle_f, n]) | Yield trees with shuffled tip names.
  `siblings`() | Return all nodes that are children of self parent.
  `subset`() | Return 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]) | Return distance matrix between pairs of tips, and a tip order.
  `tips`([include_self]) | Iterate over tips descended from self.
  `to_array`([attrs, nan_length_value]) | Return an array representation of self.
  `to_taxonomy`([allow_empty, filter_f]) | Return a taxonomy representation of self.
  `traverse`([self_before, self_after, include_self]) | Return iterator over descendants.
  `unpack`() | Unpack an internal node in place.
  `unpack_by_func`(func) | Unpack internal nodes of a tree that meet certain criteria.
  `unroot`([side]) | Convert a rooted tree into unrooted.
  `unrooted_copy`([parent, branch_attrs, ...]) | Walk the tree unrooted-style and return a copy.
  `unrooted_deepcopy`([parent]) | Walk the tree unrooted-style and returns a new deepcopy.
  `unrooted_move`([parent, branch_attrs]) | Walk the tree unrooted-style and rearrange it.
  `write`(file[, format]) | Write an instance of `TreeNode` to a file.