How to use the msprime.RecombinationMap.uniform_map function in msprime

To help you get started, we’ve selected a few msprime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tskit-dev / msprime / tests / test_simulate_from.py View on Github external
def test_small_num_loci(self):
        for m in [1, 10, 16, 100]:
            recombination_map = msprime.RecombinationMap.uniform_map(10, 1, num_loci=m)
            from_ts = msprime.simulate(
                sample_size=4, end_time=1, random_seed=5,
                recombination_map=recombination_map)
            self.assertGreater(max(tree.num_roots for tree in from_ts.trees()), 1)
            start_time = from_ts.tables.nodes.time.max()
            final_ts = msprime.simulate(
                from_ts=from_ts, start_time=start_time, random_seed=2,
                recombination_map=recombination_map)
            self.verify_from_tables(from_ts, final_ts, start_time)
            self.verify_simulation_completed(final_ts)
github tskit-dev / msprime / tests / test_simulate_from.py View on Github external
def finish_simulation(self, from_ts, recombination_rate=0, seed=1):
        population_configurations = [
            msprime.PopulationConfiguration() for _ in range(from_ts.num_populations)]
        return msprime.simulate(
            from_ts=from_ts, start_time=1,
            population_configurations=population_configurations,
            recombination_map=msprime.RecombinationMap.uniform_map(
                from_ts.sequence_length, recombination_rate,
                num_loci=int(from_ts.sequence_length)),
            random_seed=seed)
github tskit-dev / msprime / tests / test_highlevel.py View on Github external
def test_bad_inputs(self):
        recomb_map = msprime.RecombinationMap.uniform_map(1, 0)
        for bad_type in ["xd", None, 4.4]:
            self.assertRaises(
                TypeError, msprime.Simulator, [(0, 0), (0, 0)], bad_type)
        self.assertRaises(ValueError, msprime.Simulator, [], recomb_map)
        self.assertRaises(ValueError, msprime.Simulator, [(0, 0)], recomb_map)
github mcveanlab / treeseq-inference / tests / test_msprime_extras.py View on Github external
def test_nominal_case(self):
        recomb_map = msprime.RecombinationMap.uniform_map(
            length=3000, rate=0.005, num_loci=3000)
        ts = msprime.simulate(
            10, recombination_map=recomb_map, mutation_rate=0.005, random_seed=1)
        self.assertGreater(ts.num_records, 20)
        self.assertGreater(ts.num_mutations, 10)
        self.assertLess(ts.num_mutations, 500)
        self.verify_discretise(ts)
github tskit-dev / msprime / tskit_tests / test_highlevel.py View on Github external
def verify_simulation(self, n, m, r, theta):
        """
        Verifies a simulation for the specified parameters.
        """
        recomb_map = msprime.RecombinationMap.uniform_map(m, r, m)
        tree_sequence = msprime.simulate(
            n, recombination_map=recomb_map, mutation_rate=theta)
        self.verify_tree_sequence(tree_sequence)
github tskit-dev / msprime / tests / test_minimise.py View on Github external
def get_integer_edge_ts(self, n, m):
        recombination_map = msprime.RecombinationMap.uniform_map(m, 1, num_loci=m)
        ts = msprime.simulate(n, random_seed=1, recombination_map=recombination_map)
        self.assertGreater(ts.num_trees, 1)
        for edge in ts.edges():
            self.assertEqual(int(edge.left), edge.left)
            self.assertEqual(int(edge.right), edge.right)
        return ts
github tskit-dev / tsinfer / tests / test_evaluation.py View on Github external
def test_multiple_recombinations(self):
        try:
            recomb_map = msprime.RecombinationMap.uniform_map(
                length=10, rate=10, discrete=True
            )
        except TypeError:
            # Fallback for older versions of msprime, which use num_loci
            recomb_map = msprime.RecombinationMap.uniform_map(
                length=10, rate=10, num_loci=10
            )
        ts = msprime.simulate(10, recombination_map=recomb_map, random_seed=1)
        found = False
        for _, e_out, _ in ts.edge_diffs():
            if len(e_out) > 4:
                found = True
                break
        self.assertTrue(found)
        self.assertRaises(ValueError, tsinfer.insert_perfect_mutations, ts)
github tskit-dev / tsinfer / tests / test_evaluation.py View on Github external
def test_multiple_recombinations(self):
        try:
            recomb_map = msprime.RecombinationMap.uniform_map(
                length=10, rate=10, discrete=True
            )
        except TypeError:
            # Fallback for older versions of msprime, which use num_loci
            recomb_map = msprime.RecombinationMap.uniform_map(
                length=10, rate=10, num_loci=10
            )
        ts = msprime.simulate(10, recombination_map=recomb_map, random_seed=1)
        found = False
        for _, e_out, _ in ts.edge_diffs():
            if len(e_out) > 4:
                found = True
                break
        self.assertTrue(found)
        self.assertRaises(ValueError, tsinfer.insert_perfect_mutations, ts)
github mcveanlab / treeseq-inference / src / plots.py View on Github external
If Ne is a string, it is an identified used for the population model
        which will be saved into the filename & results file, while the simulation
        will be called with Ne=1

        replicate is useful to pass in for error messages etc.

        Returns a tuple of treesequence, filename (without file type extension)
        """
        logging.info(
            "Running neutral simulation for "
            "n = {}, l = {:.2g}, Ne = {}, rho = {}, mu = {}".format(
                sample_size, length, Ne, recombination_rate, mutation_rate))
        # Since we want to have a finite site model, we force the recombination map
        # to have exactly l loci with a recombination rate of rho between them.
        recombination_map = msprime.RecombinationMap.uniform_map(length, recombination_rate, length)
        rng1 = random.Random(seed)
        sim_seed = rng1.randint(1, 2**31)
        if "population_configurations" in kwargs:
            Ne_used = 1
            n_used = None
        else:
            Ne_used = Ne
            n_used = sample_size
        if mut_seed is None:
            ts = msprime.simulate(
                n_used, Ne_used, recombination_map=recombination_map, mutation_rate=mutation_rate,
                random_seed=sim_seed, **kwargs)
        else:
            #run with no mutations (should give same result regardless of mutation rate)
            ts = msprime.simulate(
                n_used, Ne_used, recombination_map=recombination_map, mutation_rate=0,