Skip to content

Commit c70ab0e

Browse files
authored
Merge pull request #137 from MannLabs/fix_notebook_plotting_functions
Restore notebook plotting functions removed by dead code cleanup
2 parents a3aa371 + 01fc591 commit c70ab0e

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

alphaquant/plotting/multicond.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import matplotlib.pyplot as plt
2+
import pandas as pd
3+
import numpy as np
4+
5+
6+
def plot_proteoform_intensity_profiles(proteoform_df: pd.DataFrame):
7+
"""Creates a panel of proteoform intensity profiles for each protein in the dataframe.
8+
9+
Args:
10+
proteoform_df: proteoform dataframe loaded from the AlphaQuant output file `medianref_proteoforms.tsv`
11+
12+
Returns:
13+
fig, axes: matplotlib figure and axes objects
14+
"""
15+
fixed_columns = ['proteoform_id', 'peptides', 'number_of_peptides', 'protein', 'corr_to_ref', 'is_reference']
16+
conditions = proteoform_df.columns.difference(fixed_columns)
17+
18+
grouped = proteoform_df.groupby('protein')
19+
n_plots = len(grouped)
20+
21+
n_cols = int(np.ceil(np.sqrt(n_plots)))
22+
n_rows = int(np.ceil(n_plots / n_cols))
23+
24+
fig, axes = plt.subplots(n_rows, n_cols, figsize=(5 * n_cols, 4 * n_rows))
25+
axes = axes.flatten()
26+
27+
for ax, (protein, sub_df) in zip(axes, grouped):
28+
for idx, row in sub_df.iterrows():
29+
style = '-' if row['is_reference'] else '--'
30+
ax.plot(conditions, row[conditions], style, label=row['proteoform_id'])
31+
ax.set_title(f'{protein}')
32+
ax.set_xlabel('Tissue')
33+
ax.set_ylabel('Expression Level')
34+
ax.legend(title='Proteoform ID')
35+
36+
for i in range(n_plots, len(axes)):
37+
axes[i].axis('off')
38+
39+
fig.tight_layout()
40+
plt.show()
41+
return fig, axes

alphaquant/plotting/pairwise.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,32 @@
1111
LOGGER = logging.getLogger(__name__)
1212

1313

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+
1440
def plot_withincond_normalization(df_c1, df_c2):
1541
LOGGER.info("without missingvals (if applicable)")
1642
plot_betweencond_fcs(aqnorm.drop_nas_if_possible(df_c1), aqnorm.drop_nas_if_possible(df_c2), True)

0 commit comments

Comments
 (0)