Beispiel #1
0
def create_gamma_model(alignment, missing_data=None, ncat=4):
    """ Create a phylo_utils.likelihood.GammaMixture for calculating
    likelihood on a tree, from a treeCl.Alignment and its matching 
    treeCl.Parameters """
    model = alignment.parameters.partitions.model
    freqs = alignment.parameters.partitions.frequencies
    alpha = alignment.parameters.partitions.alpha
    if model == 'LG':
        subs_model = LG(freqs)
    elif model == 'WAG':
        subs_model = WAG(freqs)
    elif model == 'GTR':
        rates = alignment.parameters.partitions.rates
        subs_model = GTR(rates, freqs, True)
    else:
        raise ValueError("Can't handle this model: {}".format(model))
    tm = TransitionMatrix(subs_model)
    gamma = GammaMixture(alpha, ncat)
    gamma.init_models(tm, alignment_to_partials(alignment, missing_data))
    return gamma
Beispiel #2
0
partials_2 = np.ascontiguousarray(np.array([[0, 1, 0, 0]], dtype=np.float))
partials_3 = np.ascontiguousarray(np.array([[0, 0, 1, 0]], dtype=np.float))
partials_4 = np.ascontiguousarray(np.array([[0, 1, 0, 0]], dtype=np.float))
partials_5 = np.ascontiguousarray(np.array([[0, 1, 0, 0]], dtype=np.float))

partials_dict = {"1": partials_1, "2": partials_2, "3": partials_3, "4": partials_4, "5": partials_5}


t = "(((1:0.2,2:0.2)7:0.1,3:0.2)6:0.1,(4:0.2,5:0.2)8:0.1)0;"
t = "((1:0.2,2:0.2):0.1,3:0.2,(4:0.2,5:0.2):0.2);"
runner = LnlModel(tm, partials_dict)
runner.set_tree(t)
print runner.run(True)
print runner.get_sitewise_likelihoods()

gamma = GammaMixture(400, 4)
gamma.init_models(tm, partials_dict, scale_freq=3)
gamma.set_tree(t)
print gamma.get_likelihood()
print gamma.get_sitewise_likelihoods()

kappa = 2
k80 = K80(kappa)
tm = TransitionMatrix(k80)

partials_dict = {
    "1": seq_to_partials("ACCCT"),
    "2": seq_to_partials("TCCCT"),
    "3": seq_to_partials("TCGGT"),
    "4": seq_to_partials("ACCCA"),
    "5": seq_to_partials("CCCCC"),