Exemplo n.º 1
0
def run_tellurium(input_path, output_path):
    """ Run Combine archive with tellurium and store archive with results.

    :param input_path:
    :param output_path:
    :return:
    """
    print('-' * 80)
    print('Running tellurium:\n\t', input_path)
    print('-' * 80)

    import tellurium
    import matplotlib
    matplotlib.use('Agg')
    tellurium.setDefaultPlottingEngine("matplotlib")

    filename, extension = os.path.splitext(os.path.basename(input_path))
    workingDir = os.path.join(TELLURIUM_DIR, '_te_{}'.format(filename))
    if not os.path.exists(workingDir):
        os.makedirs(workingDir)

    executeCombineArchive(input_path,
                          workingDir=workingDir,
                          outputDir=workingDir,
                          saveOutputs=True)
Exemplo n.º 2
0
def teardown_module(module):
    """ teardown any state that was previously setup with a setup_module
    method.
    """
    matplotlib.pyplot.switch_backend(MPL_BACKEND)
    matplotlib.pyplot.close('all')
    te.setDefaultPlottingEngine("plotly")
Exemplo n.º 3
0
def test_plotly1(tmpdir):
    te.setDefaultPlottingEngine("plotly")
    dgs = te.executeCombineArchive(OMEX1,
                                   printPython=True,
                                   outputDir=str(tmpdir),
                                   saveOutputs=True)
    assert dgs is not None
Exemplo n.º 4
0
def teardown_module(module):
    """ teardown any state that was previously setup with a setup_module
    method.
    """
    matplotlib.pyplot.switch_backend(MPL_BACKEND)
    matplotlib.pyplot.close('all')
    te.setDefaultPlottingEngine("plotly")
Exemplo n.º 5
0
def exec_combine_archive(archive_file, out_dir, plotting_engine='matplotlib'):
    """ Execute the SED tasks defined in a COMBINE archive and save the outputs

    Args:
        archive_file (:obj:`str`): path to COMBINE archive
        out_dir (:obj:`str`): directory to store the outputs of the tasks
        plotting_engine (:obj:`str`, optional): engine for generating plots
    """
    # set plotting engine
    tellurium.setDefaultPlottingEngine(plotting_engine)

    # check that archive exists and is in zip format
    if not os.path.isfile(archive_file):
        raise FileNotFoundError("File does not exist: {}".format(archive_file))

    if not zipfile.is_zipfile(archive_file):
        raise IOError(
            "File is not an OMEX Combine Archive in zip format: {}".format(
                archive_file))

    # extract files from archive and simulate
    try:
        tmp_dir = tempfile.mkdtemp()

        # extract archive
        tellurium.utils.omex.extractCombineArchive(omexPath=archive_file,
                                                   directory=tmp_dir)

        # get locations of SED-ML files from manifest of archive
        sedml_locations = tellurium.utils.omex.getLocationsByFormat(
            omexPath=archive_file, formatKey="sed-ml", method="omex")
        if not sedml_locations:
            # if the manifest doesn't describe any SED-ML files, try to find files with the extension .sedml in the archive
            sedml_locations = tellurium.utils.omex.getLocationsByFormat(
                omexPath=archive_file, formatKey="sed-ml", method="zip")
            warnings.warn((
                "The manifest of the COMBINE archive does not describe any SED-ML files. "
                "Nevertheless, the following SED-ML files were found in the archive:{}"
            ).format(''.join('\n  ' + loc for loc in sedml_locations)))

        # run all sedml files
        for sedml_location in sedml_locations:
            sedml_path = os.path.join(tmp_dir, sedml_location)
            sedml_out_dir = os.path.join(out_dir,
                                         os.path.splitext(sedml_location)[0])
            if not os.path.isdir(sedml_out_dir):
                os.makedirs(sedml_out_dir)
            factory = tellurium.sedml.tesedml.SEDMLCodeFactory(
                sedml_path,
                workingDir=os.path.dirname(sedml_path),
                createOutputs=True,
                saveOutputs=True,
                outputDir=sedml_out_dir,
            )
            factory.executePython()
    finally:
        shutil.rmtree(tmp_dir)
Exemplo n.º 6
0
def test_plotly1(tmpdir):
    te.setDefaultPlottingEngine("plotly")
    dgs = te.executeCombineArchive(OMEX1, printPython=True, outputDir=str(tmpdir), saveOutputs=True)
    assert dgs is not None
