コード例 #1
0
def set_temperature_constraints(model, particle, T):
    df, _ = GEMS.format_input(particle)

    etc.map_fNT(model, T, df)
    etc.map_kcatT(model, T, df)
    etc.set_NGAMT(model, T)
    etc.set_sigma(model, 0.5)
コード例 #2
0
def split_factor(particle, Ts, sigma):

    df, new_params = format_input(particle)
    dfparam = etc.calculate_thermal_params(new_params)

    results = dict()  # results = {'etcYeast7':[]}

    # Case (1) No temperature constraints
    model = pickle.load(open('../models/aerobic.pkl', 'rb'))
    with model as m:
        etc.set_sigma(m, sigma)
        r = m.optimize().objective_value
        results['ori'] = [r for T in Ts]
        print('Case 1:', results['ori'])

    # Case (2) based on (1) Include the temperature dependent NGAM
    model = pickle.load(open('../models/aerobic.pkl', 'rb'))
    for T in Ts:
        with model as m:
            etc.set_NGAMT(m, T)
            etc.set_sigma(m, sigma)

            r = m.optimize().objective_value
            results['NGAM'] = results.get('NGAM', []) + [r]
    print('Case 2:', results['NGAM'])

    # Case (3) based on (1) Include the temperatuer dependent kcat
    model = pickle.load(open('../models/aerobic.pkl', 'rb'))
    for T in Ts:
        with model as m:
            etc.map_kcatT(m, T, dfparam)
            etc.set_sigma(m, sigma)

            r = m.optimize().objective_value
            results['kcat'] = results.get('kcat', []) + [r]
    print('Case 3:', results['kcat'])

    # Case (4) based on (1) Include the temperature dependent unfolding process
    model = pickle.load(open('../models/aerobic.pkl', 'rb'))
    for T in Ts:
        with model as m:
            etc.map_fNT(m, T, dfparam)
            etc.set_sigma(m, sigma)

            try:
                r = m.optimize().objective_value
            except:
                r = None
            results['unfolding'] = results.get('unfolding', []) + [r]

    print('Case 4:', results['unfolding'])

    # Case (5) with all constraints
    model = pickle.load(open('../models/aerobic.pkl', 'rb'))
    results['etc'] = etc.simulate_growth(model, Ts, sigma, dfparam)
    print('Case 5:', results['etc'])

    return results
コード例 #3
0
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
コード例 #4
0
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        
コード例 #5
0
def simulate_a_particle(particle, T):
    df, _ = format_input(particle)

    sigma = 0.5
    # map all temperature constrains on all enzymes
    ecmodel = pickle.load(open('../models/aerobic.pkl', 'rb'))
    etcmodel = pickle.load(open('../models/aerobic.pkl', 'rb'))

    # map temperature constraints
    etc.map_fNT(etcmodel, T, df)
    etc.map_kcatT(etcmodel, T, df)
    etc.set_NGAMT(etcmodel, T)
    etc.set_sigma(etcmodel, sigma)

    # get enzyme list
    enzymes = list(
        set([
            met.id for met in ecmodel.metabolites
            if met.id.startswith('prot_') and met.id != 'prot_pool'
        ]))

    tested_enzymes = []

    try:
        r = etcmodel.optimize().objective_value
    except:
        r = 0
    rs = [r]

    for i in range(len(enzymes) - 1):
        fccs = do_a_fcc(etcmodel, tested_enzymes, enzymes)
        most_limit_enz_id = find_most_rate_limiting_enzyme(fccs)
        tested_enzymes.append(most_limit_enz_id)

        if most_limit_enz_id is not None:
            remove_temperature_constraints(ecmodel, etcmodel,
                                           most_limit_enz_id.split('_')[1])
            try:
                r = etcmodel.optimize().objective_value
            except:
                r = np.nan
        else:
            r = np.nan
            break
        print(most_limit_enz_id, r)
        rs.append(r)

    return rs, tested_enzymes