Example #1
0
def medium_Lactate_optim(isMultiProc=False, size=1, withCobraPy=False):
    SBML_FILE = "../../../examples/models/Ec_iAF1260.xml"
    modelaux = load_cbmodel(SBML_FILE, flavor="cobra")
    model = fix_exchange_reactions_model(modelaux)
    fileRes = basePath + "Results/optim_Ec_iAF1260_medium_lactate.csv"
    simulProb = StoicSimulationProblem(
        model,
        objective={"R_Ec_biomass_iAF1260_core_59p81M": 1},
        withCobraPy=withCobraPy)

    fba = simulProb.simulate()

    # calculate the essential uptake reactions to biomass production
    essential = simulProb.find_essential_drains()
    print(essential)
    if simulProb.constraints:
        simulProb.constraints.update(
            {reac: (StoicConfigurations.DEFAULT_LB, 0)
             for reac in essential})  # put essential reactions as constraints
    else:
        simulProb.constraints = {
            reac: (StoicConfigurations.DEFAULT_LB, 0)
            for reac in essential
        }

    criticalReacs = essential

    # set the minimum production of biomass

    simulProb.set_objective_function({"R_EX_lac_L_e": 1})
    simulProb.constraints.update({
        "R_Ec_biomass_iAF1260_core_59p81M":
        (fba.get_fluxes_distribution()["R_Ec_biomass_iAF1260_core_59p81M"] *
         0.75, 9999)
    })

    minObjective = {"R_EX_lac_L_e": 1e-5}
    print(
        "Biomass: " +
        str(fba.get_fluxes_distribution()["R_Ec_biomass_iAF1260_core_59p81M"] *
            0.75))
    build_evaluation_function
    evalFunc = build_evaluation_function("MinNumberReac", size, minObjective)

    cbm_strain_optim(simulProb,
                     evaluationFunc=evalFunc,
                     levels=None,
                     type=optimType.MEDIUM,
                     criticalReacs=criticalReacs,
                     isMultiProc=isMultiProc,
                     candidateSize=size,
                     resultFile=fileRes)
Example #2
0
def framed_optim(isMultiProc, size):
    model = load_cbmodel(SBML_FILE, flavor="cobra")

    fileRes = basePath + "Results/optim_Ec_iAF1260_ko.csv"
    simulProb = StoicSimulationProblem(
        model, objective={"R_Ec_biomass_iAF1260_core_59p81M": 1})
    objFunc = build_evaluation_function("targetFlux",
                                        ["R_Ec_biomass_iAF1260_core_59p81M"])
    cbm_strain_optim(simulProb,
                     evaluationFunc=objFunc,
                     levels=None,
                     isMultiProc=isMultiProc,
                     candidateSize=size,
                     resultFile=fileRes)
Example #3
0
def medium_SC_Etanol_Levels_optim(isMultiProc=False,
                                  size=1,
                                  withCobraPy=False):
    SBML_FILE = "../../../examples/models/iMM904.xml"

    model = load_cbmodel(SBML_FILE, flavor="fbc2")
    fileRes = basePath + "Results/optim_iMM904_etanol_levels.csv"
    simulProb = StoicSimulationProblem(model,
                                       objective={"R_BIOMASS_SC5_notrace": 1},
                                       withCobraPy=withCobraPy)
    fba = simulProb.simulate()
    print("Biomass: " +
          str(fba.get_fluxes_distribution()["R_BIOMASS_SC5_notrace"]))
    # calculate the essential uptake reactions to biomass production
    essential = simulProb.find_essential_drains()
    print(essential)
    if simulProb.constraints:
        simulProb.constraints.update(
            {reac: (StoicConfigurations.DEFAULT_LB, 0)
             for reac in essential})  # put essential reactions as constraints
    else:
        simulProb.constraints = {
            reac: (StoicConfigurations.DEFAULT_LB, 0)
            for reac in essential
        }

    criticalReacs = essential

    # set the minimum production of biomass
    simulProb.set_objective_function({"R_EX_etoh_e": 1})
    simulProb.constraints.update({
        "R_BIOMASS_SC5_notrace":
        (fba.get_fluxes_distribution()["R_BIOMASS_SC5_notrace"] * 0.75, 9999)
    })

    print("Biomass: " +
          str(fba.get_fluxes_distribution()["R_BIOMASS_SC5_notrace"] * 0.75))

    evalFunc = build_evaluation_function(
        "MinNumberReacAndMaxFluxWithLevels", size, LEVELS,
        {"R_EX_etoh_e": model.reactions["R_EX_etoh_e"].ub})

    cbm_strain_optim(simulProb,
                     evaluationFunc=evalFunc,
                     levels=LEVELS,
                     type=optimType.MEDIUM_LEVELS,
                     criticalReacs=criticalReacs,
                     isMultiProc=isMultiProc,
                     candidateSize=size,
                     resultFile=fileRes)
