msprime icon indicating copy to clipboard operation
msprime copied to clipboard

Accept iterators as input in sim_mutations

Open jeromekelleher opened this issue 2 years ago • 0 comments

A significant usability limitation in the 1.0 API is that we can't easily include mutations in a simulation with replicates. I think we could improve this by allowing sim_mutations accept an iterator of tree sequences as input, and return an iterator as output. Something like:

def sim_mutations(ts, ...):
    if isistance(ts, tskit.TreeSequence):
        return _sim_mutations(...)
    else:
        return _sim_mutations_iter(...)


def _sim_mutations_iter(ts_iter, ...):
    for ts in ts_iter:
        yield _sim_mutations(ts, ...)

def _sim_mutations(ts, ...)
    # As before

There'll be some details to work out around random seeds and provenance, but it shouldn't be too bad.

Seems like a worthwhile useability win?

See previous discussions in #1648, #1540

jeromekelleher avatar Jul 25 '21 05:07 jeromekelleher