Esempio n. 1
0
 def test_changed_values_step(self):
     """Tests if values changed at specified steps in step().
     Note, in m.step() CurrStep is logically tested one step later. 
     """
     m = BirthDeathModel( 0.1, 0.2, 0.3,ChangedBirthProb=0.6,\
         ChangedBirthStep=3,ChangedDeathProb=0.3,ChangedDeathStep=4,\
         MaxStep=5)
     # all values should be as initialized
     m.step()
     assert m.CurrStep == 1
     assert m.BirthProb == 0.1
     assert m.DeathProb == 0.2
     assert m.CurrBirthProb == 0.1
     assert m.CurrDeathProb == 0.2
     # continue 2 steps
     m.step()
     m.step()
     # when logically evaluated CurrBirthProb should change
     # from 0.1 to 0.6
     m.step()
     assert m.CurrStep == 4
     assert m.BirthProb == 0.1
     assert m.DeathProb == 0.2
     assert m.CurrBirthProb == 0.6
     assert m.CurrDeathProb == 0.2
     # All values other than CurrStep should be as above
     # except that CurrDeathProb should change from 0.2 to 0.3
     m.step()
     assert m.CurrStep == 5
     assert m.BirthProb == 0.1
     assert m.DeathProb == 0.2
     assert m.CurrBirthProb == 0.6
     assert m.CurrDeathProb == 0.3
Esempio n. 2
0
 def test_changed_values_step(self):
     """Tests if values changed at specified steps in step().
     Note, in m.step() CurrStep is logically tested one step later. 
     """
     m = BirthDeathModel( 0.1, 0.2, 0.3,ChangedBirthProb=0.6,\
         ChangedBirthStep=3,ChangedDeathProb=0.3,ChangedDeathStep=4,\
         MaxStep=5)
     # all values should be as initialized
     m.step()
     assert m.CurrStep == 1
     assert m.BirthProb == 0.1
     assert m.DeathProb == 0.2
     assert m.CurrBirthProb == 0.1
     assert m.CurrDeathProb == 0.2
     # continue 2 steps
     m.step()
     m.step()
     # when logically evaluated CurrBirthProb should change
     # from 0.1 to 0.6
     m.step()
     assert m.CurrStep == 4
     assert m.BirthProb == 0.1
     assert m.DeathProb == 0.2
     assert m.CurrBirthProb == 0.6
     assert m.CurrDeathProb == 0.2
     # All values other than CurrStep should be as above
     # except that CurrDeathProb should change from 0.2 to 0.3
     m.step()
     assert m.CurrStep == 5
     assert m.BirthProb == 0.1
     assert m.DeathProb == 0.2
     assert m.CurrBirthProb == 0.6
     assert m.CurrDeathProb == 0.3
Esempio n. 3
0
 def test_timeOk(self):
     """BirthDeathModel TimeOk should return True if time not exceeded"""
     b = BirthDeathModel(0.1, 0.2, 0.3, MaxStep=5)
     assert b.timeOk()
     b.CurrStep = 4
     assert b.timeOk()
     b.CurrStep = 5
     assert not b.timeOk()
     b.CurrStep = 1000
     assert not b.timeOk()
     b.MaxStep = None
     assert b.timeOk()
     b.MaxStep = 1001
     assert b.timeOk()
     b.step()
     assert not b.timeOk()
Esempio n. 4
0
 def test_timeOk(self):
     """BirthDeathModel TimeOk should return True if time not exceeded"""
     b = BirthDeathModel(0.1, 0.2, 0.3, MaxStep=5)
     assert b.timeOk()
     b.CurrStep = 4
     assert b.timeOk()
     b.CurrStep = 5
     assert not b.timeOk()
     b.CurrStep = 1000
     assert not b.timeOk()
     b.MaxStep = None
     assert b.timeOk()
     b.MaxStep = 1001
     assert b.timeOk()
     b.step()
     assert not b.timeOk()
