def testPopGenSim(self): N = 1000 demography = np.array([N] * 10 * N, dtype=np.uint32) rho = 1. r = rho / (4 * N) a = fwdpy11.Multiplicative(2.0) p = { 'nregions': [], 'sregions': [fwdpy11.ExpS(0, 1, 1, 0.01)], 'recregions': [fwdpy11.Region(0, 1, 1)], 'rates': (0.0, 0.00005, r), 'gvalue': a, 'prune_selected': True, 'demography': demography } params = fwdpy11.ModelParams(**p) rng = fwdpy11.GSLrng(101 * 45 * 110 * 210) pop = fwdpy11.DiploidPopulation(N, 1.0) fwdpy11.evolvets(rng, pop, params, 100, track_mutation_counts=True) mc = fwdpy11.count_mutations(pop.tables, pop.mutations, [i for i in range(2 * pop.N)]) assert len(pop.fixations) > 0, "Test is meaningless without fixations" fixations = np.where(mc == 2 * pop.N)[0] self.assertEqual(len(fixations), 0) # Brute-force calculation of fixations brute_force = np.zeros(len(pop.mutations), dtype=np.int32) for g in pop.haploid_genomes: if g.n > 0: for k in g.smutations: brute_force[k] += g.n self.assertTrue(np.array_equal(brute_force, mc)) self.assertTrue(np.array_equal(brute_force, pop.mcounts))
def test_count_mutations_preserved_samples(self): mc = fwdpy11.count_mutations(self.pop, self.pop.tables.preserved_nodes) pmc = np.array(self.pop.mcounts_ancient_samples) self.assertTrue(np.array_equal(mc, pmc))
def test_count_mutations(self): mc = fwdpy11.count_mutations(self.pop, [i for i in range(2 * self.pop.N)]) pmc = np.array(self.pop.mcounts) self.assertTrue(np.array_equal(mc, pmc))