def test_gecko_adjustment_sanchez_etal(): mmol_gdw = pd.read_csv(os.path.join( os.path.dirname(__file__), '../geckopy/data_files/sanchez-mmol_gdw.csv'), index_col=0, header=None, squeeze=True) ggdw = pd.Series(PROTEIN_PROPERTIES.loc[mmol_gdw.index, 'mw'] / 1000.) * pd.Series(mmol_gdw) model = GeckoModel('multi-pool') growth_rate_unlimited_protein = model.slim_optimize() model.limit_proteins(ggdw=pd.Series(ggdw)) growth_rate_limited_protein = model.slim_optimize() # should be smaller, but how much.. assert growth_rate_limited_protein < 0.8 * growth_rate_unlimited_protein measured_in_model = set(mmol_gdw.index).intersection(model.proteins) assert sum(model.concentrations[p] - ggdw[p] for p in measured_in_model) < 1e-10 assert sum( abs(rxn.upper_bound - mmol_gdw[rxn.annotation['uniprot']]) for rxn in model.individual_protein_exchanges) < 1e-6 assert sum(rxn.metabolites[model.common_protein_pool] + PROTEIN_PROPERTIES.loc[rxn.annotation['uniprot'], 'mw'] / 1000. for rxn in model.pool_protein_exchanges) < 1e-6 assert model.p_measured > 0.25 # With yeast 8.1.3 -> p_measured = 0.296 assert model.f_mass_fraction_measured_matched_to_total > 0.25 # With yeast 8.1.3 -> f = 0.304 assert model.protein_pool_exchange.upper_bound > 0.015 # With yeast 8.1.3 -> pool_exchange = 0.0212
def test_gecko_adjustment_sanchez_etal(): mmol_gdw = pd.Series.from_csv( os.path.join(os.path.dirname(__file__), '../geckopy/data_files/sanchez-mmol_gdw.csv')) ggdw = pd.Series(PROTEIN_PROPERTIES.loc[mmol_gdw.index, 'mw'] / 1000.) * pd.Series(mmol_gdw) model = GeckoModel('multi-pool') growth_rate_unlimited_protein = model.slim_optimize() model.limit_proteins(ggdw=pd.Series(ggdw)) growth_rate_limited_protein = model.slim_optimize() # should be smaller, but how much.. assert growth_rate_limited_protein < 0.8 * growth_rate_unlimited_protein measured_in_model = set(mmol_gdw.index).intersection(model.proteins) assert sum(model.concentrations[p] - ggdw[p] for p in measured_in_model) < 1e-10 assert sum( abs(rxn.upper_bound - mmol_gdw[rxn.annotation['uniprot']]) for rxn in model.individual_protein_exchanges) < 1e-6 assert abs(model.p_measured - 0.296) < 1e-2 # section 3.2.6 reports 0.283 assert sum(rxn.metabolites[model.common_protein_pool] + PROTEIN_PROPERTIES.loc[rxn.annotation['uniprot'], 'mw'] / 1000. for rxn in model.pool_protein_exchanges) < 1e-6 # FIXME: section 3.2.6 reports 0.2154 assert abs(model.f_mass_fraction_measured_matched_to_total - 0.291) < 1e-2 # FIXME: provided model had 0.0168, value including p_base term is 0.0507 as in matlab.. assert abs(model.protein_pool_exchange.upper_bound - 0.0203) < 1e-2 sanchez_biomass = pd.Series.from_csv( os.path.join(os.path.dirname(__file__), '../geckopy/data_files/sanchez-biomass.csv')) biomass = pd.Series( dict((m.id, v) for m, v in model.reactions.r_4041.metabolites.items())) # FIXME: poor match with provided model for ATP, ADP, H+, H20, P assert sum((biomass - sanchez_biomass).abs()) < 20
def prot_ko_optim(prot_measure_fractions=None, prot_measure_ggdw=None, constraints=None, isMultiProc=False, size=1): #load model if prot_measure_fractions is None and prot_measure_ggdw is None: model = GeckoModel("single-pool") else: model = GeckoModel("multi-pool") if prot_measure_fractions: model.limit_proteins(fractions=prot_measure_fractions) else: model.limit_proteins(ggdw=prot_measure_ggdw) fileRes = basePath + "Results/optim_KO_Gecko_Yeast_SUCC_max5.csv" simulProb = GeckoSimulationProblem(model, constraints=constraints) evalFunc = build_evaluation_function("BPCY", "r_2111", "r_2056", "r_1714_REV") # max succ exchange gecko_strain_optim(simulProb, evaluationFunc=evalFunc, levels=None, isMultiProc=isMultiProc, candidateSize=size, resultFile=fileRes) #KO_Reaction by default
def test_basic_gecko_adjustment(): in_model = {'P00549': 0.1, 'P31373': 0.1, 'P31382': 0.1, 'P39708': 0.1, 'P39714': 0.1, 'P39726': 0.1, 'Q01574': 0.1} not_in_model = {'P10591': 0.1, 'P31383': 0.1, 'P32471': 0.1} measurements = pd.concat([pd.Series(in_model), pd.Series(not_in_model)]) model = GeckoModel('multi-pool') model.limit_proteins(fractions=pd.Series(measurements)) sol = model.optimize() assert sol.objective_value > 0.05 assert len(model.proteins) - len(model.pool_proteins) - len(in_model) == 0 assert all(rxn.upper_bound > 0 for rxn in model.individual_protein_exchanges)
def analysis_ko(resFileName): levels = [0, 1e-10, 1e-8, 1e-6, 1e-4, 1e-2, 0.1] model = GeckoModel('single-pool') df = pandas.DataFrame(index=range(100), columns=["ko", "Biomass"]) for i in range(100): proteins = random.sample(model.proteins, 10) dic = {p: 0 for p in proteins} model.limit_proteins(pandas.Series(dic)) res = model.optimize() df.loc[i] = (dic, res.objective_value) df.to_csv(resFileName)
def test_adjust_pool_bounds(): essential = {'P00498': 0., 'P00815': 0.} in_model = {'P00549': 0.1, 'P31373': 0.1, 'P31382': 0.1, 'P39708': 0.1, 'P39714': 0.1, 'P39726': 0.1, 'Q01574': 0.1} expected = set('prot_{}_exchange'.format(pool_id) for pool_id in essential) measurements = pd.concat([pd.Series(in_model), pd.Series(essential)]) model = GeckoModel('multi-pool') model.limit_proteins(fractions=pd.Series(measurements)) assert model.slim_optimize() < 1e-3 model.adjust_pool_bounds(inplace=False) assert model.slim_optimize() < 1e-3 adjustment = model.adjust_pool_bounds(inplace=True) observed = set(adjustment['reaction']) assert abs(model.slim_optimize() - 0.05) < 1e-3 assert expected == observed
def simulate_wt_multi(): model = GeckoModel('multi-pool') import pandas some_measurements = pandas.Series({ 'P00549': 0.1, 'P31373': 0.1, 'P31382': 0.1 }) model = GeckoModel('multi-pool') model.limit_proteins(some_measurements) res = model.optimize() print(" wt simulation1 ", res.objective_value) for r in model.reactions: print(r.id, " --> ", res.fluxes[r.id])
def loading_yeast_gecko(prot_measure_fractions=None, prot_measure_ggdw=None): """ Loads the provided yeast gecko :param pd.Series prot_measure_fractions: measured fraction of proteins :param pd.Series prot_measure_ggdw: measured ggdw of proteins :return GeckoModel: """ if prot_measure_fractions is None and prot_measure_ggdw is None: model = GeckoModel("single-pool") else: model = GeckoModel("multi-pool") if prot_measure_fractions: model.limit_proteins(fractions=prot_measure_fractions) else: model.limit_proteins(ggdw=prot_measure_ggdw) return model