|
| 1 | +import matplotlib.pyplot as plt |
| 2 | +import pandas |
| 3 | +from helper import json_load |
| 4 | + |
| 5 | +def create_in_vivo_concentrations_figure(): |
| 6 | + ratio_ratio_test_data_aerobic = json_load("cosa/results_aerobic/ratio_ratio_test_data.json") |
| 7 | + concentration = "VIVOCONC" |
| 8 | + target = "OPTSUBMDF" |
| 9 | + |
| 10 | + figurename_tuple = ("aerobic", f"2C_NADH_to_NAD___to___NADPH_to_nadp_{target}_{concentration}.jpg") |
| 11 | + |
| 12 | + fig, axs = plt.subplots(nrows=2, ncols=1, dpi=500, figsize=(6, 8)) #sharex=True, figsize=(50, 25), dpi=120, facecolor="white") |
| 13 | + fig.tight_layout(pad=3.75) |
| 14 | + |
| 15 | + ######################################################## |
| 16 | + ######################################################## |
| 17 | + ######################################################## |
| 18 | + # 0: Random sampling figure |
| 19 | + str_to_float = lambda x: float(x.replace(",", ".")) |
| 20 | + list_to_float = lambda x: [str_to_float(y) for y in x] |
| 21 | + |
| 22 | + growth_rate_id = "µ [1/h]" |
| 23 | + best_id = "FLEXIBLE" |
| 24 | + in_vivo_id = "WILDTYPE" |
| 25 | + only_one_id = "SINGLE_COFACTOR" |
| 26 | + |
| 27 | + table_path = f"cosa/results_aerobic/optsubmdf_table_VIVOCONC.csv" |
| 28 | + table = pandas.read_csv( |
| 29 | + table_path, |
| 30 | + sep="\t", |
| 31 | + ) |
| 32 | + |
| 33 | + headers = list(table.keys()) |
| 34 | + del(headers[headers.index(best_id)]) |
| 35 | + del(headers[headers.index(only_one_id)]) |
| 36 | + del(headers[headers.index(in_vivo_id)]) |
| 37 | + headers += [only_one_id, in_vivo_id, best_id] |
| 38 | + |
| 39 | + growth_rates = list_to_float(table[growth_rate_id]) |
| 40 | + is_first_random = True |
| 41 | + for header in headers: |
| 42 | + if header == growth_rate_id: |
| 43 | + continue |
| 44 | + elif header == best_id: |
| 45 | + label = "Flexible specificity" |
| 46 | + linestyle = "--" |
| 47 | + color = "yellowgreen" |
| 48 | + linewidth = 2.0 |
| 49 | + elif header == in_vivo_id: |
| 50 | + label = "Wild-type specificity" |
| 51 | + linestyle = "-" |
| 52 | + color = "black" |
| 53 | + linewidth = 2.0 |
| 54 | + elif header == only_one_id: |
| 55 | + label = "Single cofactor pool" |
| 56 | + linestyle = "-" |
| 57 | + color = "red" |
| 58 | + linewidth = 2.0 |
| 59 | + else: |
| 60 | + if is_first_random: |
| 61 | + label = "Random specificities" |
| 62 | + is_first_random = False |
| 63 | + else: |
| 64 | + label = "" |
| 65 | + linestyle = "-" |
| 66 | + color = "paleturquoise" |
| 67 | + linewidth = 1.0 |
| 68 | + |
| 69 | + axs[0].plot( |
| 70 | + growth_rates[:11], # x |
| 71 | + list_to_float(table[header])[:11], # y |
| 72 | + label=label, |
| 73 | + linestyle=linestyle, |
| 74 | + color=color, |
| 75 | + linewidth=linewidth, |
| 76 | + ) |
| 77 | + axs[0].legend(loc="lower left") |
| 78 | + axs[0].set_title("A", loc="left", fontweight="bold") |
| 79 | + axs[0].set_xlabel("Growth rate [1/h]") |
| 80 | + axs[0].set_ylabel("OptSubMDF [kJ/mol]") |
| 81 | + axs[0].set_xlim(min(growth_rates[:11]), max(growth_rates[:11])) |
| 82 | + |
| 83 | + |
| 84 | + ######################################################## |
| 85 | + ######################################################## |
| 86 | + ######################################################## |
| 87 | + # 1: Ratio ratio figure |
| 88 | + ratio_ratio_test_data = ratio_ratio_test_data_aerobic |
| 89 | + |
| 90 | + min_label = "Minimal ratio" |
| 91 | + max_label = "Maximal ratio" |
| 92 | + |
| 93 | + figurename = figurename_tuple[1] |
| 94 | + plotted_growth_rates = ratio_ratio_test_data[figurename]["plotted_growth_rates"][:10] |
| 95 | + min_ratios = ratio_ratio_test_data[figurename]["min_ratios"][:10] |
| 96 | + max_ratios = ratio_ratio_test_data[figurename]["max_ratios"][:10] |
| 97 | + axs[1].plot( |
| 98 | + plotted_growth_rates[::-1], # x |
| 99 | + min_ratios[::-1], # y |
| 100 | + "bo", |
| 101 | + label=min_label, |
| 102 | + linewidth=1.0, |
| 103 | + ) |
| 104 | + axs[1].plot( |
| 105 | + plotted_growth_rates[::-1], # x |
| 106 | + max_ratios[::-1], # y |
| 107 | + "ro", |
| 108 | + label=max_label, |
| 109 | + linewidth=1.0, |
| 110 | + ) |
| 111 | + axs[1].legend(loc="upper center", ncol=2) |
| 112 | + axs[1].set_title("B", loc="left", fontweight="bold") |
| 113 | + axs[1].set_ylim(-.0005, 0.01) |
| 114 | + axs[1].set_xlabel("Growth rate [1/h]") |
| 115 | + axs[1].set_ylabel(r"$\mathrm{\frac{[NADH]/[NAD^{+}]}{[NADPH]/[NADP^{+}]}}$", fontsize=13) |
| 116 | + |
| 117 | + fig.savefig(f"./cosa/in_vivo_concentrations_figure.png", bbox_inches='tight', pad_inches=0.05) |
| 118 | + plt.close() |
| 119 | + |
| 120 | +create_in_vivo_concentrations_figure() |
0 commit comments