Beispiel #1
0
def example(model_id):
    # convert xpp to sbml
    xpp_dir = './xpp_example'
    out_dir = './xpp_example/results'

    xpp_file = os.path.join(xpp_dir, "{}.ode".format(model_id))
    sbml_file = os.path.join(out_dir, "{}.xml".format(model_id))
    xpp.xpp2sbml(xpp_file=xpp_file, sbml_file=sbml_file)
    sbmlreport.create_sbml_report(sbml_file, out_dir=out_dir, validate=False)

    # test simulation
    r = roadrunner.RoadRunner(sbml_file)
    s = r.simulate(start=0, end=1000, steps=100)

    fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(14, 7))
    axes = (ax1, ax2)

    for ax in axes:
        for sid in r.timeCourseSelections[1:]:
            ax.plot(s['time'], s[sid], label=sid)
    ax2.set_yscale('log')
    for ax in axes:
        ax.set_ylabel('Value [?]')
        ax.set_xlabel('Time [?]')
        ax.legend()

    fig.savefig(os.path.join(out_dir, "{}.png".format(model_id)),
                bbox_inches='tight')
Beispiel #2
0
def create_model(modules, target_dir, annotations=None, suffix=None, create_report=True, mid=None):
    """ Create SBML model from module information.

    This is the entry point for creating models.
    The model information is provided as a list of importable python modules.

    Additional model annotations can be provided.

    :param modules: iteratable of strings of python modules
    :param target_dir: directory in which to create SBML files
    :param annotations: list of annotations for SBML
    :param suffix: Suffix for SBML filename
    :param create_report: boolean switch to create SBML report
    :param mid: model id to use for saving file
    :return:
    """
    # preprocess
    logging.info(bcolors.OKBLUE + '\n\n' + '-'*120 + '\n' + str(modules) + '\n' + '-'*120 + bcolors.ENDC)
    model_dict = Preprocess.dict_from_modules(modules)

    # create SBML model
    core_model = CoreModel.from_dict(model_dict=model_dict)
    logging.debug(core_model.get_info())
    core_model.create_sbml()

    # write file
    if not os.path.exists(target_dir):
        logging.warning("Target directory does not exist and is created: {}".format(target_dir))
        os.makedirs(target_dir)

    if mid is None:
        mid = core_model.model.getId()
    if suffix is not None:
        filename = '{}{}.xml'.format(mid, suffix)
    else:
        filename = '{}.xml'.format(mid)
    sbml_path = os.path.join(target_dir, filename)

    core_model.write_sbml(sbml_path, validate=True)

    # annotate
    if annotations is not None:
        # overwrite the normal file
        annotation.annotate_sbml_file(sbml_path, annotations, sbml_path)

    # create report
    if create_report:
        logging.info("Create SBML report:'{}'".format(sbml_path))
        sbmlreport.create_sbml_report(sbml_path=sbml_path, out_dir=target_dir, validate=False)

    return [model_dict, core_model, sbml_path]
Beispiel #3
0
    debug, show_errors = False, False

    # test single model
    # ode_all = ["./87762/Neuron_KATP/NeuronKATP_Stoch.ode"]
    # debug, show_errors = True, True

    for k, xpp_file in enumerate(sorted(ode_all)):

        # convert xpp to sbml
        basename = os.path.basename(xpp_file)
        sbml_file = os.path.join(out_dir, "{}.xml".format(basename))
        try:
            print('[{}]'.format(k))
            xpp.xpp2sbml(xpp_file=xpp_file, sbml_file=sbml_file, force_lower=force_lower, validate=False, debug=debug)
            success = True
            sbmlreport.create_sbml_report(sbml_file, out_dir=out_dir, validate=False)
            Nall, Nerr, Nwarn = validation.check_sbml(sbml_file, name=None, ucheck=False, show_errors=show_errors)
            valid = (Nerr == 0)
            simulates = False
            if valid:
                try:
                    simulate(sbml_file)
                    simulates = True
                except:
                    # simulation exception
                    simulates = False
                    print()
                    traceback.print_exc(file=sys.stdout)
                    print()

        except:
Beispiel #4
0
"""
Writing report with distrib information.
"""

from sbmlutils.report import sbmlreport

if __name__ == "__main__":
    for path in [
            "./distrib_normal.xml", "./distrib_all.xml",
            "./uncertainty_distribution.xml", "./uncertainty_uncertspan.xml",
            "./uncertainty_uncertvalue.xml"
    ]:
        print(path)
        sbmlreport.create_sbml_report(path, out_dir="./results/")
"""
Writing report with distrib information.
"""

from sbmlutils.report import sbmlreport

if __name__ == "__main__":
    for path in ["./distrib_normal.xml",
                 "./distrib_all.xml",
                 "./uncertainty_distribution.xml",
                 "./uncertainty_uncertspan.xml",
                 "./uncertainty_uncertvalue.xml"]:
        print(path)
        sbmlreport.create_sbml_report(path, out_dir="./results/")
Beispiel #6
0
 def test_vdp_report(self):
     tmpdir = tempfile.mkdtemp(suffix="_sbml_report")
     sbmlreport.create_sbml_report(data.VDP_SBML, tmpdir)
