-
Notifications
You must be signed in to change notification settings - Fork 29
Method `baltic.tree.singleType`
Barney Potter edited this page Oct 14, 2024
·
1 revision
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.
def singleType(self)
This method doesn't take any parameters.
- Iteratively identifies nodes with only one child (multitype nodes).
- 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.
- Repeats this process until no multitype nodes remain.
- Calls
sortBranches()
to ensure the tree structure is properly ordered after modifications.
- Simplifying tree structures after certain manipulations that might introduce single-child nodes.
- Standardizing trees to ensure they follow a strictly bifurcating (or multifurcating) structure.
- Preparing trees for analyses or visualizations that assume no single-child nodes.
- Cleaning up trees after operations like subtree extraction or branch collapsing.
# 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
- 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.
Wiki written with the assistance of claude.ai 3.5 "Sonnet".
- Core
baltic
classes:-
Class
tree
- Tree Construction and Manipulation methods
- Tree Analysis methods
- Tree Conversion and Output methods
- Tree Visualization
- Utility Methods
- Class
leaf
- Class
node
- Class
clade
- Class
reticulation
-
Class