Esempio n. 1
0
    def test_plot_prob_bounded_coal(self):
        n = 1000
        k = 4
        t = 800
        alltimes = []

        # sample times
        for i in xrange(5000):
            while True:
                times = [0]
                for j in xrange(k, 1, -1):
                    times.append(times[-1] + coal.sample_coal(j, n))
                    if times[-1] >= t:
                        break
                if times[-1] < t:
                    break
            alltimes.append(times)

        p = Gnuplot()
        for i in range(1, 2):
            x, y = distrib([q[i] - q[i-1] for q in alltimes], width=20)
            p.plot(x, y, style="lines", xmax=500)

        x = list(frange(0, 500, 10))
        #for i in range(1, 2): #k):
        y2 = [coal.prob_bounded_coal(j, k, n, t) for j in x]
        p.plot(x, y2, style="lines", xmax=500)

        fequals(y, y2, rel=.05, eabs=.01)
Esempio n. 2
0
    def test_1(self):
        """Test multicoal_tree on simple 4 species tree"""

        stree = treelib.parse_newick(
            "((A:1000, B:1000):500, (C:700, D:700):800);")
        n = 500
        nsamples = 1000
        tab, tops = _test_multicoal_tree(stree, n, nsamples)
        print repr(tab[:20].get(cols=["simple_top", "percent", "prob"]))
        a, b = tab[:20].cget("percent", "prob")
        fequals(a, b, eabs=.05)
Esempio n. 3
0
    def test_cdf_mrca2(self):
        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]
        y4 = [coal.prob_coal_counts(k, 1, t, n) for t in x]

        fequals(y2, y3, eabs=.01)
        fequals(y3, y4)
Esempio n. 4
0
    def _test_recon(self):

        # test multicoal_tree on simple 4 species tree
        stree = treelib.parse_newick(
            "((A:1000, B:1000):500, (C:700, D:700):800);")
        n = 500
        T = 2000
        nsamples = 10000
        tab, tops = _test_bounded_multicoal_tree(stree, n, T, nsamples)
        print repr(tab[:20].get(cols=["simple_top", "percent", "prob"]))

        a, b = tab[:20].cget("percent", "prob")
        fequals(a, b, rel=.05, eabs=.005)
Esempio n. 5
0
    def test_cdf_coal_bounded(self):
        n = 1000
        k = 4
        t = 500
        step = .1
        x = list(frange(0, 500, step))
        y = [coal.prob_bounded_coal(i, k, n, t) * step for i in x]
        y2 = cumsum(y)
        y3 = [coal.cdf_bounded_coal(i, k, n, t) for i in x]

        p = plot(x, y2, style="lines")
        p.plot(x, y3, style="lines")
        p.plot([0, 500], [1, 1], style="lines")

        fequals(y2, y3, eabs=.01)
Esempio n. 6
0
    def test_flies(self):

        stree = treelib.parse_newick("""(
  (
    (
      (
        (
          (
            dmel:5.32,
            (
              dsec:1.89,
              dsim:1.89
            ):3.43
          ):5.91,
          (
            dere:8.57,
            dyak:8.57
          ):2.66
        ):42.17,
        dana:53.40
      ):2.40,
      (
        dpse:1.37,
        dper:1.37
      ):54.43
    ):6.69,
    dwil:62.49
  ):1.02,
  (
    (
      dmoj:32.74,
      dvir:32.74
    ):4.37,
    dgri:37.11
  ):26.40
);""")
        for node in stree:
            node.dist *= 1e6 * 10
        n = 10e6
        nsamples = 5000
        tab, tops = _test_multicoal_tree(stree, n, nsamples)
        print repr(tab[:20].get(cols=["simple_top", "percent", "prob"]))
        a, b = tab[:20].cget("percent", "prob")
        fequals(a, b, eabs=.05)