brokilon.ccd.domain.sranges.sranges module¶
Utilities for stratigraphic-range CCDs.
Provides data structures and algorithms for representing stratigraphic-range clades, constructing stratigraphic-range CCDs from phylogenetic trees, and CCD-MAP trees.
- class brokilon.ccd.domain.sranges.sranges.AncestralSplit(ancestor: SRangesClade, descendant: SRangesClade)[source]¶
Bases:
objectRepresent an ancestral split in a stratigraphic-range CCD with orientation.
- Attributes:
ancestor: The ancestral stratigraphic-range clade. descendant: The descendant stratigraphic-range clade.
- ancestor: SRangesClade¶
- descendant: SRangesClade¶
- brokilon.ccd.domain.sranges.sranges.get_callsite()[source]¶
Get the source location of the caller’s caller (for debugging not in use at the moment).
- Returns:
A string containing the filename, line number, and function name.
- brokilon.ccd.domain.sranges.sranges.get_sranges_map(trees, taxon_map)[source]¶
Construct a stratigraphic-range CCD from phylogenetic trees.
Processes the input trees to identify stratigraphic-range clades, ancestral splits, and sampled ancestors, and aggregates their counts to construct a stratigraphic-range CCD.
- Parameters:
trees – Collection of stratigraphic-range trees used to construct the CCD.
taxon_map – Mapping between taxon labels and integer identifiers from the Nexus file.
- Returns:
A tuple containing the following four objects:
clade_count_map: Dictionary mapping stratigraphic-range clades to their observed counts.clade_split_count_map: Nested dictionary mapping ancestral stratigraphic-range clades to their splits and observed counts.sranges_set: Set of stratigraphic ranges identified during processing.sampled_ancestors: Set of sampled ancestors identified in the trees.
- brokilon.ccd.domain.sranges.sranges.get_sranges_map_tree(clade_count_map, clade_split_count_map, sranges_set, sampled_ancestors)[source]¶
Construct the stratigraphic-range CCD-MAP tree.
Resolves clades in order of increasing size using their observed counts and ancestral split counts. The resolved clades are then used in a dynamic programming algorithm to construct the MAP tree, incorporating stratigraphic ranges and sampled ancestors.
- Args:
- clade_count_map: Dictionary mapping stratigraphic-range clades to
their observed counts.
- clade_split_count_map: Nested dictionary mapping ancestral clades to
their ancestral splits and corresponding counts.
- sranges_set: Set of stratigraphic ranges identified during CCD
construction.
- sampled_ancestors: Set of sampled ancestors identified during CCD
construction.
- Returns:
A tuple containing:
seen_resolved_clades: Dictionary of clades resolved during MAP tree construction, primarily for debugging.
map_tree: The resulting stratigraphic-range CCD-MAP tree.
- brokilon.ccd.domain.sranges.sranges.get_sranges_tree_from_seen_resolved_clades(seen_resolved_clades, root_clade, sranges_set, sampled_ancestors)[source]¶
Construct a stratigraphic-range tree from resolved clades.
Recursively builds a tree from the clades and ancestral splits resolved during MAP tree construction. Adds internal nodes, stratigraphic-range nodes, and sampled ancestors where appropriate, preserving their ancestral-descendant relationships and orientation annotations.
- Parameters:
seen_resolved_clades – Mapping of clades and their resolved ancestral splits used to construct the tree.
root_clade – Root clade of the stratigraphic-range CCD-MAP tree.
sranges_set – Set of stratigraphic ranges identified during CCD construction.
sampled_ancestors – Set of sampled ancestors identified during CCD construction.
- Returns:
The constructed tree, including its stratigraphic-range and orientation annotations.
- brokilon.ccd.domain.sranges.sranges.prelabel_tree(tree, taxon_map)[source]¶
A function to prelabel a stratigraphic-range tree with differnt attributes. These attributes are node features called rangetype and sampledancestor to indicate whether the node is part of a range or displays a SA etc.
- Parameters:
tree – a stratigraphic-range tree
taxon_map – the taxon map
- Returns:
opened_ranges, sampled_ancestors lists for both the ranges that were opened and the SAs