Ejemplo n.º 1
0
    def runTest(self):
        expected = [
            0.01, 0.0039340474963855641, 0.001632232380666595,
            0.014428659286578023, 0.016389703355764434, 0.0021307292762983254,
            0.45394897294494657, 0.48407248276349046, 0.022176546909804414,
            0.0036827493270788596, 0.51000000000000001, 0.20436786045422725,
            1.1317505850563239, 0.080717426949510368, 0.57473474392305157,
            0.47757106516375003, 0.036289663562129378, 1.2605207376608101,
            0.025598569446275875, 0.02436667769068299, 1.01,
            1.4219020757916292, 0.17096215398172529, 1.0457715847484181,
            1.008417839353775, 0.15725202748916964, 0.073470806288836357,
            0.80215768313618252, 7.7309806110114048, 7.4444231676578108, 1.51,
            1.1317576595037642, 9.1122414408448513, 11.189808222817929,
            0.41506807319133626, 0.02680783090697382, 1.0744945504810126,
            1.2341438671393068, 34.534823123534657, 0.70551794392946265,
            2.0099999999999998, 3.5146301765484438, 4.2304827507410794,
            3.7634976514794487, 0.17384383517242785, 0.27619684368030367,
            2.7283343215701814, 11.197459097867025, 1.9925358755666318,
            0.036458466937595801, 2.5099999999999998, 3.5972933316044275,
            6.6566017084647564, 2.7893078600612546, 6.720705581299355,
            1.6854424538625612, 0.83930915760416014, 0.00031692818644330357,
            10.67426820212137, 213.41625387395686, 3.0099999999999998,
            4.0529230827852576, 0.88784100563352941, 0.26617006989932601,
            6.9084440279478647, 5.5318019658942186, 5.436724012051565,
            3.8204558144079903, 4.6743721423293518, 2.678678109503108,
            3.5099999999999998, 9.1966644910421707, 0.40392639090720356,
            5.0919329843369292, 3.5004215324170675, 153.00193917129431,
            39.050739500681885, 0.13207256469121023, 3473.1260500607032,
            56.051794289673808, 4.0099999999999998, 16.669107027752826,
            1.4876702070018706, 0.30960589864113691, 19.637794491060113,
            2.0587090258674543, 7.9530766255051635, 1.0110130970614859,
            0.1077409554922503, 1.6140032678015137, 4.5099999999999998,
            17.245125079032153, 9.1315662720433046, 4.6324044639076911,
            6.2649028812690863, 27.752754239037028, 0.87084078040787383,
            0.76722197209428222, 0.32248653474293604, 55.963410447025701
        ]

        rng = RepeatedRandom()
        y = [
            continuous._calc_TKP_rate(0.01 + .5 * i, 1, j, rng)
            for i in xrange(10) for j in xrange(10)
        ]
        assert_vec_approx_equal(y, expected, tester=self)

        rng = RepeatedRandom()
        y = [
            continuous._calc_TKP_rate(0.01 + .5 * i, j, 1, rng)
            for i in xrange(10) for j in xrange(10)
        ]
        assert_vec_approx_equal(y, expected, tester=self)

        try:
            continuous._calc_TKP_rate(0, 1, 1, rng)
        except ValueError:
            pass
        except OverflowError:
            pass
