def update_best_p_value(): q = session.query(SNP, db.func.greatest(db.func.coalesce(db.func.max(TranscriptionFactorSNP.best_p_value), 0), db.func.coalesce(db.func.max(CellLineSNP.best_p_value), 0))) \ .join(TranscriptionFactorSNP, SNP.tf_aggregated_snps, isouter=True) \ .join(CellLineSNP, SNP.cl_aggregated_snps, isouter=True) \ .group_by(SNP) for i, (snp, best_p) in enumerate(q, 1): if i % 50000 == 1: print(i) snp.best_p_value = best_p snp.fdr_class = get_fdr_class(best_p) session.commit()
max_es = max([ x for x in (row['es_mean_ref'], row['es_mean_alt']) if x is not None ], default=None) mutation = CandidateSNP( rs_id=row['ID'], chromosome=row['#chr'], position=row['pos'], ref=row['ref'], alt=row['alt'], ag_level=param, ag_id=ag_id, best_p_value=min_pv, fdr_class=get_fdr_class(min_pv), best_es=max_es, es_class=get_es_class(max_es), ) snps.append(mutation) session.add_all(snps) session.commit() session.close() if SNP_RS: q = session.query(CandidateSNP.rs_id, db.func.max(CandidateSNP.best_p_value), db.func.max(CandidateSNP.best_es)).group_by(
snps.append(mutation) ag_data = { 'chromosome': row['#chr'], 'position': int(row['pos']), 'alt': row['alt'], ({ 'TF': 'tf_id', 'CL': 'cl_id' }[param]): ag_id, 'log_p_value_ref': -np.log10(row['fdrp_bh_ref']), 'log_p_value_alt': -np.log10(row['fdrp_bh_alt']), 'best_p_value': -np.log10(min_pv), 'best_es': max_es, 'fdr_class': get_fdr_class(-np.log10(min_pv)), 'es_class': get_es_class(max_es), 'es_ref': row['es_mean_ref'], 'es_alt': row['es_mean_alt'], 'is_asb': min_pv <= 0.1, 'mean_bad': row['mean_BAD'], 'peak_calls': row['n_peak_calls'], 'peak_callers': row['n_peak_callers'], } if param == 'TF': ag_data.update({ 'motif_log_p_ref': row['motif_log_pref'], 'motif_log_p_alt': row['motif_log_palt'], 'motif_log_2_fc': row['motif_fc'], 'motif_orientation': row['motif_orient'], 'motif_position': row['motif_pos'],