tskit icon indicating copy to clipboard operation
tskit copied to clipboard

Generic iterator class for trees and variants

Open hyanwong opened this issue 2 years ago • 1 comments

Description

Pull out the logic that iterates over trees and variants into a single base class, and allow this class to return a length. Also allows left, right, copy to be passed to the trees() iterator (to match the variants() iterator), so that we can iterate over a subset of the genome.

Also implements next() and prev() for trees, to match the variants iterator (they are handy anyway, right?)

Fixes https://github.com/tskit-dev/tskit/issues/2625, https://github.com/tskit-dev/tskit/issues/24

PR Checklist:

  • [x] Tests that fully cover new/changed functionality.
  • [x] Documentation including tutorial content if appropriate.
  • [ ] Changelogs, if there are API changes.

hyanwong avatar Jun 13 '23 11:06 hyanwong

BTW, this renders ts.aslist() a bit obsolete, as you can do ts.trees(copy=True), in the same way you do for variants.

hyanwong avatar Jun 13 '23 11:06 hyanwong