cassiopeia.tl.calculate_parsimony#

cassiopeia.tl.calculate_parsimony(tree, infer_ancestral_characters=False, treat_missing_as_mutation=False)[source]#

Calculates the number of mutations that have occurred on a tree.

Calculates the parsimony, defined as the number of character/state mutations that occur on edges of the tree, from the character state annotations at the nodes. A mutation is said to have occurred on an edge if a state is present at a character at the child node and this state is not in the parent node.

If infer_ancestral_characters is set to True, then the internal nodes’ character states are inferred by Camin-Sokal Parsimony from the current character states at the leaves. Use tree.set_character_states_at_leaves to use a different layer to infer ancestral states. Otherwise, the current annotations at the internal states are used. If treat_missing_as_mutations is set to True, then transitions from a non-missing state to a missing state are counted in the parsimony calculation. Otherwise, they are not included.

Parameters:
tree CassiopeiaTree

The tree to calculate parsimony over

infer_ancestral_characters bool (default: False)

Whether to infer the ancestral characters states of the tree

treat_missing_as_mutations

Whether to treat missing states as mutations

Return type:

int

Returns:

The number of mutations that have occurred on the tree

Raises:

TreeMetricError if the tree has not been initialized or if – a node does not have character states initialized