Example #1
0
    def get_sbml_biomodel(self, Biomodels_ID, **kwargs):
        """Get SBML model from biomodel.
        Parameters: the ID for the Biomodels
        Returns: the sbml in string format, export the SBML model into .xml file
        """

        urn = "urn:miriam:biomodels.db:" + Biomodels_ID
        sbml_str = temiriam.getSBMLFromBiomodelsURN(urn=urn)

        # modify the format exported from Biomodel to the proper xml format
        sbml_str = sbml_str.replace("><", ">  <")  # for the last line
        sbml_str = sbml_str.replace(">  ", ">\n  ")
        sbml_str = sbml_str.replace("  </sbml", "</sbml")

        filepath = os.path.join(self.workingdir0, Biomodels_ID + ".xml")

        for key, value in kwargs.items():
            if "outputfile" in key:
                filepath = value

        with open(filepath, "wb") as f:
            f.write(sbml_str.encode("utf-8"))

        print("The SBML file path: ", filepath)

        return sbml_str
Example #2
0
def test_getSBMLFromBiomodelsURN1():
    """ Check that string is returned.

    :return:
    """
    urn = 'urn:miriam:biomodels.db:BIOMD0000000139'
    sbml = temiriam.getSBMLFromBiomodelsURN(urn)
    assert sbml is not None
    # check that string
    assert isinstance(sbml, string_types)
Example #3
0
def test_getSBMLFromBiomodelsURN1():
    """ Check that model can be loaded in roadrunner.

    :return:
    """
    urn = 'urn:miriam:biomodels.db:BIOMD0000000139'
    sbml = temiriam.getSBMLFromBiomodelsURN(urn)

    print("*" * 80)
    print(type(sbml))
    print("*" * 80)
    print(sbml)
    print("*" * 80)

    r = roadrunner.RoadRunner(sbml)
    assert r is not None
Example #4
0
from tellurium.sedml.mathml import *
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d
import libsedml
import pandas
import os.path

workingDir = '/home/mkoenig/git/tellurium/tellurium/tests/testdata/sedml/sedx/_te_BIOMD0000000139'

# --------------------------------------------------------
# Models
# --------------------------------------------------------
# Model <model1>
import tellurium.temiriam as temiriam
__model1_sbml = temiriam.getSBMLFromBiomodelsURN('urn:miriam:biomodels.db:BIOMD0000000139')
model1 = te.loadSBMLModel(__model1_sbml)

# --------------------------------------------------------
# Tasks
# --------------------------------------------------------
# Task <task1>
# Task: <task1>
task1 = [None]
model1.setIntegrator('cvode')
model1.timeCourseSelections = ['Total_NFkBn', 'time']
task1[0] = model1.simulate(start=0.0, end=2500.0, steps=1000)

# --------------------------------------------------------
# DataGenerators
# --------------------------------------------------------
Example #5
0
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d
import libsedml
import pandas
import os.path

workingDir = '/home/mkoenig/git/tellurium/tellurium/tests/testdata/sedml/sed-ml'

# --------------------------------------------------------
# Models
# --------------------------------------------------------
# Model <model1>
import tellurium.temiriam as temiriam

__model1_sbml = temiriam.getSBMLFromBiomodelsURN(
    'urn:miriam:biomodels.db:BIOMD0000000021')
model1 = te.loadSBMLModel(__model1_sbml)

# --------------------------------------------------------
# Tasks
# --------------------------------------------------------
# Task <task1>
# Task: <task1>
task1 = [None]
model1.setIntegrator('cvode')
model1.timeCourseSelections = [
    '[P0]', '[T1]', '[T0]', '[CC]', '[P2]', '[T2]', '[P1]', '[Cn]', '[Mp]',
    'time', '[Mt]'
]
task1[0] = model1.simulate(start=0.0, end=100.0, steps=1000)
Example #6
0
Model is repressilator.
"""

from __future__ import absolute_import, print_function
import os
import tempfile
import shutil

from tellurium import temiriam
from tellurium.sedml.tesedml import executeCombineArchive, executeSEDML
from tellurium.utils import omex
import phrasedml

# Get SBML from URN and set for phrasedml
urn = "urn:miriam:biomodels.db:BIOMD0000000012"
sbml_str = temiriam.getSBMLFromBiomodelsURN(urn=urn)
return_code = phrasedml.setReferencedSBML(urn, sbml_str)
print('valid SBML', return_code)

# <SBML species>
#   PX - LacI protein
#   PY - TetR protein
#   PZ - cI protein
#   X - LacI mRNA
#   Y - TetR mRNA
#   Z - cI mRNA

# <SBML parameters>
#   ps_a - tps_active: Transcription from free promotor in transcripts per second and promotor
#   ps_0 - tps_repr: Transcription from fully repressed promotor in transcripts per second and promotor
Example #7
0
Model is repressilator.
"""

from __future__ import absolute_import, print_function
import os
import tempfile
import shutil

from tellurium import temiriam
from tellurium.sedml.tesedml import executeCombineArchive, executeSEDML
from tellurium.utils import omex
import phrasedml

# Get SBML from URN and set for phrasedml
urn = "urn:miriam:biomodels.db:BIOMD0000000012"
sbml_str = temiriam.getSBMLFromBiomodelsURN(urn=urn)
return_code = phrasedml.setReferencedSBML(urn, sbml_str)
print('valid SBML', return_code)

# <SBML species>
#   PX - LacI protein
#   PY - TetR protein
#   PZ - cI protein
#   X - LacI mRNA
#   Y - TetR mRNA
#   Z - cI mRNA

