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

Make tqdm(ts.variants()) work better #2625

Open
jeromekelleher opened this issue Nov 2, 2022 · 6 comments · May be fixed by #2762
Open

Make tqdm(ts.variants()) work better #2625

jeromekelleher opened this issue Nov 2, 2022 · 6 comments · May be fixed by #2762
Labels
enhancement New feature or request Python API Issue is about the Python API
Milestone

Comments

@jeromekelleher
Copy link
Member

It would be nice if this would pull out the overall length of the iter. Should be easy enough?

@jeromekelleher jeromekelleher added enhancement New feature or request Python API Issue is about the Python API labels Nov 2, 2022
@jeromekelleher
Copy link
Member Author

Should be straightforward, we just have to abstract the code for the variants function into an iterator class (which returns the right len), a bit like the current TreeIterator class.

@benjeffery benjeffery added this to the Python 0.5.5 (paper) milestone Nov 2, 2022
@hyanwong
Copy link
Member

hyanwong commented May 2, 2023

Just revisiting this. The variants() method has left and right parameters, so it's a bit more complicated. An iterator would need to know not just ts.num_sites, but the number of sites between left and right. I suspect we would also want to change the trees() iterator to have left and right too (see #24), so perhaps we should implement that first, change the TreeIterator to account for that, then use the same basic function to add len to the variants iterator.

@jeromekelleher
Copy link
Member Author

I don't think the trees iterator is needed for this, as we use the Tree class directly.

@hyanwong
Copy link
Member

hyanwong commented May 2, 2023

Sorry, I mean that the code that produces the TreeIterator wrapper could generalised to provide a wrapper that would work (subclassed, presumably) for the Variants. But only if there was a generalised way to deal with left and right.

@benjeffery
Copy link
Member

Breakpoints are stored on the tree sequence object, and are accessible from Python, so I think that could be used to get a count of the trees in the interval for len

@hyanwong
Copy link
Member

hyanwong commented May 3, 2023

Breakpoints are stored on the tree sequence object, and are accessible from Python, so I think that could be used to get a count of the trees in the interval for len

Yeah, this does it, I think:

ts._check_genomic_range(left, right)
breaks = ts.breakpoints(as_array=True)
left_index = breaks.searchsorted(left, side="right")
right_index = breaks.searchsorted(right, side="left")
num_trees = right_index - left_index + 1

@hyanwong hyanwong linked a pull request Jun 13, 2023 that will close this issue
3 tasks
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