-
Notifications
You must be signed in to change notification settings - Fork 2
/
10_7_ald_reduced_dataset_plots.py
209 lines (171 loc) · 5.65 KB
/
10_7_ald_reduced_dataset_plots.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# %% [markdown]
# # Plots for comparison on ALD dataset with 20% add MAR values
# %%
from pathlib import Path
import matplotlib.pyplot as plt
import njab
import pandas as pd
import pimmslearn
plt.rcParams['figure.figsize'] = [4, 2] # [16.0, 7.0] , [4, 3]
pimmslearn.plotting.make_large_descriptors(6)
NONE_COL_NAME = 'No imputation\n(None)'
col_mapper = {'None':
NONE_COL_NAME}
# overwrite for now to align with Fig. 3
ORDER_MODELS = ['DAE', 'VAE', 'TRKNN', 'RF', 'CF', 'Median', 'QRILC', NONE_COL_NAME]
REF_MODEL = 'None (100%)'
CUTOFF = 0.05
COLORS_TO_USE_MAPPTING = pimmslearn.plotting.defaults.color_model_mapping
COLORS_TO_USE_MAPPTING[NONE_COL_NAME] = COLORS_TO_USE_MAPPTING['None']
COLORS_CONTIGENCY_TABLE = {
k: f'C{i}' for i, k in enumerate(['FP', 'TN', 'TP', 'FN'])
}
def plot_qvalues(df, x: str, y: list, ax=None, cutoff=0.05,
alpha=1.0, style='.', markersize=3):
ax = df.plot.line(x=x,
y=y,
style=style,
ax=ax,
color=COLORS_TO_USE_MAPPTING,
alpha=alpha,
markersize=markersize)
_ = ax.hlines(cutoff,
xmin=ax.get_xlim()[0],
xmax=ax.get_xlim()[1],
linestyles='dashed',
color='grey',
linewidth=1)
return ax
# %% [markdown]
# DA analysis
# %%
out_folder = 'runs/appl_ald_data_2023_11/plasma/proteinGroups_80perc_25MNAR/diff_analysis/kleiner/'
out_folder = Path(out_folder)
# %%
files_out = dict()
fname = out_folder / 'ald_reduced_dataset_plots.xlsx'
files_out[fname.name] = fname.as_posix()
writer = pd.ExcelWriter(fname)
# %%
# %% [markdown]
# Load dumps
# %%
da_target = (pd
.read_pickle(out_folder / 'equality_rejected_target.pkl').
rename(col_mapper, axis=1)
)
da_target.describe()
# %%
qvalues = (pd
.read_pickle(out_folder / 'qvalues_target.pkl')
.rename(col_mapper, axis=1)
)
qvalues
# %% [markdown]
# take only those with different decisions
# %%
da_target = da_target.drop('RSN', axis=1)
da_target_same = (da_target.sum(axis=1) == 0) | da_target.all(axis=1)
da_target_same.value_counts()
# %%
feat_idx_w_diff = da_target_same[~da_target_same].index
feat_idx_w_diff
# %%
qvalues_sel = (qvalues
.loc[feat_idx_w_diff]
.sort_values((NONE_COL_NAME, 'qvalue')
))
# %%
da_target_sel = da_target.loc[qvalues_sel.index]
da_target_sel
# %% [markdown]
# ## Diff. abundant => not diff. abundant
# %%
mask_lost_sign = (
(da_target_sel[NONE_COL_NAME] == False)
& (da_target_sel[REF_MODEL])
)
sel = qvalues_sel.loc[mask_lost_sign.squeeze()]
sel.columns = sel.columns.droplevel(-1)
sel = sel[ORDER_MODELS + [REF_MODEL]].sort_values(REF_MODEL)
sel.to_excel(writer, sheet_name='lost_signal_qvalues')
sel
# %%
# 0: FN
# 1: TP
da_target_sel_counts = (da_target_sel[ORDER_MODELS]
.loc[mask_lost_sign.squeeze()]
.astype(int)
.replace(
{0: 'FN',
1: 'TP'}
).droplevel(-1, axis=1)
)
da_target_sel_counts = njab.pandas.combine_value_counts(da_target_sel_counts)
ax = da_target_sel_counts.T.plot.bar(ylabel='count',
color=[COLORS_CONTIGENCY_TABLE['FN'],
COLORS_CONTIGENCY_TABLE['TP']])
ax.locator_params(axis='y', integer=True)
fname = out_folder / 'lost_signal_da_counts.pdf'
da_target_sel_counts.fillna(0).to_excel(writer, sheet_name=fname.stem)
files_out[fname.name] = fname.as_posix()
pimmslearn.savefig(ax.figure, fname)
# %%
ax = plot_qvalues(df=sel,
x=REF_MODEL,
y=ORDER_MODELS,
cutoff=CUTOFF)
ax.set_xlim(-0.0005, CUTOFF + 0.015)
ax.legend(loc='upper right')
ax.set_xlabel("q-value using 100% of the data without imputation")
ax.set_ylabel("q-value using 80% of the data")
fname = out_folder / 'lost_signal_qvalues.pdf'
files_out[fname.name] = fname.as_posix()
pimmslearn.savefig(ax.figure, fname)
# %% [markdown]
# ## Not diff. abundant => diff. abundant
# %%
mask_gained_signal = (
(da_target_sel[NONE_COL_NAME])
& (da_target_sel[REF_MODEL] == False)
)
sel = qvalues_sel.loc[mask_gained_signal.squeeze()]
sel.columns = sel.columns.droplevel(-1)
sel = sel[ORDER_MODELS + [REF_MODEL]].sort_values(REF_MODEL)
sel.to_excel(writer, sheet_name='gained_signal_qvalues')
sel
# %%
da_target_sel_counts = (da_target_sel[ORDER_MODELS]
.loc[mask_gained_signal.squeeze()]
.astype(int)
.replace(
{0: 'TN',
1: 'FP'}
).droplevel(-1, axis=1)
)
da_target_sel_counts = njab.pandas.combine_value_counts(da_target_sel_counts)
ax = da_target_sel_counts.T.plot.bar(ylabel='count',
color=[COLORS_CONTIGENCY_TABLE['TN'],
COLORS_CONTIGENCY_TABLE['FP']])
ax.locator_params(axis='y', integer=True)
fname = out_folder / 'gained_signal_da_counts.pdf'
da_target_sel_counts.fillna(0).to_excel(writer, sheet_name=fname.stem)
files_out[fname.name] = fname.as_posix()
pimmslearn.savefig(ax.figure, fname)
# %%
ax = plot_qvalues(sel,
x=REF_MODEL,
y=ORDER_MODELS)
# ax.set_xlim(CUTOFF - 0.005, sel[REF_MODEL].max() + 0.005)
ax.set_xlabel("q-value using 100% of the data without imputation")
ax.set_ylabel("q-value using 80% of the data")
ax.legend(loc='upper right')
fname = out_folder / 'gained_signal_qvalues.pdf'
files_out[fname.name] = fname.as_posix()
pimmslearn.savefig(ax.figure, fname)
# %% [markdown]
# Saved files
# %%
writer.close()
files_out
# %%