Exemplo n.º 7
0
This module is to generate SEDML and COMBINE OMEX files.
"""

import os
import re
import tempfile
import io
import zipfile
import requests
import tellurium as te
import matplotlib.pyplot as plt
import phrasedml
from synbiopython.genbabel import utilities

te.setDefaultPlottingEngine("matplotlib")

plt.close("all")

plt.rcdefaults()
plt.rcParams["font.family"] = "Arial"
plt.rcParams["font.weight"] = "normal"
plt.rcParams["font.size"] = 16
plt.rcParams["axes.labelsize"] = 16
plt.rcParams["axes.labelweight"] = "normal"
plt.rcParams["axes.linewidth"] = 2
plt.rcParams["axes.formatter.limits"] = -3, 3
plt.rcParams["legend.frameon"] = False
params = {"mathtext.default": "regular"}
plt.rcParams.update(params)
plt.rcParams.update({"axes.spines.top": False, "axes.spines.right": False})
Exemplo n.º 8
0
# coding: utf-8

# Back to the main [Index](../index.ipynb)

# ### Combine archives
# The experiment, i.e. model with the simulation description, can be stored as Combine Archive.

# In[1]:

#!!! DO NOT CHANGE !!! THIS FILE WAS CREATED AUTOMATICALLY FROM NOTEBOOKS !!! CHANGES WILL BE OVERWRITTEN !!! CHANGE CORRESPONDING NOTEBOOK FILE !!!
import tellurium as te, tempfile, os
te.setDefaultPlottingEngine('matplotlib')

get_ipython().magic(u'matplotlib inline')

antimony_str = '''
model myModel
  S1 -> S2; k1*S1
  S1 = 10; S2 = 0
  k1 = 1
end
'''

phrasedml_str = '''
  model1 = model "myModel"
  sim1 = simulate uniform(0, 5, 100)
  task1 = run sim1 on model1
  plot "Figure 1" time vs S1, S2
'''

# create an inline OMEX (inline representation of a COMBINE archive)
Exemplo n.º 9
0
# coding: utf-8

# Back to the main [Index](../index.ipynb)

# #### Stochastic simulation
# 
# Stochastic simulations can be run by changing the current integrator type to 'gillespie' or by using the `r.gillespie` function.

# In[1]:

#!!! DO NOT CHANGE !!! THIS FILE WAS CREATED AUTOMATICALLY FROM NOTEBOOKS !!! CHANGES WILL BE OVERWRITTEN !!! CHANGE CORRESPONDING NOTEBOOK FILE !!!
from __future__ import print_function
import tellurium as te
te.setDefaultPlottingEngine('matplotlib')
get_ipython().magic(u'matplotlib inline')
import numpy as np

r = te.loada('S1 -> S2; k1*S1; k1 = 0.1; S1 = 40')
r.integrator = 'gillespie'
r.integrator.seed = 1234

results = []
for k in range(1, 50):
    r.reset()
    s = r.simulate(0, 40)
    results.append(s)
    r.plot(s, show=False, alpha=0.7)
te.show()

Exemplo n.º 10
0
"""
Created on Fri Oct 12 09:42:34 2018

@author: YeonMi
"""

import tellurium as te
te.setDefaultPlottingEngine("matplotlib")
import numpy as np 
import random
import roadrunner
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.gridspec as gs 
import pandas as pd 


def UncertaintySingleP(model, variables, runType = None, parameters = None, simulation = None, degreeofVariability = None,
                      excludedParameters = None, sizeofEnsemble = None, ConfidenceInterval = None,  
                      limitc = None, midc = None, fillc = None, barc = None, 
                      limitw = None, midw = None,
                      fontsize = None,  
                      callback = None, datasave = None, imagesave = None):
    
    """ Measures the contribution of a singple parameter uncertainty to the model output. 
    The row of the grid indicates individual parameter, the independent variable of the simulation.
    The column of the grid is the varaiable of interest. 
    The x-axis of the subplot is time. 
    The y-axis of the subplot is the value of the species variable. 
    For each subplot, the model is simulated multiple time (default : 10000 times) 
    while varying the value of one parameter and keeping other parameters constant.