Skip to content

Method `baltic.tree.allTMRCAs`

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

tree.allTMRCAs() Method

Description

The allTMRCAs() method in the BALTIC tree class calculates the time to the most recent common ancestor (TMRCA) for all pairs of tips in the tree. This method is crucial for understanding the evolutionary relationships and divergence times between all taxa represented in the phylogeny.

Syntax

def allTMRCAs(self)

Parameters

This method doesn't take any parameters.

Return Value

  • dict: A nested dictionary where each key is a tip name and the corresponding value is another dictionary with tip names as keys and their TMRCA as values.

Functionality

  1. Creates a list of all tip names in the tree.
  2. Initializes a nested dictionary to store TMRCA values for all pairs of tips.
  3. Iterates through all internal nodes of the tree.
  4. For each internal node:
    • Identifies all descendant tips.
    • Updates the TMRCA for each pair of these descendant tips with the node's absolute time, if it's more recent than any previously recorded TMRCA.
  5. Ensures the matrix is symmetric and sets the TMRCA of a tip with itself to 0.0.

Use Cases

  1. Analyzing the overall structure of evolutionary relationships in the tree.
  2. Identifying closely related pairs or groups of taxa.
  3. Studying patterns of diversification across the phylogeny.
  4. Investigating the timescale of evolutionary events across different lineages.

Example

# Calculate all TMRCAs
tmrca_matrix = tree.allTMRCAs()

# Print TMRCA for a specific pair of tips
tip1, tip2 = "TaxonA", "TaxonB"
print(f"TMRCA between {tip1} and {tip2}: {tmrca_matrix[tip1][tip2]}")

# Find the most recently diverged pair of tips
most_recent_pair = min(
    ((t1, t2) for t1 in tmrca_matrix for t2 in tmrca_matrix[t1] if t1 != t2),
    key=lambda pair: tmrca_matrix[pair[0]][pair[1]]
)
print(f"Most recently diverged pair: {most_recent_pair}")

# Calculate average TMRCA across all pairs
all_tmrcas = [tmrca_matrix[t1][t2] for t1 in tmrca_matrix for t2 in tmrca_matrix[t1] if t1 != t2]
average_tmrca = sum(all_tmrcas) / len(all_tmrcas)
print(f"Average TMRCA across all pairs: {average_tmrca}")

Notes

  • This method assumes that the tree has been time-calibrated, with the absoluteTime attribute set for all nodes. Use setAbsoluteTime() if necessary before calling this method.
  • The resulting matrix is symmetric, meaning tmrca_matrix[tip1][tip2] is equal to tmrca_matrix[tip2][tip1].
  • The TMRCA of a tip with itself is set to 0.0.
  • For large trees, this method can be computationally intensive and memory-consuming, as it calculates TMRCAs for all possible pairs of tips.
  • The TMRCA values are based on the absoluteTime of nodes, so the units will be the same as those used for setting absolute times in the tree.
  • This method can be particularly useful for comparative studies, molecular clock analyses, or investigating patterns of speciation and extinction.
Clone this wiki locally