def test_toy_wholecell_simulation(self): toyfactory.create_model(self.test_dir) sbml_path = os.path.join(versioned_directory(self.test_dir, settings.VERSION), settings.TOP_LOCATION) print(sbml_path) toysimulate.simulate_toy(sbml_path, self.test_dir, dts=[1.0], figures=False)
def test_diauxic_simulation(self): dgfactory.create_model(self.test_dir) sbml_path = os.path.join(versioned_directory(self.test_dir, dgsettings.VERSION), dgsettings.TOP_LOCATION) print(sbml_path) dgsimulate.simulate_diauxic_growth(sbml_path, self.test_dir, dts=[0.01], figures=False)
def test_toy_atp_simulation(self): atpfactory.create_model(self.test_dir) sbml_path = os.path.join( versioned_directory(self.test_dir, atpsettings.VERSION), atpsettings.TOP_LOCATION) print(sbml_path) atpsimulate.simulate_toy_atp(sbml_path, self.test_dir, dts=[1.0], figures=False)
def test_validate_toy(self): """ Validate the toy model. """ sbml_path = os.path.join(utils.versioned_directory(toysettings.OUT_DIR, toyfactory.VERSION), toysettings.TOP_LOCATION) print(sbml_path) # run simulation with the top model # df, dfba_model, dfba_simulator = simulate_dfba(sbml_path, tend=50, dt=5.0) validator.validate_dfba(sbml_path) assert False
def test_validate_toy(self): """ Validate the toy model. """ sbml_path = os.path.join( utils.versioned_directory(toysettings.OUT_DIR, toyfactory.VERSION), toysettings.TOP_LOCATION) print(sbml_path) # run simulation with the top model # df, dfba_model, dfba_simulator = simulate_dfba(sbml_path, tend=50, dt=5.0) validator.validate_dfba(sbml_path) assert False
def create_model(output_dir): """ Create all submodels and comp model. :param output_dir: results directory :rtype: :return directory in which model files exist. """ f_annotations = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'annotations.xlsx') annotations = annotation.ModelAnnotator.annotations_from_file(f_annotations) directory = utils.versioned_directory(output_dir, version=settings.VERSION) # create sbml doc_fba = fba_model(settings.FBA_LOCATION, directory, annotations=annotations) bounds_model(settings.BOUNDS_LOCATION, directory, doc_fba=doc_fba, annotations=annotations) update_model(settings.UPDATE_LOCATION, directory, doc_fba=doc_fba, annotations=annotations) emds = { "{}_fba".format(settings.MODEL_ID): settings.FBA_LOCATION, "{}_bounds".format(settings.MODEL_ID): settings.BOUNDS_LOCATION, "{}_update".format(settings.MODEL_ID): settings.UPDATE_LOCATION, } # flatten top model top_model(settings.TOP_LOCATION, directory, emds, doc_fba, annotations=annotations) comp.flattenSBMLFile(sbml_path=pjoin(directory, settings.TOP_LOCATION), output_path=pjoin(directory, settings.FLATTENED_LOCATION)) # create reports locations = [ settings.FBA_LOCATION, settings.BOUNDS_LOCATION, settings.UPDATE_LOCATION, settings.TOP_LOCATION, settings.FLATTENED_LOCATION ] sbml_paths = [pjoin(directory, fname) for fname in locations] sbmlreport.create_sbml_reports(sbml_paths, directory, validate=False) # create sedml from sbmlutils.dfba.sedml import create_sedml species_ids = ", ".join(['atp', 'adp', 'glc', 'pyr']) reaction_ids = ", ".join(['EX_atp', 'EX_adp', 'EX_glc', 'EX_pyr', 'RATP']) create_sedml(settings.SEDML_LOCATION, settings.TOP_LOCATION, directory=directory, dt=0.1, tend=15, species_ids=species_ids, reaction_ids=reaction_ids) return directory
def create_model(output_dir): """ Create all submodels and comp model. :param output_dir: results directory :rtype: :return directory in which model files exist. """ directory = utils.versioned_directory(output_dir, version=settings.VERSION) f_annotations = os.path.join(os.path.dirname(os.path.abspath(__file__)), settings.ANNOTATIONS_LOCATION) annotations = annotator.ModelAnnotator.read_annotations(f_annotations) # create sbml doc_fba = fba_model(settings.FBA_LOCATION, directory, annotations=annotations) bounds_model(settings.BOUNDS_LOCATION, directory, doc_fba=doc_fba, annotations=annotations) update_model(settings.UPDATE_LOCATION, directory, doc_fba=doc_fba, annotations=annotations) emds = { "{}_fba".format(settings.MODEL_ID): settings.FBA_LOCATION, "{}_bounds".format(settings.MODEL_ID): settings.BOUNDS_LOCATION, "{}_update".format(settings.MODEL_ID): settings.UPDATE_LOCATION, } # flatten top model top_model(settings.TOP_LOCATION, directory, emds, doc_fba, annotations=annotations) comp.flattenSBMLFile(sbml_path=pjoin(directory, settings.TOP_LOCATION), output_path=pjoin(directory, settings.FLATTENED_LOCATION)) # create reports locations = [ settings.FBA_LOCATION, settings.BOUNDS_LOCATION, settings.UPDATE_LOCATION, settings.TOP_LOCATION, settings.FLATTENED_LOCATION ] sbml_paths = [pjoin(directory, fname) for fname in locations] sbmlreport.create_reports(sbml_paths, directory, validate=False) # create sedml from sbmlutils.dfba.sedml import create_sedml species_ids = ", ".join(['A', 'C', 'D']) reaction_ids = ", ".join(['R4', 'EX_A', 'EX_C']) create_sedml(settings.SEDML_LOCATION, settings.TOP_LOCATION, directory=directory, dt=0.1, tend=50, species_ids=species_ids, reaction_ids=reaction_ids) return directory
def create_model(output_dir): """ Create all models. :return: """ directory = utils.versioned_directory(output_dir, version=settings.VERSION) f_annotations = os.path.join(os.path.dirname(os.path.abspath(__file__)), settings.ANNOTATIONS_LOCATION) annotations = annotation.ModelAnnotator.annotations_from_file(f_annotations) # create sbml doc_fba = fba_model(settings.FBA_LOCATION, directory, annotations=annotations) bounds_model(settings.BOUNDS_LOCATION, directory, doc_fba=doc_fba, annotations=annotations) update_model(settings.UPDATE_LOCATION, directory, doc_fba=doc_fba, annotations=annotations) emds = { "diauxic_fba": settings.FBA_LOCATION, "diauxic_bounds": settings.BOUNDS_LOCATION, "diauxic_update": settings.UPDATE_LOCATION, } top_model(settings.TOP_LOCATION, directory, emds, doc_fba=doc_fba, annotations=annotations) # flatten top model comp.flattenSBMLFile(sbml_path=pjoin(directory, settings.TOP_LOCATION), output_path=pjoin(directory, settings.FLATTENED_LOCATION)) # create reports locations = [ settings.FBA_LOCATION, settings.BOUNDS_LOCATION, settings.UPDATE_LOCATION, settings.TOP_LOCATION, settings.FLATTENED_LOCATION ] sbml_paths = [pjoin(directory, fname) for fname in locations] sbmlreport.create_sbml_reports(sbml_paths, directory, validate=False) # create sedml from sbmlutils.dfba.sedml import create_sedml species_ids = ", ".join(['Ac', 'Glcxt', 'O2', 'X']) reaction_ids = ", ".join(['vO2_transfer', 'EX_Ac', 'EX_Glcxt', 'EX_O2', 'EX_X']) create_sedml(settings.SEDML_LOCATION, settings.TOP_LOCATION, directory=directory, dt=0.01, tend=15, species_ids=species_ids, reaction_ids=reaction_ids) return directory
def create_model(output_dir): """ Create all models. :return: directory where SBML files are located """ directory = utils.versioned_directory(output_dir, version=settings.VERSION) print("FBA") doc_fba = fba_model(settings.FBA_LOCATION, directory) print("BOUNDS") bounds_model(settings.BOUNDS_LOCATION, directory, doc_fba=doc_fba) print("UPDATE") update_model(settings.UPDATE_LOCATION, directory, doc_fba=doc_fba) emds = { "{}_fba".format(settings.MODEL_ID): settings.FBA_LOCATION, "{}_bounds".format(settings.MODEL_ID): settings.BOUNDS_LOCATION, "{}_update".format(settings.MODEL_ID): settings.UPDATE_LOCATION, } print("TOP") top_model(settings.TOP_LOCATION, directory, emds, doc_fba=doc_fba, validate=True) # flatten top model print("FLATTENING") comp.flattenSBMLFile(sbml_path=pjoin(directory, settings.TOP_LOCATION), output_path=pjoin(directory, settings.FLATTENED_LOCATION)) # create report locations = [ settings.FBA_LOCATION, settings.BOUNDS_LOCATION, settings.UPDATE_LOCATION, settings.TOP_LOCATION, settings.FLATTENED_LOCATION ] sbml_paths = [pjoin(directory, fname) for fname in locations] sbmlreport.create_sbml_reports(sbml_paths, directory, validate=False) return directory
def create_model(output_dir): """ Create all models. :return: directory where SBML files are located """ directory = utils.versioned_directory(output_dir, version=settings.VERSION) print("FBA") doc_fba = fba_model(settings.FBA_LOCATION, directory) print("BOUNDS") bounds_model(settings.BOUNDS_LOCATION, directory, doc_fba=doc_fba) print("UPDATE") update_model(settings.UPDATE_LOCATION, directory, doc_fba=doc_fba) emds = { "{}_fba".format(settings.MODEL_ID): settings.FBA_LOCATION, "{}_bounds".format(settings.MODEL_ID): settings.BOUNDS_LOCATION, "{}_update".format(settings.MODEL_ID): settings.UPDATE_LOCATION, } print("TOP") top_model(settings.TOP_LOCATION, directory, emds, doc_fba=doc_fba, validate=False) # flatten top model print("FLATTENING") comp.flattenSBMLFile(sbml_path=pjoin(directory, settings.TOP_LOCATION), output_path=pjoin(directory, settings.FLATTENED_LOCATION)) # create report locations = [ settings.FBA_LOCATION, settings.BOUNDS_LOCATION, settings.UPDATE_LOCATION, settings.TOP_LOCATION, settings.FLATTENED_LOCATION ] sbml_paths = [pjoin(directory, fname) for fname in locations] sbmlreport.create_sbml_reports(sbml_paths, directory, validate=False) return directory
if figures: analysis.plot_reactions(os.path.join(out_dir, "fig_reactions_generic_dt{}.png".format(dt)), **plot_kwargs) analysis.plot_species(os.path.join(out_dir, "fig_species_generic_dt{}.png".format(dt)), **plot_kwargs) analysis.save_csv(os.path.join(out_dir, "data_simulation_generic_dt{}.csv".format(dt))) # custom model plots if figures: print_species(dfs=dfs, filepath=os.path.join(out_dir, "fig_species.png"), **plot_kwargs) print_fluxes(dfs=dfs, filepath=os.path.join(out_dir, "fig_fluxes.png"), **plot_kwargs) return dfs if __name__ == "__main__": directory = versioned_directory(settings.OUT_DIR, settings.VERSION) sbml_path = os.path.join(directory, settings.TOP_LOCATION) # logging.basicConfig(level=logging.DEBUG) from sbmlutils.dfba.model import DFBAModel dfba_model = DFBAModel(sbml_path=sbml_path) # simulate_toy(sbml_path, out_dir=directory, dts=[5.0], tend=10) simulate_toy(sbml_path, out_dir=directory, ode_integrator="gillespie") # create COMBINE archive from tellurium.utils import omex creators = [
from sbmlutils import dfba from sbmlutils.dfba import utils # ## Simulate DFBA model # To run an existing DFBA model call use `simulate_dfba`. # In[3]: # get the absolute path to the top model from sbmlutils.dfba.toy_wholecell import settings as toysettings from sbmlutils.dfba.toy_wholecell import model_factory as toyfactory from sbmlutils.dfba.toy_wholecell import simulate as toysimulate sbml_path = os.path.join(utils.versioned_directory(toysettings.OUT_DIR, toysettings.VERSION), toysettings.TOP_LOCATION) print(sbml_path) # run simulation with the top model from sbmlutils.dfba.simulator import simulate_dfba df, dfba_model, dfba_simulator = simulate_dfba(sbml_path, tend=50, dt=5.0) df # ## Toy example # In[4]: from sbmlutils.dfba.toy_wholecell import settings as toysettings
def test_toy_atp_simulation(self): atpfactory.create_model(self.test_dir) sbml_path = os.path.join(versioned_directory(self.test_dir, atpsettings.VERSION), atpsettings.TOP_LOCATION) print(sbml_path) atpsimulate.simulate_toy_atp(sbml_path, self.test_dir, dts=[1.0], figures=False)
def create_model(output_dir): """ Create all models. :return: """ directory = utils.versioned_directory(output_dir, version=settings.VERSION) f_annotations = os.path.join(os.path.dirname(os.path.abspath(__file__)), settings.ANNOTATIONS_LOCATION) annotations = annotator.ModelAnnotator.annotations_from_file(f_annotations) # create sbml doc_fba = fba_model(settings.FBA_LOCATION, directory, annotations=annotations) bounds_model(settings.BOUNDS_LOCATION, directory, doc_fba=doc_fba, annotations=annotations) update_model(settings.UPDATE_LOCATION, directory, doc_fba=doc_fba, annotations=annotations) emds = { "diauxic_fba": settings.FBA_LOCATION, "diauxic_bounds": settings.BOUNDS_LOCATION, "diauxic_update": settings.UPDATE_LOCATION, } top_model(settings.TOP_LOCATION, directory, emds, doc_fba=doc_fba, annotations=annotations) # flatten top model comp.flattenSBMLFile(sbml_path=pjoin(directory, settings.TOP_LOCATION), output_path=pjoin(directory, settings.FLATTENED_LOCATION)) # create reports locations = [ settings.FBA_LOCATION, settings.BOUNDS_LOCATION, settings.UPDATE_LOCATION, settings.TOP_LOCATION, settings.FLATTENED_LOCATION ] sbml_paths = [pjoin(directory, fname) for fname in locations] sbmlreport.create_sbml_reports(sbml_paths, directory, validate=False) # create sedml from sbmlutils.dfba.sedml import create_sedml species_ids = ", ".join(['Ac', 'Glcxt', 'O2', 'X']) reaction_ids = ", ".join( ['vO2_transfer', 'EX_Ac', 'EX_Glcxt', 'EX_O2', 'EX_X']) create_sedml(settings.SEDML_LOCATION, settings.TOP_LOCATION, directory=directory, dt=0.01, tend=15, species_ids=species_ids, reaction_ids=reaction_ids) return directory
import sbmlutils from sbmlutils import dfba from sbmlutils.dfba import utils # ## Simulate DFBA model # To run an existing DFBA model call use `simulate_dfba`. # In[3]: # get the absolute path to the top model from sbmlutils.dfba.toy_wholecell import settings as toysettings from sbmlutils.dfba.toy_wholecell import model_factory as toyfactory from sbmlutils.dfba.toy_wholecell import simulate as toysimulate sbml_path = os.path.join( utils.versioned_directory(toysettings.OUT_DIR, toysettings.VERSION), toysettings.TOP_LOCATION) print(sbml_path) # run simulation with the top model from sbmlutils.dfba.simulator import simulate_dfba df, dfba_model, dfba_simulator = simulate_dfba(sbml_path, tend=50, dt=5.0) df # ## Toy example # In[4]: from sbmlutils.dfba.toy_wholecell import settings as toysettings from sbmlutils.dfba.toy_wholecell import model_factory as toyfactory from sbmlutils.dfba.toy_wholecell import simulate as toysimulate
**plot_kwargs) analysis.save_csv( os.path.join(out_dir, "data_simulation_generic_dt{}.csv".format(dt))) # custom model plots if figures: print_species(dfs=dfs, filepath=os.path.join(out_dir, "fig_species.png"), **plot_kwargs) # print_fluxes(dfs=dfs, filepath=os.path.join(out_dir, "fig_fluxes.png"), **plot_kwargs) return dfs if __name__ == "__main__": directory = versioned_directory(settings.OUT_DIR, settings.VERSION) sbml_path = os.path.join(directory, settings.TOP_LOCATION) import logging # logging.basicConfig(level=logging.DEBUG) from sbmlutils.dfba.model import DFBAModel dfba_model = DFBAModel(sbml_path=sbml_path) # simulate_toy(sbml_path, out_dir=directory, dts=[5.0], tend=10) simulate_toy_atp(sbml_path, out_dir=directory) # create COMBINE archive from tellurium.utils import omex creators = [ omex.Creator(givenName="Matthias",
def create_model(output_dir): """ Create all models. :return: directory where SBML files are located """ directory = utils.versioned_directory(output_dir, version=settings.VERSION) # create sbml import time t_start = time.time() doc_fba = fba_model(settings.FBA_LOCATION, directory) t_fba = time.time() print('{:<10}: {:3.2f}'.format('fba', t_fba-t_start)) bounds_model(settings.BOUNDS_LOCATION, directory, doc_fba=doc_fba) t_bounds = time.time() print('{:<10}: {:3.2f}'.format('bounds', t_bounds-t_fba)) update_model(settings.UPDATE_LOCATION, directory, doc_fba=doc_fba) t_update = time.time() print('{:<10}: {:3.2f}'.format('update', t_update-t_bounds)) emds = { "ecoli_fba": settings.FBA_LOCATION, "ecoli_bounds": settings.BOUNDS_LOCATION, "ecoli_update": settings.UPDATE_LOCATION, } # flatten top model top_model(settings.TOP_LOCATION, directory, emds, doc_fba=doc_fba) t_top = time.time() print('{:<10}: {:3.2f}'.format('top', t_top-t_update)) comp.flattenSBMLFile(sbml_path=pjoin(directory, settings.TOP_LOCATION), output_path=pjoin(directory, settings.FLATTENED_LOCATION)) t_flat = time.time() print('{:<10}: {:3.2f}'.format('flat', t_flat-t_top)) # create reports locations = [ settings.FBA_LOCATION, settings.BOUNDS_LOCATION, settings.UPDATE_LOCATION, settings.TOP_LOCATION, settings.FLATTENED_LOCATION ] sbml_paths = [pjoin(directory, fname) for fname in locations] sbmlreport.create_sbml_reports(sbml_paths, directory, validate=False) # create sedml from sbmlutils.dfba.sedml import create_sedml sids = ['ac_e', 'acald_e', 'akg_e', 'co2_e', 'etoh_e', 'for_e', 'fru_e', 'fum_e', 'glc__D_e', 'gln__L_e', 'glu__L_e', 'h_e', 'h2o_e', 'lac__D_e', 'mal__L_e', 'nh4_e', 'o2_e', 'pi_e', 'pyr_e', 'succ_e', 'X'] species_ids = ", ".join(sids) reaction_ids = ", ".join(['EX_{}'.format(sid) for sid in sids]) create_sedml(settings.SEDML_LOCATION, settings.TOP_LOCATION, directory=directory, dt=0.01, tend=3.5, species_ids=species_ids, reaction_ids=reaction_ids) return directory
def create_model(output_dir): """ Create all models. :return: directory where SBML files are located """ directory = utils.versioned_directory(output_dir, version=settings.VERSION) # create sbml import time t_start = time.time() doc_fba = fba_model(settings.FBA_LOCATION, directory) t_fba = time.time() print('{:<10}: {:3.2f}'.format('fba', t_fba - t_start)) bounds_model(settings.BOUNDS_LOCATION, directory, doc_fba=doc_fba) t_bounds = time.time() print('{:<10}: {:3.2f}'.format('bounds', t_bounds - t_fba)) update_model(settings.UPDATE_LOCATION, directory, doc_fba=doc_fba) t_update = time.time() print('{:<10}: {:3.2f}'.format('update', t_update - t_bounds)) emds = { "ecoli_fba": settings.FBA_LOCATION, "ecoli_bounds": settings.BOUNDS_LOCATION, "ecoli_update": settings.UPDATE_LOCATION, } # flatten top model top_model(settings.TOP_LOCATION, directory, emds, doc_fba=doc_fba) t_top = time.time() print('{:<10}: {:3.2f}'.format('top', t_top - t_update)) comp.flattenSBMLFile(sbml_path=pjoin(directory, settings.TOP_LOCATION), output_path=pjoin(directory, settings.FLATTENED_LOCATION)) t_flat = time.time() print('{:<10}: {:3.2f}'.format('flat', t_flat - t_top)) # create reports locations = [ settings.FBA_LOCATION, settings.BOUNDS_LOCATION, settings.UPDATE_LOCATION, settings.TOP_LOCATION, settings.FLATTENED_LOCATION ] sbml_paths = [pjoin(directory, fname) for fname in locations] sbmlreport.create_reports(sbml_paths, directory, validate=False) # create sedml from sbmlutils.dfba.sedml import create_sedml sids = [ 'ac_e', 'acald_e', 'akg_e', 'co2_e', 'etoh_e', 'for_e', 'fru_e', 'fum_e', 'glc__D_e', 'gln__L_e', 'glu__L_e', 'h_e', 'h2o_e', 'lac__D_e', 'mal__L_e', 'nh4_e', 'o2_e', 'pi_e', 'pyr_e', 'succ_e', 'X' ] species_ids = ", ".join(sids) reaction_ids = ", ".join(['EX_{}'.format(sid) for sid in sids]) create_sedml(settings.SEDML_LOCATION, settings.TOP_LOCATION, directory=directory, dt=0.01, tend=3.5, species_ids=species_ids, reaction_ids=reaction_ids) return directory