Make tqdm(ts.variants()) work better
It would be nice if this would pull out the overall length of the iter. Should be easy enough?
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.
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 https://github.com/tskit-dev/tskit/issues/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.
I don't think the trees iterator is needed for this, as we use the Tree class directly.
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.
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
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