Exemple #1
0
    def test_sample_birth_times(self):

        stree = read_tree("test/data/flies.stree")

        birth = 8.1
        death = 2.1 * 1.0001

        print spidir.birthDeathCount(4, .005, birth, death)
        print spidir.birthDeathCounts(1, 4, .005, birth, death)

        maxgenes = [5, 10, 20, 40, 50]
        tic("time")
        counts = [2, 2, 3, 3, 3, 2, 1, 1, 1, 3, 3, 2]
        for maxgene in maxgenes:
            logl = spidir.birth_death_tree_counts(stree,
                                                  counts,
                                                  birth,
                                                  death,
                                                  maxgene=maxgene,
                                                  rootgene=1)
            print maxgene, logl
        toc()

        counts = [1] * 12
        for maxgene in maxgenes:
            logl = spidir.birth_death_tree_counts(stree,
                                                  counts,
                                                  birth,
                                                  death,
                                                  maxgene=maxgene,
                                                  rootgene=1)
            print maxgene, logl

        counts = [4] * 12
        for maxgene in maxgenes:
            logl = spidir.birth_death_tree_counts(stree,
                                                  counts,
                                                  birth,
                                                  death,
                                                  maxgene=maxgene,
                                                  rootgene=1)
            print maxgene, logl
Exemple #2
0
    def test_sample_birth_rates(self):

        prep_dir("test/output/birth_death_est")

        stree = read_tree("test/data/flies.stree")

        maxgene = 20
        counts = [2, 2, 3, 3, 3, 2, 0, 0, 0, 3, 3, 2]
        #counts = [5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

        rates = list(frange(.1, 20, 1))

        top = -INF

        x = []
        y = []
        z = []

        for birth in rates:
            for death in rates:
                l = spidir.birth_death_tree_counts(stree,
                                                   counts,
                                                   birth,
                                                   death,
                                                   maxgene=maxgene,
                                                   rootgene=1)
                x.append(birth)
                y.append(death)
                z.append(l)

                if l > top:
                    top = l
                    b = birth
                    d = death
                print birth, death, l

        print "best:", b, d, top

        write_delim("test/output/birth_death_est/rates.txt", zip(x, y, z))

        mat = [
            mget(z, range(ind, ind + len(rates)))
            for ind in xrange(0, len(z), len(rates))
        ]
        #mat = map2(log, mat)

        heatmap(mat,
                rlabels=map(str, rates),
                clabels=map(str, rates),
                display=True,
                xmargin=100,
                ymargin=100)
    def test_sample_birth_times(self):

        stree = read_tree("test/data/flies.stree")
        
        birth = 8.1
        death = 2.1 * 1.0001

        print spidir.birthDeathCount(4, .005, birth, death)
        print spidir.birthDeathCounts(1, 4, .005, birth, death)
        

        
        maxgenes = [5, 10, 20, 40, 50]
        tic("time")
        counts = [2, 2, 3, 3, 3, 2, 1, 1, 1, 3, 3, 2]
        for maxgene in maxgenes:
            logl = spidir.birth_death_tree_counts(stree, counts,
                                                     birth, death,
                                                     maxgene=maxgene,
                                                     rootgene=1)
            print maxgene, logl
        toc()

        counts = [1] * 12
        for maxgene in maxgenes:
            logl = spidir.birth_death_tree_counts(stree, counts,
                                                     birth, death,
                                                     maxgene=maxgene,
                                                     rootgene=1)
            print maxgene, logl

                                          
        counts = [4] * 12        
        for maxgene in maxgenes:
            logl = spidir.birth_death_tree_counts(stree, counts,
                                                     birth, death,
                                                     maxgene=maxgene,
                                                     rootgene=1)
            print maxgene, logl
    def test_sample_birth_rates(self):

        prep_dir("test/output/birth_death_est")

        stree = read_tree("test/data/flies.stree")
    
        maxgene = 20
        counts = [2, 2, 3, 3, 3, 2, 0, 0, 0, 3, 3, 2]
        #counts = [5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        
        rates = list(frange(.1, 20, 1))
        
        top = -INF

        x = []
        y = []
        z = []
        
        for birth in rates:
            for death in rates:
                l = spidir.birth_death_tree_counts(stree, counts,
                                                   birth, death,
                                                   maxgene=maxgene,
                                                   rootgene=1)
                x.append(birth)
                y.append(death)
                z.append(l)
                
                if l > top:
                    top = l
                    b = birth
                    d = death
                print birth, death, l

        print "best:", b, d, top

        write_delim("test/output/birth_death_est/rates.txt", zip(x, y, z))

        mat = [mget(z, range(ind, ind+len(rates)))
               for ind in xrange(0, len(z), len(rates))]
        #mat = map2(log, mat)

        heatmap(mat, rlabels=map(str, rates), clabels=map(str, rates),
                display=True, xmargin=100, ymargin=100)