Esempio n. 1
0
def check_predestinations(tree, reps=10000):
    dic = {}

    for _ in xrange(reps):
        pks = {}
        ntree, _, _ = deladmix(tree, pks=pks)
        unique_id = unique_identifier(ntree)
        tup = (pks['remove_key'], pks['remove_branch']
               )  #,pks['sink_key'],pks['sink_branch'])
        if tup in dic:
            assert dic[tup][
                0] == unique_id, 'There is not a unique mapping from sink source to unique id'
            assert 1.0 / dic[tup][1] == pks[
                'forward_choices'], 'There was not a unqiue number of forward choices for '  #+str(tup)+' : '+str(pks['forward_choices'])+'><'
            dic[tup] = (unique_id, 1.0 / pks['forward_choices'],
                        dic[tup][2] + 1)
        else:
            dic[tup] = (unique_id, 1.0 / pks['forward_choices'], 1)
    res_ret = []
    total = 0
    for key, element in dic.items():
        print key, ': ', element
        total += element[1]
        res_ret.append(list(key) + list(element))
    print 'TOTAL=', total
    with open("results3.csv", "wb") as f:
        wr = writer(f)
        wr.writerows(res_ret)
    return 'done'
Esempio n. 2
0
def test_topological_prior_density(n, k, sim_length):
    dictionary_of_probabilities = {}
    list_of_simulated_trees = []
    for _ in xrange(sim_length):
        tree = generate_admix_topology(n, k)
        unique_id = unique_identifier(tree)
        list_of_simulated_trees.append(unique_id)
        if unique_id not in dictionary_of_probabilities:
            print unique_id
            dictionary_of_probabilities[unique_id] = exp(
                uniform_topological_prior_function(tree))
    ad, ad2 = dictionary_of_probabilities, Counter(list_of_simulated_trees)
    for key, val in ad.items():
        print val, 'vs', float(ad2[key]) / sim_length, ': ', key
    print 'Total number of simulations', sim_length
    print 'Unique sampled trees', len(ad2)
    print 'Simulated total probability', sum(ad.values())
    n = float(sim_length)
    c = float(len(ad2))

    def f(m):
        return m * (1 - ((m - 1) / m)**n) - c

    maxval = c
    while f(maxval) < 0:
        maxval *= 2
    ex = brentq(f, c, maxval)
    print 'Expected number of unique', ex
    print 'Expected total probability', c / ex
Esempio n. 3
0
 def summary_of_phylogeny(self, tree):
     return unique_identifier(tree)
Esempio n. 4
0
 def __call__(self, **kwargs):
     tree = kwargs['proposed_tree']
     return unique_identifier(tree)
Esempio n. 5
0
 def __call__(self, **kwargs):
     old_tree = kwargs['tree']
     return unique_identifier(old_tree)