예제 #1
0
    def test_cdf_coal_cond_counts(self):

        # test coalescent pdf when conditioned on future lineage counts

        outdir = 'test/tmp/test_coal/Coal_test_cdf_coal_cond_counts/'
        make_clean_dir(outdir)

        a = 5
        for b in xrange(2, a):
            t = 500
            n = 1000
            p = Gnuplot()
            p.enableOutput(False)
            p.plotfunc(lambda x: coal.cdf_coal_cond_counts(
                x, a, b, t, n), 0, t, 10)

            # draw single coal samples using rejection sampling
            s = []
            for i in xrange(1000):
                while True:
                    times = coal.sample_coal_times(a, n)
                    if times[a-b-1] < t and (b == 1 or times[a-b] > t):
                        break
                s.append(times[0])

            x2, y2 = stats.cdf(s)
            p.plot(x2, y2, style='lines')
            p.enableOutput(True)
            p.save(outdir + 'plot-%d.png' % b)

            eq_sample_pdf(
                x2, lambda x: coal.prob_coal_cond_counts(x, a, b, t, n), 40)
예제 #2
0
    def test_sample_bounded_coal(self):
        n = 1000
        k = 5
        T = 500

        d = [coal.sample_bounded_coal(k, n, T) for i in xrange(2000)]

        p = plotdistrib(d, 40)
        p.plotfunc(lambda t: coal.prob_bounded_coal(t, k, n, T), 0, T, T/200)

        eq_sample_pdf(d, lambda t: coal.prob_bounded_coal(t, k, n, T), 40)
예제 #3
0
    def test_sample_coal_cond_counts(self):

        # test coalescent pdf when conditioned on future lineage counts

        a = 5
        for b in xrange(2, a):
            t = 500
            n = 1000

            # draw single coal samples using rejection sampling
            s = [coal.sample_coal_cond_counts(a, b, t, n)
                 for i in xrange(1000)]

            eq_sample_pdf(s, lambda x: coal.prob_coal_cond_counts(
                x, a, b, t, n), 40)
예제 #4
0
    def test_prob_coal2(self):

        outdir = 'test/tmp/test_coal/Coal_test_prob_coal2/'
        make_clean_dir(outdir)

        k = 2
        n = 1000
        p = Gnuplot()
        p.enableOutput(False)
        p.plotfunc(lambda t: coal.prob_coal(t, k, n), 0, 4000, 10,
                   ymin=0)

        # draw single coal samples
        x = [coal.sample_coal(k, n) for i in xrange(200)]
        plotdistrib(x, 40, plot=p)
        p.enableOutput(True)
        p.save(outdir + 'plot.png')

        eq_sample_pdf(x, lambda t: coal.prob_coal(t, k, n), 40)
예제 #5
0
    def test_prob_coal_cond_counts2(self):

        # test coalescent pdf when conditioned on future lineage counts

        a = 5
        for b in xrange(2, a):
            t = 500
            n = 1000

            # draw single coal samples using rejection sampling
            x2 = []
            for i in xrange(1000):
                while True:
                    times = coal.sample_coal_times(a, n)
                    if times[a-b-1] < t and (b == 1 or times[a-b]) > t:
                        break
                x2.append(times[0])

            eq_sample_pdf(x2, lambda x: coal.prob_coal_cond_counts(
                x, a, b, t, n), 40)
예제 #6
0
    def test_cdf_mrca(self):

        outdir = 'test/tmp/test_coal/Coal_test_cdf_mrca/'
        make_clean_dir(outdir)

        n = 1000
        k = 6
        step = 10
        x = list(frange(0, 5000, step))
        y = [coal.prob_mrca(i, k, n) * step for i in x]
        y2 = cumsum(y)
        y3 = [coal.cdf_mrca(t, k, n) for t in x]

        p = Gnuplot()
        p.enableOutput(False)
        p.plot(x, y2, style="lines")
        p.plot(x, y3, style="lines")
        p.enableOutput(True)
        p.save(outdir + 'plot.png')

        eq_sample_pdf(x, lambda t: coal.cdf_mrca(t, k, n), 40)
예제 #7
0
    def test_prob_mrca(self):
        n = 1000
        k = 50

        x = [coal.sample_coal_times(k, n)[-1] for i in xrange(10000)]
        eq_sample_pdf(x, lambda t: coal.prob_mrca(t, k, n), 40)