Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/topological-analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,30 @@ on high performance methods including the `numba` approach.
:::


(sec_simplification_roots)=

## Roots after simplification

With the default options, {meth}`TreeSequence.simplify` removes ancestry above
the most recent common ancestors (MRCAs) of the selected samples. With
`keep_unary=True`, it retains nodes that have one child in the ancestry of
the selected samples. This can include nodes above their MRCAs, even with
`keep_input_roots=False`.

In this three-sample tree, samples 1 and 2 share an MRCA at time 1. Simplifying
to those two samples makes their MRCA the root with the default options. With
`keep_unary=True`, the original root at time 2 remains and has one child.

```{code-cell} ipython3
comb_ts = tskit.Tree.generate_comb(3).tree_sequence
for keep_unary in (False, True):
simplified_tree = comb_ts.simplify(
[1, 2], keep_unary=keep_unary, keep_input_roots=False
).first()
print(f"{keep_unary=}, root time = {simplified_tree.time(simplified_tree.root)}")
```


(sec_combinatorics)=

## Identifying and counting topologies
Expand Down
10 changes: 5 additions & 5 deletions python/tskit/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3651,11 +3651,11 @@ def simplify(
associated with an individual in the individuals table. Cannot be
specified at the same time as ``keep_unary``. (Default: ``None``,
equivalent to False)
:param bool keep_input_roots: Whether to retain history ancestral to the
MRCA of the samples. If ``False``, no topology older than the MRCAs of the
samples will be included. If ``True`` the roots of all trees in the returned
tree sequence will be the same roots as in the original tree sequence.
(Default: False)
:param bool keep_input_roots: If ``True``, retain the roots of the input trees
that are ancestral to the selected samples. If ``False``, ancestry above the
most recent common ancestors of the samples can still be retained by
``keep_unary`` or ``keep_unary_in_individuals``.
See :ref:`sec_simplification_roots` for an example. (Default: False)
:param bool record_provenance: If True, record details of this call to
simplify in the returned tree sequence's provenance information
(Default: True).
Expand Down
10 changes: 5 additions & 5 deletions python/tskit/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -7082,11 +7082,11 @@ def simplify(
associated with an individual in the individuals table. Cannot be
specified at the same time as ``keep_unary``. (Default: ``None``,
equivalent to False)
:param bool keep_input_roots: Whether to retain history ancestral to the
MRCA of the samples. If ``False``, no topology older than the MRCAs of the
samples will be included. If ``True`` the roots of all trees in the returned
tree sequence will be the same roots as in the original tree sequence.
(Default: False)
:param bool keep_input_roots: If ``True``, retain the roots of the input trees
that are ancestral to the selected samples. If ``False``, ancestry above the
most recent common ancestors of the samples can still be retained by
``keep_unary`` or ``keep_unary_in_individuals``.
See :ref:`sec_simplification_roots` for an example. (Default: False)
:param bool record_provenance: If True, record details of this call to
simplify in the returned tree sequence's provenance information
(Default: True).
Expand Down