<jupyter_start><jupyter_text>IntroductionCritical to the prediction of the model, is the medium the cell is being grown in. This notebook will investigate the medium and modify it to a realistic medium.<jupyter_code>import cameo
import pandas as pd
import cobra.io
import escher
model = cobra.io.read_sbml_model('../model/p-thermo.xml')
#for inspiration 
model_e_coli = cameo.load_model('iML1515')
len(model.medium)
len(model_e_coli.medium)
model.reactions.EX_Biomass_e.bounds = (0,1000)<jupyter_output><empty_output><jupyter_text>Here I see that in notebook 17, I added demand reactions instead of exchanges. Therefore these 18 demands are not included in the list of exchanges & medium. So here I first quickly have to modify this before running the script below.First I will remove all of the demands and then add exchanges for the metabolites without one.<jupyter_code>#make listof of metabolites without exchange, i.e. metabolites in the demand
need_exchanges=[]
for rct in model.demands:
    met =  next(iter(rct.metabolites))
    need_exchanges.append(met)
model.remove_reactions(model.demands)
#add exchange reactions for metabolites
for met in need_exchanges:
    model.add_boundary(met, type = 'exchange', reaction_id = f"EX_{met.id}")
len(model.exchanges)<jupyter_output><empty_output><jupyter_text>You can see there is a clear difference in the number of components in the medium between the models. Our model has all exchanges as irreversible, and so all components are *in silico* supplied to the model. Therefore this needs to be changed.I will change this so that the only carbon source is glucose to start with, and we assume a somewhat minimal medium: i.e. no amino acids are supplemented. First of all, there are many more exchanges and extracellular metabolites than there are transported into the cell. These will be removed. Then I can re-evaluate how many exchanges too much there are.To approach the problem, first I will make a list of the exchanges that I think should only be excreted and not taken up. I will run this by Martyn before implementing it.Then for each reaction one by one i can remove it and check that it doesn't kill biomass accumulation. If so, i will make a note of it and need to look into why it is needed. Then I can remove the medium components that are not required to slim it down.<jupyter_code>extracell_mets = []
for met in model.metabolites:
    met_id = met.id
    if met_id[-1:] in 'e':
        extracell_mets.append(met)
    else:
        continue
len(extracell_mets)
#make a list and remove all extracellular metabolites with no transport into the cell
e_met_wo_trans = []
e_met_w_trans =[]
for met in model.metabolites:
    if met in extracell_mets:
        rcts = met.reactions
        if len(met.reactions) == 1:
            rct_id = next(iter(met.reactions)).id
            if rct_id[:2] in 'EX':
                e_met_wo_trans.append(met)
            else:
                print(met)
        else: 
            e_met_w_trans.append(met)
    else:
        continue<jupyter_output>pyr_e<jupyter_text>Here, pyr_e is printed as it doesn't have a demand yet, so I will add that now.<jupyter_code>model.add_boundary(model.metabolites.pyr_e, type = 'exchange', reaction_id = 'EX_pyr_e')
#Pyruvate is not supplied
model.reactions.EX_pyr_e.bounds = (0,1000)
len(e_met_w_trans)
len(e_met_wo_trans)
#e_met_wo_trans contains all extracellular metabolites without transport. 
#so these metabolites and their exchange reactions can be removed.
for met in e_met_wo_trans:
    rct_id = next(iter(met.reactions)).id
    rct = model.reactions.get_by_id(rct_id)
    model.remove_metabolites(met)
    model.remove_reactions(rct)
