def get_pre_Q(cls, log_counts, codon_distn, ts, tv, syn, nonsyn, compo, asym_compo, natural_theta, ): cls.check_theta(theta) kappa = natural_theta[0] omega = natural_theta[1] nt_distn = markovutil.ratios_to_distn(theta[2:5]) codon_distn = codon1994.get_f1x4_codon_distn(compo, nt_distn) pre_Q = codon1994.get_pre_Q( ts, tv, syn, nonsyn, codon_distn, kappa, omega) return pre_Q
def get_neg_ll(cls, patterns, pattern_weights, stationary_distn, ts, tv, syn, nonsyn, theta, ): """ This model has only a single omega parameter. @param theta: vector of free variables with sensitivities """ # unpack theta log_mus = theta[0:3] log_kappa = theta[3] log_omega = theta[4] # construct the transition matrices transition_matrices = [] for i in range(3): mu = algopy.exp(log_mus[i]) kappa = algopy.exp(log_kappa) omega = algopy.exp(log_omega) pre_Q = codon1994.get_pre_Q( ts, tv, syn, nonsyn, stationary_distn, kappa, omega) Q = markovutil.pre_Q_to_Q(pre_Q, stationary_distn, mu) P = algopy.expm(Q) transition_matrices.append(P) # return the neg log likelihood ov = range(4) v_to_children = {3 : [0, 1, 2]} de_to_P = { (3, 0) : transition_matrices[0], (3, 1) : transition_matrices[1], (3, 2) : transition_matrices[2], } root_prior = stationary_distn log_likelihood = alignll.fast_fels( #log_likelihood = alignll.fels( ov, v_to_children, de_to_P, root_prior, patterns, pattern_weights, ) neg_ll = -log_likelihood print neg_ll return neg_ll