-
Notifications
You must be signed in to change notification settings - Fork 29
Method `baltic.tree.commonAncestor`
Barney Potter edited this page Oct 14, 2024
·
1 revision
The commonAncestor()
method in the BALTIC tree
class is used to find the most recent common ancestor (MRCA) of a given set of descendant branches. This method is crucial for various phylogenetic analyses, including identifying clades, measuring evolutionary distances, and understanding relationships between specific taxa.
def commonAncestor(self, descendants)
-
descendants
(list): A list of descendant branches (asnode
,leaf
,clade
and/orreticulation
objects) for which to find the most recent common ancestor.
-
node
: The most recent common ancestor node of the given descendants.
- Asserts that there are at least two descendants provided.
- Creates a dictionary to store the path from each descendant to the root.
- For each descendant:
- Traces the path from the descendant to the root, storing each node encountered.
- Finds the intersection of all paths to identify common ancestors.
- Returns the most recent (lowest) common ancestor from the set of common ancestors.
- Identifying the clade that contains a specific set of taxa.
- Calculating the evolutionary distance between two or more species.
- Determining the point of divergence for a group of species.
- Analyzing the evolutionary relationships within a subset of the tree.
# Assuming we have a tree and some leaf nodes
leaf1 = tree.getExternal()[0]
leaf2 = tree.getExternal()[5]
leaf3 = tree.getExternal()[10]
# Find the common ancestor of these three leaves
mrca = tree.commonAncestor([leaf1, leaf2, leaf3])
print(f"Common ancestor index: {mrca.index}")
print(f"Height of common ancestor: {mrca.height}")
# We can also use this to check if a set of leaves form a monophyletic group
all_leaves = tree.getExternal()
group_of_interest = all_leaves[:5] # First 5 leaves
mrca_of_group = tree.commonAncestor(group_of_interest)
is_monophyletic = set(mrca_of_group.leaves) == set(leaf.name for leaf in group_of_interest)
print(f"Is the group monophyletic? {is_monophyletic}")
- This method requires at least two descendants to find a common ancestor. It will raise an AssertionError if fewer than two are provided.
- The method works by tracing paths to the root, so it's efficient even for large trees.
- The returned node is guaranteed to be the most recent common ancestor, i.e., the lowest node in the tree that is an ancestor to all provided descendants.
- This method can be particularly useful in combination with other tree analysis methods to study specific clades or evolutionary events.
- When using this method, ensure that all provided descendants actually belong to the tree to avoid unexpected results.
- The common ancestor returned will always be an internal node unless the descendants list includes the root node.
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