• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python msprime.simulate函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中msprime.simulate函数的典型用法代码示例。如果您正苦于以下问题:Python simulate函数的具体用法?Python simulate怎么用?Python simulate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了simulate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_two_populations_no_migration_one_locus

 def test_two_populations_no_migration_one_locus(self):
     seed = 1234
     ts1 = msprime.simulate(
         population_configurations=[
             msprime.PopulationConfiguration(10),
             msprime.PopulationConfiguration(10)],
         migration_matrix=np.zeros((2, 2)),
         __tmp_max_time=0.1,
         random_seed=seed)
     ts2 = msprime.simulate(
         population_configurations=[
             msprime.PopulationConfiguration(),
             msprime.PopulationConfiguration()],
         migration_matrix=np.zeros((2, 2)),
         from_ts=ts1,
         demographic_events=[
             msprime.MassMigration(100, 0, 1, 1.0)],
         random_seed=seed)
     tree = ts2.first()
     # We should have two children at the root, and every node below
     # should be in one population.
     root_children = tree.children(tree.root)
     self.assertEqual(len(root_children), 2)
     populations = {ts2.node(u).population: u for u in root_children}
     self.assertEqual(len(populations), 2)
     for pop in [0, 1]:
         for node in tree.nodes(populations[pop]):
             self.assertEqual(ts2.node(node).population, pop)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:28,代码来源:test_simulate_from.py


示例2: test_gaps

    def test_gaps(self):
        # SMC simulations should never have adjacent edgesets with
        # a non-zero distance between them and the same parent.
        # First we do a simulation with the standard model to make sure
        # we have plausible parameter values.
        sample_size = 10
        recombination_rate = 20
        random_seed = 1

        ts = msprime.simulate(
            sample_size=sample_size, recombination_rate=recombination_rate,
            random_seed=random_seed)
        edgesets = sorted(ts.edgesets(), key=lambda e: (e.parent, e.left))
        num_found = 0
        for j in range(1, len(edgesets)):
            r = edgesets[j - 1]
            s = edgesets[j]
            if r.right != s.left and r.parent == s.parent:
                num_found += 1
        self.assertGreater(num_found, 10)  # Make a reasonable threshold

        # Now do the same for SMC and SMC'.
        for model in ["smc", "smc_prime"]:
            ts = msprime.simulate(
                sample_size=sample_size, recombination_rate=recombination_rate,
                random_seed=random_seed, model=model)
            edgesets = sorted(ts.edgesets(), key=lambda e: (e.parent, e.left))
            num_found = 0
            for j in range(1, len(edgesets)):
                r = edgesets[j - 1]
                s = edgesets[j]
                if r.right != s.left and r.parent == s.parent:
                    num_found += 1
            self.assertEqual(num_found, 0)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:34,代码来源:test_models.py


示例3: test_simple_cases

 def test_simple_cases(self):
     for n in range(2, 10):
         st = next(msprime.simulate(n).trees())
         self.verify_sparse_tree(st)
     for n in [11, 13, 19, 101]:
         st = next(msprime.simulate(n).trees())
         self.verify_sparse_tree(st)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:7,代码来源:test_highlevel.py


示例4: test_two_populations_migration

 def test_two_populations_migration(self):
     n = 10
     seed = 1234
     ts1 = msprime.simulate(
         population_configurations=[
             msprime.PopulationConfiguration(n),
             msprime.PopulationConfiguration(0)],
         migration_matrix=[[0, 1], [1, 0]],
         random_seed=seed)
     tables = msprime.TableCollection(1)
     tables.populations.add_row()
     tables.populations.add_row()
     for _ in range(n):
         tables.nodes.add_row(
             flags=msprime.NODE_IS_SAMPLE, time=0, population=0)
     ts2 = msprime.simulate(
         from_ts=tables.tree_sequence(), start_time=0,
         population_configurations=[
             msprime.PopulationConfiguration(),
             msprime.PopulationConfiguration()],
         migration_matrix=[[0, 1], [1, 0]],
         random_seed=seed)
     tables1 = ts1.dump_tables()
     tables2 = ts2.dump_tables()
     tables1.provenances.clear()
     tables2.provenances.clear()
     self.assertEqual(tables1, tables2)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:27,代码来源:test_simulate_from.py


示例5: test_sequence_length

 def test_sequence_length(self):
     from_ts = msprime.simulate(
         5, __tmp_max_time=0.1, random_seed=5, length=5)
     start_time = from_ts.tables.nodes.time.max()
     final_ts = msprime.simulate(
         from_ts=from_ts, start_time=start_time, random_seed=2, length=5)
     self.verify_from_tables(from_ts, final_ts, start_time)
     self.verify_simulation_completed(final_ts)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:8,代码来源:test_simulate_from.py


示例6: test_single_locus_max_time

 def test_single_locus_max_time(self):
     from_ts = msprime.simulate(20, __tmp_max_time=1, random_seed=5)
     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)
     self.verify_from_tables(from_ts, final_ts, start_time)
     self.verify_simulation_completed(final_ts)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:8,代码来源:test_simulate_from.py


示例7: test_from_single_locus_decapitated

 def test_from_single_locus_decapitated(self):
     ts = msprime.simulate(10, random_seed=5)
     from_ts = tsutil.decapitate(ts, ts.num_edges // 2)
     start_time = from_ts.tables.nodes.time.max()
     final_ts = msprime.simulate(
         from_ts=from_ts, start_time=start_time, random_seed=2)
     self.verify_from_tables(from_ts, final_ts, start_time)
     self.verify_simulation_completed(final_ts)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:8,代码来源:test_simulate_from.py


示例8: test_provenance

 def test_provenance(self):
     ts = msprime.simulate(10)
     self.assertEqual(ts.num_provenances, 1)
     self.verify_provenance(ts.provenance(0))
     # TODO check the form of the dictionary
     for ts in msprime.simulate(10, num_replicates=10):
         self.assertEqual(ts.num_provenances, 1)
         self.verify_provenance(ts.provenance(0))
开发者ID:jeromekelleher,项目名称:msprime,代码行数:8,代码来源:test_highlevel.py


示例9: test_sequence_length_mismatch

 def test_sequence_length_mismatch(self):
     base_ts = self.get_example_base(length=5)
     for bad_length in [1, 4.99, 5.01, 100]:
         with self.assertRaises(ValueError):
             msprime.simulate(from_ts=base_ts, start_time=100, length=bad_length)
         recomb_map = msprime.RecombinationMap.uniform_map(bad_length, 1)
         with self.assertRaises(ValueError):
             msprime.simulate(
                 from_ts=base_ts, start_time=100, recombination_map=recomb_map)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:9,代码来源:test_simulate_from.py


示例10: test_decapitated_mutations

 def test_decapitated_mutations(self):
     ts = msprime.simulate(10, random_seed=5, mutation_rate=10)
     from_ts = tsutil.decapitate(ts, ts.num_edges // 2)
     self.assertGreater(from_ts.num_mutations, 0)
     start_time = from_ts.tables.nodes.time.max()
     final_ts = msprime.simulate(
         from_ts=from_ts, start_time=start_time, random_seed=2)
     self.verify_from_tables(from_ts, final_ts, start_time)
     self.verify_simulation_completed(final_ts)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:9,代码来源:test_simulate_from.py


示例11: test_individuals

 def test_individuals(self):
     from_ts = msprime.simulate(25, random_seed=5, __tmp_max_time=0.5)
     self.assertTrue(any(tree.num_roots > 1 for tree in from_ts.trees()))
     from_ts = tsutil.insert_random_ploidy_individuals(from_ts, seed=2)
     start_time = from_ts.tables.nodes.time.max()
     final_ts = msprime.simulate(
         from_ts=from_ts, start_time=start_time, random_seed=2)
     self.verify_from_tables(from_ts, final_ts, start_time)
     self.verify_simulation_completed(final_ts)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:9,代码来源:test_simulate_from.py


示例12: test_from_multi_locus_old_recombination

 def test_from_multi_locus_old_recombination(self):
     ts = msprime.simulate(10, recombination_rate=2, random_seed=5)
     self.assertGreater(ts.num_trees, 1)
     from_ts = tsutil.decapitate(ts, ts.num_edges // 2)
     start_time = from_ts.tables.nodes.time.max()
     final_ts = msprime.simulate(
         from_ts=from_ts, start_time=start_time, random_seed=2,
         recombination_rate=2)
     self.verify_from_tables(from_ts, final_ts, start_time)
     self.verify_simulation_completed(final_ts)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:10,代码来源:test_simulate_from.py


示例13: test_models

 def test_models(self):
     # Exponential growth of 0 and constant model should be identical.
     for n in [2, 10, 100]:
         m1 = msprime.PopulationConfiguration(n, growth_rate=0)
         m2 = msprime.PopulationConfiguration(n, initial_size=1.0)
         st1 = next(msprime.simulate(
             random_seed=1, population_configurations=[m1]).trees())
         st2 = next(msprime.simulate(
             random_seed=1, population_configurations=[m2]).trees())
         self.assertEqual(st1.parent_dict, st2.parent_dict)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:10,代码来源:test_highlevel.py


示例14: test_population_mismatch

 def test_population_mismatch(self):
     for N in range(1, 5):
         base_ts = self.get_example_base(num_populations=N)
         start_time = max(node.time for node in base_ts.nodes())
         for k in range(1, N):
             if k != N:
                 with self.assertRaises(ValueError):
                     msprime.simulate(
                         from_ts=base_ts, start_time=start_time,
                         population_configurations=[
                             msprime.PopulationConfiguration() for _ in range(k)])
开发者ID:jeromekelleher,项目名称:msprime,代码行数:11,代码来源:test_simulate_from.py


示例15: test_zero_recombination_rate

 def test_zero_recombination_rate(self):
     from_ts = msprime.simulate(
         sample_size=4, __tmp_max_time=1, random_seed=5, recombination_rate=1)
     self.assertGreater(max(tree.num_roots for tree in from_ts.trees()), 1)
     start_time = from_ts.tables.nodes.time.max()
     with self.assertRaises(_msprime.InputError):
         # Raises:
         # The specified recombination map is too coarse to translate...
         msprime.simulate(
             from_ts=from_ts, start_time=start_time, random_seed=2,
             recombination_rate=0)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:11,代码来源:test_simulate_from.py


示例16: test_small_num_loci

 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, __tmp_max_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)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:13,代码来源:test_simulate_from.py


示例17: test_nonuniform_recombination_map

 def test_nonuniform_recombination_map(self):
     positions = [0, 0.25, 0.5, 0.75, 1]
     rates = [1, 2, 1, 3, 0]
     num_loci = 100
     recomb_map = msprime.RecombinationMap(positions, rates, num_loci)
     from_ts = msprime.simulate(
         5, __tmp_max_time=0.1, random_seed=5, recombination_map=recomb_map)
     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=recomb_map)
     self.verify_from_tables(from_ts, final_ts, start_time)
     self.verify_simulation_completed(final_ts)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:13,代码来源:test_simulate_from.py


示例18: test_fine_to_coarse_map

 def test_fine_to_coarse_map(self):
     from_ts = msprime.simulate(
         sample_size=4, __tmp_max_time=1, random_seed=5, recombination_rate=1)
     self.assertGreater(max(tree.num_roots for tree in from_ts.trees()), 1)
     self.assertGreater(from_ts.num_edges, 2)
     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=msprime.RecombinationMap.uniform_map(1, 1, num_loci=10))
     max_roots = max(tree.num_roots for tree in final_ts.trees())
     # We don't correctly finish the tree sequence when we get mapping problems.
     # This must be documented as a "known issue".
     self.assertGreater(max_roots, 1)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:13,代码来源:test_simulate_from.py


示例19: test_from_subclass

    def test_from_subclass(self):
        from_ts = msprime.simulate(20, __tmp_max_time=1, random_seed=5)

        class MockTreeSequence(msprime.TreeSequence):
            pass

        subclass_instance = MockTreeSequence(from_ts.ll_tree_sequence)
        self.assertTrue(type(subclass_instance), MockTreeSequence)
        self.assertIsInstance(subclass_instance, msprime.TreeSequence)
        self.assertGreater(max(tree.num_roots for tree in subclass_instance.trees()), 1)
        start_time = subclass_instance.tables.nodes.time.max()
        final_ts = msprime.simulate(
            from_ts=subclass_instance, start_time=start_time, random_seed=2)
        self.verify_from_tables(subclass_instance, final_ts, start_time)
        self.verify_simulation_completed(final_ts)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:15,代码来源:test_simulate_from.py


示例20: test_low_recombination_rate_interval

    def test_low_recombination_rate_interval(self):
        from_ts = msprime.simulate(
            sample_size=4, __tmp_max_time=1, random_seed=16, recombination_rate=1,
            length=10)
        self.assertGreater(max(tree.num_roots for tree in from_ts.trees()), 1)
        start_time = from_ts.tables.nodes.time.max()

        recombination_map = msprime.RecombinationMap(
            positions=[0, 3, 7, 10], rates=[1, 1e-6, 1, 0], num_loci=100)
        with self.assertRaises(_msprime.InputError):
            # Raises:
            # The specified recombination map is too coarse to translate...
            msprime.simulate(
                from_ts=from_ts, start_time=start_time, random_seed=2,
                recombination_map=recombination_map)
开发者ID:jeromekelleher,项目名称:msprime,代码行数:15,代码来源:test_simulate_from.py



注:本文中的msprime.simulate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python msqr.modular_sqrt函数代码示例发布时间:2022-05-27
下一篇:
Python utils.verboseload函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap