Skip to content

Commit

Permalink
Correct logic for definition of roots
Browse files Browse the repository at this point in the history
To include root_threshold
  • Loading branch information
hyanwong authored and mergify[bot] committed Nov 21, 2022
1 parent 0928172 commit 71c699b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions python/tskit/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -1527,16 +1527,18 @@ def has_multiple_roots(self):
@property
def roots(self):
"""
The list of roots in this tree. A root is defined as a unique endpoint of
the paths starting at samples. We can define the set of roots as follows:
The list of roots in this tree. A root is defined as a unique endpoint of the
paths starting at samples, subject to the condition that it is connected to at
least :attr:`root_threshold` samples. We can define the set of roots as follows:
.. code-block:: python
roots = set()
for u in tree_sequence.samples():
while tree.parent(u) != tskit.NULL:
u = tree.parent(u)
roots.add(u)
if tree.num_samples(u) >= tree.root_threshold:
roots.add(u)
# roots is now the set of all roots in this tree.
assert sorted(roots) == sorted(tree.roots)
Expand Down

0 comments on commit 71c699b

Please sign in to comment.