-
Notifications
You must be signed in to change notification settings - Fork 0
/
11) plot flux histograms for flux maps.py
131 lines (113 loc) · 4.98 KB
/
11) plot flux histograms for flux maps.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
import matplotlib.pyplot as plt
import hopsy
import cobra
import os
import numpy as np
import helpers
import pandas as pd
import time
if __name__ == "__main__":
models = [
'iEZ481_PCA_Gluc',
'iEZ481_Glucose-MOPS',
'iEZ481_Citrat-MOPS',
]
b_samples = {}
for i, model in enumerate(models):
b_samples[model] = np.load(file=os.path.join('data', f'{model}_boltzmann_samples_thinned.npz'))['samples']
media = {
'iEZ481_PCA_Gluc': 'PCA',
'iEZ481_Glucose-MOPS': 'GLC',
'iEZ481_Citrat-MOPS': 'CIT',
}
fba_keys = { 'iEZ481_PCA_Gluc': 'PCA-Gluc_fluxes.csv', 'iEZ481_Glucose-MOPS': 'glucose-MOPS_fluxes.csv', 'iEZ481_Citrat-MOPS': 'citrat-MOPS_fluxes.csv'}
fba_results = {}
for m in models:
fba_results[m] = pd.read_csv(f'data/fba_results/{fba_keys[m]}')[['Unnamed: 0','mean0stds']]
fba_results[m].columns = ['flux', 'fba result']
fba_results[m].set_index('flux', inplace=True)
fba_results[m] = fba_results[m].T
flux_names = {}
for m in models:
model_path = os.path.join("models", m + ".xml")
cobra_model = cobra.io.read_sbml_model(model_path)
# open up growth rate constraints
flux_names[m] = []
for i, rxn in enumerate(cobra_model.reactions):
flux_names[m].append(rxn.id)
assert flux_names[models[0]] == flux_names[models[1]]
assert flux_names[models[1]] == flux_names[models[2]]
flux_names = flux_names[models[0]]
n_bins = 20
# fluxes_to_plot = \
# ["pcaGH", "biomass_a", "acnA", "icd", "odhA", "sucD", "sdhCAB", "fumC", "mqo", "gltA", "pgi", "pyk", "pdh", "aceB", "aceA", "mdh", "odx", "pyc", "mez", "pckG", "ppc", "pfkA", "fda", "gapA", "pgk", "eno", "zwf", "opcA", "gnd", "pgm", "rpe", "rpi", "tkt_1", "tal", "tkt_2", "tpiA", "pps", "fbp", "pts", "acnB", "gapB", "actA", "pcaGF"]
fluxes_to_plot = [
# "acnB",
# "gnd",
# "icd",
# "ldh",
# "mdh",
# "pgk",
'tkt_2', 'pgi', 'sdhCAB', 'rpi', 'fda', 'sucD', 'gltA', 'pyc', 'pgk', 'aceA',
]
# print('plotting', len( fluxes_to_plot ), 'fluxes')
n_bins = 20
for i, flux_name in enumerate(fluxes_to_plot):
time.sleep(0.5)
flux_index = flux_names.index(flux_name)
maximum_flux = np.max([np.max(b_samples[m][:,:,flux_index].flatten()) for m in models])
minimum_flux = np.min([np.min(b_samples[m][:,:,flux_index].flatten()) for m in models])
minimum_flux = np.min([0, minimum_flux])
maximum_flux = np.max([maximum_flux] + [fba_results[m][flux_name].values.flatten()[0] for m in models])
flux_range = (maximum_flux - minimum_flux)
maximum_flux += 0.01 * flux_range
minimum_flux -= 0.01 * flux_range
# densly dashed, loosely dashed, losely dotted
style = (0, (5, 1))
for j, m in enumerate(models):
plt.figure(figsize=(2.5, 2.5))
# plt.title(flux_name)
# print('range', m, np.max(b_samples[m][:, :, i].flatten())), np.min(b_samples[m][:, :, i].flatten())
fba = fba_results[m][flux_name].values.flatten()[0]
print(m, flux_name, fba)
_, bins, _ = plt.hist(
b_samples[m][:, :, flux_index].flatten(),
bins=n_bins, # if bins is None else bins,
alpha=0.25,
density=True,
# label=f'MaxEnt {media[m]}',
color=f'C{j}',
)
_, bins, _ = plt.hist(
b_samples[m][:, :, flux_index].flatten(),
bins=n_bins, # if bins is None else bins,
histtype='step',
linewidth=3,
density=True,
color=f'C{j}',
)
# plt.axvline(x=fba_results[m][flux_name].values.flatten(), color=f'k', linewidth=3, linestyle=style,
# label=f'FBA'
# )
# plt.xlabel('flux value [mmol/gwd/h]')
# plt.ylabel('density')
# plt.tick_params(
# axis='both', # changes apply to the x-axis
# which='both', # both major and minor ticks are affected
# bottom=False, # ticks along the bottom edge are off
# top=False, # ticks along the top edge are off
# labelbottom=False)
# plt.tick_params(
# axis='y', # changes apply to the x-axis
# which='both', # both major and minor ticks are affected
# bottom=False, # ticks along the bottom edge are off
# top=False, # ticks along the top edge are off
# labelbottom=False)
plt.axis('off')
# leg = plt.legend(bbox_to_anchor=(1.0, 1))
plt.tight_layout()
# plt.title(flux_name)
plt.savefig(f'flux_map_components_svg/{m}_{flux_name}.svg', bbox_inches='tight',
# bbox_extra_artists=(leg,))
)
plt.show()