def add_min_log_displacement(tmodel, min_log_displacement, tva_fluxes=None, inplace=True): EPSILON = tmodel.solver.configuration.tolerances.feasibility if inplace: temp_model = tmodel else: temp_model = tmodel.copy() if tva_fluxes is None: tva_fluxes = variability_analysis(temp_model, kind='reactions') for ln_gamma in temp_model.thermo_displacement: if tva_fluxes["minimum"][ln_gamma.id] >= -EPSILON and \ tva_fluxes["maximum"][ln_gamma.id] > -EPSILON : ln_gamma.variable.ub = -min_log_displacement elif tva_fluxes["minimum"][ln_gamma.id] < EPSILON and \ tva_fluxes["maximum"][ln_gamma.id] <= EPSILON : ln_gamma.variable.lb = min_log_displacement else: raise ValueError("Not a model with fixed directionality!") temp_model.repair() return temp_model
continuous_model.growth_reaction.upper_bound = 10 continuous_model.reactions.EX_glc__D_e.lower_bound = glc_uptake - 0.1 continuous_model.reactions.EX_glc__D_e.upper_bound = glc_uptake + 0.1 continuous_model.optimize() mu = continuous_model.growth_reaction.flux mu_lo, mu_hi = get_mu_bin(continuous_model, mu) continuous_model.growth_reaction.upper_bound = mu_hi continuous_model.growth_reaction.lower_bound = mu_lo print_sol(continuous_model) variables = EnzymeVariable eva = variability_analysis(continuous_model, variables) peptides_conc_min = pd.Series(enzymes_to_peptides_conc(continuous_model, eva['minimum'])) peptides_conc_max = pd.Series(enzymes_to_peptides_conc(continuous_model, eva['maximum'])) peptides_conc = pd.concat([peptides_conc_min,peptides_conc_max], axis=1) peptides_conc.to_csv('outputs/iJO_T1E1N1_low_hi_{}_pep.csv'.format(glc_uptake)) rescale = lambda row: ecoli.mrnas.get_by_id(row.name[3:]).scaling_factor * row eva_real = eva.apply(rescale, axis=1) eva_real.to_csv('outputs/iJO_T1E1N1_low_hi_{}_enz.csv'.format(glc_uptake)) # mva = variability_analysis(continuous_model, mRNAVariable) # rescale = lambda row: ecoli.mrnas.get_by_id(row.name[3:]).scaling_factor * row # mva_real = mva.apply(rescale, axis=1) # mva_real.to_csv('outputs/iJO_T1E1N1_low_hi_{}_mrna.csv'.format(glc_uptake))
# Set the solver tmodel.solver = GLPK ## TFA conversion tmodel.prepare() tmodel.convert(add_displacement=True) ## Info on the cobra_model tmodel.print_info() ## Optimality solution = tmodel.optimize() # Calculate variability analysis on all continuous variables fva_fluxes = flux_variability_analysis(cobra_model) tva_fluxes = variability_analysis(tmodel, kind='reactions') # Add more specific concentration data def apply_concentration_bound(met, lb, ub): the_conc_var = tmodel.log_concentration.get_by_id(met) # Do not forget the variables in the model are logs ! the_conc_var.ub = log(ub) the_conc_var.lb = log(lb) apply_concentration_bound('atp_c', lb=1e-3, ub=1e-2) apply_concentration_bound('adp_c', lb=4e-4, ub=7e-4) apply_concentration_bound('amp_c', lb=2e-4, ub=3e-4) tmodel.optimize()
## TFA conversion tmodel.prepare() tmodel.convert(add_displacement=True) ## Info on the cobra_model tmodel.print_info() ## Optimality solution = tmodel.optimize() # Apply the directionality of the solution to the cobra_model fixed_directionality_model = apply_directionality(tmodel, solution) # Calculate variability analysis on all continuous variables tva_fluxes = variability_analysis(fixed_directionality_model, kind='reactions') thermo_vars = [DeltaG, DeltaGstd, ThermoDisplacement] tva_thermo = variability_analysis(fixed_directionality_model, kind=thermo_vars) tight_model = apply_reaction_variability(fixed_directionality_model, tva_fluxes) tight_model = apply_generic_variability(tight_model, tva_thermo) ## Sample space from pytfa.optim import strip_from_integer_variables from pytfa.analysis import sample continuous_model = strip_from_integer_variables(tight_model) sampling = sample(continuous_model, 10, processes=10) directory = 'outputs/'