diff --git a/fwdpy11/src/functions/add_mutation.cc b/fwdpy11/src/functions/add_mutation.cc index 2e94a3ae29..1a55f0533f 100644 --- a/fwdpy11/src/functions/add_mutation.cc +++ b/fwdpy11/src/functions/add_mutation.cc @@ -319,6 +319,11 @@ add_mutation(const fwdpy11::GSLrng_t& rng, const double left, const double right } } + for(auto & d : pop.diploids) + { + if(pop.haploid_genomes[d.first].n == 0) { throw std::runtime_error("bad1a"); } + if(pop.haploid_genomes[d.second].n == 0) { throw std::runtime_error("bad2a"); } + } std::size_t new_mutation_key = std::numeric_limits::max(); auto candidates = generate_canidate_list(left, right, ndescendants, deme, pop); diff --git a/tests/test_selective_sweeps.py b/tests/test_selective_sweeps.py index 1d2f62655f..061e2b3111 100644 --- a/tests/test_selective_sweeps.py +++ b/tests/test_selective_sweeps.py @@ -30,12 +30,12 @@ def make_pop_with_msprime_ancestry(seed): - N = 500 + N = 100 rho = 1000 L = 1.0 initial_ts = msprime.sim_ancestry( samples=N, - population_size=1000, + population_size=2 * N, recombination_rate=rho / 4 / N, random_seed=seed, sequence_length=L, @@ -59,7 +59,7 @@ def run_selective_sweep( msprime_seed, fp11_seed, ndescendants, - N=500, + N=100, alpha=1000, # 2Ns rho=100, L=1.0, @@ -67,7 +67,7 @@ def run_selective_sweep( ): for initial_ts in msprime.sim_ancestry( samples=N, - population_size=1000, + population_size=2 * N, recombination_rate=rho / 4 / N, random_seed=msprime_seed, sequence_length=1.0, @@ -91,6 +91,13 @@ def run_selective_sweep( if idx is None: continue + c = 0 + for dip in pop.diploids: + for genome in [dip.first, dip.second]: + if idx in pop.haploid_genomes[genome].smutations: + c += 1 + assert c == ndescendants + # Make sure we've chosen a valid time assert ( pop.mutations[idx].g <= pop.tables.nodes[pop.tables.mutations[0].node].time @@ -135,7 +142,7 @@ def test_sweep_from_new_mutation(msprime_seed, fp11_seed): @pytest.mark.parametrize("msprime_seed", seed_list(135123, 5)) @pytest.mark.parametrize("fp11_seed", seed_list(5130125, 5)) -@pytest.mark.parametrize("ndescendants", [2, 7, 10, 23, 100, 257]) +@pytest.mark.parametrize("ndescendants", [2, 7, 10, 23, 12, 100]) def test_sweep_from_standing_variation(msprime_seed, fp11_seed, ndescendants): pop_with_fixation, idx = run_selective_sweep(msprime_seed, fp11_seed, ndescendants) if pop_with_fixation is not None: @@ -162,11 +169,7 @@ def test_sweep_from_new_mutation_using_API(msprime_seed, fp11_seed, alpha): "window": (0.49, 0.51), } rng = fwdpy11.GSLrng(fp11_seed) - ( - pop_with_fixation, - idx, - _, - ) = fwdpy11.conditional_models.selective_sweep( + (pop_with_fixation, idx, _,) = fwdpy11.conditional_models.selective_sweep( rng, pop, params, @@ -181,7 +184,7 @@ def test_sweep_from_new_mutation_using_API(msprime_seed, fp11_seed, alpha): @pytest.mark.parametrize("msprime_seed", seed_list(135123, 5)) @pytest.mark.parametrize("fp11_seed", seed_list(5130125, 5)) -@pytest.mark.parametrize("ndescendants", [2, 7, 10, 23, 100, 257]) +@pytest.mark.parametrize("ndescendants", [2, 7, 10, 23, 12, 100]) @pytest.mark.parametrize("alpha", [1000.0]) def test_sweep_from_standing_variation_using_API( msprime_seed, fp11_seed, ndescendants, alpha @@ -200,13 +203,10 @@ def test_sweep_from_standing_variation_using_API( "data": fwdpy11.NewMutationData(effect_size=alpha / 2 / pop.N, dominance=1.0), "window": (0.49, 0.51), } + finished = False + rng = fwdpy11.GSLrng(fp11_seed) try: - rng = fwdpy11.GSLrng(fp11_seed) - ( - pop_with_fixation, - idx, - _, - ) = fwdpy11.conditional_models.selective_sweep( + (pop_with_fixation, idx, _,) = fwdpy11.conditional_models.selective_sweep( rng, pop, params, @@ -217,6 +217,7 @@ def test_sweep_from_standing_variation_using_API( if pop_with_fixation is not None: assert pop_with_fixation.mcounts[idx] == 2 * pop_with_fixation.N _ = pop_with_fixation.dump_tables_to_tskit() + finished = True except fwdpy11.conditional_models.AddMutationFailure as a: pass except Exception as e: @@ -334,11 +335,7 @@ def test_sweep_from_new_mutation_in_singe_deme_using_API(fp11_seed, demes_yaml, "window": (0.49, 0.51), } rng = fwdpy11.GSLrng(fp11_seed) - ( - pop_with_fixation, - idx, - _, - ) = fwdpy11.conditional_models.selective_sweep( + (pop_with_fixation, idx, _,) = fwdpy11.conditional_models.selective_sweep( rng, pop, params, @@ -389,11 +386,7 @@ def test_sweep_from_new_mutation_with_demography_using_API( "window": (0.49, 0.51), } rng = fwdpy11.GSLrng(fp11_seed) - ( - pop_with_fixation, - idx, - _, - ) = fwdpy11.conditional_models.selective_sweep( + (pop_with_fixation, idx, _,) = fwdpy11.conditional_models.selective_sweep( rng, pop, params, @@ -438,11 +431,7 @@ def test_origination_deme1_fixation_in_deme_2(fp11_seed, demes_yaml, alpha): "window": (0.49, 0.51), } rng = fwdpy11.GSLrng(fp11_seed) - ( - pop_with_fixation, - idx, - _, - ) = fwdpy11.conditional_models.selective_sweep( + (pop_with_fixation, idx, _,) = fwdpy11.conditional_models.selective_sweep( rng, pop, params, @@ -547,11 +536,7 @@ def test_origination_deme2_fixation_in_deme_2_no_migration( "window": (0.49, 0.51), } rng = fwdpy11.GSLrng(fp11_seed) - ( - pop_with_fixation, - idx, - _, - ) = fwdpy11.conditional_models.selective_sweep( + (pop_with_fixation, idx, _,) = fwdpy11.conditional_models.selective_sweep( rng, pop, params,