Example #4
0
def medium_reac_ko_optim(isMultiProc=False, size=[5, 5], withCobraPy=False):
    SBML_FILE = "../../../examples/models/Ec_iAF1260.xml"
    model = load_cbmodel(SBML_FILE, flavor="cobra")
    newModel = fix_exchange_reactions_model(model)
    fileRes = basePath + "Results/optim_Ec_iAF1260_medium_ko_succ.csv"
    simulProb = StoicSimulationProblem(
        newModel,
        objective={"R_Ec_biomass_iAF1260_core_59p81M": 1},
        withCobraPy=withCobraPy)

    # set the minimum production of biomass
    fba = simulProb.simulate()

    # calculate the essential uptake reactions to biomass production
    essential = simulProb.find_essential_drains()
    print(essential)
    if simulProb.constraints:
        simulProb.constraints.update(
            {reac: (StoicConfigurations.DEFAULT_LB, 0)
             for reac in essential})  # put essential reactions as constraints
    else:
        simulProb.constraints = {
            reac: (StoicConfigurations.DEFAULT_LB, 0)
            for reac in essential
        }

    simulProb.set_objective_function({"R_EX_succ_e_": 1})
    simulProb.constraints.update({
        "R_Ec_biomass_iAF1260_core_59p81M":
        (fba.get_fluxes_distribution()["R_Ec_biomass_iAF1260_core_59p81M"] *
         0.25, 9999)
    })
    print(
        "Biomass: " +
        str(fba.get_fluxes_distribution()["R_Ec_biomass_iAF1260_core_59p81M"] *
            0.25))

    evalFunc = build_evaluation_function(
        "MinNumberReacAndMaxFlux", sum(size),
        {"R_EX_succ_e": model.reactions["R_EX_succ_e"].ub})

    cbm_strain_optim(simulProb,
                     evaluationFunc=evalFunc,
                     levels=None,
                     type=optimType.MEDIUM_REACTION_KO,
                     criticalReacs=essential,
                     isMultiProc=isMultiProc,
                     candidateSize=size,
                     resultFile=fileRes)  # KO_Reaction by default
Example #5
0
def reac_ko_medium_optim_CM(isMultiProc=False, size=(1, 1), withCobraPy=False):
    SBML_FILE = basePath + "Data/EC_SC_model.xml"
    modelaux = load_cbmodel(SBML_FILE, exchange_detection_mode="R_EX_")
    model = fix_exchange_reactions_model(modelaux)
    fileRes = basePath + "Results/optim_Comunity_KO_medium_pFBA.csv"

    for r_id, rxn in model.reactions.items():
        if r_id.startswith(
                'R_EX_'):  # ou tambem podes fazer if rxn.is_exchange:
            rxn.lb = -1000 if rxn.lb is None else rxn.lb
            rxn.ub = 1000 if rxn.ub is None else rxn.ub

    simulProb = StoicSimulationProblem(model,
                                       objective={"R_BM_total_Synth": 1},
                                       withCobraPy=withCobraPy)
    res = simulProb.simulate()
    print(res.print())
    evalFunc = build_evaluation_function("BP_MinModifications",
                                         "R_BM_total_Synth",
                                         "R_EX_succ_medium_")

    result = cbm_strain_optim(simulProb,
                              evaluationFunc=evalFunc,
                              levels=None,
                              type=optimType.MEDIUM_REACTION_KO,
                              isMultiProc=isMultiProc,
                              candidateSize=size,
                              resultFile=fileRes)
Example #6
0
def cobra_optim(isMultiProc, size):
    model = read_sbml_model(SBML_FILE)
    fileRes = basePath + "Results/optim_Ec_iAF1260_ko_cobra.csv"

    simulProb = StoicSimulationProblem(
        model,
        objective={"Ec_biomass_iAF1260_core_59p81M": 1},
        withCobraPy=True)
    objFunc = build_evaluation_function("targetFlux",
                                        ["Ec_biomass_iAF1260_core_59p81M"])

    print(simulProb.simulate())
    cbm_strain_optim(simulProb,
                     evaluationFunc=objFunc,
                     levels=None,
                     isMultiProc=isMultiProc,
                     candidateSize=size,
                     resultFile=fileRes)
