-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcosa_create_special_aerobic_figures.py
288 lines (249 loc) · 10.7 KB
/
cosa_create_special_aerobic_figures.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
"""In this script, the following figures are generated:
1) The figure for the solutions with in vivo concentraitons from Bennett et al., 2009.
2) The figure with results under acetate.
Both figures depict the situation under aerobic conditions as this is the only repective viable environment.
"""
# IMPORTS #
# External
import matplotlib.pyplot as plt
import pandas
# Internal
from helper import json_load
# PUBLIC FUNCTIONS #
def create_in_vivo_concentrations_figure():
"""Creates figure for results with in vivo concentration ranges."""
ratio_ratio_test_data_aerobic = json_load("cosa/results_aerobic/ratio_ratio_test_data.json")
concentration = "VIVOCONC"
output_path = "./cosa/in_vivo_concentrations_figure.png"
table_path = f"cosa/results_aerobic/optsubmdf_table_{concentration}.csv"
pad = 1.6
target = "OPTSUBMDF"
figurename_tuple = ("aerobic", f"2C_NADH_to_NAD___to___NADPH_to_nadp_{target}_{concentration}.jpg")
cm = 1/2.54
# fig, axs = plt.subplots(nrows=1, ncols=2, dpi=500, figsize=(18, 6)) #sharex=True, figsize=(50, 25), dpi=120, facecolor="white")
fig, axs = plt.subplots(nrows=2, ncols=1, dpi=500, figsize=(10*cm, 12.5*cm)) #sharex=True, figsize=(50, 25), dpi=120, facecolor="white")
fig.tight_layout(pad=pad)
########################################################
########################################################
########################################################
# 0: Random sampling figure
str_to_float = lambda x: float(x.replace(",", "."))
list_to_float = lambda x: [str_to_float(y) for y in x]
growth_rate_id = "µ [1/h]"
best_id = "FLEXIBLE"
in_vivo_id = "WILDTYPE"
only_one_id = "SINGLE_COFACTOR"
table = pandas.read_csv(
table_path,
sep="\t",
)
headers = list(table.keys())
del(headers[headers.index(best_id)])
del(headers[headers.index(only_one_id)])
del(headers[headers.index(in_vivo_id)])
headers += [only_one_id, in_vivo_id, best_id]
growth_rates = list_to_float(table[growth_rate_id])
is_first_random = True
for header in headers:
if header == growth_rate_id:
continue
elif header == best_id:
label = "Flexible specificity"
linestyle = "--"
color = "yellowgreen"
linewidth = 1.1
elif header == in_vivo_id:
label = "Wild-type specificity"
linestyle = "-"
color = "black"
linewidth = 1.1
elif header == only_one_id:
label = "Single cofactor pool"
linestyle = "-"
color = "red"
linewidth = 1.1
else:
if is_first_random:
label = "Random specificities"
is_first_random = False
else:
label = ""
linestyle = "-"
color = "paleturquoise"
linewidth = 0.6
axs[0].plot(
growth_rates[:-1], # x
list_to_float(table[header])[:-1], # y
label=label,
linestyle=linestyle,
color=color,
linewidth=linewidth,
)
axs[0].legend(loc="lower left", fontsize=7)
axs[0].set_title("a", loc="left", fontweight="bold", fontsize=7)
axs[0].set_xlabel("Growth rate [1/h]", fontsize=7)
axs[0].set_ylabel("SubMDF [kJ/mol]", fontsize=7)
axs[0].set_xlim(min(growth_rates[:-1]), max(growth_rates[:-1]))
axs[0].tick_params(axis="both", labelsize=6)
########################################################
########################################################
########################################################
# 1: Ratio ratio figure
ratio_ratio_test_data = ratio_ratio_test_data_aerobic
min_label = "Minimal ratio"
max_label = "Maximal ratio"
figurename = figurename_tuple[1]
plotted_growth_rates = [float(x) for x in ratio_ratio_test_data[figurename]["plotted_growth_rates"][:-1]]
min_ratios = [float(x) for x in ratio_ratio_test_data[figurename]["min_ratios"][:-1]]
max_ratios = [float(x) for x in ratio_ratio_test_data[figurename]["max_ratios"][:-1]]
axs[1].plot(
plotted_growth_rates[::-1], # x
min_ratios[::-1], # y
"bo",
label=min_label,
linewidth=1.0,
markersize=2.75,
)
axs[1].plot(
plotted_growth_rates[::-1], # x
max_ratios[::-1], # y
"ro",
label=max_label,
linewidth=1.0,
markersize=2.75,
)
axs[1].legend(loc="upper center", ncol=2, fontsize=7)
axs[1].set_title("b", loc="left", fontweight="bold", fontsize=7)
axs[1].set_xlabel("Growth rate [1/h]", fontsize=7)
# axs[1].set_ylabel(r"$\mathrm{\frac{[NADH]/[NAD^{+}]}{[NADPH]/[NADP^{+}]}}$", fontsize=15)
axs[1].set_ylabel(r"$\mathrm{[NADH]/[NAD^{+}] \ / \ [NADPH]/[NADP^{+}]}$", fontsize=7)
axs[1].tick_params(labelsize=6)
axs[1].set_ylim(-.00003, 0.0006)
axs[1].set_xlim(0.025, 0.89)
pad_inches = 0.05
# fig.subplots_adjust(right=1.1)
fig.savefig(output_path, bbox_inches='tight', pad_inches=pad_inches)
fig.savefig("./cosa/FigureS2.png", bbox_inches='tight', pad_inches=pad_inches)
fig.savefig("./cosa/FigureS2.pdf", bbox_inches='tight', pad_inches=pad_inches)
plt.close()
def create_acetate_figure():
"""Creates figure for results under acetate."""
ratio_ratio_test_data_aerobic = json_load("cosa/results_aerobic_acetate/ratio_ratio_test_data.json")
concentration = "STANDARDCONC"
output_path = "./cosa/acetate_figure.png"
pad = 1.724
cm = 1/2.54
fig, axs = plt.subplots(nrows=2, ncols=2, dpi=500, figsize=(18*cm, 14.14*cm)) #sharex=True, figsize=(50, 25), dpi=120, facecolor="white")
# fig, axs = plt.subplots(nrows=2, ncols=2, dpi=500, figsize=(14, 11)) #sharex=True, figsize=(50, 25), dpi=120, facecolor="white")
fig.tight_layout(pad=pad)
for target in ("OPTSUBMDF", "OPTMDF"):
if target == "OPTSUBMDF":
xpos = 1
else:
xpos = 0
table_path = f"cosa/results_aerobic_acetate/{target.lower()}_table_{concentration}.csv"
figurename_tuple = ("aerobic", f"2C_NADH_to_NAD___to___NADPH_to_nadp_{target}_{concentration}.jpg")
########################################################
########################################################
########################################################
# 0: Random sampling figures
str_to_float = lambda x: float(x.replace(",", "."))
list_to_float = lambda x: [str_to_float(y) for y in x]
growth_rate_id = "µ [1/h]"
best_id = "FLEXIBLE"
in_vivo_id = "WILDTYPE"
only_one_id = "SINGLE_COFACTOR"
table = pandas.read_csv(
table_path,
sep="\t",
)
headers = list(table.keys())
del(headers[headers.index(best_id)])
del(headers[headers.index(only_one_id)])
del(headers[headers.index(in_vivo_id)])
headers += [only_one_id, in_vivo_id, best_id]
growth_rates = list_to_float(table[growth_rate_id])
is_first_random = True
for header in headers:
if header == growth_rate_id:
continue
elif header == best_id:
label = "Flexible specificity"
linestyle = "--"
color = "yellowgreen"
linewidth = 1.0
elif header == in_vivo_id:
label = "Wild-type specificity"
linestyle = "-"
color = "black"
linewidth = 1.0
elif header == only_one_id:
label = "Single cofactor pool"
linestyle = "-"
color = "red"
linewidth = 1.0
else:
if is_first_random:
label = "Random specificities"
is_first_random = False
else:
label = ""
linestyle = "-"
color = "paleturquoise"
linewidth = .6
axs[xpos, 0].plot(
growth_rates[:-1], # x
list_to_float(table[header])[:-1], # y
label=label,
linestyle=linestyle,
color=color,
linewidth=linewidth,
)
axs[xpos, 0].legend(loc="lower left", fontsize=7)
axs[xpos, 0].set_title("c" if "SUB" in target else "a", loc="left", fontweight="bold", fontsize=7)
axs[xpos, 0].set_xlabel("Growth rate [1/h]", fontsize=7)
axs[xpos, 0].set_ylabel(f"{target.replace('OPT', '').replace('SUB', 'Sub')} [kJ/mol]", fontsize=7)
axs[xpos, 0].set_xlim(min(growth_rates[:-1]), max(growth_rates[:-1]))
axs[xpos, 0].tick_params(axis="both", labelsize=7)
########################################################
########################################################
########################################################
# 1: Ratio ratio figures
ratio_ratio_test_data = ratio_ratio_test_data_aerobic
min_label = "Minimal ratio"
max_label = "Maximal ratio"
figurename = figurename_tuple[1]
plotted_growth_rates = [float(x) for x in ratio_ratio_test_data[figurename]["plotted_growth_rates"][:-1]]
min_ratios = [float(x) for x in ratio_ratio_test_data[figurename]["min_ratios"][:-1]]
max_ratios = [float(x) for x in ratio_ratio_test_data[figurename]["max_ratios"][:-1]]
axs[xpos, 1].plot(
plotted_growth_rates[::-1], # x
min_ratios[::-1], # y
"bo",
label=min_label,
linewidth=1.0,
markersize=3,
)
axs[xpos, 1].plot(
plotted_growth_rates[::-1], # x
max_ratios[::-1], # y
"ro",
label=max_label,
linewidth=1.0,
markersize=3,
)
axs[xpos, 1].legend(loc="upper center", ncol=2, fontsize=7)
axs[xpos, 1].set_title("d" if "SUB" in target else "b", loc="left", fontweight="bold", fontsize=7)
axs[xpos, 1].set_xlabel("Growth rate [1/h]", fontsize=7)
axs[xpos, 1].set_ylabel(r"$\mathrm{[NADH]/[NAD^{+}] \ / \ [NADPH]/[NADP^{+}]}$", fontsize=7)
axs[xpos, 1].tick_params(labelsize=7)
axs[xpos, 1].set_ylim(-.00001 if "SUB" in target else -0.0025, 0.0003 if "SUB" in target else 0.06)
axs[xpos, 1].set_xlim(0.045, 0.21)
axs[xpos, 1].tick_params(axis="both", labelsize=7)
pad_inches = 0.05
# fig.subplots_adjust(right=1.1)
fig.savefig(output_path, bbox_inches='tight', pad_inches=pad_inches)
fig.savefig("./cosa/Figure6.pdf", bbox_inches='tight', pad_inches=pad_inches)
plt.close()
create_in_vivo_concentrations_figure()
create_acetate_figure()