-
Notifications
You must be signed in to change notification settings - Fork 29
Method `baltic.tree.allTMRCAs`
Barney Potter edited this page Oct 14, 2024
·
1 revision
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.
def allTMRCAs(self)
This method doesn't take any parameters.
- 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.
- Creates a list of all tip names in the tree.
- Initializes a nested dictionary to store TMRCA values for all pairs of tips.
- Iterates through all internal nodes of the tree.
- 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.
- Ensures the matrix is symmetric and sets the TMRCA of a tip with itself to 0.0.
- Analyzing the overall structure of evolutionary relationships in the tree.
- Identifying closely related pairs or groups of taxa.
- Studying patterns of diversification across the phylogeny.
- Investigating the timescale of evolutionary events across different lineages.
# 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}")
- This method assumes that the tree has been time-calibrated, with the
absoluteTime
attribute set for all nodes. UsesetAbsoluteTime()
if necessary before calling this method. - The resulting matrix is symmetric, meaning
tmrca_matrix[tip1][tip2]
is equal totmrca_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.
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