<jupyter_start><jupyter_text>Flux distribution analysis First load the model which grows on SNM3 media. Note than in previous notebook the default media was set to be SNM3 so we only have to load it.<jupyter_code>model = cobra.io.read_sbml_model("consistent_DP_SNM.xml")
print(model.slim_optimize())
snm3 = pd.read_csv("SNM3.csv", sep=";")
snm3.head()<jupyter_output><empty_output><jupyter_text>We now will compute all fluxes through FBA, together with their bounds using FVA. This is done for all reactions.<jupyter_code># Computing all fluxes
sol = model.optimize()
# Flux variability analyisis for all
fva = cobra.flux_analysis.flux_variability_analysis(model)
# Sticking them together
df_fluxes = fva.copy()
df_fluxes["flux"] = sol.fluxes
df_fluxes.to_excel("fluxes_DP.xlsx")
df_fluxes.head()<jupyter_output><empty_output><jupyter_text>Here we plot all non-zero fluxes which are around 256. They are mostly rather small with some outliears. The x-axis contains labels from fluxes which were rather high/low.<jupyter_code>plt.figure(figsize=(20,5))
non_zero_flux = df_fluxes["flux"].loc[df_fluxes["flux"] != 0]
plt.plot(non_zero_flux.index, non_zero_flux, ".--")
high_vals = df_fluxes.index[df_fluxes["flux"] > 5].tolist() + df_fluxes.index[df_fluxes["flux"] < -5].tolist()
a = plt.xticks(high_vals, rotation=90)<jupyter_output><empty_output><jupyter_text>Plotting exchange fluxesWe will plot the bounds for the exchange fluxes such that the organism still achives maximal growth. This is done with FVA, we recompute them here for convecnience but can also be extracted from previous list.<jupyter_code># Exchange fluxes fva, for all non-zero exchanges
fva_ex = model.summary(fva=1.0)
fva_ex = fva_ex.to_frame()
fva_ex.head()
# Get necessary values for plotting
x = []
y_fluxes = []
y_min_flux = []
y_max_flux = []
for _, data in fva_ex.iterrows():
    id = str(data.metabolite[:-2])
    f = data.factor*data.flux 
    f_min = data.factor*data.minimum 
    f_max = data.factor*data.maximum

    if not (f_min == 0 and f_max == 0):
        for j in range(len(snm3)):
            ide = str(snm3.iloc[j][1]) + "_e"
            if ide == id + "_e":
                x.append(str(snm3.iloc[j][0]))
                y_fluxes.append(f)
                y_min_flux.append(f_min)
                y_max_flux.append(f_max)

len(x)
# Draw plot
title_font = {'fontname':'Arial', 'size':'12', 'color':'black', 'weight':'normal'} 
fig = plt.figure(figsize=(10,5), dpi= 160)
plt.vlines(x=x, ymin=y_min_flux, ymax=y_max_flux, alpha=0.8, color="C0")

# Plot FBA flux value as black dot
plt.scatter(x=x, y= y_fluxes, color="black",s=5)

#Plot maximum/minimum value in green
for y_min, x1, y_max in zip(y_min_flux, x, y_max_flux):
    t = plt.text(x1,y_min+0.1, round(y_min, 2), horizontalalignment='left', color="green",
                verticalalignment='bottom', size=4)
    t = plt.text(x1,y_max-1.5, round(y_max, 2), horizontalalignment='left', color="red",
                verticalalignment='bottom', size=4)

# Decorations    
#plt.title('Exchange flux range', **title_font)

plt.xticks(x,rotation=90)
plt.grid(linestyle='--', alpha=0.5)
plt.ylabel("Flux")
fig.tight_layout()
#plt.gcf().subplots_adjust(bottom=0.1)
plt.show()
fig.savefig("ex_flux_DP_RM.pdf")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13740458015267176, 'fraction_numerical': 0.016793893129770993, 'mean_word_length': 4.6678200692041525, 'pattern_counts': {'":': 1, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '321661', 'license': 'MIT', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1193, 'n_words': 280, 'path': 'flux_distribution_DP.ipynb', 'repo_name': 'Biomathsys/community-D-pigrum-S-aureus-human-nose', 'size': '3275'}