Esempio n. 5
0
 def test_step(self):
     """BirthDeathModel step should match hand-calculated results"""
     m = BirthDeathModel(BirthProb=0.1, DeathProb=0.2, TimePerStep=1)
     born_and_died = FakeRandom([0], True)
     born_only = FakeRandom([1, 0], True)
     died_only = FakeRandom([0, 1], True)
     neither = FakeRandom([1], True)
     kill_alternate = FakeRandom([0, 1, 1, 1], True)
     born_alternate = FakeRandom([1, 1, 1, 0], True)
     #check that with neither birth nor death, we just continue
     m.step(neither)
     self.assertEqual(len(m.Tree.Children), 0)
     #check that with born_only we get a duplication
     m.step(born_only)
     self.assertEqual(len(m.Tree.Children), 2)
     assert m.Tree not in m.CurrTaxa
     for i in m.CurrTaxa:
         assert i.Parent is m.Tree
         self.assertEqual(i.Length, 1)
     #check that with a second round of born_only we duplicate again
     m.step(born_only)
     self.assertEqual(len(m.Tree.Children), 2)
     self.assertEqual(len(list(m.Tree.traverse())), 4)
     for i in m.Tree.traverse():
         self.assertEqual(i.Length, 1)
     for i in m.Tree.Children:
         self.assertEqual(i.Length, 1)
     #check that branch lengths add correctly
     for i in range(4):
         m.step(neither)
     self.assertEqual(len(m.CurrTaxa), 4)
     self.assertEqual(len(m.Tree.Children), 2)
     self.assertEqual(len(list(m.Tree.traverse())), 4)
     for i in m.Tree.traverse():
         self.assertEqual(i.Length, 5)
     for i in m.Tree.Children:
         self.assertEqual(i.Length, 1)
     #check that we can kill offspring correctly
     m.step(kill_alternate)
     self.assertEqual(len(m.CurrTaxa), 2)
     #make sure we killed the right children
     m.Tree.assignIds()
     for i in m.Tree.Children:
         #note that killing a child doesn't remove it, just stops it changing
         self.assertEqual(len(i.Children), 2)
         self.assertEqual(i.Children[0].Length, 5)
         self.assertEqual(i.Children[1].Length, 6)
     self.assertEqual([i.Length for i in m.Tree.traverse()], \
         [5,6,5,6])
     #make sure that born_and_died does the same thing as neither
     m.step(born_and_died)
     self.assertEqual([i.Length for i in m.Tree.traverse()], \
         [5,7,5,7])
     m.step(neither)
     self.assertEqual([i.Length for i in m.Tree.traverse()], \
         [5,8,5,8])
     #check that only CurrTaxa are brought forward
     self.assertEqual([i.Length for i in m.CurrTaxa], [8, 8])
     #check that we can duplicate a particular taxon
     m.step(born_alternate)
     self.assertEqual([i.Length for i in m.CurrTaxa], [9, 1, 1])
     self.assertEqual(m.CurrTaxa[1].Parent.Length, 8)
     #check that we can kill 'em all
     m.step(died_only)
     self.assertEqual(len(m.CurrTaxa), 0)
Esempio n. 6
0
 def test_taxaOk(self):
     """BirthDeathModel TaxaOk should return True if taxa not exceeded"""
     b = BirthDeathModel(0.1, 0.2, 0.3, MaxTaxa=5)
     born_alternate = FakeRandom([1, 1, 1, 0], True)
     born_only = FakeRandom([1, 0], True)
     kill_only = FakeRandom([0, 1, 0, 1], True)
     #start off with single taxon
     assert b.taxaOk()
     #taxa are OK if there are a few
     b.step(born_only)  #now 2 taxa
     assert b.taxaOk()
     b.step(born_only)  #now 4 taxa
     assert b.taxaOk()
     b.step(born_only)  #now 8 taxa
     assert not b.taxaOk()
     b.MaxTaxa = 8
     assert not b.taxaOk()
     b.MaxTaxa = 9
     assert b.taxaOk()
     b.MaxTaxa = 17
     assert b.taxaOk()
     b.step(born_only)
     assert b.taxaOk()
     b.step(born_only)
     assert not b.taxaOk()
     #ok if no maximum
     b.MaxTaxa = None
     assert b.taxaOk()
     #not ok if there are no taxa left
     b.step(kill_only)
     assert not b.taxaOk()
     #still not OK if not MaxTaxa
     b.MaxTaxa = None
     assert not b.taxaOk()
