def test_reaction_info(): cobra_model = read_cobra_model(FBC_SBML) df = cobra_reaction_info(cobra_model) assert df is not None assert df.at["v1", "objective_coefficient"] == 1 assert df.at["v2", "objective_coefficient"] == 1 assert df.at["v3", "objective_coefficient"] == 1 assert df.at["v4", "objective_coefficient"] == 1 assert df.at["EX_Ac", "objective_coefficient"] == 0 assert df.at["EX_Glcxt", "objective_coefficient"] == 0 assert df.at["EX_O2", "objective_coefficient"] == 0 assert df.at["EX_X", "objective_coefficient"] == 0
def test_mass_balance(tmp_path): doc = read_sbml(DEMO_SBML) # add defaults add_default_flux_bounds(doc) filepath = tmp_path / "test.xml" write_sbml(doc, filepath=filepath) model = read_cobra_model(filepath) # mass/charge balance for r in model.reactions: mb = r.check_mass_balance() # all metabolites are balanced assert len(mb) == 0
def tiny_simulation() -> None: """Analysis of the tiny model. Creates model and runs simulation. """ # ----------------------------------------------------------------------------- # create model # ----------------------------------------------------------------------------- factory_result = tiny_factory.create() # ----------------------------------------------------------------------------- # run ode simulation # ----------------------------------------------------------------------------- # tiny_sbml = os.path.join(os.path.dirname(os.path.abspath(__file__)), # 'results', # '{}_{}.xml'.format(model.mid, model.version)) tiny_dir = Path(__file__).parent r = roadrunner.RoadRunner(str(factory_result.sbml_path)) r.timeCourseSelections = (["time"] + r.model.getBoundarySpeciesIds() + r.model.getFloatingSpeciesIds() + r.model.getReactionIds() + r.model.getGlobalParameterIds()) r.timeCourseSelections += [ "[{}]".format(key) for key in r.model.getFloatingSpeciesIds() ] # print(r) s = r.simulate(0, 400, steps=400) df = pd.DataFrame(s, columns=s.colnames) # r.plot() f, (ax1, ax2) = plt.subplots(nrows=1, ncols=2) ax1.set_title("SBML species") ax1.plot(df.time, df["[glc]"]) ax1.plot(df.time, df["[g6p]"]) ax1.plot(df.time, df["[atp]"]) ax1.plot(df.time, df["[adp]"]) ax1.plot(df.time, df["a_sum"], color="grey", linestyle="--", label="[atp]+[adp]") ax1.set_ylabel("concentration [mmole/litre]=[mM]") ax2.set_title("SBML reactions") ax2.plot(df.time, 1e6 * df.GK) ax2.plot(df.time, 1e6 * df.ATPPROD) ax2.set_ylabel("reaction rate 1E-6[mmole/s]") for ax in (ax1, ax2): ax.legend() ax.set_xlabel("time [s]") plt.show() f.savefig( tiny_dir / "results" / f"{model_definition.mid}_{model_definition.version}_roadrunner.png", bbox_inches="tight", ) # ----------------------------------------------------------------------------- # fba simulation # ----------------------------------------------------------------------------- model = read_cobra_model(factory_result.sbml_path) print(model) # Iterate through the the objects in the model print("Reactions") print("---------") for x in model.reactions: print("%s : %s [%s<->%s]" % (x.id, x.reaction, x.lower_bound, x.upper_bound)) print("") print("Metabolites") print("-----------") for x in model.metabolites: print("%9s (%s) : %s, %s, %s" % (x.id, x.compartment, x.formula, x.charge, x.annotation)) print("") print("Genes") print("-----") for x in model.genes: associated_ids = (i.id for i in x.reactions) print("%s is associated with reactions: %s" % (x.id, "{" + ", ".join(associated_ids) + "}")) solution = model.optimize() print(solution)
def test_load_cobra_model(): model = read_cobra_model(FBC_SBML) assert model
for ax in (ax1, ax2): ax.legend() ax.set_xlabel("time [s]") plt.show() f.savefig( tiny_dir / "results" / f"{model_definition.mid}_{model_definition.version}_roadrunner.png", bbox_inches="tight", ) # ----------------------------------------------------------------------------- # fba simulation # ----------------------------------------------------------------------------- model = read_cobra_model(tiny_sbml) print(model) # Iterate through the the objects in the model print("Reactions") print("---------") for x in model.reactions: print("%s : %s [%s<->%s]" % (x.id, x.reaction, x.lower_bound, x.upper_bound)) print("") print("Metabolites") print("-----------") for x in model.metabolites: print("%9s (%s) : %s, %s, %s" % (x.id, x.compartment, x.formula, x.charge, x.annotation))