Skip to content

Method `baltic.tree.countLineages`

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

tree.countLineages() Method

Description

The countLineages() method in the BALTIC tree class counts the number of lineages present at a specific time point in the tree. This method is useful for analyzing the diversity and branching patterns of the phylogeny through time.

Syntax

def countLineages(self, t, attr='absoluteTime', condition=lambda x: True)

Parameters

  • t (float): The time point at which to count the lineages.
  • attr (str): The attribute used to determine the time of the nodes. Default is 'absoluteTime'.
  • condition (function): A function that determines whether a lineage should be included in the count. Default is a function that always returns True.

Return Value

  • int: The number of lineages present at the specified time point.

Functionality

  1. Iterates through all objects in the tree.
  2. Counts the number of branches that:
    • Have a parent with the specified time attribute less than t.
    • Have their own time attribute greater than or equal to t.
    • Satisfy the given condition function.

Use Cases

  1. Generating lineages-through-time (LTT) plots.
  2. Analyzing diversification rates at different time points in the tree.
  3. Identifying periods of rapid lineage accumulation or extinction.
  4. Comparing lineage diversity across different clades or time periods.

Example

# Assuming we have a time-calibrated tree

# Count lineages at a specific time point
time_point = 2000  # e.g., year 2000
lineage_count = tree.countLineages(time_point)
print(f"Number of lineages at year {time_point}: {lineage_count}")

# Count lineages over a range of time points (e.g., for an LTT plot)
start_time = tree.root.absoluteTime
end_time = max(leaf.absoluteTime for leaf in tree.getExternal())
time_points = np.linspace(start_time, end_time, 100)
ltt_data = [(t, tree.countLineages(t)) for t in time_points]

# Count lineages with a specific trait
trait_condition = lambda node: node.traits.get('some_trait') == 'value'
trait_lineage_count = tree.countLineages(time_point, condition=trait_condition)
print(f"Number of lineages with specific trait at year {time_point}: {trait_lineage_count}")

Notes

  • This method assumes that the tree has been time-calibrated, with the specified time attribute (default 'absoluteTime') set for all nodes and tips.
  • The count includes all lineages that exist at the given time point, including those that may go extinct before the present.
  • The condition parameter allows for flexible filtering of lineages based on any criteria definable in a Python function.
  • For trees with many objects, this method can be computationally intensive if called repeatedly (e.g., when generating an LTT plot).
  • The time scale used should be consistent with the time calibration of the tree (e.g., years, millions of years).
  • This method can be particularly useful in combination with other BALTIC methods for comprehensive phylodynamic analyses.
Clone this wiki locally