Esempio n. 7
0
 def test_step(self):
     """BirthDeathModel step should match hand-calculated results"""
     m = BirthDeathModel(BirthProb=0.1, DeathProb=0.2, TimePerStep=1)
     born_and_died = FakeRandom([0],True)
     born_only = FakeRandom([1,0],True)
     died_only = FakeRandom([0,1],True)
     neither = FakeRandom([1],True)
     kill_alternate = FakeRandom([0,1,1,1], True)
     born_alternate = FakeRandom([1,1,1,0], True)
     #check that with neither birth nor death, we just continue
     m.step(neither)
     self.assertEqual(len(m.Tree.Children), 0)
     #check that with born_only we get a duplication
     m.step(born_only)
     self.assertEqual(len(m.Tree.Children), 2)
     assert m.Tree not in m.CurrTaxa
     for i in m.CurrTaxa:
         assert i.Parent is m.Tree
         self.assertEqual(i.Length, 1)
     #check that with a second round of born_only we duplicate again
     m.step(born_only)
     self.assertEqual(len(m.Tree.Children), 2)
     self.assertEqual(len(list(m.Tree.traverse())), 4)
     for i in m.Tree.traverse():
         self.assertEqual(i.Length, 1)
     for i in m.Tree.Children:
         self.assertEqual(i.Length, 1)
     #check that branch lengths add correctly
     for i in range(4):
         m.step(neither)
     self.assertEqual(len(m.CurrTaxa), 4)
     self.assertEqual(len(m.Tree.Children), 2)
     self.assertEqual(len(list(m.Tree.traverse())), 4)
     for i in m.Tree.traverse():
         self.assertEqual(i.Length, 5)
     for i in m.Tree.Children:
         self.assertEqual(i.Length, 1)
     #check that we can kill offspring correctly
     m.step(kill_alternate)
     self.assertEqual(len(m.CurrTaxa), 2)
     #make sure we killed the right children
     m.Tree.assignIds()
     for i in m.Tree.Children:
         #note that killing a child doesn't remove it, just stops it changing
         self.assertEqual(len(i.Children), 2)
         self.assertEqual(i.Children[0].Length, 5)
         self.assertEqual(i.Children[1].Length, 6)
     self.assertEqual([i.Length for i in m.Tree.traverse()], \
         [5,6,5,6])
     #make sure that born_and_died does the same thing as neither
     m.step(born_and_died)
     self.assertEqual([i.Length for i in m.Tree.traverse()], \
         [5,7,5,7])
     m.step(neither)
     self.assertEqual([i.Length for i in m.Tree.traverse()], \
         [5,8,5,8])
     #check that only CurrTaxa are brought forward
     self.assertEqual([i.Length for i in m.CurrTaxa], [8,8])
     #check that we can duplicate a particular taxon
     m.step(born_alternate)
     self.assertEqual([i.Length for i in m.CurrTaxa], [9,1,1])
     self.assertEqual(m.CurrTaxa[1].Parent.Length, 8)
     #check that we can kill 'em all
     m.step(died_only)
     self.assertEqual(len(m.CurrTaxa), 0)
Esempio n. 8
0
 def test_taxaOk(self):
     """BirthDeathModel TaxaOk should return True if taxa not exceeded"""
     b = BirthDeathModel(0.1, 0.2, 0.3, MaxTaxa=5)
     born_alternate = FakeRandom([1,1,1,0], True)
     born_only = FakeRandom([1,0],True)
     kill_only = FakeRandom([0,1,0,1], True)
     #start off with single taxon
     assert b.taxaOk()
     #taxa are OK if there are a few
     b.step(born_only)   #now 2 taxa
     assert b.taxaOk()   
     b.step(born_only)   #now 4 taxa
     assert b.taxaOk()
     b.step(born_only)   #now 8 taxa
     assert not b.taxaOk()
     b.MaxTaxa = 8
     assert not b.taxaOk()
     b.MaxTaxa = 9
     assert b.taxaOk()
     b.MaxTaxa = 17
     assert b.taxaOk()
     b.step(born_only)
     assert b.taxaOk()
     b.step(born_only)
     assert not b.taxaOk()
     #ok if no maximum
     b.MaxTaxa = None
     assert b.taxaOk()
     #not ok if there are no taxa left
     b.step(kill_only)
     assert not b.taxaOk()
     #still not OK if not MaxTaxa
     b.MaxTaxa = None
     assert not b.taxaOk()