-
Notifications
You must be signed in to change notification settings - Fork 29
Method `baltic.tree.countLineages`
Barney Potter edited this page Oct 14, 2024
·
1 revision
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.
def countLineages(self, t, attr='absoluteTime', condition=lambda x: True)
-
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.
- int: The number of lineages present at the specified time point.
- Iterates through all objects in the tree.
- 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.
- Have a parent with the specified time attribute less than
- Generating lineages-through-time (LTT) plots.
- Analyzing diversification rates at different time points in the tree.
- Identifying periods of rapid lineage accumulation or extinction.
- Comparing lineage diversity across different clades or time periods.
# 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}")
- 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.
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