def update_best_es():
    q = session.query(SNP, db.func.greatest(db.func.coalesce(db.func.max(TranscriptionFactorSNP.best_es), -1000),
                                            db.func.coalesce(db.func.max(CellLineSNP.best_es), -1000))) \
        .join(TranscriptionFactorSNP, SNP.tf_aggregated_snps, isouter=True) \
        .join(CellLineSNP, SNP.cl_aggregated_snps, isouter=True) \
        .group_by(SNP)
    for i, (snp, best_es) in enumerate(q, 1):
        if i % 50000 == 1:
            print(i)
        snp.best_es = None if best_es == -1000 else best_es
        snp.es_class = get_es_class(best_es)
    session.commit()
Exemple #2
0
                    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'],
                            'motif_concordance': row['motif_conc'],
                        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(
                              CandidateSNP.rs_id)
        snps = []
Exemple #4
0
     }[param]):
     ag_id,
     'log_p_value_ref':
     -np.log10(row['fdrp_bh_ref'])
     if row['fdrp_bh_ref'] != 0 else 310,
     'log_p_value_alt':
     -np.log10(row['fdrp_bh_alt'])
     if row['fdrp_bh_alt'] != 0 else 310,
     '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({