Skip to content

Method `baltic.tree.singleType`

Barney Potter edited this page Oct 14, 2024 · 1 revision

tree.singleType() Method

Description

The singleType() method in the BALTIC tree class is used to remove any branches with a single child (multitype nodes) from the tree. This process simplifies the tree structure by ensuring that each internal node has either no children (leaves) or multiple children.

Syntax

def singleType(self)

Parameters

This method doesn't take any parameters.

Functionality

  1. Iteratively identifies nodes with only one child (multitype nodes).
  2. For each identified multitype node:
    • Reassigns the child node to the grandparent of the original single-child node.
    • Adjusts the branch length of the child to account for the removed node.
    • Removes the single-child node from the tree structure.
  3. Repeats this process until no multitype nodes remain.
  4. Calls sortBranches() to ensure the tree structure is properly ordered after modifications.

Use Cases

  1. Simplifying tree structures after certain manipulations that might introduce single-child nodes.
  2. Standardizing trees to ensure they follow a strictly bifurcating (or multifurcating) structure.
  3. Preparing trees for analyses or visualizations that assume no single-child nodes.
  4. Cleaning up trees after operations like subtree extraction or branch collapsing.

Example

# Assuming we have a tree object that might have single-child nodes
tree.singleType()

# The tree is now simplified, with all single-child nodes removed

Notes

  • This method modifies the tree in-place. If you need to preserve the original tree, make a deep copy before calling singleType().
  • The method adjusts branch lengths to preserve the overall tree structure and timing relationships.
  • After removing single-child nodes, the tree's topology may change, but the relationships between leaves and the total tree length should remain the same.
  • This method is particularly useful when working with trees that have undergone complex manipulations or when preparing trees for certain types of analyses that assume a particular tree structure.
  • The sortBranches() call at the end ensures that the tree is in a consistent state after the modifications.
Clone this wiki locally