Example #7
0
def medium_SC_optim(isMultiProc=False, size=1, withCobraPy=False):
    SBML_FILE = "../../../examples/models/iMM904.xml"
    model = load_cbmodel(SBML_FILE, flavor="fbc2")
    fileRes = basePath + "Results/optim_iMM904_medium.csv"

    simulProb = StoicSimulationProblem(model,
                                       objective={"R_BIOMASS_SC5_notrace": 1},
                                       withCobraPy=withCobraPy)

    fba = simulProb.simulate()

    # calculate the essential uptake reactions to biomass production
    essential = simulProb.find_essential_drains()
    print(essential)
    if simulProb.constraints:
        simulProb.constraints.update(
            {reac: (StoicConfigurations.DEFAULT_LB, 0)
             for reac in essential})  # put essential reactions as constraints
    else:
        simulProb.constraints = {
            reac: (StoicConfigurations.DEFAULT_LB, 0)
            for reac in essential
        }

    criticalReacs = essential

    # set the minimum production of biomass
    minObjective = {
        "R_BIOMASS_SC5_notrace":
        fba.get_fluxes_distribution()["R_BIOMASS_SC5_notrace"] * 0.75
    }
    evalFunc = build_evaluation_function("MinNumberReac", size, minObjective)

    cbm_strain_optim(simulProb,
                     evaluationFunc=evalFunc,
                     levels=None,
                     type=optimType.MEDIUM,
                     criticalReacs=criticalReacs,
                     isMultiProc=isMultiProc,
                     candidateSize=size,
                     resultFile=fileRes)
Example #8
0
def stoic_optimization(model, optim_type, eval_func, **kwargs):
    cand_size = kwargs.get("size", None)
    stoic_obj = kwargs.get("objective", {})
    withCobraPy = cobra_or_framed(model)
    min_flag = kwargs.get("minimize", False)
    multi_thread = kwargs.get("isMultiProc", False)
    stoic_constraints = kwargs.get("constraints", {})
    output_file = kwargs.get("output_file", "results.csv")
    stoic_method = kwargs.get("method", StoicConfigurations.SOLVER_METHOD)
    stoic_uo_levels = kwargs.get(
        "levels",
        [2**-5, 2**-4, 2**-3, 2**-2, 2**-1, 2**1, 2**2, 2**3, 2**4, 2**5])

    types_dict = {
        "KO": optimType.REACTION_KO,
        "UO": optimType.REACTION_UO,
        "MEDKO": optimType.MEDIUM,
        "MEDUO": optimType.MEDIUM_LEVELS,
        "KO+MEDKO": optimType.MEDIUM_REACTION_KO
    }

    stoic_simul_problem = StoicSimulationProblem(model=model,
                                                 objective=stoic_obj,
                                                 minimize=min_flag,
                                                 constraints=stoic_constraints,
                                                 method=stoic_method,
                                                 withCobraPy=withCobraPy)

    critical_proteins = kwargs.get("critical_proteins", [])
    if critical_proteins == "auto":
        critical_proteins = stoic_simul_problem.find_essential_drains()

    res = cbm_strain_optim(simulProblem=stoic_simul_problem,
                           evaluationFunc=eval_func,
                           levels=stoic_uo_levels,
                           type=types_dict[optim_type],
                           criticalReacs=critical_proteins,
                           isMultiProc=multi_thread,
                           candidateSize=cand_size,
                           resultFile=output_file)

    return res
Example #9
0
def reac_ko_optim(isMultiProc=False, size=1, withCobraPy=False):
    SBML_FILE = "../../../examples/models/Ec_iAF1260.xml"
    if withCobraPy:
        model = read_sbml_model(SBML_FILE)
        fileRes = basePath + "Results/optim_Ec_iAF1260_ko_cobra.csv"
    else:
        model = load_cbmodel(SBML_FILE, flavor="cobra")
        fileRes = basePath + "Results/optim_Ec_iAF1260_ko.csv"

    simulProb = StoicSimulationProblem(
        model,
        objective={"Ec_biomass_iAF1260_core_59p81M": 1},
        withCobraPy=withCobraPy)
    evalFunc = build_evaluation_function("targetFlux",
                                         ["Ec_biomass_iAF1260_core_59p81M"])
    result = cbm_strain_optim(simulProb,
                              evaluationFunc=evalFunc,
                              levels=None,
                              isMultiProc=isMultiProc,
                              candidateSize=size,
                              resultFile=fileRes)  # KO_Reaction by default
    result.print()