Beispiel #7
0
 def test_glucose_report(self):
     tmpdir = tempfile.mkdtemp(suffix="_sbml_report")
     sbmlreport.create_sbml_report(data.GLUCOSE_SBML, tmpdir)
Beispiel #8
0
 def test_galactose_report(self):
     tmpdir = tempfile.mkdtemp(suffix="_sbml_report")
     sbmlreport.create_sbml_report(data.GALACTOSE_SINGLECELL_SBML, tmpdir)
Beispiel #9
0
 def test_demo_report(self):
     tmpdir = tempfile.mkdtemp(suffix="_sbml_report")
     sbmlreport.create_sbml_report(data.DEMO_SBML, tmpdir)
Beispiel #10
0
"""
Script to check the model files.
"""

import os
from os import walk
from sbmlutils.validation import check_sbml
from sbmlutils.report import sbmlreport

# directory to write files to
directory = os.path.dirname(os.path.abspath(__file__))

xml_files = []
for (dirpath, dirnames, filenames) in walk(directory):
    xml_files.extend([name for name in filenames if name.endswith('.xml')])
    break

print(xml_files)

# perform a model validation
for sbml_file in xml_files:
    check_sbml(sbml_file)

# create the model reports

for sbml_file in xml_files:
    sbmlreport.create_sbml_report(sbml_file, directory)
Beispiel #11
0
        p.setName(port_sid)
        p.setMetaId(port_sid)
        p.setSBOTerm(599)  # port
        p.setIdRef(sid)
        return p

    # add ports
    cmodel = model.getPlugin("comp")  # type: libsbml.CompModelPlugin
    for sid in ['Vplasma', 'glcEXT', 'lacEXT', 'phosEXT', 'pyrEXT']:
        create_port(sid)

    output_path = os.path.join(target_dir, "{}.xml".format(name))
    libsbml.writeSBMLToFile(doc, output_path)
    return output_path


if __name__ == "__main__":
    from sbmlutils.report import sbmlreport
    if False:
        sbmlreport.create_sbml_report(MODEL_PATH,
                                      out_dir=os.path.join(
                                          path_dir, "./input/"))

    target_dir = os.path.join(path_dir, './model/')
    name = 'rbc_parasite_model'
    output_path = prepare_rbc_model(model_path=MODEL_PATH,
                                    name=name,
                                    target_dir=target_dir)
    sbmlreport.create_sbml_report(output_path,
                                  out_dir=os.path.join(path_dir, "./model/"))
Beispiel #12
0
"""
Script to check the model files.
"""

import os
from os import walk
from sbmlutils.validation import check_sbml
from sbmlutils.report import sbmlreport

# directory to write files to
directory = os.path.dirname(os.path.abspath(__file__))

xml_files = []
for (dirpath, dirnames, filenames) in walk(directory):
    xml_files.extend([name for name in filenames if name.endswith('.xml')])
    break

print(xml_files)


# perform a model validation
for sbml_file in xml_files:
    check_sbml(sbml_file)

# create the model reports

for sbml_file in xml_files:
    sbmlreport.create_sbml_report(sbml_file, directory)
Beispiel #13
0
def create_model(modules,
                 target_dir,
                 annotations=None,
                 suffix=None,
                 create_report=True,
                 mid=None):
    """ Create SBML model from module information.

    This is the entry point for creating models.
    The model information is provided as a list of importable python modules.

    Additional model annotations can be provided.

    :param modules: iteratable of strings of python modules
    :param target_dir: directory in which to create SBML files
    :param annotations: list of annotations for SBML
    :param suffix: Suffix for SBML filename
    :param create_report: boolean switch to create SBML report
    :param mid: model id to use for saving file
    :return:
    """
    # preprocess
    logging.info(bcolors.OKBLUE + '\n\n' + '-' * 120 + '\n' + str(modules) +
                 '\n' + '-' * 120 + bcolors.ENDC)
    model_dict = Preprocess.dict_from_modules(modules)

    # create SBML model
    core_model = CoreModel.from_dict(model_dict=model_dict)
    logging.debug(core_model.get_info())
    core_model.create_sbml()

    # write file
    if not os.path.exists(target_dir):
        logging.warning(
            "Target directory does not exist and is created: {}".format(
                target_dir))
        os.makedirs(target_dir)

    if mid is None:
        mid = core_model.model.getId()
    if suffix is not None:
        filename = '{}{}.xml'.format(mid, suffix)
    else:
        filename = '{}.xml'.format(mid)
    sbml_path = os.path.join(target_dir, filename)

    core_model.write_sbml(sbml_path, validate=True)

    # annotate
    if annotations is not None:
        # overwrite the normal file
        annotator.annotate_sbml_file(sbml_path, annotations, sbml_path)

    # create report
    if create_report:
        logging.info("Create SBML report:'{}'".format(sbml_path))
        sbmlreport.create_sbml_report(sbml_path=sbml_path,
                                      out_dir=target_dir,
                                      validate=False)

    return [model_dict, core_model, sbml_path]
Beispiel #14
0
        # 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)
Beispiel #15
0
import os.path

from sbmlutils.report import sbmlreport

if __name__ == "__main__":

    # create the sbml report
    f_path = os.path.join(os.path.curdir, 'yeast_glycolysis.xml')
    print(f_path)
    sbmlreport.create_sbml_report(sbml_path=f_path, out_dir=os.path.curdir)