def remove_temperature_constraints(ecmodel, etcmodel, prot): # ecmodel: original model without temperature constraints # etcmodel: model which have temperature constraints for some/all enzymes # prot: uniprot id # original coeffes met1 = ecmodel.metabolites.get_by_id('prot_{0}'.format(prot)) old_kcat_coeffs = { rxn.id: rxn.get_coefficient(met1) for rxn in met1.reactions } met2 = ecmodel.metabolites.prot_pool rxn = ecmodel.reactions.get_by_id('draw_prot_{0}'.format(prot)) old_fnt_coeff = rxn.get_coefficient(met2) # rescue prot met1 = etcmodel.metabolites.get_by_id('prot_{0}'.format(prot)) for rxn_id, old_coeff in old_kcat_coeffs.items(): rxn = etcmodel.reactions.get_by_id(rxn_id) etc.change_rxn_coeff(rxn, met1, old_coeff) met2 = etcmodel.metabolites.prot_pool rxn = etcmodel.reactions.get_by_id('draw_prot_{0}'.format(prot)) etc.change_rxn_coeff(rxn, met2, old_fnt_coeff)
def do_a_fcc(model, tested_enzymes, enzymes): # tsted_enzymes: a list of enzyme already test. In the order of test iteration # 2. do fcc at each temperature fccs = dict() delta = 10 # Get all enzymes try: u0 = model.optimize().objective_value except: u0 = np.nan print('Model Track u0:', T, u0) for enz_id in enzymes: if enz_id in tested_enzymes: continue if np.isnan(u0) or u0 == 0: fccs[enz_id] = np.nan else: with model as m: enz = m.metabolites.get_by_id(enz_id) # Perturbe kcat in all reactions of this enzyme for rxn in enz.reactions: if rxn.id.startswith('draw_'): continue new_coeff = rxn.get_coefficient(enz) / (1 + delta) etc.change_rxn_coeff(rxn, enz, new_coeff) try: u = m.optimize().objective_value except: u = np.nan if u is None: fc = np.nan else: fc = (u - u0) / u0 / delta fccs[enz.id] = fc return fccs
def simulate_growth(model, Ts, sigma, df, prot): ''' # model, cobra model # Ts, a list of temperatures in K # sigma, enzyme saturation factor # df, a dataframe containing thermal parameters of enzymes: dHTH, dSTS, dCpu, Topt # Ensure that Topt is in K. Other parameters are in standard units. # prot: uniprotid, enzyme to be rescued ''' rs0 = list() rs = list() met1 = model.metabolites.get_by_id('prot_{0}'.format(prot)) old_kcat_coeffs = { rxn.id: rxn.get_coefficient(met1) for rxn in met1.reactions } met2 = model.metabolites.prot_pool rxn = model.reactions.get_by_id('draw_prot_{0}'.format(prot)) old_fnt_coeff = rxn.get_coefficient(met2) for T in Ts: with model: # map temperature constraints etc.map_fNT(model, T, df) etc.map_kcatT(model, T, df) etc.set_NGAMT(model, T) etc.set_sigma(model, sigma) try: r = model.optimize().objective_value except: print('Failed to solve the problem') r = 0 print(T - 273.15, r) rs0.append(r) # rescue prot met1 = model.metabolites.get_by_id('prot_{0}'.format(prot)) for rxn_id, old_coeff in old_kcat_coeffs.items(): rxn = model.reactions.get_by_id(rxn_id) etc.change_rxn_coeff(rxn, met1, old_coeff) met2 = model.metabolites.prot_pool rxn = model.reactions.get_by_id('draw_prot_{0}'.format(prot)) etc.change_rxn_coeff(rxn, met2, old_fnt_coeff) try: r = model.optimize().objective_value except: print('Failed to solve the problem') r = 0 print(T - 273.15, r) rs.append(r) return rs0, rs
def do_fcc_at_T(T,params,sigma,delta): # Ts: temperatures at which simulation will be performed # params: a dataframe with Topt, Tm, T90, dCpt of all enzymes # sigma: enzyme saturation factor # delta: the fold change to be made for kcat of each enzyme # # return a dataframe with temperature as column and enzyme id as index model = pickle.load(open('../models/aerobic.pkl','rb')) # 1. Calculate thermal parameters dfparam = etc.calculate_thermal_params(params) enzymes = list(set([met.id for met in model.metabolites if met.id.startswith('prot_') and met.id != 'prot_pool'])) # 2. do fcc at each temperature data = dict() etc.map_fNT(model,T,dfparam) etc.map_kcatT(model,T,dfparam) etc.set_NGAMT(model,T) etc.set_sigma(model,sigma) # Get all enzymes try: u0 = model.optimize().objective_value except: u0 = None print('Model Track u0:',T,u0) for enz_id in enzymes: if u0 is None or u0 == 0: data[enz_id.split('_')[1]] = None else: with model as m: enz = m.metabolites.get_by_id(enz_id) # Perturbe kcat in all reactions of this enzyme for rxn in enz.reactions: if rxn.id.startswith('draw_'): continue new_coeff = rxn.get_coefficient(enz)/(1+delta) etc.change_rxn_coeff(rxn,enz,new_coeff) try:u = m.optimize().objective_value except: u = None if u is None: fc = None else: fc = (u-u0)/u0/delta data[enz.id.split('_')[1]] = fc # 3. Create a dataframe with temperature as column and enzyme ids as index lst, index = [], [] for k,v in data.items(): lst.append(v) index.append(k) dfres = pd.DataFrame(data={T:lst},index=index) return dfres
def simulate_one_particle(particle, T, ps): growth_id = 'r_2111' print('Load model') mae = pickle.load(open('../models/aerobic.pkl', 'rb')) # get ori coeffs for ERG1 met1 = mae.metabolites.get_by_id('prot_{0}'.format('P32476')) old_kcat_coeffs = { rxn.id: rxn.get_coefficient(met1) for rxn in met1.reactions } met2 = mae.metabolites.prot_pool rxn = mae.reactions.get_by_id('draw_prot_{0}'.format('P32476')) old_fnt_coeff = rxn.get_coefficient(met2) print('Set temperature constraits') set_temperature_constraints(mae, particle, T) erg_rxns = get_erg_rxns(mae) print('Get vmax') # This is to avoid some unbounded results for rxn_id in erg_rxns: mae.reactions.get_by_id(rxn_id).upper_bound = 1000 erg_vmax = { rxn_id: get_maximal_flux_through_given_rxn(mae, rxn_id, growth_id) for rxn_id in erg_rxns } rmax_vary_p = [] rmax_vary_p_rescue = [] print('Simulate down regulation') for p in ps: with mae: down_regulate_erg_genes(mae, erg_vmax, p) rmax_vary_p.append(mae.optimize().objective_value) # rescue prot for rxn_id, old_coeff in old_kcat_coeffs.items(): rxn = mae.reactions.get_by_id(rxn_id) etc.change_rxn_coeff(rxn, met1, old_coeff) rxn = mae.reactions.get_by_id('draw_prot_{0}'.format('P32476')) etc.change_rxn_coeff(rxn, met2, old_fnt_coeff) rmax_vary_p_rescue.append(mae.optimize().objective_value) return rmax_vary_p, rmax_vary_p_rescue