def predict_expression_log_likelihood_for_gene(CurrStackSum, State, nr_of_genes, gene_nr, EmissionParameters, curr_type = 'fg'): ''' This function predicts the likelihood of expression for a gene ''' nr_of_rep = EmissionParameters['NrOfReplicates'] mean_mat, var_mat = get_expected_mean_and_var(CurrStackSum, State, nr_of_genes, gene_nr, EmissionParameters, curr_type = curr_type) #reset the variance if the empirical variance is larger than the estimated variance if EmissionParameters['emp_var'] and (mean_mat.shape[0] > 1): mu = np.zeros_like(mean_mat) emp_var = np.zeros_like(mean_mat) for rep in range(nr_of_rep): for i in range(nr_of_rep): mu[i, :] = CurrStackSum[i, :] / mean_mat[i, :] * mean_mat[rep, :] emp_var[rep, :] = np.var(mu, axis = 0) var_mat[rep, :] = np.max(np.vstack([var_mat[rep, :], emp_var[rep, :]]), axis = 0) #Get the parameters for the NB distributions p, n = NB_parameter_estimation(mean_mat, var_mat) #Compute the likelihood ix_nonzero = np.sum(CurrStackSum, axis=0) > 0 zero_array = nbinom._logpmf(np.zeros((CurrStackSum.shape[0], 1)), np.expand_dims(n[:,0], axis=1), np.expand_dims(p[:,0], axis=1)) loglike = np.tile(zero_array, (1, CurrStackSum.shape[1])) loglike[:, ix_nonzero] = nbinom._logpmf(CurrStackSum[:, ix_nonzero], n[:, ix_nonzero], p[:, ix_nonzero]) #combine the replicates loglike = loglike.sum(axis = 0) return loglike
def log_like_constitutive(params, data_uv5): k_burst, mean_burst, _, _ = params # k_burst, mean_burst = params # mRNA, counts = data_constit[0], data_constit[1] # change vars for scipy's goofy parametrization p = (1 + mean_burst)**(-1) return np.sum(data_uv5[1] * neg_binom._logpmf(data_uv5[0], k_burst, p))
def log_like_constitutive(params, data_constit): k_burst, mean_burst = params[:2] # change vars for scipy's goofy parametrization p = (1 + mean_burst)**(-1) return np.sum(data_constit[1] * neg_binom._logpmf(data_constit[0], k_burst, p))