Ejemplo n.º 2
0
    def runTest(self):
        expected = [
            0.01, 0.00238612042332357, 0.00060046473606155989,
            0.0032194690573412836, 0.0022181051458164411,
            0.00017490090971284891, 0.022600788551531675, 0.014617722366202806,
            0.00040617762499905189, 4.0911649525733303e-05,
            0.51000000000000001, 0.12395537322536185, 0.41634777277597329,
            0.018010492402013432, 0.077781889354748265, 0.039201420226780297,
            0.0018067559608145154, 0.038064428026927236, 0.000468854154046173,
            0.00027068933811426338, 1.01, 0.86242720407665974,
            0.062893461668263165, 0.23334318118359176, 0.13647451390979612,
            0.012908032460053776, 0.0036578960557443821, 0.024223063122821967,
            0.14159784912709042, 0.082700071198721442, 1.51, 0.686445719853644,
            3.3522062890772624, 2.4967837007875815, 0.056173355247824582,
            0.0022005207631086566, 0.053495933645695409, 0.037267915554308549,
            0.63252734941696775, 0.0078375963967802359, 2.0099999999999998,
            2.1317309596278573, 1.5563076302280545, 0.83974983369284895,
            0.023527204671999535, 0.022671617533422929, 0.13583576739840431,
            0.33813396573401916, 0.036494567569726223, 0.00040501698299937316,
            2.5099999999999998, 2.1818686975978907, 2.4488269166108831,
            0.62237870951874186, 0.90954859339503202, 0.13834954150596895,
            0.041786742411412607, 9.5704019633684995e-06, 0.19550604179155287,
            2.3708404254904281, 3.0099999999999998, 2.4582221111663025,
            0.32661845300155418, 0.059390570323355388, 0.9349562292466097,
            0.45407795675810753, 0.27067855008521879, 0.1153677690757042,
            0.085614112190463207, 0.029757425845535486, 3.5099999999999998,
            5.5780589809075565, 0.14859621496133962, 1.1361638222601711,
            0.47373053953720168, 12.559163966329541, 1.9442218373360938,
            0.003988245875549439, 63.612522547967608, 0.62267918872625649,
            4.0099999999999998, 10.110324482363417, 0.54728328439925211,
            0.069082413746695395, 2.657686479590013, 0.16898912755533801,
            0.39596036968888626, 0.030529950136951384, 0.0019733444343232381,
            0.017929956714718788, 4.5099999999999998, 10.45969709101225,
            3.3593154971792818, 1.0336291499040244, 0.84786240588642281,
            2.278084793520756, 0.043356609471690816, 0.023168096061358393,
            0.0059065469168308469, 0.62169733292424179
        ]

        rng = RepeatedRandom()
        y = [
            continuous._calc_KTB_rate(0.01 + .5 * i, 1, j, rng)
            for i in xrange(10) for j in xrange(10)
        ]
        assert_vec_approx_equal(y, expected, tester=self)

        rng = RepeatedRandom()
        y = [
            continuous._calc_KTB_rate(0.01 + .5 * i, j, 1, rng)
            for i in xrange(10) for j in xrange(10)
        ]
        assert_vec_approx_equal(y, expected, tester=self)

        self.assertRaises(ValueError, continuous._calc_KTB_rate, 0, 1, 1, rng)
Ejemplo n.º 3
0
    def get_species_tree(self, ntax=10):
        _RNG = RepeatedRandom()
        ages = [random.randint(1000, 10000) for age in range(ntax)]
        ages.sort()
        pop_sizes = [
            random.randint(1000, 10000) for pop in range(2 * ntax + 1)
        ]
        taxon_set = dendropy.new_taxon_set(ntax)
        species_tree = treesim.pop_gen_tree(taxon_set=taxon_set,
                                            ages=ages,
                                            num_genes=4,
                                            pop_sizes=pop_sizes,
                                            rng=_RNG)
        ages2 = []
        for node in species_tree.postorder_node_iter():
            distance_from_tip = node.distance_from_tip()
            if distance_from_tip > 0:
                ages2.append(distance_from_tip)
        ages2.sort()
        for index in range(len(ages2)):
            assert (ages[index] - ages2[index]) < 10e-6

        pop_sizes2 = []
        for edge in species_tree.postorder_edge_iter():
            pop_sizes2.append(edge.pop_size)
        pop_sizes2.sort()

        return species_tree
Ejemplo n.º 4
0
 def testBDTree(self):
     """PureCoalescentTreeTest -- tree generation without checking [TODO: checks]"""
     _RNG = RepeatedRandom()
     for num_leaves in range(2, 20):
         t = treesim.birth_death(birth_rate=1.0,
                                 death_rate=0.2,
                                 ntax=num_leaves,
                                 rng=_RNG)
         self.assertTrue(t._debug_tree_is_valid())
         self.assertEquals(num_leaves, len(t.leaf_nodes()))
