Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree.is_root() method #2620

Closed
hyanwong opened this issue Oct 31, 2022 · 3 comments · Fixed by #2669
Closed

tree.is_root() method #2620

hyanwong opened this issue Oct 31, 2022 · 3 comments · Fixed by #2669
Assignees
Labels
enhancement New feature or request Python API Issue is about the Python API

Comments

@hyanwong
Copy link
Member

It's tempting to check whether a node is a root by looking for u in tree.roots without realising that tree.roots might be huge. I think a more efficient way to check is

def is_root(self, u)
    return self.num_samples(u) > 0 and self.parent(u) == tskit.NULL

Is that right @jeromekelleher ? This might be useful for @szhan in #2618

@hyanwong hyanwong mentioned this issue Oct 31, 2022
3 tasks
@jeromekelleher
Copy link
Member

Yes I agree this is useful. Your code is almost right, we just have to change the num_samples > 0 to take the root threshold into account. (I can't remember what the motivation for root threshold is, it's in the git blame presumably!)

@hyanwong
Copy link
Member Author

Oh yes, I forgot about that. So many complex parts!

@hyanwong
Copy link
Member Author

So I guess:

def is_root(self, u)
    return self.num_samples(u) >= self.root_threshold and self.parent(u) == tskit.NULL

@szhan szhan added enhancement New feature or request Python API Issue is about the Python API labels Oct 31, 2022
@szhan szhan self-assigned this Oct 31, 2022
hyanwong added a commit to hyanwong/tskit that referenced this issue Dec 23, 2022
@hyanwong hyanwong mentioned this issue Dec 23, 2022
3 tasks
hyanwong added a commit to hyanwong/tskit that referenced this issue Dec 23, 2022
hyanwong added a commit to hyanwong/tskit that referenced this issue Jan 10, 2023
@mergify mergify bot closed this as completed in #2669 Jan 10, 2023
mergify bot pushed a commit that referenced this issue Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Python API Issue is about the Python API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants