How to use the msprime.SimpleBottleneck 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 / tskit_tests / test_highlevel.py View on Github external
def get_bottleneck_examples():
    """
    Returns an iterator of example tree sequences with nonbinary
    trees.
    """
    bottlenecks = [
        msprime.SimpleBottleneck(0.01, 0, proportion=0.05),
        msprime.SimpleBottleneck(0.02, 0, proportion=0.25),
        msprime.SimpleBottleneck(0.03, 0, proportion=1)]
    for n in [3, 10, 100]:
        ts = msprime.simulate(
            n, length=100, recombination_rate=1,
            demographic_events=bottlenecks,
            random_seed=n)
        yield ts
github tskit-dev / msprime / tskit_tests / test_file_format.py View on Github external
def test_v2_non_binary_records(self):
        demographic_events = [
            msprime.SimpleBottleneck(time=0.01, population=0, proportion=1)
        ]
        ts = msprime.simulate(
            sample_size=10,
            demographic_events=demographic_events,
            random_seed=1)
        self.assertRaises(ValueError, tskit.dump_legacy, ts, self.temp_file, 2)
github tskit-dev / msprime / tests / test_simulate_from.py View on Github external
msprime.PopulationConfiguration(10),
                msprime.PopulationConfiguration(10)],
            migration_matrix=np.zeros((3, 3)),
            recombination_rate=0.5,
            end_time=0.1,
            random_seed=seed)
        ts2 = msprime.simulate(
            population_configurations=[
                msprime.PopulationConfiguration(),
                msprime.PopulationConfiguration(),
                msprime.PopulationConfiguration()],
            migration_matrix=np.zeros((3, 3)),
            from_ts=ts1,
            recombination_rate=0.5,
            demographic_events=[
                msprime.SimpleBottleneck(time=0.5, population=0, proportion=1.0),
                msprime.SimpleBottleneck(time=0.5, population=1, proportion=1.0),
                msprime.SimpleBottleneck(time=0.5, population=2, proportion=1.0),
                msprime.MassMigration(0.61, 1, 0, 1.0),
                msprime.MassMigration(0.61, 2, 0, 1.0),
                msprime.SimpleBottleneck(0.61, population=0, proportion=1.0)],
            random_seed=seed)
        self.assertGreater(ts2.num_trees, 1)
        for tree in ts2.trees():
            # We should have three children at the root, and every node below
            # should be in one population.
            root_children = tree.children(tree.root)
            self.assertEqual(len(root_children), 3)
            populations = {ts2.node(u).population: u for u in root_children}
            self.assertEqual(len(populations), 3)
            for pop in [0, 1, 2]:
                for node in tree.nodes(populations[pop]):
github tskit-dev / msprime / tskit_tests / test_newick.py View on Github external
def get_nonbinary_example(self):
        ts = msprime.simulate(
            sample_size=20, recombination_rate=10, random_seed=self.random_seed,
            demographic_events=[
                msprime.SimpleBottleneck(time=0.5, population=0, proportion=1)])
        # Make sure this really has some non-binary nodes
        found = False
        for e in ts.edgesets():
            if len(e.children) > 2:
                found = True
                break
        self.assertTrue(found)
        return ts
github tskit-dev / msprime / tests / test_highlevel.py View on Github external
def get_bottleneck_examples():
    """
    Returns an iterator of example tree sequences with nonbinary
    trees.
    """
    bottlenecks = [
        msprime.SimpleBottleneck(0.01, 0, proportion=0.05),
        msprime.SimpleBottleneck(0.02, 0, proportion=0.25),
        msprime.SimpleBottleneck(0.03, 0, proportion=1)]
    for n in [3, 10, 100]:
        ts = msprime.simulate(
            n, length=100, recombination_rate=1,
            demographic_events=bottlenecks,
            random_seed=n)
        yield ts
github tskit-dev / msprime / tskit_tests / test_highlevel.py View on Github external
def get_bottleneck_examples():
    """
    Returns an iterator of example tree sequences with nonbinary
    trees.
    """
    bottlenecks = [
        msprime.SimpleBottleneck(0.01, 0, proportion=0.05),
        msprime.SimpleBottleneck(0.02, 0, proportion=0.25),
        msprime.SimpleBottleneck(0.03, 0, proportion=1)]
    for n in [3, 10, 100]:
        ts = msprime.simulate(
            n, length=100, recombination_rate=1,
            demographic_events=bottlenecks,
            random_seed=n)
        yield ts
github mcveanlab / treeseq-inference / tests / test_argmetrics.py View on Github external
def get_nonbinary_example(random_seed=1, sample_size=20, length=10):
    demographic_events = [
        msprime.SimpleBottleneck(time=0.5, proportion=0.9)]
    ts = msprime.simulate(
        sample_size, random_seed=random_seed, demographic_events=demographic_events,
        recombination_rate=2)
    nonbinary = False
    for e in ts.edgesets():
        if len(e.children) > 2:
            nonbinary = True
    assert nonbinary
    assert 5 < ts.num_trees < 100
    return ts
github tskit-dev / msprime / dev.py View on Github external
def subset_samples(n, samples, random_seed=5):
    demographic_events=[msprime.SimpleBottleneck(1000, 0.15)]
    demographic_events = []
    ts = msprime.simulate(
        sample_size=n, Ne=1e4, length=1e4, recombination_rate=5e-8,
        mutation_rate=2e-8, random_seed=random_seed,
        demographic_events=demographic_events)
    # ts = msprime.load(sys.argv[1])

    subset = ts.subset(samples)
    # subset = simplify(ts, samples)

#     print("starting subsetting", len(samples))
#     before = time.clock()
#     subset = ts.subset(samples)
#     duration = time.clock() - before
#     print("Subsetting done", duration)