Exemple #1
0
def generate_covariance(size, scale_metod='beta', return_tree=False):
    tree = generate_phylogeny(size)
    cov = make_covariance(tree)
    s = calc_s(scale_metod)
    if return_tree:
        return cov * s, scale_tree(tree, s)
    return cov * s
def create_treemix_csv_output(tree, add, m_scale, outfile):
    if m_scale is not None:
        tree = scale_tree(tree, 1.0 / m_scale)
        add = add / m_scale
    with open(outfile, 'w') as f:
        f.write('tree,add' + '\n')
        f.write(unique_identifier_and_branch_lengths(tree) + ',' + str(add))
Exemple #3
0
def get_two_estimates(no_leaves, no_snps, no_individuals_per_population,
                      rho=0.0,
                      no_admixtures=None, 
                      no_bootstrap_samples=100,
                      scale_factor=0.02, 
                      blocksize=100,
                      reps=1,
                      collapsing=['nothing', 'Areduce','Rreduce'], 
                      summaries=[np.mean, np.std],
                      sim_method=['normal','ms']):
    lik_based=[]
    var_based=[]
    sim_method=initor(sim_method)
    for _ in range(reps):
        if sim_method=='normal':
            Sigma=generate_covariance(no_leaves, scale_metod='None')*scale_factor
            Ps=simulate_ps(no_snps, Sigma, rho)
            #print Ps
            #print Ps
            Ps, p0s=decentralize(Ps, no_individuals_per_population)
        elif sim_method=='ms':
            Sigma, tree=generate_covariance(no_leaves, scale_metod='None', return_tree=True)
            tree=scale_tree(tree, scale_factor)
            Ps,p0s=simulate_P_from_tree(tree, no_individuals_per_population, no_snps)
            
            
        print Ps, p0s   
        #print Ps
        #print Ps
        bPs,b_p0s= draw_bootstrap_sample(Ps, no_bootstrap_samples, optional_p0=p0s, blocksize=blocksize)
        print 'drew bootstrap samples'
        #print bPs
        covs=np.array(calc_covs(bPs, b_p0s, collapsing))
        print 'calculated covs'
        #print covs
        #print covs
        lik_based.append(likelihood_mean_based(covs))
        print 'calculated likelihood based tickets'
        print lik_based[-1]
        var_based.append(variance_mean_based(covs))
        print 'calculated variance based'
        
        print var_based[-1]
    lik_based=[lik for lik in lik_based if lik is not None]
    lik_summa=[summary(lik_based) for summary in summaries]
    var_summa=[summary(var_based) for summary in summaries]
    return lik_summa, var_summa
Exemple #4
0
def scale_tree_wrapper(tree, **kwargs):
    if kwargs['time_adjust']:
        tree=time_adjust_tree(tree) 
    return scale_tree(tree, kwargs['scale_tree_factor'])
def create_treemix_sfull_tree_csv_output(tree, m_scale, outfile):
    if m_scale is not None:
        tree = scale_tree(tree, 1.0 / m_scale)
    with open(outfile, 'w') as f:
        f.write('sfull_tree' + '\n')
        f.write(unique_identifier_and_branch_lengths(tree))
if __name__=='__main__':
    
    #print reduce_covariance(identity(10), 5)
    
    #print file_to_emp_cov('out_stem.cov',4)
    
    
    
    
    from sys import exit
    
    exit()
    from generate_prior_trees import generate_phylogeny
    from Rcatalogue_of_trees import *
    from Rtree_operations import create_trivial_tree, scale_tree
    tree2=scale_tree(generate_phylogeny(5,1),0.05)
    print pretty_string(tree2)
    print pretty_string(identifier_to_tree_clean(unique_identifier_and_branch_lengths(tree2)))
    print supplementary_text_ms_string()
    tree_good=generate_phylogeny(7)
    a=tree_to_ms_command(tree_good, 50,20)
    #print call_ms_string(a, 'supp.txt')
    b=time_adjusted_tree_to_ms_command(tree_good,50,20)
    #print call_ms_string(b, 'supp2.txt')
    #print call_ms_string(tree_to_ms_command(tree2, 50,20), 'tmp.txt')
    #cov= ms_to_treemix2('supp.txt', 20, 20,400)
    #cov= ms_to_treemix2('tmp.txt', 50, 5,20)
    #cov2=calculate_covariance_matrix('tmp.txt', 50, 5,20)
    #print cov
    #print cov2
    #print make_covariance(tree2)