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
from models.liver.model_liver import create_model as create_liver_model from models.kidney.model_kidney import create_model as create_kidney_model from models.body.model_body import create_model as create_body_model if __name__ == "__main__": results_path = "./models" # create tissue models create_kidney_model(results_path) create_liver_model(results_path) # create whole-body model [_, _, sbml_path] = create_body_model(results_path) print(sbml_path) assert os.path.exists(sbml_path) sbml_path_flat = "./models/codeine_body_flat.xml" import libsbml doc = libsbml.readSBMLFromFile( os.path.abspath(sbml_path)) # type: libsbml.SBMLDocument model = doc.getModel() # type: libsbml.Model ## FIXME: not working with relative paths flattenSBMLFile(os.path.abspath(sbml_path), output_path=os.path.abspath(sbml_path_flat)) # create model report sbmlreport.create_report(sbml_path_flat, "./models/")
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
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 = 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
########################################### # Create single models ########################################### model_factory.create_fba(fba_file) model_factory.create_ode_bounds(ode_bounds_file) model_factory.create_ode_update(ode_update_file) model_factory.create_ode_model(ode_model_file) ########################################### # Create top level model ########################################### comp_factory.create_top_level_model(top_level_file) # flatten the combined model comp.flattenSBMLFile(top_level_file, output_file=flattened_file) ########################################### # Simulate the comp models ########################################### def simulate_model(tend=50.0, step_size=0.1): # Run simulation of the hybrid model from simsettings import top_level_file, out_dir import timeit # Simulate simulator = Simulator(top_level_file=top_level_file) start_time = timeit.default_timer() df = simulator.simulate(tstart=0.0, tend=tend, step_size=step_size) elapsed = timeit.default_timer() - start_time
# rbc creator.create_model( modules=['pylimax.models.glucose_pkpd.glucose_rbc_model'], target_dir=target_dir, annotations=None, create_report=create_report) # liver creator.create_model( modules=['pylimax.models.glucose_pkpd.glucose_liver_model'], target_dir=target_dir, annotations=None, create_report=create_report) # exit() # create comp model [_, _, body_path] = creator.create_model( modules=['pylimax.models.glucose_pkpd.glucose_pkpd_model'], target_dir=target_dir, annotations=None, create_report=create_report) from pylimax.models.glucose_pkpd.glucose_pkpd_model import mid, version flat_body_path = os.path.join(target_dir, "{}_{}_flat.xml".format(mid, version)) flattenSBMLFile(body_path, output_path=flat_body_path) # create model report sbmlreport.create_sbml_report(flat_body_path, out_dir=target_dir)