Ejemplo n.º 5
0
 def testYule(self):
     """test that the pure-birth process produces the correct number of tips."""
     _RNG = RepeatedRandom()
     for num_leaves in range(2, 20):
         t = treesim.birth_death(birth_rate=1.0,
                                 death_rate=0.0,
                                 ntax=num_leaves,
                                 rng=_RNG)
         self.assertTrue(t._debug_tree_is_valid())
         self.assertEquals(num_leaves, len(t.leaf_nodes()))
Ejemplo n.º 6
0
 def testGSABD(self):
     """test that the birth-death process produces the correct number of tips with GSA."""
     _RNG = RepeatedRandom()
     for num_leaves in range(2, 15):
         _LOG.debug("Generating tree with %d leaves" % num_leaves)
         t = treesim.birth_death(birth_rate=1.0,
                                 death_rate=0.2,
                                 ntax=num_leaves,
                                 gsa_ntax=3 * num_leaves,
                                 rng=_RNG)
         self.assertTrue(t._debug_tree_is_valid())
         self.assertEquals(num_leaves, len(t.leaf_nodes()))
Ejemplo n.º 7
0
 def runTest(self):
     n = '(Basichlsac,(Lamprothma,Mougeotisp),(((Haplomitr2,Petalaphy),((Angiopteri,(((Azollacaro,((Dennstasam,(Oleandrapi,Polypodapp)),Dicksonant)),Vittarifle),Botrychbit)),(Isoetesmel,((((Agathismac,Agathisova),Pseudotsu),(((Libocedrus,Juniperusc),Callitris),Athrotaxi)),((Liriodchi,Nelumbo),Sagittari))))),Thuidium));'
     k = dendropy.TreeList(stream=StringIO(n), schema="newick")[0]
     trees = dendropy.TreeList(stream=StringIO(n+n), schema="newick", encode_splits=True, taxon_set=k.taxon_set)
     ref = trees[0]
     changing = trees[1]
     rng = RepeatedRandom()
     for i in xrange(50):
         treemanip.randomly_reorient_tree(changing, rng=rng, splits=True)
         self.assertNotEqual(str(changing), n)
         changing.debug_check_tree(logger_obj=_LOG, splits=True)
         if treecalc.symmetric_difference(ref, changing) != 0:
             self.fail("\n%s\n!=\n%s" % (str(ref), str(changing)))
Ejemplo n.º 8
0
 def testConflict(self):
     taxa = TaxonSet([str(i) for i in xrange(1, 7)])
     o = [
         '(1,5,(2,((3,6),4)));',
         '(2,1,(3,(6,4)));',
     ]
     m = [o[0], o[1], '(1,5,(2,(3,6,4)));']
     trees = trees_from_newick_str_list(m)
     self.kernelOfTest(trees)
     rng = RepeatedRandom()
     for i in xrange(50):
         trees = trees_from_newick_str_list(m)
         for t in trees:
             randomly_reorient_tree(t, rng=rng)
         self.kernelOfTest(trees)
Ejemplo n.º 9
0
 def runTest(self):
     rng = RepeatedRandom()
     newick = "((t5:1611.75,t6:1611.75):3922.93,((t4:1043.81,(t2:754.11,t1:754.11):2896.9):6584.0,t3:1702.21):3832.47);"
     tree = dendropy.Tree(str=newick, schema="newick")
     root = tree.seed_node
     root.mutation_rate = 1e-5
     root.mean_edge_rate = root.mutation_rate
     continuous.simulate_continuous(root,
                                    rng,
                                    roeotroe=0.01,
                                    min_rate=1.0e-6,
                                    max_rate=1.0e-3,
                                    model='KTB',
                                    time_attr='edge_length',
                                    val_attr='mutation_rate',
                                    mean_val_attr='mean_edge_rate',
                                    constrain_rate_mode="linear_bounce")
     for i in tree.preorder_node_iter():
         if i.edge_length is not None:
             i.edge_length *= i.mean_edge_rate
Ejemplo n.º 10
0
 def runTest(self):
     """PureCoalescentTreeTest -- tree generation without checking [TODO: checks]"""
     _RNG = RepeatedRandom()
     t = treesim.pure_kingman(dendropy.new_taxon_set(100), rng=_RNG)
     assert t._debug_tree_is_valid()