RbaOptmization¶
Optimization support for resource balance constraint models (RBA and TRBA).
- class f2xba.RbaOptimization(fname, cobra_model=None)[source]¶
Support optimization of SBML encoded RBA based models generated by f2xba.
Optimization support is provided via COBRApy and guropipy interfaces for RBA models created by f2xba, utilizing the bisection algorithm of RbaPy (Bulović et al., 2019).
Ref: Bulović, A., Fischer, S., Dinh, M., Golib, F., Liebermeister, W., Poirier, C., Tournier, L., Klipp, E., Fromion, V., & Goelzer, A. (2019). Automated generation of bacterial resource allocation models. Metabolic Engineering, 55, 12-22. https://doi.org/https://doi.org/10.1016/j.ymben.2019.06.001
Using the COBRApy interface for optimization of RBA and TRBA models:
import cobra cobra_model = cobra.io.read_sbml_model('iML1515_RBA.xml') ro = RbaOptimization('iML1515_RBA.xml', cobra_model) sigma = ro.avg_enz_saturation importer_km = ro.importer_km rel_mmol_per_l = (sigma / (1.0-min(sigma, .99))) * importer_km ex_sidx2mmol_per_l = {re.sub('EX_', '', ex_ridx): rel_mmol_per_l for ex_ridx in lb_medium} ex_sidx2mmol_per_l['h_e'] = 100.0 * sigma ro.medium = ex_sidx2mmol_per_l solution = ro.solve(gr_min=0.01, gr_max=1.2, bisection_tol=1e-3)
Using the gurobipy interface for optimization of RBA and TRBA models, providing significant speed improvements: Note: GUROBI optimizer with gurobipy (https://www.gurobi.com) needs to be installed on your system.
ro = RbaOptimization('iML1515_RBA.xml') sigma = ro.avg_enz_saturation importer_km = ro.importer_km rel_mmol_per_l = (sigma / (1.0-min(sigma, .99))) * importer_km ex_sidx2mmol_per_l = {re.sub('EX_', '', ex_ridx): rel_mmol_per_l for ex_ridx in lb_medium} ex_sidx2mmol_per_l['h_e'] = 100.0 * sigma ro.medium = ex_sidx2mmol_per_l solution = ro.solve(gr_min=0.01, gr_max=1.2, bisection_tol=1e-3)
- df_mm_data¶
Pandas DataFrame with macromolecule related information.
- df_enz_data¶
Pandas DataFramw with enzyme molecular weights.
- enz_mm_composition¶
Mapping enzyme identifiers to enzyme composition.
- initial_assignments¶
Initial assignments configured in the RBA model.
- property medium¶
Mimic medium property of COBRApy to set and retrieve medium wrt concentrations.
Medium concentrations returned in units of mmol/l.
- Returns:
metabolite concentrations in external medium in mmol/l
- Return type:
dict
- scale_efficiencies(scale_effs)[source]¶
Scale enzyme efficiencies in RBA models to support manual parameter tuning.
Use unscale_efficiencies() to return to original values.
ro = RbaOptimization('iML1515_RBA.xml) scale_effs = {'PDH': {'fwd': 10.0}, 'ACt2rpp': {'fwd': 2.0, 'rev': 5.0}} ro.scale_efficiencies(scale_effs) solution = ro.solve(gr_min=0.02, gr_max=1.2, bisection_tol=1e-3) ro.unscale_efficiencies()
- Parameters:
scale_effs (dict of dict) – reaction ids (without prefix R_) and dict with reactions ‘fwd’ and/or ‘rev’ with float
- get_init_assign_math(ia_refs)[source]¶
Get expanded math string used in initial assignments of RBA models.
RBA model uses initial assignments for model update during optimization. Model parameter values can be set depending on external media concentrations and growth rate. This method retrieves the expanded math for a list of initial assignment references, each reference contains a dictionary with the attributes: var_id: variable identifier, constr_id: constraint identifier, and constr_type: reactants, products, or flux_bounds.
ro.get_init_assign_math([{'var_id': 'V_TSMC', 'constr_type': 'reactants', 'constr_id': 'M_hemeA_c'}])
- Parameters:
ia_refs (list(dict)) – reference to specific initial assignment
- Returns:
extended math strings
- Return type:
list(dict), like input with additional attribute ‘math_str’
- set_init_assign_math(ia_data)[source]¶
Set expanded math string used in initial assignments of RBA models.
RBA model uses initial assignments for model update during optimization. Model parameter values can be set depending on external media concentrations and growth rate. This method sets the expanded math for a list of initial assignment references, each reference contains a dictionary with the attributes: var_id: variable identifier, constr_id: constraint identifier, constr_type: reactants, products, or flux_bounds, and math: math string, e.g. growth_rate * 0.002 or a fixed value as 0.0.
ia_data_anaerobe = [{'var_id': 'V_TSMC', 'constr_type': 'reactants', 'constr_id': 'M_hemeA_c', 'math_str': '0.0'}] if 'EX_o2_e' not in medium: orig_ia_data = ro.set_init_assign_math(ia_data_anaerobe) solution = ro.solve(gr_min=0.01, gr_max=0.7, bisection_tol=1e-3) if 'EX_o2_e' not in medium: ro.set_init_assign_math(orig_ia_data) :param list(dict) ia_data: reference to specific initial assignment :return: the original math string, prior to modification :rtype: list(dict), like input, but with original math string
- solve(gr_min=0.0, gr_max=1.5, bisection_tol=1e-05, max_iter=40)[source]¶
Solve RBA feasibility problem using bisection algorithm.
Support both COBRApy and gurobipy interfaces.
- Parameters:
gr_min (float) – minimum growth rate in h-1
gr_max (float) – maximum growth rate in h-1
bisection_tol (float) – stop criteria based on growth rate tolerances (default: 1e-3)
max_iter (int) – stop criteria based on iteration number (default: 40)
- Returns:
optimization solution
- Return type:
class:Solution
- single_gene_deletion(genes=None, solution=None, **kwargs)[source]¶
Perform a single gene deletion analysis for RBA based models using gurobipy interface.
Interface aligned to COBRApy single_gene_deletion() method. Perform single gene deletion simulations for provided list of gene in genes. If genes is not provided, perform gene deletion for all genes that may be active in the wild type solution. In case a gene is not required in the wild type solution, a knockout simulation is not performed for this gene. Its growth rate value is set to the wild type value and its optimization status is set to wt_solution. A wild type solution can be provided with parameter solution, alternatively a wild type solution is determined automatically.
Following keyword arguments can be added to the list of parameters: gr_min: (default 0.0) minimum growth rate to test in h-1, gr_min_alt: (optional) alternative minimum growth rate in h-1 (used, if infeasible solution with gr_min), gr_max: (default 1.5) maximum growth rate to test in h-1, bisection_tol: (default 1e-5) stop criteria based on growth rate tolerance, max_iter: (default 40) stop criteria based on number of iterations.
- Parameters:
genes (list or set) – (optional) gene ids,
solution (
Solution) – (optional) wild type RBA solutionkwargs – keyword arguments used for RBA bisectional optimization
- Returns:
single gene deletion results per gene with growth rate in h-1, optimization status and fitness value
- Return type:
pandas.DataFrame