pycea.tl.fitch_count#
- pycea.tl.fitch_count(tdata, key, states=None, missing_state=None, root=None, tree=None, key_added='fitch_count', copy=True)#
Runs the FitchCount algorithm.
Performs the FitchCount algorithm for inferring the number of times that two states transition to one another across all equally-parsimonious solutions returned by the Fitch-Hartigan algorithm. The original algorithm was described in [QJO+21]. The output is an MxM count matrix, where the values indicate the number of times that
m1transitioned tom2along an edge in a Fitch-Hartigan solution. To obtain probabilitiesP(m1 -> m2), divide each row by its row-sum.This procedure will only work on categorical data.
- Parameters:
tdata (
TreeData) – TreeData object.key (
str) – Anobs.keys()corresponding to a categorical variable.states (
Sequence[str] |None(default:None)) – State space that can be optionally provided by the user. If not provided, the unique non-missing values intdata.obs[key]are used.missing_state (
str|None(default:None)) – The state to consider as missing data. Missing leaves are treated as wildcards (may take on any state instates).root (
str|None(default:None)) – Node to treat as the root. Only the subtree below this node is considered. Only valid when a single tree is used.tree (
str|Sequence[str] |None(default:None)) – Theobstkey or keys of the trees to use. IfNone, all trees are used.key_added (
str(default:'fitch_count')) – Key intdata.unswhere the count matrix is stored.copy (
Literal[True,False] (default:True)) – If True, returns the count matrix.
- Return type:
- Returns:
Returns
Noneifcopy=False. Otherwise returns an MxMDataFrame. When multiple trees are used, the per-tree count matrices are summed into a single matrix.Sets the following fields:
tdata.uns[key_added]DataFrameCount matrix, summed across all trees used.
Examples
Count state transitions across equally-parsimonious solutions:
>>> py.tl.fitch_count(tdata, key="tissue", copy=True)