|
11 | 11 | LOGGER = logging.getLogger(__name__) |
12 | 12 |
|
13 | 13 |
|
| 14 | +def plot_normalization_overview(normed_df, samplemap_df): |
| 15 | + normed_df, sample2cond = aq_diff_utils.prepare_loaded_tables(normed_df, samplemap_df) |
| 16 | + sample2cond = dict(zip(samplemap_df["sample"], samplemap_df["condition"])) |
| 17 | + conditions = list(set([sample2cond.get(x) for x in normed_df.columns])) |
| 18 | + conditions = [x for x in conditions if x is not None] |
| 19 | + df_c1 = normed_df[[x for x in normed_df.columns if sample2cond.get(x) == conditions[0]]] |
| 20 | + df_c2 = normed_df[[x for x in normed_df.columns if sample2cond.get(x) == conditions[1]]] |
| 21 | + |
| 22 | + plot_betweencond_fcs(df_c1, df_c2, merge_samples=True) |
| 23 | + plot_sample_vs_median_fcs(df_c1, df_c2) |
| 24 | + |
| 25 | + |
| 26 | +def plot_sample_vs_median_fcs(df_c1_normed, df_c2_normed): |
| 27 | + combined_median = pd.concat([df_c1_normed, df_c2_normed], axis=1).median(axis=1, skipna=True) |
| 28 | + fig, axes = plt.subplots() |
| 29 | + for df in [df_c1_normed, df_c2_normed]: |
| 30 | + for col in df.columns: |
| 31 | + diff_fcs = df[col].subtract(combined_median) |
| 32 | + axes.axvline(0, color='red', linestyle="dashed") |
| 33 | + cutoff = max(abs(np.nanquantile(diff_fcs, 0.025)), abs(np.nanquantile(diff_fcs, 0.975))) |
| 34 | + axes.hist(diff_fcs, 80, density=True, histtype='step', range=(-cutoff, cutoff), label=col) |
| 35 | + axes.set_xlabel("log2(fc)") |
| 36 | + axes.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.) |
| 37 | + return fig, axes |
| 38 | + |
| 39 | + |
14 | 40 | def plot_withincond_normalization(df_c1, df_c2): |
15 | 41 | LOGGER.info("without missingvals (if applicable)") |
16 | 42 | plot_betweencond_fcs(aqnorm.drop_nas_if_possible(df_c1), aqnorm.drop_nas_if_possible(df_c2), True) |
|
0 commit comments