# <SBML parameters>
#   ps_a - tps_active: Transcription from free promotor in transcripts per second and promotor
#   ps_0 - tps_repr: Transcription from fully repressed promotor in transcripts per second and promotor
Example #8
0
    def test_repressilator(self):

        # Get SBML from URN and set for phrasedml
        urn = "urn:miriam:biomodels.db:BIOMD0000000012"
        sbml_str = temiriam.getSBMLFromBiomodelsURN(urn=urn)
        return_code = phrasedml.setReferencedSBML(urn, sbml_str)
        assert return_code  # valid SBML

        # <SBML species>
        #   PX - LacI protein
        #   PY - TetR protein
        #   PZ - cI protein
        #   X - LacI mRNA
        #   Y - TetR mRNA
        #   Z - cI mRNA

        # <SBML parameters>
        #   ps_a - tps_active: Transcription from free promotor in transcripts per second and promotor
        #   ps_0 - tps_repr: Transcription from fully repressed promotor in transcripts per second and promotor
        phrasedml_str = """
            model1 = model "{}"
            model2 = model model1 with ps_0=1.3E-5, ps_a=0.013
            sim1 = simulate uniform(0, 1000, 1000)
            task1 = run sim1 on model1
            task2 = run sim1 on model2

            # A simple timecourse simulation
            plot "Timecourse of repressilator" task1.time vs task1.PX, task1.PZ, task1.PY

            # Applying preprocessing
            plot "Timecourse after pre-processing" task2.time vs task2.PX, task2.PZ, task2.PY

            # Applying postprocessing
            plot "Timecourse after post-processing" task1.PX/max(task1.PX) vs task1.PZ/max(task1.PZ), \
                                                               task1.PY/max(task1.PY) vs task1.PX/max(task1.PX), \
                                                               task1.PZ/max(task1.PZ) vs task1.PY/max(task1.PY)
        """.format(urn)

        # convert to sedml
        print(phrasedml_str)
        sedml_str = phrasedml.convertString(phrasedml_str)
        if sedml_str is None:
            print(phrasedml.getLastError())
            raise IOError("sedml could not be generated")

        # run SEDML directly
        try:
            tmp_dir = tempfile.mkdtemp()
            executeSEDML(sedml_str, workingDir=tmp_dir)
        finally:
            shutil.rmtree(tmp_dir)

        # create combine archive and execute
        try:
            tmp_dir = tempfile.mkdtemp()
            sedml_location = "repressilator_sedml.xml"
            sedml_path = os.path.join(tmp_dir, sedml_location)
            omex_path = os.path.join(tmp_dir, "repressilator.omex")
            with open(sedml_path, "w") as f:
                f.write(sedml_str)

            entries = [
                omex.Entry(location=sedml_location, formatKey="sedml", master=True)
            ]
            omex.combineArchiveFromEntries(omexPath=omex_path, entries=entries, workingDir=tmp_dir)
            executeCombineArchive(omex_path, workingDir=tmp_dir)
        finally:
            shutil.rmtree(tmp_dir)
Example #9
0
    def test_repressilator(self):

        # Get SBML from URN and set for phrasedml
        urn = "urn:miriam:biomodels.db:BIOMD0000000012"
        sbml_str = temiriam.getSBMLFromBiomodelsURN(urn=urn)
        return_code = phrasedml.setReferencedSBML(urn, sbml_str)
        assert return_code  # valid SBML

        # <SBML species>
        #   PX - LacI protein
        #   PY - TetR protein
        #   PZ - cI protein
        #   X - LacI mRNA
        #   Y - TetR mRNA
        #   Z - cI mRNA

        # <SBML parameters>
        #   ps_a - tps_active: Transcription from free promotor in transcripts per second and promotor
        #   ps_0 - tps_repr: Transcription from fully repressed promotor in transcripts per second and promotor
        phrasedml_str = """
            model1 = model "{}"
            model2 = model model1 with ps_0=1.3E-5, ps_a=0.013
            sim1 = simulate uniform(0, 1000, 1000)
            task1 = run sim1 on model1
            task2 = run sim1 on model2

            # A simple timecourse simulation
            plot "Timecourse of repressilator" task1.time vs task1.PX, task1.PZ, task1.PY

            # Applying preprocessing
            plot "Timecourse after pre-processing" task2.time vs task2.PX, task2.PZ, task2.PY

            # Applying postprocessing
            plot "Timecourse after post-processing" task1.PX/max(task1.PX) vs task1.PZ/max(task1.PZ), \
                                                               task1.PY/max(task1.PY) vs task1.PX/max(task1.PX), \
                                                               task1.PZ/max(task1.PZ) vs task1.PY/max(task1.PY)
        """.format(urn)

        # convert to sedml
        print(phrasedml_str)
        sedml_str = phrasedml.convertString(phrasedml_str)
        if sedml_str is None:
            print(phrasedml.getLastError())
            raise IOError("sedml could not be generated")

        # run SEDML directly
        try:
            tmp_dir = tempfile.mkdtemp()
            executeSEDML(sedml_str, workingDir=tmp_dir)
        finally:
            shutil.rmtree(tmp_dir)

        # create combine archive and execute
        try:
            tmp_dir = tempfile.mkdtemp()
            sedml_location = "repressilator_sedml.xml"
            sedml_path = os.path.join(tmp_dir, sedml_location)
            omex_path = os.path.join(tmp_dir, "repressilator.omex")
            with open(sedml_path, "w") as f:
                f.write(sedml_str)

            entries = [
                omex.Entry(location=sedml_location,
                           formatKey="sedml",
                           master=True)
            ]
            omex.combineArchiveFromEntries(omexPath=omex_path,
                                           entries=entries,
                                           workingDir=tmp_dir)
            executeCombineArchive(omex_path, workingDir=tmp_dir)
        finally:
            shutil.rmtree(tmp_dir)