pycea.tl.parsimony#
- pycea.tl.parsimony(tdata, key, method='fitch_hartigan', missing_state=None, costs=None, reconstruct=True, tree=None, key_added='parsimony', copy=True)#
Computes the small-parsimony score of a tree.
The parsimony score is the number of edges along which the state of a categorical attribute changes. Ancestral states can be reconstructed on the fly (default) or read from states already present on the tree.
- Parameters:
tdata (
TreeData) – TreeData object.key (
str) – Anobs.keys()corresponding to a categorical variable.method (
str|Callable(default:'fitch_hartigan')) – Method used to reconstruct ancestral states whenreconstruct=True. Passed topycea.tl.ancestral_states(). Typically'fitch_hartigan'or'sankoff'.missing_state (
str|None(default:None)) – The state to consider as missing data. Edges touching a missing state are not counted.costs (
DataFrame|None(default:None)) – ADataFramewith the costs of changing states (from rows to columns). Only used ifmethod='sankoff'.reconstruct (
bool(default:True)) – If True, reconstruct ancestral states withpycea.tl.ancestral_states()before scoring. If False, use states already stored underkeyon the tree.tree (
str|Sequence[str] |None(default:None)) – Theobstkey or keys of the trees to use. IfNone, all trees are used.key_added (
str(default:'parsimony')) – Key intdata.unswhere the parsimony score(s) are stored.copy (
Literal[True,False] (default:True)) – If True, returns the parsimony score(s).
- Return type:
- Returns:
Returns
Noneifcopy=False. Otherwise returns anintfor a single tree, or aSeriesof scores indexed by tree for multiple trees.Sets the following fields:
tdata.uns[key_added]int|SeriesParsimony score for a single tree, or a Series of scores for multiple trees.
Examples
Compute the parsimony score of a categorical character:
>>> py.tl.parsimony(tdata, key="clone")