Skip to content

Method `baltic.tree.commonAncestor`

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

tree.commonAncestor() Method

Description

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.

Syntax

def commonAncestor(self, descendants)

Parameters

  • descendants (list): A list of descendant branches (as node, leaf, clade and/or reticulation objects) for which to find the most recent common ancestor.

Return Value

  • node: The most recent common ancestor node of the given descendants.

Functionality

  1. Asserts that there are at least two descendants provided.
  2. Creates a dictionary to store the path from each descendant to the root.
  3. For each descendant:
    • Traces the path from the descendant to the root, storing each node encountered.
  4. Finds the intersection of all paths to identify common ancestors.
  5. Returns the most recent (lowest) common ancestor from the set of common ancestors.

Use Cases

  1. Identifying the clade that contains a specific set of taxa.
  2. Calculating the evolutionary distance between two or more species.
  3. Determining the point of divergence for a group of species.
  4. Analyzing the evolutionary relationships within a subset of the tree.

Example

# 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}")

Notes

  • 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.
Clone this wiki locally