tskit-dev / msprime

Simulate genealogical trees and genomic sequence data using population genetic models
GNU General Public License v3.0
170 stars 84 forks source link

recording migrants with sweep model #2190

Closed GertjanBisschop closed 9 months ago

GertjanBisschop commented 11 months ago

I was trying to record msprime.NodeType.MIGRANT in the SweepGenicModel. In theory, this should allow us to record lineages that recombine away from the selected background (= changing labels in the structured coalescent).

Ne = 10_000
model = msprime.SweepGenicSelection(position=10, start_frequency=0.1, end_frequency=0.9, s=0.01, dt=1/(40 * Ne))
msprime.sim_ancestry(
    samples=4,
    model=model, 
    recombination_rate=1e-8, 
    sequence_length=1000, 
    coalescing_segments_only=False, 
    additional_nodes=msprime.NodeType.MIGRANT,
    population_size=Ne
)

This returns the following error: msprime._msprime.LibraryError: The simulation model supplied resulted in a parent node having a time value <= to its child. This can occur as a result of multiple bottlenecks happening at the same time, multiple census events at the same time or numerical imprecision with very smallpopulation sizes.

This is due to how the sweep is set up: msp_sweep_initialise. The move individuals function is applied here to the sampled lineages. We shouldn't be registering an additional node here. The same error will happen when the sweep is finalised I think.

molpopgen commented 11 months ago

In the long run, recording events this way may cause some issues. Arguably, one goal is for msprime to replace, e.g., discoal, in terms of functionality. If that happens, then the notion of a "migration" will get overloaded: between fitness classes and between "real" demes.

GertjanBisschop commented 11 months ago

Yes, agreed. We need a new msprime.NodeType, or a way of recording fitness classes in a flexible way. In the mean time I will make sure we throw an error when trying to record MIGRANTS for the SweepGenicModel.

GertjanBisschop commented 9 months ago

Solved in #2199.