From 71c699b44edece9203d6ef0a790030cc177fdee8 Mon Sep 17 00:00:00 2001 From: Yan Wong Date: Fri, 18 Nov 2022 11:12:08 +0000 Subject: [PATCH] Correct logic for definition of roots To include root_threshold --- python/tskit/trees.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/python/tskit/trees.py b/python/tskit/trees.py index 814e0103c2..7b58c37917 100644 --- a/python/tskit/trees.py +++ b/python/tskit/trees.py @@ -1527,8 +1527,9 @@ 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 @@ -1536,7 +1537,8 @@ def roots(self): 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)