<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 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