len(model.exchanges)
#save&commit cleaning of exchanges
cobra.io.write_sbml_model(model,'../model/p-thermo.xml')
#model.medium<jupyter_output><empty_output><jupyter_text>From the above code we have made the list of medium to revisit a lot smaller. You can clearly see some things that have to be changed. For example, the strain should (in principle) be able to produce ethanol, acetate, succinate and lactate, but not consume it. Also, we asume a minimal medium with no amino acid supplements, explaining some other changes that should be made (e.g. dlglu_c and asn__L_e).<jupyter_code>model.reactions.EX_asn__L_e.bounds = (0,1000)
model.reactions.EX_etoh_e.bounds = (0,1000)
model.reactions.EX_ac_e.bounds = (0,1000)
model.reactions.EX_succ_e.bounds = (0,1000)
model.reactions.EX_lac__D_e.bounds = (0,1000)
model.reactions.EX_lac__L_e.bounds = (0,1000)
#a wrong metabolite, so can be removed
model.remove_metabolites(model.metabolites.succcoa_c)
#this met can be removed as there is already a glutamate intracellularly.
model.remove_metabolites(model.metabolites.dlglu_c)
#oxygen should only be taken up, never producted
model.reactions.EX_o2_e.bounds = (-1000,0)<jupyter_output><empty_output><jupyter_text>Thiamin exchange should be investigated further at a later stage. We know from experiments that supplementing minimal medium with Thiamin or TPP significantly increases the growth. And so I will leave this in here for now, and we can take a look at it later.<jupyter_code>model.reactions.EX_oh1_e.id = 'EX_h2o_e'<jupyter_output><empty_output><jupyter_text>We assume glucose is the only carbon source, as we know on minimal medium, our strain can grow on glucose. So I will remove all other exchanges from the medium by setting the lower bound to 0.<jupyter_code>model.reactions.EX_rib__D_e.bounds = (0,1000)
model.reactions.EX_pydx5p_e.bounds = (0,1000)
model.reactions.EX_gal_e.bounds = (0,1000)
model.reactions.EX_man_e.bounds = (0,1000)
model.reactions.EX_arbt_e.bounds = (0,1000)
model.reactions.EX_salcn_e.bounds = (0,1000)
model.reactions.EX_glyc_e.bounds = (0,1000)
model.reactions.EX_tre_e.bounds = (0,1000)
model.reactions.EX_fru_e.bounds = (0,1000)
model.reactions.EX_arab__L_e.bounds = (0,1000)
model.reactions.EX_xyl__D_e.bounds = (0,1000)
model.reactions.EX_mnl_e.bounds = (0,1000)
model.reactions.EX_cellb_e.bounds = (0,1000)
model.reactions.EX_sucr_e.bounds = (0,1000)
model.reactions.EX_sbt__D_e.bounds = (0,1000)
model.reactions.EX_acgam_e.bounds = (0,1000)
model.reactions.EX_malt_e.bounds = (0,1000)
model.reactions.EX_rmn_e.bounds = (0,1000)
model.reactions.EX_melib_e.bounds = (0,1000)
model.reactions.EX_gtbi_e.bounds = (0,1000)
model.reactions.EX_tura_e.bounds = (0,1000)
model.reactions.EX_kdg2_e.bounds = (0,1000)
model.reactions.EX_dglcn5_e.bounds = (0,1000)
model.reactions.EX_mdgp_e.bounds = (0,1000)
model.reactions.EX_tag__D_e.bounds = (0,1000)
model.reactions.EX_amylose_e.bounds = (0,1000)
solution= model.optimize()
solution.objective_value<jupyter_output><empty_output><jupyter_text>__Notes__: Reactions that I cannot remove and maintain biomass right now. These reactions need further investigation when I've opened the flux constrains as they should and the model is mass balanced.- EX_gthrd_e- EX_thm_e- EX_qh2_e- EX_nadp_e<jupyter_code>#intrestingly TPP is not critical to the model....
model.reactions.EX_thmtp_e.bounds = (0,1000)
model.medium
#save&commit
cobra.io.write_sbml_model(model,'../model/p-thermo.xml')
#check on map
solution = model.optimize()
solution<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08733019129470473, 'fraction_numerical': 0.027585250901025784, 'mean_word_length': 4.9925249169435215, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '421973', 'license': 'Apache-2.0', 'n_tokens_mistral': 2606, 'n_tokens_neox': 2384, 'n_words': 740, 'path': 'notebooks/18. Defining medium.ipynb', 'repo_name': 'biosustain/p-thermo', 'size': '7214'}