Skip to content

How to skip empty regions at the start and end of a tree seq #2600

Closed
@hyanwong

Description

@hyanwong

We are about to make a change to tsinfer so that the regions before the last site and after the last site in a tree sequence have no topology. I imagine that this could be quite confusing for people looping through the trees, as sometimes (if the first site is not at position 0), the first tree will have num_roots == num_samples, and will not have any topology.

I suspect it would be useful to be able to skip these empty regions at the start and end of a tree sequence when using the trees() iterator. Have we any suggestions for a nice interface to do this? At the moment I'm doing something like this:

for tree in output_ts.trees():
    if tree.num_edges == 0 and (tree.index == 0 or tree.index == ts.num_trees - 1):
        continue
    ...

But I think that might be a bit advanced for normal users to have to do regularly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions