Example #1
0
 def testBDTree(self):
     """PureCoalescentTreeTest -- tree generation without checking [TODO: checks]"""
     _RNG = MockRandom()
     for num_leaves in range(2, 20):
         t = birthdeath.birth_death_tree(birth_rate=1.0, death_rate=0.2, ntax=num_leaves, rng=_RNG)
         self.assertTrue(t._debug_tree_is_valid())
         self.assertEqual(num_leaves, len(t.leaf_nodes()))
Example #2
0
 def testGSA(self):
     """test that the pure-birth process produces the correct number of tips with GSA."""
     _RNG = MockRandom()
     for num_leaves in range(2, 20):
         t = birthdeath.birth_death_tree(birth_rate=1.0, death_rate=0.0, ntax=num_leaves, gsa_ntax=4*num_leaves, rng=_RNG)
         self.assertTrue(t._debug_tree_is_valid())
         self.assertEqual(num_leaves, len(t.leaf_nodes()))
Example #3
0
 def testGSA(self):
     """test that the pure-birth process produces the correct number of tips with GSA."""
     _RNG = MockRandom()
     for num_leaves in range(2, 20):
         t = birthdeath.birth_death_tree(birth_rate=1.0, death_rate=0.0, num_extant_tips=num_leaves, gsa_ntax=4*num_leaves, rng=_RNG)
         self.assertTrue(t._debug_tree_is_valid())
         self.assertEqual(num_leaves, len(t.leaf_nodes()))
Example #4
0
 def testBDTree(self):
     """PureCoalescentTreeTest -- tree generation without checking [TODO: checks]"""
     _RNG = MockRandom()
     for num_leaves in range(2, 20):
         t = birthdeath.birth_death_tree(birth_rate=1.0, death_rate=0.2, num_extant_tips=num_leaves, rng=_RNG)
         self.assertTrue(t._debug_tree_is_valid())
         self.assertEqual(num_leaves, len(t.leaf_nodes()))
Example #5
0
 def evolve_to_current_time(node, finalize=False):
     viruses = [virus for virus in node.viruses()]
     for virus in viruses:
         time = GC.time - virus.get_time()
         if time > 0:
             node.remove_virus(virus)
             success = False
             for _ in range(100):
                 tree = birth_death_tree(GC.bd_birth,
                                         GC.bd_death,
                                         birth_rate_sd=GC.bd_birth_sd,
                                         death_rate_sd=GC.bd_death_sd,
                                         max_time=time,
                                         repeat_until_success=True,
                                         rng=rng)
                 if tree.seed_node.num_child_nodes() > 1:
                     success = True
                     break
             assert success, "Failed to create non-empty Birth-Death tree after 100 attempts. Perhaps try a higher birth rate or lower death rate?"
             virus.set_time(virus.get_time() + tree.seed_node.edge_length)
             for c in tree.seed_node.child_node_iter():
                 GC.treenode_add_child(virus, c, node)