2.1. wc_lang package

2.1.2. Submodules

2.1.3. wc_lang.__main__ module

Command line programs for manipulating model definitions

Author:Jonathan Karr <karr@mssm.edu>
Date:2016-12-07
Copyright:2016, Karr Lab
License:MIT
class wc_lang.__main__.App(label=None, **kw)[source]

Bases: cement.core.foundation.App

Command line application

class Meta[source]

Bases: object

base_controller = 'base'[source]
handlers = [<class 'wc_lang.__main__.BaseController'>, <class 'wc_lang.__main__.ValidateController'>, <class 'wc_lang.__main__.DifferenceController'>, <class 'wc_lang.__main__.TransformController'>, <class 'wc_lang.__main__.NormalizeController'>, <class 'wc_lang.__main__.ConvertController'>, <class 'wc_lang.__main__.CreateTemplateController'>, <class 'wc_lang.__main__.UpdateVersionMetadataController'>][source]
label = 'wc_lang'[source]
class wc_lang.__main__.BaseController(*args, **kw)[source]

Bases: cement.ext.ext_argparse.ArgparseController

Base controller for command line application

class Meta[source]

Bases: object

arguments = [(['-v', '--version'], {'action': 'version', 'version': '0.0.1'})][source]
description = 'Command line utilities for managing whole-cell model definitions'[source]
label = 'base'[source]
class wc_lang.__main__.ConvertController(*args, **kw)[source]

Bases: cement.ext.ext_argparse.ArgparseController

Convert model definition among Excel (.xlsx), comma separated (.csv), JavaScript Object Notation (.json), tab separated (.tsv), and Yet Another Markup Language (.yaml, .yml) formats

class Meta[source]

Bases: object

arguments = [(['source'], {'type': <class 'str'>, 'help': 'Path to model definition'}), (['dest'], {'type': <class 'str'>, 'help': 'Path to save model in converted format'}), (['--sloppy'], {'dest': 'strict', 'default': True, 'action': 'store_false', 'help': 'If set, do not validate the format of the model file(s)'})][source]
description = 'Convert model definition among .csv, .json, .tsv, .xlsx, .yaml, and .yml formats'[source]
label = 'convert'[source]
stacked_on = 'base'[source]
stacked_type = 'nested'[source]
class wc_lang.__main__.CreateTemplateController(*args, **kw)[source]

Bases: cement.ext.ext_argparse.ArgparseController

Create file with model template (i.e. create file with row and column labels)

class Meta[source]

Bases: object

arguments = [(['path'], {'type': <class 'str'>, 'help': 'Path to save model template'}), (['--ignore-repo-metadata'], {'dest': 'set_repo_metadata_from_path', 'default': True, 'action': 'store_false', 'help': 'If set, do not set the Git repository metadata for the knowledge base from the parent directory of `path`'})][source]
description = 'Create file with model template: blank file(s) with row and column labels'[source]
label = 'create-template'[source]
stacked_on = 'base'[source]
stacked_type = 'nested'[source]
class wc_lang.__main__.DifferenceController(*args, **kw)[source]

Bases: cement.ext.ext_argparse.ArgparseController

Display difference between two model definitions

class Meta[source]

Bases: object

arguments = [(['path_1'], {'type': <class 'str'>, 'help': 'Path to first model definition'}), (['path_2'], {'type': <class 'str'>, 'help': 'Path to second model definition'}), (['--compare-files'], {'dest': 'compare_files', 'default': False, 'action': 'store_true', 'help': 'If true, compare models; otherwise compare files directly'}), (['--sloppy'], {'dest': 'strict', 'default': True, 'action': 'store_false', 'help': 'If set, do not validate the format of the model file(s)'})][source]
description = 'Get difference between two model definitions'[source]
label = 'difference'[source]
stacked_on = 'base'[source]
stacked_type = 'nested'[source]
class wc_lang.__main__.NormalizeController(*args, **kw)[source]

Bases: cement.ext.ext_argparse.ArgparseController

Normalize model definition

class Meta[source]

Bases: object

arguments = [(['source'], {'type': <class 'str'>, 'help': 'Path to model definition'}), (['--dest'], {'default': '', 'type': <class 'str'>, 'help': 'Path to save normalized model definition'}), (['--sloppy'], {'dest': 'strict', 'default': True, 'action': 'store_false', 'help': 'If set, do not validate the format of the model file(s)'})][source]
description = 'Normalize model definition'[source]
label = 'normalize'[source]
stacked_on = 'base'[source]
stacked_type = 'nested'[source]
class wc_lang.__main__.TransformController(*args, **kw)[source]

Bases: cement.ext.ext_argparse.ArgparseController

Apply one, or more, transforms to a model and save the result

class Meta[source]

Bases: object

arguments = [(['source'], {'type': <class 'str'>, 'help': 'Path to model definition'}), (['dest'], {'type': <class 'str'>, 'help': 'Path to save transformed model definition'}), (['--transform'], {'dest': 'transforms', 'action': 'append', 'help': 'Model transform:\n ChangeValue: Change a value of an attribute of a model\n MergeAlgorithmicallyLikeSubmodels: Merge groups of algorithmically-like submodels into individual submodels\n SplitReversibleReactions: Split reversible reactions into separate forward and backward reactions'}), (['--sloppy'], {'dest': 'strict', 'default': True, 'action': 'store_false', 'help': 'If set, do not validate the format of the model file(s)'})][source]
description = 'Apply one, or more, transforms to a model and save the result'[source]
label = 'transform'[source]
stacked_on = 'base'[source]
stacked_type = 'nested'[source]
class wc_lang.__main__.UpdateVersionMetadataController(*args, **kw)[source]

Bases: cement.ext.ext_argparse.ArgparseController

Update the version metadata (repository URL, branch, revision; wc_lang version) of a model

class Meta[source]

Bases: object

arguments = [(['path'], {'type': <class 'str'>, 'help': 'Path to model'}), (['--ignore-repo-metadata'], {'dest': 'set_repo_metadata_from_path', 'default': True, 'action': 'store_false', 'help': 'If set, do not set the Git repository metadata for the knowledge base from the parent directory of `path-core`'}), (['--sloppy'], {'dest': 'strict', 'default': True, 'action': 'store_false', 'help': 'If set, do not validate the format of the model file(s)'})][source]
description = 'Update the version metadata (repository URL, branch, revision; wc_lang version) of a model'[source]
label = 'update-version-metadata'[source]
stacked_on = 'base'[source]
stacked_type = 'nested'[source]
class wc_lang.__main__.ValidateController(*args, **kw)[source]

Bases: cement.ext.ext_argparse.ArgparseController

Validate model definition and display errors

class Meta[source]

Bases: object

arguments = [(['path'], {'type': <class 'str'>, 'help': 'Path to model definition'}), (['--sloppy'], {'dest': 'strict', 'default': True, 'action': 'store_false', 'help': 'If set, do not validate the format of the model file(s)'})][source]
description = 'Validate model definition and display errors'[source]
label = 'validate'[source]
stacked_on = 'base'[source]
stacked_type = 'nested'[source]
wc_lang.__main__.main()[source]

2.1.4. wc_lang.core module

Data model to represent biochemical models.

This module defines classes that represent the schema of a biochemical model:

These are all instances of obj_model.Model, an alias for obj_model.Model. A biochemical model may contain a list of instances of each of these classes, interlinked by object references. For example, a Reaction will reference its constituent SpeciesCoefficient instances, and the RateLaw that describes the reaction’s rate.

This module also defines numerous classes that serve as attributes of these classes.

Author:Jonathan Karr <karr@mssm.edu>
Author:Arthur Goldberg <Arthur.Goldberg@mssm.edu>
Date:2016-11-10
Copyright:2016-2017, Karr Lab
License:MIT
class wc_lang.core.BiomassComponent(**kwargs)[source]

Bases: obj_model.core.Model

A biomass reaction contains a list of BiomassComponent instances. Distinct BiomassComponents enable separate comments and references for each one.

id[source]

unique identifier per BiomassComponent

Type:str
name[source]

name

Type:str
biomass_reaction[source]

the biomass reaction that uses the biomass component

Type:BiomassReaction
coefficient[source]

the specie’s reaction coefficient

Type:float
species[source]

species

Type:Species
comments[source]

comments

Type:str
references[source]

references

Type:list
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('id', 'name', 'biomass_reaction', 'coefficient', 'species', 'comments', 'references')[source]
attributes = {'biomass_reaction': <obj_model.core.ManyToOneAttribute object>, 'coefficient': <obj_model.core.FloatAttribute object>, 'comments': <obj_model.core.LongStringAttribute object>, 'id': <obj_model.core.SlugAttribute object>, 'name': <obj_model.core.StringAttribute object>, 'references': <obj_model.core.ManyToManyAttribute object>, 'species': <obj_model.core.ManyToOneAttribute object>}[source]
indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.BiomassComponent'>,)[source]
local_attributes = {'biomass_reaction': <obj_model.core.LocalAttribute object>, 'coefficient': <obj_model.core.LocalAttribute object>, 'comments': <obj_model.core.LocalAttribute object>, 'id': <obj_model.core.LocalAttribute object>, 'name': <obj_model.core.LocalAttribute object>, 'references': <obj_model.core.LocalAttribute object>, 'species': <obj_model.core.LocalAttribute object>}[source]
ordering = ('id',)[source]
primary_attribute = <obj_model.core.SlugAttribute object>[source]
related_attributes = {}[source]
unique_together = (('biomass_reaction', 'species'),)[source]
verbose_name = 'Biomass component'[source]
verbose_name_plural = 'Biomass components'[source]
biomass_reaction = <obj_model.core.ManyToOneAttribute object>[source]
coefficient = <obj_model.core.FloatAttribute object>[source]
comments = <obj_model.core.LongStringAttribute object>[source]
id = <obj_model.core.SlugAttribute object>[source]
name = <obj_model.core.StringAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
references = <obj_model.core.ManyToManyAttribute object>[source]
species = <obj_model.core.ManyToOneAttribute object>[source]
class wc_lang.core.BiomassReaction(**kwargs)[source]

Bases: obj_model.core.Model

A pseudo-reaction used to represent the interface between metabolism and other cell processes.

id[source]

unique identifier

Type:str
name[source]

name

Type:str
submodel[source]

submodel that uses this reaction

Type:Submodel
comments[source]

comments

Type:str
references[source]

references

Type:list
Related attributes:
objective_functions (list of ObjectiveFunction): objective functions that use this
biomass reaction

biomass_components (list of BiomassComponent): the components of this biomass reaction

class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('id', 'name', 'submodel', 'comments', 'references')[source]
attributes = {'comments': <obj_model.core.LongStringAttribute object>, 'id': <obj_model.core.SlugAttribute object>, 'name': <obj_model.core.StringAttribute object>, 'references': <obj_model.core.ManyToManyAttribute object>, 'submodel': <obj_model.core.ManyToOneAttribute object>}[source]
indexed_attrs_tuples = (('id',),)[source]
inheritance = (<class 'wc_lang.core.BiomassReaction'>,)[source]
local_attributes = {'biomass_components': <obj_model.core.LocalAttribute object>, 'comments': <obj_model.core.LocalAttribute object>, 'id': <obj_model.core.LocalAttribute object>, 'name': <obj_model.core.LocalAttribute object>, 'objective_functions': <obj_model.core.LocalAttribute object>, 'references': <obj_model.core.LocalAttribute object>, 'submodel': <obj_model.core.LocalAttribute object>}[source]
ordering = ('id',)[source]
primary_attribute = <obj_model.core.SlugAttribute object>[source]
related_attributes = {'biomass_components': <obj_model.core.ManyToOneAttribute object>, 'objective_functions': <obj_model.core.ManyToManyAttribute object>}[source]
unique_together = ()[source]
verbose_name = 'Biomass reaction'[source]
verbose_name_plural = 'Biomass reactions'[source]
add_to_sbml_doc(sbml_document)[source]

Add a BiomassReaction to a libsbml SBML document.

BiomassReactions are added to the SBML document because they can be used in a dFBA submodel’s objective function. In fact the default objective function is the submodel’s biomass reaction. Since SBML does not define BiomassReaction as a separate class, BiomassReactions are added to the SBML model as SBML reactions. CheckModel ensures that wc_lang BiomassReactions and Reactions have distinct ids.

Parameters:sbml_document (obj) – a libsbml SBMLDocument
Returns:the libsbml reaction that’s created
Return type:libsbml.reaction
Raises:LibSBMLError – if calling libsbml raises an error
comments = <obj_model.core.LongStringAttribute object>[source]
id = <obj_model.core.SlugAttribute object>[source]
name = <obj_model.core.StringAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
references = <obj_model.core.ManyToManyAttribute object>[source]
submodel = <obj_model.core.ManyToOneAttribute object>[source]
class wc_lang.core.Compartment(**kwargs)[source]

Bases: obj_model.core.Model

id[source]

unique identifier

Type:str
name[source]

name

Type:str
model[source]

model

Type:Model
initial_volume[source]

initial volume (L)

Type:float
comments[source]

comments

Type:str
references[source]

references

Type:list
Related attributes:
species (list of Species): species in this compartment database_references (list of DatabaseReference): database references
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('id', 'name', 'initial_volume', 'comments', 'references')[source]
attributes = {'comments': <obj_model.core.LongStringAttribute object>, 'id': <obj_model.core.SlugAttribute object>, 'initial_volume': <obj_model.core.FloatAttribute object>, 'model': <obj_model.core.ManyToOneAttribute object>, 'name': <obj_model.core.StringAttribute object>, 'references': <obj_model.core.ManyToManyAttribute object>}[source]
indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.Compartment'>,)[source]
local_attributes = {'comments': <obj_model.core.LocalAttribute object>, 'database_references': <obj_model.core.LocalAttribute object>, 'id': <obj_model.core.LocalAttribute object>, 'initial_volume': <obj_model.core.LocalAttribute object>, 'model': <obj_model.core.LocalAttribute object>, 'name': <obj_model.core.LocalAttribute object>, 'references': <obj_model.core.LocalAttribute object>, 'species': <obj_model.core.LocalAttribute object>}[source]
ordering = ('id',)[source]
primary_attribute = <obj_model.core.SlugAttribute object>[source]
related_attributes = {'database_references': <obj_model.core.ManyToOneAttribute object>, 'species': <obj_model.core.ManyToOneAttribute object>}[source]
unique_together = ()[source]
verbose_name = 'Compartment'[source]
verbose_name_plural = 'Compartments'[source]
add_to_sbml_doc(sbml_document)[source]

Add this Compartment to a libsbml SBML document.

Parameters:sbml_document (obj) – a libsbml SBMLDocument
Returns:the libsbml compartment that’s created
Return type:libsbml.compartment
Raises:LibSBMLError – if calling libsbml raises an error
comments = <obj_model.core.LongStringAttribute object>[source]
id = <obj_model.core.SlugAttribute object>[source]
initial_volume = <obj_model.core.FloatAttribute object>[source]
model = <obj_model.core.ManyToOneAttribute object>[source]
name = <obj_model.core.StringAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
references = <obj_model.core.ManyToManyAttribute object>[source]
class wc_lang.core.Concentration(**kwargs)[source]

Bases: obj_model.core.Model

Species concentration

species[source]

species

Type:Species
value[source]

value

Type:float
units[source]

units; default units is M

Type:ConcentrationUnit
comments[source]

comments

Type:str
references[source]

references

Type:list
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('species', 'value', 'units', 'comments', 'references')[source]
attributes = {'comments': <obj_model.core.LongStringAttribute object>, 'references': <obj_model.core.ManyToManyAttribute object>, 'species': <obj_model.core.OneToOneAttribute object>, 'units': <obj_model.core.EnumAttribute object>, 'value': <obj_model.core.FloatAttribute object>}[source]
frozen_columns = 1[source]
indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.Concentration'>,)[source]
local_attributes = {'comments': <obj_model.core.LocalAttribute object>, 'references': <obj_model.core.LocalAttribute object>, 'species': <obj_model.core.LocalAttribute object>, 'units': <obj_model.core.LocalAttribute object>, 'value': <obj_model.core.LocalAttribute object>}[source]
ordering = ('species',)[source]
primary_attribute = None[source]
related_attributes = {}[source]
unique_together = (('species',),)[source]
verbose_name = 'Concentration'[source]
verbose_name_plural = 'Concentrations'[source]
comments = <obj_model.core.LongStringAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
references = <obj_model.core.ManyToManyAttribute object>[source]
serialize()[source]

Generate string representation

Returns:string representation
Return type:str
species = <obj_model.core.OneToOneAttribute object>[source]
units = <obj_model.core.EnumAttribute object>[source]
value = <obj_model.core.FloatAttribute object>[source]
class wc_lang.core.ConcentrationUnit[source]

Bases: int, enum.Enum

An enumeration.

M = 2[source]
aM = 8[source]
fM = 7[source]
mM = 3[source]
molecules = 1[source]
nM = 5[source]
pM = 6[source]
uM = 4[source]
class wc_lang.core.DatabaseReference(**kwargs)[source]

Bases: obj_model.core.Model

Reference to a source database entry

database[source]

database name

Type:str
id[source]

id of database entry

Type:str
url[source]

URL of database entry

Type:str
model[source]

model

Type:Model
taxon[source]

taxon

Type:Taxon
submodel[source]

submodel

Type:Submodel
species_type[source]

species type

Type:SpeciesType
reaction[source]

reaction

Type:Reaction
reference[source]

reference

Type:Reference
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('database', 'id', 'url', 'model', 'taxon', 'submodel', 'compartment', 'species_type', 'reaction', 'reference')[source]
attributes = {'compartment': <obj_model.core.ManyToOneAttribute object>, 'database': <obj_model.core.StringAttribute object>, 'id': <obj_model.core.StringAttribute object>, 'model': <obj_model.core.ManyToOneAttribute object>, 'reaction': <obj_model.core.ManyToOneAttribute object>, 'reference': <obj_model.core.ManyToOneAttribute object>, 'species_type': <obj_model.core.ManyToOneAttribute object>, 'submodel': <obj_model.core.ManyToOneAttribute object>, 'taxon': <obj_model.core.ManyToOneAttribute object>, 'url': <obj_model.core.UrlAttribute object>}[source]
frozen_columns = 2[source]
indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.DatabaseReference'>,)[source]
local_attributes = {'compartment': <obj_model.core.LocalAttribute object>, 'database': <obj_model.core.LocalAttribute object>, 'id': <obj_model.core.LocalAttribute object>, 'model': <obj_model.core.LocalAttribute object>, 'reaction': <obj_model.core.LocalAttribute object>, 'reference': <obj_model.core.LocalAttribute object>, 'species_type': <obj_model.core.LocalAttribute object>, 'submodel': <obj_model.core.LocalAttribute object>, 'taxon': <obj_model.core.LocalAttribute object>, 'url': <obj_model.core.LocalAttribute object>}[source]
ordering = ('database', 'id')[source]
primary_attribute = None[source]
related_attributes = {}[source]
unique_together = (('database', 'id'),)[source]
verbose_name = 'Database reference'[source]
verbose_name_plural = 'Database references'[source]
compartment = <obj_model.core.ManyToOneAttribute object>[source]
database = <obj_model.core.StringAttribute object>[source]
id = <obj_model.core.StringAttribute object>[source]
model = <obj_model.core.ManyToOneAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
reaction = <obj_model.core.ManyToOneAttribute object>[source]
reference = <obj_model.core.ManyToOneAttribute object>[source]
serialize()[source]

Generate string representation

Returns:value of primary attribute
Return type:str
species_type = <obj_model.core.ManyToOneAttribute object>[source]
submodel = <obj_model.core.ManyToOneAttribute object>[source]
taxon = <obj_model.core.ManyToOneAttribute object>[source]
url = <obj_model.core.UrlAttribute object>[source]
class wc_lang.core.ExpressionMethods[source]

Bases: object

Generic methods for mathematical expressions

static deserialize(model_class, attribute, value, objects, decoded=None)[source]

Deserialize expression

Parameters:
  • attribute (Attribute) – expression attribute
  • value (str) – string representation of the mathematical expression, in a Python expression
  • objects (dict) – dictionary of objects which can be used in expression, grouped by model
Returns:

on error return (None, InvalidAttribute),

otherwise return (object in this class with instantiated analyzed_expr, None)

Return type:

tuple

static make_expression_obj(model_type, expression, objects)[source]

Make an expression object

Parameters:
  • model_type (type) – an obj_model.Model that uses a mathemetical expression, like Function and Observable
  • expression (str) – the expression used by the model_type being created
  • objects (dict of dict) – all objects that are referenced in expression
Returns:

if successful, (obj_model.Model, None) containing a new instance of

model_type’s expression helper class; otherwise, (None, InvalidAttribute) reporting the error

Return type:

tuple

static make_obj(model, model_type, id, expression, objects, allow_invalid_objects=False)[source]

Make a model that contains an expression by using its expression helper class

For example, this uses FunctionExpression to make a Function.

Parameters:
  • model (obj_model.Model) – a wc_lang.core.Model which is the root model
  • model_type (type) – an obj_model.Model that uses a mathemetical expression, like Function and Observable
  • id (str) – the id of the model_type being created
  • expression (str) – the expression used by the model_type being created
  • objects (dict of dict) – all objects that are referenced in expression
  • allow_invalid_objects (bool, optional) – if set, return object - not error - if the expression object does not validate
Returns:

a new instance of model_type, or,

if an error occurs, an InvalidAttribute reporting the error

Return type:

obj_model.Model or InvalidAttribute

static serialize(model_obj)[source]

Generate string representation

Returns:value of primary attribute
Return type:str
static validate(model_obj, return_type=None)[source]

Determine whether an expression model is valid by eval’ing its deserialized expression

Parameters:return_type (type, optional) – if provided, an expression’s required return type
Returns:
None if the object is valid,
otherwise return a list of errors in an InvalidObject instance
Return type:InvalidObject or None
class wc_lang.core.Function(**kwargs)[source]

Bases: obj_model.core.Model

Function: a mathematical expression of Functions, Observbles, Parameters and Python functions

id[source]

unique id

Type:str
name[source]

name

Type:str
model[source]

model

Type:Model
expression[source]

mathematical expression for a Function

Type:FunctionExpression
comments[source]

comments

Type:str
Related attributes:
expressions (Expressions): expressions
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('id', 'name', 'expression', 'comments')[source]
attributes = {'comments': <obj_model.core.LongStringAttribute object>, 'expression': <wc_lang.core.FunctionExpressionAttribute object>, 'id': <obj_model.core.SlugAttribute object>, 'model': <obj_model.core.ManyToOneAttribute object>, 'name': <obj_model.core.StringAttribute object>}[source]
expression_model[source]

alias of FunctionExpression

indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.Function'>,)[source]
local_attributes = {'comments': <obj_model.core.LocalAttribute object>, 'expression': <obj_model.core.LocalAttribute object>, 'functions': <obj_model.core.LocalAttribute object>, 'id': <obj_model.core.LocalAttribute object>, 'model': <obj_model.core.LocalAttribute object>, 'name': <obj_model.core.LocalAttribute object>, 'stop_conditions': <obj_model.core.LocalAttribute object>}[source]
ordering = ('id',)[source]
primary_attribute = <obj_model.core.SlugAttribute object>[source]
related_attributes = {'functions': <obj_model.core.ManyToManyAttribute object>, 'stop_conditions': <obj_model.core.OneToManyAttribute object>}[source]
unique_together = ()[source]
verbose_name = 'Function'[source]
verbose_name_plural = 'Functions'[source]
comments = <obj_model.core.LongStringAttribute object>[source]
expression = <wc_lang.core.FunctionExpressionAttribute object>[source]
id = <obj_model.core.SlugAttribute object>[source]
model = <obj_model.core.ManyToOneAttribute object>[source]
name = <obj_model.core.StringAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
serialize()[source]

Generate string representation

Returns:value of related FunctionExpression
Return type:str
class wc_lang.core.FunctionExpression(**kwargs)[source]

Bases: obj_model.core.Model

A mathematical expression of Functions, Observbles, Parameters and Python functions

The expression used by a Function.

expression[source]

mathematical expression for a Function

Type:str
analyzed_expr[source]

an analyzed expression; not an obj_model.Model

Type:WcLangExpression
observables[source]

Observables used by this function expression

Type:list
parameters[source]

Parameters used by this function expression

Type:list
functions[source]

other Functions used by this function expression

Type:list
Related attributes:
function (Function): function
class Meta[source]

Bases: obj_model.core.Meta

valid_functions[source]

tuple of functions that can be used in this Function`s `expression

Type:tuple
valid_used_models[source]

names of obj_model.Model`s in this module that a `Function is allowed to reference in its expression

Type:tuple
attribute_order = ()[source]
attributes = {'expression': <obj_model.core.LongStringAttribute object>, 'functions': <obj_model.core.ManyToManyAttribute object>, 'observables': <obj_model.core.ManyToManyAttribute object>, 'parameters': <obj_model.core.ManyToManyAttribute object>}[source]
indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.FunctionExpression'>,)[source]
local_attributes = {'expression': <obj_model.core.LocalAttribute object>, 'function': <obj_model.core.LocalAttribute object>, 'functions': <obj_model.core.LocalAttribute object>, 'observables': <obj_model.core.LocalAttribute object>, 'parameters': <obj_model.core.LocalAttribute object>}[source]
ordering = ('expression',)[source]
primary_attribute = <obj_model.core.LongStringAttribute object>[source]
related_attributes = {'function': <wc_lang.core.FunctionExpressionAttribute object>}[source]
tabular_orientation = 3[source]
unique_together = ()[source]
valid_functions = (<built-in function ceil>, <built-in function floor>, <built-in function exp>, <built-in function pow>, <built-in function log>, <built-in function log10>, <built-in function min>, <built-in function max>)[source]
valid_used_models = ('Parameter', 'Observable', 'Function')[source]
verbose_name = 'Function expression'[source]
verbose_name_plural = 'Function expressions'[source]
classmethod deserialize(attribute, value, objects, decoded=None)[source]

Deserialize value

Parameters:
  • value (str) – String representation
  • objects (dict) – dictionary of objects, grouped by model
Returns:

tuple of cleaned value

and cleaning error

Return type:

tuple of object, InvalidAttribute or None

expression = <obj_model.core.LongStringAttribute object>[source]
functions = <obj_model.core.ManyToManyAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
observables = <obj_model.core.ManyToManyAttribute object>[source]
parameters = <obj_model.core.ManyToManyAttribute object>[source]
serialize()[source]

Get value of primary attribute

Returns:value of primary attribute
Return type:str
validate()[source]

Determine if the object is valid

Returns:
None if the object is valid,
otherwise return a list of errors as an instance of InvalidObject
Return type:InvalidObject or None
class wc_lang.core.FunctionExpressionAttribute(related_name='', verbose_name='', verbose_related_name='', help='')[source]

Bases: obj_model.core.ManyToOneAttribute

Function expression attribute

deserialize(value, objects, decoded=None)[source]

Deserialize value

Parameters:
  • value (str) – String representation
  • objects (dict) – dictionary of objects, grouped by model
  • decoded (dict, optional) – dictionary of objects that have already been decoded
Returns:

tuple of cleaned value and cleaning error

Return type:

tuple of object, InvalidAttribute or None

serialize(function_expression, encoded=None)[source]

Serialize related object

Parameters:
  • function_expression (FunctionExpression) – the referenced FunctionExpression
  • encoded (dict, optional) – dictionary of objects that have already been encoded
Returns:

simple Python representation

Return type:

str

class wc_lang.core.Model(**kwargs)[source]

Bases: obj_model.core.Model

id[source]

unique identifier

Type:str
name[source]

name

Type:str
version[source]

version of the model

Type:str
url[source]

url of the model Git repository

Type:str
branch[source]

branch of the model Git repository

Type:str
revision[source]

revision of the model Git repository

Type:str
wc_lang_version[source]

version of wc_lang

Type:str
comments[source]

comments

Type:str
Related attributes:
taxon (Taxon): taxon submodels (list of Submodel): submodels compartments (list of Compartment): compartments species_types (list of SpeciesType): species types functions (list of Function): functions observables (list of Observable): observables parameters (list of Parameter): parameters stop_conditions (list of StopCondition): stop conditions references (list of Reference): references database_references (list of DatabaseReference): database references
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('id', 'name', 'version', 'url', 'branch', 'revision', 'wc_lang_version', 'comments')[source]
attributes = {'branch': <obj_model.core.StringAttribute object>, 'comments': <obj_model.core.LongStringAttribute object>, 'id': <obj_model.core.SlugAttribute object>, 'name': <obj_model.core.StringAttribute object>, 'revision': <obj_model.core.StringAttribute object>, 'url': <obj_model.core.StringAttribute object>, 'version': <obj_model.core.RegexAttribute object>, 'wc_lang_version': <obj_model.core.RegexAttribute object>}[source]
indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.Model'>,)[source]
local_attributes = {'branch': <obj_model.core.LocalAttribute object>, 'comments': <obj_model.core.LocalAttribute object>, 'compartments': <obj_model.core.LocalAttribute object>, 'database_references': <obj_model.core.LocalAttribute object>, 'functions': <obj_model.core.LocalAttribute object>, 'id': <obj_model.core.LocalAttribute object>, 'name': <obj_model.core.LocalAttribute object>, 'observables': <obj_model.core.LocalAttribute object>, 'parameters': <obj_model.core.LocalAttribute object>, 'references': <obj_model.core.LocalAttribute object>, 'revision': <obj_model.core.LocalAttribute object>, 'species_types': <obj_model.core.LocalAttribute object>, 'stop_conditions': <obj_model.core.LocalAttribute object>, 'submodels': <obj_model.core.LocalAttribute object>, 'taxon': <obj_model.core.LocalAttribute object>, 'url': <obj_model.core.LocalAttribute object>, 'version': <obj_model.core.LocalAttribute object>, 'wc_lang_version': <obj_model.core.LocalAttribute object>}[source]
ordering = ('id',)[source]
primary_attribute = <obj_model.core.SlugAttribute object>[source]
related_attributes = {'compartments': <obj_model.core.ManyToOneAttribute object>, 'database_references': <obj_model.core.ManyToOneAttribute object>, 'functions': <obj_model.core.ManyToOneAttribute object>, 'observables': <obj_model.core.ManyToOneAttribute object>, 'parameters': <obj_model.core.ManyToOneAttribute object>, 'references': <obj_model.core.ManyToOneAttribute object>, 'species_types': <obj_model.core.ManyToOneAttribute object>, 'stop_conditions': <obj_model.core.ManyToOneAttribute object>, 'submodels': <obj_model.core.ManyToOneAttribute object>, 'taxon': <obj_model.core.OneToOneAttribute object>}[source]
tabular_orientation = 2[source]
unique_together = ()[source]
verbose_name = 'Model'[source]
verbose_name_plural = 'Models'[source]
branch = <obj_model.core.StringAttribute object>[source]
comments = <obj_model.core.LongStringAttribute object>[source]
get_biomass_reactions(_Model__type=None, **kwargs)[source]

Get all biomass reactions used by submodels

Parameters:__type (types.TypeType or tuple of types.TypeType) – subclass(es) of Model
:param **kwargs (dict of str: object): dictionary of attribute name/value pairs to find matching
objects
Returns:biomass reactions
Return type:list of BiomassReaction
get_compartments(_Model__type=None, **kwargs)[source]

Get all compartments

Parameters:__type (types.TypeType or tuple of types.TypeType) – subclass(es) of Model
:param **kwargs (dict of str: object): dictionary of attribute name/value pairs to find matching
objects
Returns:compartments
Return type:list of Compartment
get_component(type, id)[source]

Find model component of type with id

Parameters:
  • type (str) –
  • id (str) – id of component to find
Returns:

component with id, or None if there is no component with id`=`id

Return type:

obj_model.Model

get_concentrations(_Model__type=None, **kwargs)[source]

Get all concentrations from species types

Parameters:__type (types.TypeType or tuple of types.TypeType) – subclass(es) of Model
:param **kwargs (dict of str: object): dictionary of attribute name/value pairs to find matching
objects
Returns:concentations
Return type:list of Concentration
get_parameters(_Model__type=None, **kwargs)[source]

Get all parameters from model and submodels

Parameters:__type (types.TypeType or tuple of types.TypeType) – subclass(es) of Model
:param **kwargs (dict of str: object): dictionary of attribute name/value pairs to find matching
objects
Returns:parameters
Return type:list of Parameter
get_rate_laws(_Model__type=None, **kwargs)[source]

Get all rate laws from reactions

Parameters:__type (types.TypeType or tuple of types.TypeType) – subclass(es) of Model
:param **kwargs (dict of str: object): dictionary of attribute name/value pairs to find matching
objects
Returns:rate laws
Return type:list of RateLaw
get_reactions(_Model__type=None, **kwargs)[source]

Get all reactions from submodels

Parameters:__type (types.TypeType or tuple of types.TypeType) – subclass(es) of Model
:param **kwargs (dict of str: object): dictionary of attribute name/value pairs to find matching
objects
Returns:reactions
Return type:list of Reaction
get_references(_Model__type=None, **kwargs)[source]

Get all references from model and children

Parameters:__type (types.TypeType or tuple of types.TypeType) – subclass(es) of Model
:param **kwargs (dict of str: object): dictionary of attribute name/value pairs to find matching
objects
Returns:references
Return type:list of Reference
get_species(_Model__type=None, **kwargs)[source]

Get all species from submodels

Parameters:__type (types.TypeType or tuple of types.TypeType) – subclass(es) of Model
:param **kwargs (dict of str: object): dictionary of attribute name/value pairs to find matching
objects
Returns:species
Return type:list of Species
get_species_types(_Model__type=None, **kwargs)[source]

Get all species types

Parameters:__type (types.TypeType or tuple of types.TypeType) – subclass(es) of Model
:param **kwargs (dict of str: object): dictionary of attribute name/value pairs to find matching
objects
Returns:species types
Return type:list of SpeciesType
get_submodels(_Model__type=None, **kwargs)[source]

Get all submodels

Parameters:__type (types.TypeType or tuple of types.TypeType) – subclass(es) of Model
:param **kwargs (dict of str: object): dictionary of attribute name/value pairs to find matching
objects
Returns:submodels
Return type:list of Submodel
id = <obj_model.core.SlugAttribute object>[source]
name = <obj_model.core.StringAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
revision = <obj_model.core.StringAttribute object>[source]
url = <obj_model.core.StringAttribute object>[source]
version = <obj_model.core.RegexAttribute object>[source]
wc_lang_version = <obj_model.core.RegexAttribute object>[source]
class wc_lang.core.ObjectiveFunction(**kwargs)[source]

Bases: obj_model.core.Model

Objective function

expression[source]

input mathematical expression of the objective function

Type:str
analyzed_expr[source]

an analyzed expression

Type:WcLangExpression
linear[source]

indicates whether objective function is linear function of reaction fluxes

Type:bool
reactions[source]

if linear, reactions whose fluxes are used in the objective function

Type:list
reaction_coefficients[source]

parallel list of coefficients for reactions

Type:list
biomass_reactions[source]

if linear, biomass reactions whose fluxes are used in the objective function

Type:list
biomass_reaction_coefficients[source]

parallel list of coefficients for reactions in biomass_reactions

Type:list
Related attributes:
submodel (Submodel): the Submodel which uses this ObjectiveFunction
ACTIVE_OBJECTIVE = 'active_objective'[source]
class Meta[source]

Bases: obj_model.core.Meta

valid_functions[source]

tuple of functions that can be used in this ObjectiveFunction`s `expression

Type:tuple
valid_used_models[source]

names of obj_model.Model`s in this module that an `ObjectiveFunction is allowed to reference in its expression

Type:tuple
attribute_order = ('linear', 'expression', 'reactions', 'biomass_reactions')[source]
attributes = {'biomass_reactions': <obj_model.core.ManyToManyAttribute object>, 'expression': <obj_model.core.LongStringAttribute object>, 'linear': <obj_model.core.BooleanAttribute object>, 'reactions': <obj_model.core.ManyToManyAttribute object>}[source]
indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.ObjectiveFunction'>,)[source]
local_attributes = {'biomass_reactions': <obj_model.core.LocalAttribute object>, 'expression': <obj_model.core.LocalAttribute object>, 'linear': <obj_model.core.LocalAttribute object>, 'reactions': <obj_model.core.LocalAttribute object>, 'submodels': <obj_model.core.LocalAttribute object>}[source]
ordering = ()[source]
primary_attribute = None[source]
related_attributes = {'submodels': <wc_lang.core.ObjectiveFunctionAttribute object>}[source]
tabular_orientation = 3[source]
unique_together = ()[source]
valid_functions = (<built-in function exp>, <built-in function pow>, <built-in function log>, <built-in function log10>)[source]
valid_used_models = ('Parameter', 'Observable', 'Reaction', 'BiomassReaction')[source]
verbose_name = 'Objective function'[source]
verbose_name_plural = 'Objective functions'[source]
add_to_sbml_doc(sbml_document)[source]

Add this ObjectiveFunction to a libsbml SBML document in a libsbml.model.ListOfObjectives.

This uses version 2 of the ‘Flux Balance Constraints’ extension. SBML assumes that an ObjectiveFunction is a linear combination of reaction fluxes.

Parameters:sbml_document (obj) – a libsbml SBMLDocument
Returns:the libsbml Objective that’s created
Return type:libsbml.Objective
Raises:LibSBMLError – if calling libsbml raises an error
biomass_reactions = <obj_model.core.ManyToManyAttribute object>[source]
classmethod deserialize(attribute, value, objects)[source]

Deserialize value

Parameters:
  • attribute (Attribute) – attribute
  • value (str) – String representation
  • objects (dict) – dictionary of all Model objects, grouped by model
Returns:

tuple of cleaned value and cleaning error

Return type:

tuple of object, InvalidAttribute or None

expression = <obj_model.core.LongStringAttribute object>[source]
get_products(_ObjectiveFunction__type=None, **kwargs)[source]

Get the species produced by this objective function

Parameters:__type (types.TypeType or tuple of types.TypeType) – subclass(es) of Model
:param **kwargs (dict of str: object): dictionary of attribute name/value pairs to find matching
objects
Returns:species produced by this objective function
Return type:list of Species
linear = <obj_model.core.BooleanAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
reactions = <obj_model.core.ManyToManyAttribute object>[source]
serialize()[source]

Generate string representation

Returns:value of primary attribute
Return type:str
validate()[source]

Determine whether an ObjectiveFunction is valid

Ensure that self.expression evaluates as valid Python.

Returns:
None if the object is valid,
otherwise return a list of errors in an InvalidObject instance
Return type:InvalidObject or None
class wc_lang.core.ObjectiveFunctionAttribute(related_name='', verbose_name='', verbose_related_name='', help='')[source]

Bases: obj_model.core.ManyToOneAttribute

Objective function attribute

deserialize(value, objects, decoded=None)[source]

Deserialize value

Parameters:
  • value (str) – String representation
  • objects (dict) – dictionary of objects, grouped by model
  • decoded (dict, optional) – dictionary of objects that have already been decoded
Returns:

tuple of cleaned value and cleaning error

Return type:

tuple of object, InvalidAttribute or None

serialize(value, encoded=None)[source]

Serialize related object

Parameters:
  • value (ObjectiveFunction) – the referenced ObjectiveFunction
  • encoded (dict, optional) – dictionary of objects that have already been encoded
Returns:

simple Python representation

Return type:

str

class wc_lang.core.Observable(**kwargs)[source]

Bases: obj_model.core.Model

Observable: a linear function of other Observbles and Species

id[source]

unique id

Type:str
name[source]

name

Type:str
model[source]

model

Type:Model
expression[source]

mathematical expression for an Observable

Type:ObservableExpression
comments[source]

comments

Type:str
Related attributes:
expressions (Expressions): expressions
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('id', 'name', 'expression', 'comments')[source]
attributes = {'comments': <obj_model.core.LongStringAttribute object>, 'expression': <wc_lang.core.ObservableExpressionAttribute object>, 'id': <obj_model.core.SlugAttribute object>, 'model': <obj_model.core.ManyToOneAttribute object>, 'name': <obj_model.core.StringAttribute object>}[source]
expression_model[source]

alias of ObservableExpression

indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.Observable'>,)[source]
local_attributes = {'comments': <obj_model.core.LocalAttribute object>, 'expression': <obj_model.core.LocalAttribute object>, 'functions': <obj_model.core.LocalAttribute object>, 'id': <obj_model.core.LocalAttribute object>, 'model': <obj_model.core.LocalAttribute object>, 'name': <obj_model.core.LocalAttribute object>, 'observable_expressions': <obj_model.core.LocalAttribute object>, 'stop_conditions': <obj_model.core.LocalAttribute object>}[source]
ordering = ('id',)[source]
primary_attribute = <obj_model.core.SlugAttribute object>[source]
related_attributes = {'functions': <obj_model.core.ManyToManyAttribute object>, 'observable_expressions': <obj_model.core.ManyToManyAttribute object>, 'stop_conditions': <obj_model.core.OneToManyAttribute object>}[source]
unique_together = ()[source]
verbose_name = 'Observable'[source]
verbose_name_plural = 'Observables'[source]
comments = <obj_model.core.LongStringAttribute object>[source]
expression = <wc_lang.core.ObservableExpressionAttribute object>[source]
id = <obj_model.core.SlugAttribute object>[source]
model = <obj_model.core.ManyToOneAttribute object>[source]
name = <obj_model.core.StringAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
serialize()[source]

Generate string representation

Returns:value of related ObservableExpression
Return type:str
class wc_lang.core.ObservableExpression(**kwargs)[source]

Bases: obj_model.core.Model

A mathematical expression of Observables and Species

The expression used by a Observable.

expression[source]

mathematical expression for an Observable

Type:str
analyzed_expr[source]

an analyzed expression; not an obj_model.Model

Type:WcLangExpression
observables[source]

other Observables used by this Observable expression

Type:list
species[source]

Species used by this Observable expression

Type:list
Related attributes:
observable_expressions (ObservableExpression): observable expressions
class Meta[source]

Bases: obj_model.core.Meta

valid_Observables[source]

tuple of Observables that can be used in this Observable`s `expression

Type:tuple
valid_used_models[source]

names of obj_model.Model`s in this module that a `Observable is allowed to reference in its expression

Type:tuple
attribute_order = ()[source]
attributes = {'expression': <obj_model.core.LongStringAttribute object>, 'observables': <obj_model.core.ManyToManyAttribute object>, 'species': <obj_model.core.ManyToManyAttribute object>}[source]
indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.ObservableExpression'>,)[source]
local_attributes = {'expression': <obj_model.core.LocalAttribute object>, 'observable': <obj_model.core.LocalAttribute object>, 'observables': <obj_model.core.LocalAttribute object>, 'species': <obj_model.core.LocalAttribute object>}[source]
ordering = ('expression',)[source]
primary_attribute = <obj_model.core.LongStringAttribute object>[source]
related_attributes = {'observable': <wc_lang.core.ObservableExpressionAttribute object>}[source]
tabular_orientation = 3[source]
unique_together = ()[source]
valid_used_models = ('Species', 'Observable')[source]
verbose_name = 'Observable expression'[source]
verbose_name_plural = 'Observable expressions'[source]
classmethod deserialize(attribute, value, objects, decoded=None)[source]

Deserialize value

Parameters:
  • value (str) – String representation
  • objects (dict) – dictionary of objects, grouped by model
Returns:

tuple of cleaned value

and cleaning error

Return type:

tuple of object, InvalidAttribute or None

expression = <obj_model.core.LongStringAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
observables = <obj_model.core.ManyToManyAttribute object>[source]
serialize()[source]

Get value of primary attribute

Returns:value of primary attribute
Return type:str
species = <obj_model.core.ManyToManyAttribute object>[source]
validate()[source]

Determine if the object is valid

Returns:
None if the object is valid,
otherwise return a list of errors as an instance of InvalidObject
Return type:InvalidObject or None
class wc_lang.core.ObservableExpressionAttribute(related_name='', verbose_name='', verbose_related_name='', help='')[source]

Bases: obj_model.core.ManyToOneAttribute

Observable expression attribute

deserialize(value, objects, decoded=None)[source]

Deserialize value

Parameters:
  • value (str) – String representation
  • objects (dict) – dictionary of objects, grouped by model
  • decoded (dict, optional) – dictionary of objects that have already been decoded
Returns:

tuple of cleaned value and cleaning error

Return type:

tuple of object, InvalidAttribute or None

serialize(observable_expression, encoded=None)[source]

Serialize related object

Parameters:
  • observable_expression (ObservableExpression) – the referenced ObservableExpression
  • encoded (dict, optional) – dictionary of objects that have already been encoded
Returns:

simple Python representation

Return type:

str

class wc_lang.core.Parameter(**kwargs)[source]

Bases: obj_model.core.Model

id[source]

unique identifier per model/submodel

Type:str
name[source]

name

Type:str
model[source]

model

Type:Model
submodels[source]

submodels

Type:list
value[source]

value

Type:float
units[source]

units of value

Type:str
comments[source]

comments

Type:str
references[source]

references

Type:list
Related attributes:
functions (list of FunctionExpression): FunctionExpressions that use a Parameter
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('id', 'name', 'model', 'submodels', 'value', 'units', 'comments', 'references')[source]
attributes = {'comments': <obj_model.core.LongStringAttribute object>, 'id': <obj_model.core.SlugAttribute object>, 'model': <obj_model.core.ManyToOneAttribute object>, 'name': <obj_model.core.StringAttribute object>, 'references': <obj_model.core.ManyToManyAttribute object>, 'submodels': <obj_model.core.ManyToManyAttribute object>, 'units': <obj_model.core.StringAttribute object>, 'value': <obj_model.core.FloatAttribute object>}[source]
indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.Parameter'>,)[source]
local_attributes = {'comments': <obj_model.core.LocalAttribute object>, 'functions': <obj_model.core.LocalAttribute object>, 'id': <obj_model.core.LocalAttribute object>, 'model': <obj_model.core.LocalAttribute object>, 'name': <obj_model.core.LocalAttribute object>, 'rate_law_equations': <obj_model.core.LocalAttribute object>, 'references': <obj_model.core.LocalAttribute object>, 'stop_conditions': <obj_model.core.LocalAttribute object>, 'submodels': <obj_model.core.LocalAttribute object>, 'units': <obj_model.core.LocalAttribute object>, 'value': <obj_model.core.LocalAttribute object>}[source]
ordering = ('id',)[source]
primary_attribute = <obj_model.core.SlugAttribute object>[source]
related_attributes = {'functions': <obj_model.core.ManyToManyAttribute object>, 'rate_law_equations': <obj_model.core.ManyToManyAttribute object>, 'stop_conditions': <obj_model.core.OneToManyAttribute object>}[source]
unique_together = (('id', 'model', 'submodels'),)[source]
verbose_name = 'Parameter'[source]
verbose_name_plural = 'Parameters'[source]
add_to_sbml_doc(sbml_document)[source]

Add this Parameter to a libsbml SBML document.

Parameters:sbml_document (obj) – a libsbml SBMLDocument
Returns:the libsbml Parameter that’s created
Return type:libsbml.Parameter
Raises:LibSBMLError – if calling libsbml raises an error
comments = <obj_model.core.LongStringAttribute object>[source]
id = <obj_model.core.SlugAttribute object>[source]
model = <obj_model.core.ManyToOneAttribute object>[source]
name = <obj_model.core.StringAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
references = <obj_model.core.ManyToManyAttribute object>[source]
submodels = <obj_model.core.ManyToManyAttribute object>[source]
units = <obj_model.core.StringAttribute object>[source]
value = <obj_model.core.FloatAttribute object>[source]
class wc_lang.core.RateLaw(**kwargs)[source]

Bases: obj_model.core.Model

Rate law

reaction[source]

reaction

Type:Reaction
direction[source]

direction

Type:RateLawDirection
equation[source]

equation

Type:RateLawEquation
k_cat[source]

v_max (reactions enz^-1 s^-1)

Type:float
k_m[source]

k_m (M)

Type:float
comments[source]

comments

Type:str
references[source]

references

Type:list
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('reaction', 'direction', 'equation', 'k_cat', 'k_m', 'comments', 'references')[source]
attributes = {'comments': <obj_model.core.LongStringAttribute object>, 'direction': <obj_model.core.EnumAttribute object>, 'equation': <wc_lang.core.RateLawEquationAttribute object>, 'k_cat': <obj_model.core.FloatAttribute object>, 'k_m': <obj_model.core.FloatAttribute object>, 'reaction': <obj_model.core.ManyToOneAttribute object>, 'references': <obj_model.core.ManyToManyAttribute object>}[source]
indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.RateLaw'>,)[source]
local_attributes = {'comments': <obj_model.core.LocalAttribute object>, 'direction': <obj_model.core.LocalAttribute object>, 'equation': <obj_model.core.LocalAttribute object>, 'k_cat': <obj_model.core.LocalAttribute object>, 'k_m': <obj_model.core.LocalAttribute object>, 'reaction': <obj_model.core.LocalAttribute object>, 'references': <obj_model.core.LocalAttribute object>}[source]
ordering = ('reaction', 'direction')[source]
primary_attribute = None[source]
related_attributes = {}[source]
unique_together = (('direction', 'reaction'),)[source]
verbose_name = 'Rate law'[source]
verbose_name_plural = 'Rate laws'[source]
comments = <obj_model.core.LongStringAttribute object>[source]
direction = <obj_model.core.EnumAttribute object>[source]
equation = <wc_lang.core.RateLawEquationAttribute object>[source]
k_cat = <obj_model.core.FloatAttribute object>[source]
k_m = <obj_model.core.FloatAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
reaction = <obj_model.core.ManyToOneAttribute object>[source]
references = <obj_model.core.ManyToManyAttribute object>[source]
serialize()[source]

Generate string representation

Returns:value of primary attribute
Return type:str
validate()[source]

Determine whether this RateLaw is valid

Returns:
None if the object is valid,
otherwise return a list of errors in an InvalidObject instance
Return type:InvalidObject or None
class wc_lang.core.RateLawDirection[source]

Bases: int, wc_utils.util.enumerate.CaseInsensitiveEnum

Rate law directions

backward = -1[source]
forward = 1[source]
class wc_lang.core.RateLawEquation(**kwargs)[source]

Bases: obj_model.core.Model

Rate law equation

expression[source]

mathematical expression of the rate law

Type:str
transcoded[source]

transcoded expression, suitable for evaluating as a Python expression

Type:str
modifiers[source]

species whose concentrations are used in the rate law

Type:list
parameters[source]

parameters whose values are used in the rate law

Type:list
Related attributes:
rate_law (RateLaw): the RateLaw which uses this RateLawEquation
class Meta[source]

Bases: obj_model.core.Meta

valid_functions[source]

tuple of functions that can be used in a RateLawEquation`s `expression

Type:tuple
valid_used_models[source]

names of obj_model.Model`s in this module that a `RateLawEquation is allowed to reference in its expression

Type:tuple
attribute_order = ('expression', 'modifiers', 'parameters')[source]
attributes = {'expression': <obj_model.core.LongStringAttribute object>, 'modifiers': <obj_model.core.ManyToManyAttribute object>, 'parameters': <obj_model.core.ManyToManyAttribute object>, 'transcoded': <obj_model.core.LongStringAttribute object>}[source]
indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.RateLawEquation'>,)[source]
local_attributes = {'expression': <obj_model.core.LocalAttribute object>, 'modifiers': <obj_model.core.LocalAttribute object>, 'parameters': <obj_model.core.LocalAttribute object>, 'rate_laws': <obj_model.core.LocalAttribute object>, 'transcoded': <obj_model.core.LocalAttribute object>}[source]
ordering = ('rate_law',)[source]
primary_attribute = <obj_model.core.LongStringAttribute object>[source]
related_attributes = {'rate_laws': <wc_lang.core.RateLawEquationAttribute object>}[source]
tabular_orientation = 3[source]
unique_together = ()[source]
valid_functions = (<built-in function ceil>, <built-in function floor>, <built-in function exp>, <built-in function pow>, <built-in function log>, <built-in function log10>, <built-in function min>, <built-in function max>)[source]
valid_used_models = ('Species', 'Parameter', 'Observable', 'Function')[source]
verbose_name = 'Rate law equation'[source]
verbose_name_plural = 'Rate law equations'[source]
classmethod deserialize(attribute, value, objects)[source]

Deserialize value

Parameters:
  • attribute (Attribute) – attribute
  • value (str) – String representation
  • objects (dict) – dictionary of objects, grouped by model
Returns:

tuple of cleaned value and cleaning error

Return type:

tuple of object, InvalidAttribute or None

expression = <obj_model.core.LongStringAttribute object>[source]
modifiers = <obj_model.core.ManyToManyAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
parameters = <obj_model.core.ManyToManyAttribute object>[source]
serialize()[source]

Generate string representation

Returns:value of primary attribute
Return type:str
transcoded = <obj_model.core.LongStringAttribute object>[source]
validate()[source]

Determine whether a RateLawEquation is valid

  • Check that all of the modifiers and parameters contribute to the expression
  • Check that the modifiers and parameters encompass of the named entities in the expression
Returns:
None if the object is valid,
otherwise return a list of errors in an InvalidObject instance
Return type:InvalidObject or None
class wc_lang.core.RateLawEquationAttribute(related_name='', verbose_name='', verbose_related_name='', help='')[source]

Bases: obj_model.core.ManyToOneAttribute

Rate law equation

deserialize(value, objects, decoded=None)[source]

Deserialize value

Parameters:
  • value (str) – String representation
  • objects (dict) – dictionary of objects, grouped by model
  • decoded (dict, optional) – dictionary of objects that have already been decoded
Returns:

tuple of cleaned value and cleaning error

Return type:

tuple of object, InvalidAttribute or None

serialize(rate_law_equation, encoded=None)[source]

Serialize related object

Parameters:
  • rate_law_equation (RateLawEquation) – the related RateLawEquation
  • encoded (dict, optional) – dictionary of objects that have already been encoded
Returns:

simple Python representation of the rate law equation

Return type:

str

class wc_lang.core.Reaction(**kwargs)[source]

Bases: obj_model.core.Model

id[source]

unique identifier

Type:str
name[source]

name

Type:str
submodel[source]

submodel that reaction belongs to

Type:Submodel
participants[source]

participants

Type:list
reversible[source]

indicates if reaction is thermodynamically reversible

Type:bool
min_flux[source]

minimum flux bound for solving an FBA model; negative for reversible reactions

Type:float
max_flux[source]

maximum flux bound for solving an FBA model

Type:float
comments[source]

comments

Type:str
references[source]

references

Type:list
Related attributes:

database_references (list of DatabaseReference): database references rate_laws (list of RateLaw): rate laws; if present, rate_laws[0] is the forward

rate law, and rate_laws[0] is the backward rate law
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('id', 'name', 'submodel', 'participants', 'reversible', 'min_flux', 'max_flux', 'comments', 'references')[source]
attributes = {'comments': <obj_model.core.LongStringAttribute object>, 'id': <obj_model.core.SlugAttribute object>, 'max_flux': <obj_model.core.FloatAttribute object>, 'min_flux': <obj_model.core.FloatAttribute object>, 'name': <obj_model.core.StringAttribute object>, 'participants': <wc_lang.core.ReactionParticipantAttribute object>, 'references': <obj_model.core.ManyToManyAttribute object>, 'reversible': <obj_model.core.BooleanAttribute object>, 'submodel': <obj_model.core.ManyToOneAttribute object>}[source]
indexed_attrs_tuples = (('id',),)[source]
inheritance = (<class 'wc_lang.core.Reaction'>,)[source]
local_attributes = {'comments': <obj_model.core.LocalAttribute object>, 'database_references': <obj_model.core.LocalAttribute object>, 'id': <obj_model.core.LocalAttribute object>, 'max_flux': <obj_model.core.LocalAttribute object>, 'min_flux': <obj_model.core.LocalAttribute object>, 'name': <obj_model.core.LocalAttribute object>, 'objective_functions': <obj_model.core.LocalAttribute object>, 'participants': <obj_model.core.LocalAttribute object>, 'rate_laws': <obj_model.core.LocalAttribute object>, 'references': <obj_model.core.LocalAttribute object>, 'reversible': <obj_model.core.LocalAttribute object>, 'submodel': <obj_model.core.LocalAttribute object>}[source]
ordering = ('id',)[source]
primary_attribute = <obj_model.core.SlugAttribute object>[source]
related_attributes = {'database_references': <obj_model.core.ManyToOneAttribute object>, 'objective_functions': <obj_model.core.ManyToManyAttribute object>, 'rate_laws': <obj_model.core.ManyToOneAttribute object>}[source]
unique_together = ()[source]
verbose_name = 'Reaction'[source]
verbose_name_plural = 'Reactions'[source]
add_to_sbml_doc(sbml_document)[source]

Add this Reaction to a libsbml SBML document.

Parameters:sbml_document (obj) – a libsbml SBMLDocument
Returns:the libsbml reaction that’s created
Return type:libsbml.reaction
Raises:LibSBMLError – if calling libsbml raises an error
comments = <obj_model.core.LongStringAttribute object>[source]
get_species(_Reaction__type=None, **kwargs)[source]

Get species

Parameters:__type (types.TypeType or tuple of types.TypeType) – subclass(es) of Model
:param **kwargs (dict of str: object): dictionary of attribute name/value pairs to find matching
objects
Returns:list of Species
Return type:list
id = <obj_model.core.SlugAttribute object>[source]
max_flux = <obj_model.core.FloatAttribute object>[source]
min_flux = <obj_model.core.FloatAttribute object>[source]
name = <obj_model.core.StringAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
participants = <wc_lang.core.ReactionParticipantAttribute object>[source]
references = <obj_model.core.ManyToManyAttribute object>[source]
reversible = <obj_model.core.BooleanAttribute object>[source]
submodel = <obj_model.core.ManyToOneAttribute object>[source]
class wc_lang.core.ReactionParticipantAttribute(related_name='', verbose_name='', verbose_related_name='', help='')[source]

Bases: obj_model.core.ManyToManyAttribute

Reaction participants

deserialize(value, objects, decoded=None)[source]

Deserialize value

Parameters:
  • value (str) – String representation
  • objects (dict) – dictionary of objects, grouped by model
  • decoded (dict, optional) – dictionary of objects that have already been decoded
Returns:

tuple of cleaned value

and cleaning error

Return type:

tuple of list of SpeciesCoefficient, InvalidAttribute or None

deserialize_side(direction, value, objects, global_comp)[source]

Deserialize the LHS or RHS of a reaction equation

Parameters:
  • direction (float) – -1. indicates LHS, +1. indicates RHS
  • value (str) – String representation
  • objects (dict) – dictionary of objects, grouped by model
  • global_comp (Compartment) – global compartment of the reaction
  • decoded (dict, optional) – dictionary of objects that have already been decoded
Returns:

  • list of SpeciesCoefficient: list of species coefficients
  • list of Exception: list of errors

Return type:

tuple

serialize(participants, encoded=None)[source]

Serialize related object

Parameters:
  • participants (list of SpeciesCoefficient) – Python representation of reaction participants
  • encoded (dict, optional) – dictionary of objects that have already been encoded
Returns:

simple Python representation

Return type:

str

validate(obj, value)[source]

Determine if value is a valid value of the attribute

Parameters:
Returns:

None if attribute is valid, other return list of errors as an instance of InvalidAttribute

Return type:

InvalidAttribute or None

class wc_lang.core.Reference(**kwargs)[source]

Bases: obj_model.core.Model

id[source]

unique identifier

Type:str
name[source]

name

Type:str
model[source]

model

Type:Model
title[source]

title

Type:str
author[source]

author(s)

Type:str
editor[source]

editor(s)

Type:str
year[source]

year

Type:int
type[source]

type

Type:ReferenceType
publication[source]

publication title

Type:str
publisher[source]

publisher

Type:str
series[source]

series

Type:str
volume[source]

volume

Type:str
number[source]

number

Type:str
issue[source]

issue

Type:str
edition[source]

edition

Type:str
chapter[source]

chapter

Type:str
pages[source]

page range

Type:str
comments[source]

comments

Type:str
Related attributes:
database_references (list of DatabaseReference): database references taxa (list of Taxon): taxa submodels (list of Submodel): submodels compartments (list of Compartment): compartments species_types (list of SpeciesType): species types species (list of Species): species concentrations (list of Concentration): concentrations reactions (list of Reaction): reactions rate_laws (list of RateLaw): rate laws biomass_components (list of BiomassComponent): biomass components parameters (list of Parameter): parameters
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('id', 'name', 'title', 'author', 'editor', 'year', 'type', 'publication', 'publisher', 'series', 'volume', 'number', 'issue', 'edition', 'chapter', 'pages', 'comments')[source]
attributes = {'author': <obj_model.core.StringAttribute object>, 'chapter': <obj_model.core.StringAttribute object>, 'comments': <obj_model.core.LongStringAttribute object>, 'edition': <obj_model.core.StringAttribute object>, 'editor': <obj_model.core.StringAttribute object>, 'id': <obj_model.core.SlugAttribute object>, 'issue': <obj_model.core.StringAttribute object>, 'model': <obj_model.core.ManyToOneAttribute object>, 'name': <obj_model.core.StringAttribute object>, 'number': <obj_model.core.StringAttribute object>, 'pages': <obj_model.core.StringAttribute object>, 'publication': <obj_model.core.StringAttribute object>, 'publisher': <obj_model.core.StringAttribute object>, 'series': <obj_model.core.StringAttribute object>, 'title': <obj_model.core.StringAttribute object>, 'type': <obj_model.core.EnumAttribute object>, 'volume': <obj_model.core.StringAttribute object>, 'year': <obj_model.core.PositiveIntegerAttribute object>}[source]
indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.Reference'>,)[source]
local_attributes = {'author': <obj_model.core.LocalAttribute object>, 'biomass_components': <obj_model.core.LocalAttribute object>, 'biomass_reactions': <obj_model.core.LocalAttribute object>, 'chapter': <obj_model.core.LocalAttribute object>, 'comments': <obj_model.core.LocalAttribute object>, 'compartments': <obj_model.core.LocalAttribute object>, 'concentrations': <obj_model.core.LocalAttribute object>, 'database_references': <obj_model.core.LocalAttribute object>, 'edition': <obj_model.core.LocalAttribute object>, 'editor': <obj_model.core.LocalAttribute object>, 'id': <obj_model.core.LocalAttribute object>, 'issue': <obj_model.core.LocalAttribute object>, 'model': <obj_model.core.LocalAttribute object>, 'name': <obj_model.core.LocalAttribute object>, 'number': <obj_model.core.LocalAttribute object>, 'pages': <obj_model.core.LocalAttribute object>, 'parameters': <obj_model.core.LocalAttribute object>, 'publication': <obj_model.core.LocalAttribute object>, 'publisher': <obj_model.core.LocalAttribute object>, 'rate_laws': <obj_model.core.LocalAttribute object>, 'reactions': <obj_model.core.LocalAttribute object>, 'series': <obj_model.core.LocalAttribute object>, 'species': <obj_model.core.LocalAttribute object>, 'species_types': <obj_model.core.LocalAttribute object>, 'submodels': <obj_model.core.LocalAttribute object>, 'taxa': <obj_model.core.LocalAttribute object>, 'title': <obj_model.core.LocalAttribute object>, 'type': <obj_model.core.LocalAttribute object>, 'volume': <obj_model.core.LocalAttribute object>, 'year': <obj_model.core.LocalAttribute object>}[source]
ordering = ('id',)[source]
primary_attribute = <obj_model.core.SlugAttribute object>[source]
related_attributes = {'biomass_components': <obj_model.core.ManyToManyAttribute object>, 'biomass_reactions': <obj_model.core.ManyToManyAttribute object>, 'compartments': <obj_model.core.ManyToManyAttribute object>, 'concentrations': <obj_model.core.ManyToManyAttribute object>, 'database_references': <obj_model.core.ManyToOneAttribute object>, 'parameters': <obj_model.core.ManyToManyAttribute object>, 'rate_laws': <obj_model.core.ManyToManyAttribute object>, 'reactions': <obj_model.core.ManyToManyAttribute object>, 'species': <obj_model.core.ManyToManyAttribute object>, 'species_types': <obj_model.core.ManyToManyAttribute object>, 'submodels': <obj_model.core.ManyToManyAttribute object>, 'taxa': <obj_model.core.ManyToManyAttribute object>}[source]
unique_together = ()[source]
verbose_name = 'Reference'[source]
verbose_name_plural = 'References'[source]
author = <obj_model.core.StringAttribute object>[source]
chapter = <obj_model.core.StringAttribute object>[source]
comments = <obj_model.core.LongStringAttribute object>[source]
edition = <obj_model.core.StringAttribute object>[source]
editor = <obj_model.core.StringAttribute object>[source]
id = <obj_model.core.SlugAttribute object>[source]
issue = <obj_model.core.StringAttribute object>[source]
model = <obj_model.core.ManyToOneAttribute object>[source]
name = <obj_model.core.StringAttribute object>[source]
number = <obj_model.core.StringAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
pages = <obj_model.core.StringAttribute object>[source]
publication = <obj_model.core.StringAttribute object>[source]
publisher = <obj_model.core.StringAttribute object>[source]
series = <obj_model.core.StringAttribute object>[source]
title = <obj_model.core.StringAttribute object>[source]
type = <obj_model.core.EnumAttribute object>[source]
volume = <obj_model.core.StringAttribute object>[source]
year = <obj_model.core.PositiveIntegerAttribute object>[source]
class wc_lang.core.ReferenceType[source]

Bases: int, wc_utils.util.enumerate.CaseInsensitiveEnum

Reference types

article = 1[source]
book = 2[source]
inbook = 6[source]
incollection = 7[source]
inproceedings = 8[source]
misc = 9[source]
online = 3[source]
proceedings = 4[source]
thesis = 5[source]
class wc_lang.core.Species(tuple of species type, compartment)[source]

Bases: obj_model.core.Model

id[source]

identifier equal to {species_type.id}[{compartment.id}]

Type:str
name[source]

name

Type:str
species_type[source]

species type

Type:SpeciesType
compartment[source]

compartment

Type:Compartment
comments[source]

comments

Type:str
references[source]

references

Type:list
Related attributes:
concentration (Concentration): concentration species_coefficients (list of SpeciesCoefficient): participations in reactions and observables rate_law_equations (list of RateLawEquation): rate law equations observable_expressions (list of ObservableExpression): observable expressions biomass_components (list of BiomassComponent): biomass components
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('id', 'name', 'species_type', 'compartment', 'comments', 'references')[source]
attributes = {'comments': <obj_model.core.LongStringAttribute object>, 'compartment': <obj_model.core.ManyToOneAttribute object>, 'id': <obj_model.core.StringAttribute object>, 'name': <obj_model.core.StringAttribute object>, 'references': <obj_model.core.ManyToManyAttribute object>, 'species_type': <obj_model.core.ManyToOneAttribute object>}[source]
frozen_columns = 1[source]
indexed_attrs_tuples = (('compartment', 'species_type'),)[source]
inheritance = (<class 'wc_lang.core.Species'>,)[source]
local_attributes = {'biomass_components': <obj_model.core.LocalAttribute object>, 'comments': <obj_model.core.LocalAttribute object>, 'compartment': <obj_model.core.LocalAttribute object>, 'concentration': <obj_model.core.LocalAttribute object>, 'id': <obj_model.core.LocalAttribute object>, 'name': <obj_model.core.LocalAttribute object>, 'observable_expressions': <obj_model.core.LocalAttribute object>, 'rate_law_equations': <obj_model.core.LocalAttribute object>, 'references': <obj_model.core.LocalAttribute object>, 'species_coefficients': <obj_model.core.LocalAttribute object>, 'species_type': <obj_model.core.LocalAttribute object>}[source]
ordering = ('id',)[source]
primary_attribute = <obj_model.core.StringAttribute object>[source]
related_attributes = {'biomass_components': <obj_model.core.ManyToOneAttribute object>, 'concentration': <obj_model.core.OneToOneAttribute object>, 'observable_expressions': <obj_model.core.ManyToManyAttribute object>, 'rate_law_equations': <obj_model.core.ManyToManyAttribute object>, 'species_coefficients': <obj_model.core.ManyToOneAttribute object>}[source]
token_pattern = (1, 9, 1, 10)[source]
unique_together = ()[source]
verbose_name = 'Species'[source]
verbose_name_plural = 'Species'[source]
add_to_sbml_doc(sbml_document)[source]

Add this Species to a libsbml SBML document.

Parameters:sbml_document (obj) – a libsbml SBMLDocument
Returns:the libsbml species that’s created
Return type:libsbml.species
Raises:LibSBMLError – if calling libsbml raises an error
comments = <obj_model.core.LongStringAttribute object>[source]
compartment = <obj_model.core.ManyToOneAttribute object>[source]
static gen_id(species_type_id, compartment_id)[source]

Generate identifier

Parameters:
  • species_type_id (str) – species type id
  • compartment_id (str) – species type id
Returns:

identifier

Return type:

str

gen_sbml_id()[source]

Make a Species id that satisfies the SBML string id syntax.

Replaces the ‘[‘ and ‘]’ in Species.id with double-underscores ‘__’. See Finney and Hucka, “Systems Biology Markup Language (SBML) Level 2: Structures and Facilities for Model Definitions”, 2003, section 3.4.

Returns:SBML id
Return type:str
static get(ids, species_iterator)[source]

Find some Species instances

Parameters:
  • ids (Iterator of str) – an iterator over some species identifiers
  • species_iterator (Iterator) – an iterator over some species
Returns:

each element of the list corresponds to an element

of ids and contains either a Species with id() equal to the element in ids, or None indicating that species_iterator does not contain a matching Species

Return type:

list of Species or None

id = <obj_model.core.StringAttribute object>[source]
name = <obj_model.core.StringAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
references = <obj_model.core.ManyToManyAttribute object>[source]
static sbml_id_to_id(sbml_id)[source]

Convert an sbml_id to its species id.

Returns:species id
Return type:str
species_type = <obj_model.core.ManyToOneAttribute object>[source]
validate()[source]

Validate that identifier is equal to {species_type.id}[{compartment.id}]

Returns:
None if the object is valid,
otherwise return a list of errors as an instance of InvalidObject
Return type:InvalidObject or None
class wc_lang.core.SpeciesCoefficient(**kwargs)[source]

Bases: obj_model.core.Model

A tuple of a species and a coefficient

species[source]

species

Type:Species
coefficient[source]

coefficient

Type:float
Related attributes:
reaction (Reaction): reaction observables (Observable): observables
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('species', 'coefficient')[source]
attributes = {'coefficient': <obj_model.core.FloatAttribute object>, 'species': <obj_model.core.ManyToOneAttribute object>}[source]
frozen_columns = 1[source]
indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.SpeciesCoefficient'>,)[source]
local_attributes = {'coefficient': <obj_model.core.LocalAttribute object>, 'reactions': <obj_model.core.LocalAttribute object>, 'species': <obj_model.core.LocalAttribute object>}[source]
ordering = ('species',)[source]
primary_attribute = None[source]
related_attributes = {'reactions': <wc_lang.core.ReactionParticipantAttribute object>}[source]
tabular_orientation = 3[source]
unique_together = (('coefficient', 'species'),)[source]
verbose_name = 'Species coefficient'[source]
verbose_name_plural = 'Species coefficients'[source]
coefficient = <obj_model.core.FloatAttribute object>[source]
classmethod deserialize(attribute, value, objects, compartment=None)[source]

Deserialize value

Parameters:
  • attribute (Attribute) – attribute
  • value (str) – String representation
  • objects (dict) – dictionary of objects, grouped by model
  • compartment (Compartment, optional) – compartment
Returns:

tuple of cleaned value

and cleaning error

Return type:

tuple of list of SpeciesCoefficient, InvalidAttribute or None

objects = <obj_model.core.Manager object>[source]
serialize(show_compartment=True, show_coefficient_sign=True)[source]

Serialize related object

Parameters:
  • show_compartment (bool, optional) – if true, show compartment
  • show_coefficient_sign (bool, optional) – if true, show coefficient sign
Returns:

simple Python representation

Return type:

str

species = <obj_model.core.ManyToOneAttribute object>[source]
class wc_lang.core.SpeciesType(**kwargs)[source]

Bases: obj_model.core.Model

Species type

id[source]

unique identifier

Type:str
name[source]

name

Type:str
model[source]

model

Type:Model
structure[source]

structure (InChI for metabolites; sequence for DNA, RNA, proteins)

Type:str
empirical_formula[source]

empirical formula

Type:str
molecular_weight[source]

molecular weight

Type:float
charge[source]

charge

Type:int
type[source]

type

Type:SpeciesTypeType
comments[source]

comments

Type:str
references[source]

references

Type:list
Related attributes:
species (list of Species): species database_references (list of DatabaseReference): database references concentrations (list of Concentration): concentrations
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('id', 'name', 'structure', 'empirical_formula', 'molecular_weight', 'charge', 'type', 'comments', 'references')[source]
attributes = {'charge': <obj_model.core.IntegerAttribute object>, 'comments': <obj_model.core.LongStringAttribute object>, 'empirical_formula': <obj_model.core.RegexAttribute object>, 'id': <obj_model.core.SlugAttribute object>, 'model': <obj_model.core.ManyToOneAttribute object>, 'molecular_weight': <obj_model.core.FloatAttribute object>, 'name': <obj_model.core.StringAttribute object>, 'references': <obj_model.core.ManyToManyAttribute object>, 'structure': <obj_model.core.LongStringAttribute object>, 'type': <obj_model.core.EnumAttribute object>}[source]
indexed_attrs_tuples = (('id',),)[source]
inheritance = (<class 'wc_lang.core.SpeciesType'>,)[source]
local_attributes = {'charge': <obj_model.core.LocalAttribute object>, 'comments': <obj_model.core.LocalAttribute object>, 'database_references': <obj_model.core.LocalAttribute object>, 'empirical_formula': <obj_model.core.LocalAttribute object>, 'id': <obj_model.core.LocalAttribute object>, 'model': <obj_model.core.LocalAttribute object>, 'molecular_weight': <obj_model.core.LocalAttribute object>, 'name': <obj_model.core.LocalAttribute object>, 'references': <obj_model.core.LocalAttribute object>, 'species': <obj_model.core.LocalAttribute object>, 'structure': <obj_model.core.LocalAttribute object>, 'type': <obj_model.core.LocalAttribute object>}[source]
ordering = ('id',)[source]
primary_attribute = <obj_model.core.SlugAttribute object>[source]
related_attributes = {'database_references': <obj_model.core.ManyToOneAttribute object>, 'species': <obj_model.core.ManyToOneAttribute object>}[source]
unique_together = ()[source]
verbose_name = 'Species type'[source]
verbose_name_plural = 'Species types'[source]
charge = <obj_model.core.IntegerAttribute object>[source]
comments = <obj_model.core.LongStringAttribute object>[source]
empirical_formula = <obj_model.core.RegexAttribute object>[source]
id = <obj_model.core.SlugAttribute object>[source]
is_carbon_containing()[source]

Returns True is species contains at least one carbon atom.

Returns:True is species contains at least one carbon atom.
Return type:bool
model = <obj_model.core.ManyToOneAttribute object>[source]
molecular_weight = <obj_model.core.FloatAttribute object>[source]
name = <obj_model.core.StringAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
references = <obj_model.core.ManyToManyAttribute object>[source]
structure = <obj_model.core.LongStringAttribute object>[source]
type = <obj_model.core.EnumAttribute object>[source]
class wc_lang.core.SpeciesTypeType[source]

Bases: int, wc_utils.util.enumerate.CaseInsensitiveEnum

Types of species types

dna = 3[source]
metabolite = 1[source]
protein = 2[source]
pseudo_species = 5[source]
rna = 4[source]
class wc_lang.core.StopCondition(**kwargs)[source]

Bases: obj_model.core.Model

StopCondition: Simulation of a model terminates when its StopCondition is true.

A mathematical expression of Functions, Observbles, Parameters and Python functions `StopCondition`s are optional. It must return a Boolean.

id[source]

unique id

Type:str
name[source]

name

Type:str
model[source]

model

Type:Model
expression[source]

mathematical expression for a StopCondition

Type:StopConditionExpression
comments[source]

comments

Type:str
Related attributes:
expressions (Expressions): expressions
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('id', 'name', 'expression', 'comments')[source]
attributes = {'comments': <obj_model.core.LongStringAttribute object>, 'expression': <wc_lang.core.StopConditionExpressionAttribute object>, 'id': <obj_model.core.SlugAttribute object>, 'model': <obj_model.core.ManyToOneAttribute object>, 'name': <obj_model.core.StringAttribute object>}[source]
expression_model[source]

alias of StopConditionExpression

indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.StopCondition'>,)[source]
local_attributes = {'comments': <obj_model.core.LocalAttribute object>, 'expression': <obj_model.core.LocalAttribute object>, 'id': <obj_model.core.LocalAttribute object>, 'model': <obj_model.core.LocalAttribute object>, 'name': <obj_model.core.LocalAttribute object>}[source]
ordering = ('id',)[source]
primary_attribute = <obj_model.core.SlugAttribute object>[source]
related_attributes = {}[source]
unique_together = ()[source]
verbose_name = 'Stop condition'[source]
verbose_name_plural = 'Stop conditions'[source]
comments = <obj_model.core.LongStringAttribute object>[source]
expression = <wc_lang.core.StopConditionExpressionAttribute object>[source]
id = <obj_model.core.SlugAttribute object>[source]
model = <obj_model.core.ManyToOneAttribute object>[source]
name = <obj_model.core.StringAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
serialize()[source]

Generate string representation

Returns:value of related StopConditionExpression
Return type:str
class wc_lang.core.StopConditionExpression(**kwargs)[source]

Bases: obj_model.core.Model

A mathematical expression of Functions, Observbles, Parameters and Python functions

The expression used by a StopCondition.

expression[source]

mathematical expression for a StopCondition

Type:str
analyzed_expr[source]

an analyzed expression; not an obj_model.Model

Type:WcLangExpression
observables[source]

Observables used by this stop condition expression

Type:list
parameters[source]

Parameters used by this stop condition expression

Type:list
functions[source]

Functions used by this stop condition expression

Type:list
Related attributes:
stop_condition (StopCondition): stop condition
class Meta[source]

Bases: obj_model.core.Meta

valid_functions[source]

tuple of functions that can be used in this StopCondition`s `expression

Type:tuple
valid_used_models[source]

names of obj_model.Model`s in this module that a `StopCondition is allowed to reference in its expression

Type:tuple
attribute_order = ()[source]
attributes = {'expression': <obj_model.core.LongStringAttribute object>, 'functions': <obj_model.core.OneToManyAttribute object>, 'observables': <obj_model.core.OneToManyAttribute object>, 'parameters': <obj_model.core.OneToManyAttribute object>}[source]
indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.StopConditionExpression'>,)[source]
local_attributes = {'expression': <obj_model.core.LocalAttribute object>, 'functions': <obj_model.core.LocalAttribute object>, 'observables': <obj_model.core.LocalAttribute object>, 'parameters': <obj_model.core.LocalAttribute object>, 'stop_condition': <obj_model.core.LocalAttribute object>}[source]
ordering = ('expression',)[source]
primary_attribute = <obj_model.core.LongStringAttribute object>[source]
related_attributes = {'stop_condition': <wc_lang.core.StopConditionExpressionAttribute object>}[source]
tabular_orientation = 3[source]
unique_together = ()[source]
valid_functions = (<built-in function ceil>, <built-in function floor>, <built-in function exp>, <built-in function pow>, <built-in function log>, <built-in function log10>, <built-in function min>, <built-in function max>)[source]
valid_used_models = ('Parameter', 'Observable', 'Function')[source]
verbose_name = 'Stop condition expression'[source]
verbose_name_plural = 'Stop condition expressions'[source]
classmethod deserialize(attribute, value, objects, decoded=None)[source]

Deserialize value

Parameters:
  • value (str) – String representation
  • objects (dict) – dictionary of objects, grouped by model
Returns:

tuple of cleaned value

and cleaning error

Return type:

tuple of object, InvalidAttribute or None

expression = <obj_model.core.LongStringAttribute object>[source]
functions = <obj_model.core.OneToManyAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
observables = <obj_model.core.OneToManyAttribute object>[source]
parameters = <obj_model.core.OneToManyAttribute object>[source]
serialize()[source]

Get value of primary attribute

Returns:value of primary attribute
Return type:str
validate()[source]

A StopConditionExpression must return a Boolean

class wc_lang.core.StopConditionExpressionAttribute(related_name='', verbose_name='', verbose_related_name='', help='')[source]

Bases: obj_model.core.ManyToOneAttribute

StopCondition expression attribute

deserialize(value, objects, decoded=None)[source]

Deserialize value

Parameters:
  • value (str) – String representation
  • objects (dict) – dictionary of objects, grouped by model
  • decoded (dict, optional) – dictionary of objects that have already been decoded
Returns:

tuple of cleaned value and cleaning error

Return type:

tuple of object, InvalidAttribute or None

serialize(stop_condition_expression, encoded=None)[source]

Serialize related object

Parameters:
  • stop_condition_expression (StopConditionExpression) – the referenced StopConditionExpression
  • encoded (dict, optional) – dictionary of objects that have already been encoded
Returns:

simple Python representation

Return type:

str

class wc_lang.core.Submodel(**kwargs)[source]

Bases: obj_model.core.Model

id[source]

unique identifier

Type:str
name[source]

name

Type:str
model[source]

model

Type:Model
algorithm[source]

algorithm

Type:SubmodelAlgorithm
objective_function[source]

objective function for a dFBA submodel; if not initialized, then biomass_reaction is used as the objective function

Type:ObjectiveFunction
comments[source]

comments

Type:str
references[source]

references

Type:list
Related attributes:
database_references (list of DatabaseReference): database references reactions (list of Reaction): reactions biomass_reactions (list of BiomassReaction): the growth reaction for a dFBA submodel parameters (list of Parameter): parameters
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('id', 'name', 'algorithm', 'objective_function', 'comments', 'references')[source]
attributes = {'algorithm': <obj_model.core.EnumAttribute object>, 'comments': <obj_model.core.LongStringAttribute object>, 'id': <obj_model.core.SlugAttribute object>, 'model': <obj_model.core.ManyToOneAttribute object>, 'name': <obj_model.core.StringAttribute object>, 'objective_function': <wc_lang.core.ObjectiveFunctionAttribute object>, 'references': <obj_model.core.ManyToManyAttribute object>}[source]
indexed_attrs_tuples = (('id',),)[source]
inheritance = (<class 'wc_lang.core.Submodel'>,)[source]
local_attributes = {'algorithm': <obj_model.core.LocalAttribute object>, 'biomass_reactions': <obj_model.core.LocalAttribute object>, 'comments': <obj_model.core.LocalAttribute object>, 'database_references': <obj_model.core.LocalAttribute object>, 'id': <obj_model.core.LocalAttribute object>, 'model': <obj_model.core.LocalAttribute object>, 'name': <obj_model.core.LocalAttribute object>, 'objective_function': <obj_model.core.LocalAttribute object>, 'parameters': <obj_model.core.LocalAttribute object>, 'reactions': <obj_model.core.LocalAttribute object>, 'references': <obj_model.core.LocalAttribute object>}[source]
ordering = ('id',)[source]
primary_attribute = <obj_model.core.SlugAttribute object>[source]
related_attributes = {'biomass_reactions': <obj_model.core.ManyToOneAttribute object>, 'database_references': <obj_model.core.ManyToOneAttribute object>, 'parameters': <obj_model.core.ManyToManyAttribute object>, 'reactions': <obj_model.core.ManyToOneAttribute object>}[source]
unique_together = ()[source]
verbose_name = 'Submodel'[source]
verbose_name_plural = 'Submodels'[source]
add_to_sbml_doc(sbml_document)[source]

Add this Submodel to a libsbml SBML document as a libsbml.model.

Parameters:sbml_document (obj) – a libsbml SBMLDocument
Returns:the libsbml model
Return type:libsbml.model
Raises:LibSBMLError – if calling libsbml raises an error
algorithm = <obj_model.core.EnumAttribute object>[source]
comments = <obj_model.core.LongStringAttribute object>[source]
get_species(_Submodel__type=None, **kwargs)[source]

Get species in reactions

Parameters:__type (types.TypeType or tuple of types.TypeType) – subclass(es) of Model
:param **kwargs (dict of str: object): dictionary of attribute name/value pairs to find matching
objects
Returns:species in reactions
Return type:list of Species
id = <obj_model.core.SlugAttribute object>[source]
model = <obj_model.core.ManyToOneAttribute object>[source]
name = <obj_model.core.StringAttribute object>[source]
objective_function = <wc_lang.core.ObjectiveFunctionAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
references = <obj_model.core.ManyToManyAttribute object>[source]
class wc_lang.core.SubmodelAlgorithm[source]

Bases: int, wc_utils.util.enumerate.CaseInsensitiveEnum

Submodel algorithms

dfba = 1[source]
ode = 2[source]
ssa = 3[source]
class wc_lang.core.Taxon(**kwargs)[source]

Bases: obj_model.core.Model

Biological taxon (e.g. family, genus, species, strain, etc.)

id[source]

unique identifier

Type:str
name[source]

name

Type:str
model[source]

model

Type:Model
rank[source]

rank

Type:TaxonRank
comments[source]

comments

Type:str
references[source]

references

Type:list
Related attributes:
database_references (list of DatabaseReference): database references
class Meta[source]

Bases: obj_model.core.Meta

attribute_order = ('id', 'name', 'rank', 'comments', 'references')[source]
attributes = {'comments': <obj_model.core.LongStringAttribute object>, 'id': <obj_model.core.SlugAttribute object>, 'model': <obj_model.core.OneToOneAttribute object>, 'name': <obj_model.core.StringAttribute object>, 'rank': <obj_model.core.EnumAttribute object>, 'references': <obj_model.core.ManyToManyAttribute object>}[source]
indexed_attrs_tuples = ()[source]
inheritance = (<class 'wc_lang.core.Taxon'>,)[source]
local_attributes = {'comments': <obj_model.core.LocalAttribute object>, 'database_references': <obj_model.core.LocalAttribute object>, 'id': <obj_model.core.LocalAttribute object>, 'model': <obj_model.core.LocalAttribute object>, 'name': <obj_model.core.LocalAttribute object>, 'rank': <obj_model.core.LocalAttribute object>, 'references': <obj_model.core.LocalAttribute object>}[source]
ordering = ('id',)[source]
primary_attribute = <obj_model.core.SlugAttribute object>[source]
related_attributes = {'database_references': <obj_model.core.ManyToOneAttribute object>}[source]
tabular_orientation = 2[source]
unique_together = ()[source]
verbose_name = 'Taxon'[source]
verbose_name_plural = 'Taxons'[source]
comments = <obj_model.core.LongStringAttribute object>[source]
id = <obj_model.core.SlugAttribute object>[source]
model = <obj_model.core.OneToOneAttribute object>[source]
name = <obj_model.core.StringAttribute object>[source]
objects = <obj_model.core.Manager object>[source]
rank = <obj_model.core.EnumAttribute object>[source]
references = <obj_model.core.ManyToManyAttribute object>[source]
class wc_lang.core.TaxonRank[source]

Bases: int, enum.Enum

Taxonomic ranks

classis = 4[source]
domain = 1[source]
family = 6[source]
genus = 8[source]
kingdom = 2[source]
order = 5[source]
phylum = 3[source]
species = 9[source]
tribe = 7[source]
variety = 10[source]
class wc_lang.core.TaxonRankMeta[source]

Bases: wc_utils.util.enumerate.CaseInsensitiveEnumMeta

__getattr__(name)[source]

Get value by name

Parameters:name (str) – attribute name
Returns:taxonomic rank
Return type:TaxonRank
__getitem__(name)[source]

Get value by name

Parameters:name (str) – attribute name
Returns:taxonomic rank
Return type:TaxonRank

2.1.5. wc_lang.expression_utils module

Utilities for processing mathematical expressions used by wc_lang models

Author:Arthur Goldberg, Arthur.Goldberg@mssm.edu
Date:2017-10-23
Copyright:2016-2018, Karr Lab
License:MIT
exception wc_lang.expression_utils.Error(message=None)[source]

Bases: Exception

Base class for exceptions in WcLangExpression

message[source]

the exception’s message

Type:str
class wc_lang.expression_utils.ExpressionVerifier(start_state, accepting_state, transitions, empty_is_valid=False)[source]

Bases: object

Verify whether a sequence of WcLangToken tokens

An ExpressionVerifier consists of two parts:
  • An optional method valid_wc_lang_tokens that examines the content of individual tokens

and returns (True, True) if they are all valid, or (False, error) otherwise. It can be overridden by subclasses. * A DFSMAcceptor which determines whether the tokens describe a particular pattern

validate() combines these parts.

dfsm_acceptor[source]

the DFSM acceptor

Type:DFSMAcceptor
empty_is_valid[source]

if set, then an empty sequence of tokens is valid

Type:bool
make_dfsa_messages(wc_lang_tokens)[source]

Convert a sequence of `WcLangToken`s into a list of messages for transitions

Parameters:wc_lang_tokens (iterator of WcLangToken) – sequence of `WcLangToken`s
Returns:
None if wc_lang_tokens cannot be converted into a sequence of messages,
or a list of tuple of pairs (token code, message modifier)
Return type:object
valid_wc_lang_tokens(wc_lang_tokens)[source]
validate(wc_lang_tokens)[source]

Indicate whether wc_lang_tokens is valid

Parameters:wc_lang_tokens (iterator of WcLangToken) – sequence of `WcLangToken`s
Returns:(False, error) if wc_lang_tokens is valid, or (True, None) if it is
Return type:tuple
class wc_lang.expression_utils.IdMatch[source]

Bases: tuple

IdMatch(model_type, token_pattern, match_string): Matched token pattern used by tokenize

__getnewargs__()[source]

Return self as a plain tuple. Used by copy and pickle.

static __new__(_cls, model_type, token_pattern, match_string)[source]

Create new instance of IdMatch(model_type, token_pattern, match_string)

__repr__()[source]

Return a nicely formatted representation string

match_string[source]

The matched string

model_type[source]

The type of Model matched

token_pattern[source]

The token pattern used by the match

class wc_lang.expression_utils.LexMatch[source]

Bases: tuple

LexMatch(wc_lang_tokens, num_py_tokens): result returned by a lexer method that matches a wc_lang expression element

__getnewargs__()[source]

Return self as a plain tuple. Used by copy and pickle.

static __new__(_cls, wc_lang_tokens, num_py_tokens)[source]

Create new instance of LexMatch(wc_lang_tokens, num_py_tokens)

__repr__()[source]

Return a nicely formatted representation string

num_py_tokens[source]

Number of Python tokens consumed

wc_lang_tokens[source]

List of WcLangTokens created

class wc_lang.expression_utils.LinearExpressionVerifier[source]

Bases: wc_lang.expression_utils.ExpressionVerifier

Verify whether a sequence of tokens (`WcLangToken`s) describes a linear function of identifiers

In particular, a valid linear expression must have the structure:
  • (identifier | number ‘*’ identifier) ((‘+’ | ‘-‘) (identifier | number ‘*’ identifier))*
linear_expr_transitions = [('need number or id', (<TokCodes.number: 3>, None), 'need *'), ('need *', (<TokCodes.op: 4>, '*'), 'need id'), ('need id', (<TokCodes.wc_lang_obj_id: 1>, None), 'need + | - | end'), ('need number or id', (<TokCodes.wc_lang_obj_id: 1>, None), 'need + | - | end'), ('need + | - | end', (<TokCodes.op: 4>, '+'), 'need number or id'), ('need + | - | end', (<TokCodes.op: 4>, '-'), 'need number or id'), ('need + | - | end', (None, None), 'end')][source]
make_dfsa_messages(wc_lang_tokens)[source]

Convert a sequence of WcLangToken`s into a list of messages for transitions in `linear_expr_transitions

Parameters:wc_lang_tokens (iterator of WcLangToken) – sequence of `WcLangToken`s
Returns:
None if wc_lang_tokens cannot be converted into a sequence of messages
to validate a linear expression, or a list of tuple of pairs (token code, message modifier)
Return type:object
valid_wc_lang_tokens(wc_lang_tokens)[source]

Check whether the content of a sequence of `WcLangToken`s is valid

In particular, all numbers in wc_lang_tokens must be floats, and all token codes must not be math_fun_id or other.

Parameters:wc_lang_tokens (iterator of WcLangToken) – sequence of `WcLangToken`s
Returns:
(False, error) if wc_lang_tokens cannot be a linear expression, or
(True, True) if it can
Return type:tuple
wc_lang.expression_utils.PARAMETERS_DICT = 'parameters'[source]

replace MakeModels

class wc_lang.expression_utils.RateLawUtils[source]

Bases: object

A set of static rate_law methods

static eval_rate_law(rate_law, concentrations, parameters, transcoded_equation=None)[source]

Evaluate a rate law at the given species concentrations and parameter values

Parameters:
  • rate_law (wc_lang.core.RateLaw) – a RateLaw instance
  • concentrations (dict of species_id -> float) – a dictionary of species concentrations
  • parameters (dict of parameter_id -> float) – a dictionary of parameter values
  • transcoded_equation (str, optional) – the rate law’s transcoded_equation; if not provided, will be taken from rate_law.equation.transcoded
Returns:

the rate law’s rate

Return type:

float)

Raises:
  • ValueError – if the rate law has a syntax error
  • NameError – if the rate law references a specie whose concentration is not provided in concentrations or a parameter whose value is not provided in parameters
  • Exception – if the rate law has other errors, such as a reference to an unknown function
static eval_reaction_rate_laws(reaction, concentrations, parameters)[source]

Evaluate a reaction’s rate laws at the given species concentrations and parameter values

Parameters:
  • reaction (wc_lang.core.Reaction) – a Reaction instance
  • concentrations (dict of species_id -> float) – a dictionary of species concentrations
  • parameters (dict of parameter_id -> float) – a dictionary of parameter values
Returns:

the reaction’s forward and, perhaps, backward rates

Return type:

(list of float)

static transcode(rate_law_equation, species_ids, parameter_ids)[source]

Translate a wc_lang.core.RateLawEquation into a python expression that can be evaluated during a simulation.

Parameters:
  • rate_law_equation (wc_lang.core.RateLawEquation) – a rate law equation
  • species_ids (set of str) – ids of the species that the rate law might use
  • parameter_ids (set of str) – ids of the parameters that the rate law might use
Returns:

The python expression, or None if the rate law doesn’t have an equation

Raises:
  • ValueError – if rate_law_equation contains __, which increases its security risk, or
  • if rate_law_equation refers to species not in species or parameters not in parameters
class wc_lang.expression_utils.TokCodes[source]

Bases: int, wc_utils.util.enumerate.CaseInsensitiveEnum

Token codes used in parsed expressions

math_fun_id = 2[source]
number = 3[source]
op = 4[source]
other = 5[source]
wc_lang_obj_id = 1[source]
class wc_lang.expression_utils.WcLangExpression(model_class, attribute, expression, objects)[source]

Bases: object

An expression in a wc_lang Model

Expressions are currently (July, 2018) used in five wc_lang Model`s: `RateLawEquation, Function, StopCondition (which is just a special case of Function that returns a boolean), ObjectiveFunction, and Observable. These expressions are limited Python expressions with specific semantics:

  • They must be syntactically correct Python.
  • No Python keywords, strings, or tokens that do not belong in expressions are allowed.
  • All Python identifiers must be the ID of an object in a whole-cell model, or components of
    an ID of an object in the model, or the name of a function in the math package. Objects in the model are provided in objects, and the allowed subset of functions in math must be provided in an iterator in the valid_functions attribute of the Meta class of a model whose whose expression is being processed.
  • Currently (July, 2018), identifiers may refer to `Species`s, `Parameter`s, `Observable`s, `Reaction`s,
    Observable’s and `BiomassReaction`s.
  • Cycles of references are illegal.
  • An identifier must unambiguously refer to exactly one related Model in a model.
  • Each wc_lang Model that can be used in an expression must have an ID that is a simple Python identifier,
    or define token_pattern as an attribute that describes the Model’s syntactic Python structure. See Species for an example.
  • Every expression must be computable at any time during a simulation. The evaluation of an expression
    always occurs at a precise simulation time, which is implied by the expression but not explicitly represented. E.g., a reference to a Species means its concentration at the time the expression is eval`ed. These are the meanings of references: * `Species: its current concentration * Parameter: its value, which is static * Observable: its current value, whose units depend on its definition * Reaction: its current flux * BiomassReaction: its current flux
  • The modeller is responsible for ensuring that units in expressions are internally consistent and appropriate
    for the expression’s use
model_class[source]

the wc_lang Model which has an expression

Type:obj_model.Model
attribute[source]

the attribute name of the expression in model_class

Type:str
expression[source]

the expression defined in the wc_lang Model

Type:str
tokens[source]

a list of Python tokens generated by tokenize.tokenize()

Type:list
objects[source]

dict of wc_lang Models that might be referenced in expression; maps model type to a dict mapping ids to Model instances

Type:dict
valid_used_models[source]
wc_lang Models that model_class objects are allowed to use,
as indicated in model_class.Meta.valid_used_models, intersected with objects.keys()

might be referenced in expression; maps

Type:set
valid_functions[source]

the union of all valid_functions attributes for objects

Type:set
related_objects[source]

models that are referenced in expression; maps model type to dict that maps model id to model instance

Type:dict
errors[source]

errors found when parsing an expression fails

Type:list
wc_tokens[source]

tokens obtained when an expression is successfully tokenize`d; if empty, then this `WcLangExpression cannot use eval_expr()

Type:list
disambiguated_id(idx, case_fold_match=False)[source]

Try to parse a disambuated wc_lang id from self.tokens at idx

Look for a disambugated id (either a Function written as Function.identifier(), or a Model written as ModelType.model_id). If tokens do not match, return None. If tokens match, but their values are wrong, return an error str. If a disambugated id is found, return a LexMatch describing it.

Parameters:
  • idx (int) – current index into tokens
  • case_fold_match (bool, optional) – if set, casefold() identifiers before matching; in a WcLangToken, token_string retains the original expression text, while model_id contains the casefold’ed value; identifier keys in self.objects must already be casefold’ed; default=False
Returns:

If tokens do not match, return None. If tokens match,

but their values are wrong, return an error str. If a disambugated id is found, return a LexMatch describing it.

Return type:

object

fun_call_id(idx, case_fold_match='unused')[source]

Try to parse a Python math function call from self.tokens at idx

Each wc_lang object model_class that contains an expression which can use Python math functions must define the set of allowed functions in Meta.valid_functions of the model_class Expression Model.

Parameters:
  • idx (int) – current index into self.tokens
  • case_fold_match (str, optional) – ignored keyword; makes WcLangExpression.tokenize() simpler
Returns:

If tokens do not match, return None. If tokens match,

but their values are wrong, return an error str. If a function call is found, return a LexMatch describing it.

Return type:

object

fun_type_disambig_patttern = (1, 23, 1, 7, 8)[source]
function_pattern = (1, 7)[source]
get_wc_lang_model_type(model_type_name)[source]

Find the wc_lang model type corresponding to model_type_name

Parameters:model_type_name (str) – the name of a purported wc_lang model type in an expression
Returns:
None if no model named model_type_name exists in self.valid_used_models,
else the type of the model with that name
Return type:object
illegal_name = 'NT_OFFSET'[source]
illegal_token_names = ['ENDMARKER', 'NEWLINE', 'INDENT', 'DEDENT', 'COLON', 'LBRACE', 'RBRACE', 'PLUSEQUAL', 'MINEQUAL', 'STAREQUAL', 'SLASHEQUAL', 'PERCENTEQUAL', 'AMPEREQUAL', 'VBAREQUAL', 'CIRCUMFLEXEQUAL', 'LEFTSHIFTEQUAL', 'RIGHTSHIFTEQUAL', 'DOUBLESTAREQUAL', 'DOUBLESLASHEQUAL', 'ATEQUAL', 'RARROW', 'ELLIPSIS', 'AWAIT', 'ASYNC', 'ERRORTOKEN', 'N_TOKENS', 'NT_OFFSET'][source]
illegal_tokens = {0, 4, 5, 6, 11, 25, 26, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 48, 50, 51, 52, 54, 55, 56, 57, 256}[source]
match_tokens(token_pattern, idx)[source]

Indicate whether tokens begins with a pattern of tokens that match token_pattern

Parameters:
  • token_pattern (tuple of int) – a tuple of Python token numbers, taken from the
  • module (token) –
  • idx (int) – current index into tokens
  • Returnsobject: bool, False if the initial elements of tokens do not match the syntax in token_pattern, or str, the matching string
model_type_disambig_pattern = (1, 23, 1)[source]
related_object_id(idx, case_fold_match=False)[source]

Try to parse a related object wc_lang id from self.tokens at idx

Different wc_lang objects match different Python token patterns. The default pattern is (token.NAME, ), but an object of type model_type can define a custom pattern in model_type.Meta.token_pattern, as Species does. Some patterns may consume multiple Python tokens.

Parameters:
  • idx (int) – current index into tokens
  • case_fold_match (bool, optional) – if set, casefold identifiers before matching; identifier keys in self.objects must already be casefold’ed; default=False
Returns:

If tokens do not match, return None. If tokens match,

but their values are wrong, return an error str. If a related object id is found, return a LexMatch describing it.

Return type:

object

test_eval_expr(test_val=1.0)[source]

Test evaluate the Python expression in this WcLangExpression

Called to validate this WcLangExpression. This expression must have been successfully tokenize`d. All Models it uses are assumed to have the value `test_val.

Approach:
  • Replace references to used Models in self.wc_tokens with test_val
  • Join the elements of self.wc_tokens into a Python expression
  • eval the Python expression
Parameters:test_val (float, optional) – the value assumed for used Models
Returns:the value of the expression
Return type:(object)
Raises:(WcLangExpressionError) – if the expression evaluation fails
tokenize(case_fold_match=False)[source]

Tokenize a Python expression in self.expression

Parameters:case_fold_match (bool, optional) – if set, casefold identifiers before matching; identifier keys in self.objects must already be casefold’ed; default = False
Returns:
either (None, :obj:list of :obj:str) containing a list of errors, or
(:obj:list, :obj:dict) containing a list of :obj:`WcLangToken`s and a dict of Model instances used by this list, grouped by Model type
Return type:(tuple)
Raises:(WcLangExpressionError) – if model_class does not have a Meta attribute
exception wc_lang.expression_utils.WcLangExpressionError(message=None)[source]

Bases: wc_lang.expression_utils.Error

Exception raised for errors in WcLangExpression

message[source]

the exception’s message

Type:str
class wc_lang.expression_utils.WcLangToken[source]

Bases: tuple

WcLangToken(tok_code, token_string, model_type, model_id, model): Token in a parsed wc_lang expression

__getnewargs__()[source]

Return self as a plain tuple. Used by copy and pickle.

static __new__(_cls, tok_code, token_string, model_type=None, model_id=None, model=None)[source]

Create new instance of WcLangToken(tok_code, token_string, model_type, model_id, model)

__repr__()[source]

Return a nicely formatted representation string

model[source]

When tok_code is wc_lang_obj_id, the wc_lang obj

model_id[source]

When tok_code is wc_lang_obj_id, the wc_lang obj’s id

model_type[source]

When tok_code is wc_lang_obj_id, the wc_lang obj’s type

tok_code[source]

TokCodes encoding

token_string[source]

The token’s string

2.1.6. wc_lang.io module

Reading and writing models to/from files.

Supported file types:

  • Comma separated values (.csv)
  • Excel (.xlsx)
  • Tab separated values (.tsv)
Author:Jonathan Karr <karr@mssm.edu>
Date:2016-12-05
Copyright:2016, Karr Lab
License:MIT
class wc_lang.io.Reader[source]

Bases: object

Read model from file(s)

run(path, strict=True)[source]

Read model from file(s)

Parameters:
  • path (str) – path to file(s)
  • strict (bool, optional) –

    if True, validate that the the model file(s) strictly follow the obj_model serialization format:

    • The worksheets are in the expected order
    • There are no missing worksheets
    • There are no extra worksheets
    • The columns are in the expected order
    • There are no missing columns
    • There are no extra columns
Returns:

model

Return type:

core.Model

Raises:

ValueError – if path defines multiple models

class wc_lang.io.Writer[source]

Bases: object

Write model to file(s)

model_order = [<class 'wc_lang.core.Model'>, <class 'wc_lang.core.Taxon'>, <class 'wc_lang.core.Submodel'>, <class 'wc_lang.core.Compartment'>, <class 'wc_lang.core.SpeciesType'>, <class 'wc_lang.core.Species'>, <class 'wc_lang.core.Concentration'>, <class 'wc_lang.core.Observable'>, <class 'wc_lang.core.Function'>, <class 'wc_lang.core.Reaction'>, <class 'wc_lang.core.RateLaw'>, <class 'wc_lang.core.BiomassReaction'>, <class 'wc_lang.core.BiomassComponent'>, <class 'wc_lang.core.Parameter'>, <class 'wc_lang.core.StopCondition'>, <class 'wc_lang.core.Reference'>, <class 'wc_lang.core.DatabaseReference'>][source]
run(model, path, set_repo_metadata_from_path=True)[source]

Write model to file(s)

Parameters:
  • model (core.Model) – model
  • path (str) – path to file(s)
  • set_repo_metadata_from_path (bool, optional) – if True, set the Git repository metadata (URL, branch, revision) for the model from the parent directory of core_path
classmethod validate_implicit_relationships()[source]

Check that relationships to core.Model do not need to be explicitly written to workbooks because they can be inferred by Reader.run

wc_lang.io.convert(source, destination, strict=True)[source]

Convert among Excel (.xlsx), comma separated (.csv), and tab separated (.tsv) file formats

Read a model from the source files(s) and write it to the destination files(s). A path to a delimiter separated set of models must be represented by a Unix glob pattern (with a *) that matches all delimiter separated files.

Parameters:
  • source (str) – path to source file(s)
  • destination (str) – path to save converted file
  • strict (bool, optional) –

    if True, validate that the the model file(s) strictly follow the obj_model serialization format:

    • The worksheets are in the expected order
    • There are no missing worksheets
    • There are no extra worksheets
    • The columns are in the expected order
    • There are no missing columns
    • There are no extra columns
wc_lang.io.create_template(path, set_repo_metadata_from_path=True)[source]

Create file with model template, including row and column headings

Parameters:
  • path (str) – path to file(s)
  • set_repo_metadata_from_path (bool, optional) – if True, set the Git repository metadata (URL, branch, revision) for the model from the parent directory of core_path

2.1.7. wc_lang.prepare module

Prepare a WC model for further processing, such as export or simulation.

Author:Arthur Goldberg <Arthur.Goldberg@mssm.edu>
Date:2017-10-22
Copyright:2017, Karr Lab
License:MIT
class wc_lang.prepare.AnalyzeModel(model)[source]

Bases: object

Statically analyze a model

AnalyzeModel performs static analysis of WC-lang models which are useful for constructing models.

Current analyses:

  • Identify dead end species and reaction network gaps in dFBA submodels
static digraph_of_rxn_network(submodel)[source]

Create a NetworkX network representing the reaction network in submodel

To leverage the algorithms in NetworkX, map a reaction network onto a NetworkX directed graph. The digraph is bipartite, with Reaction and Species nodes. A reaction is represented a Reaction node, with an edge from each reactant Species node to the Reaction node, and an edge from the Reaction node to each product Species node.

Parameters:submodel (Submodel) – a DFBA submodel
Returns:a NetworkX directed graph representing submodel’s reaction network
Return type:DiGraph
static find_dead_end_species(submodel, inactive_reactions)[source]

Find the dead end species in a reaction network

Given a set of inactive reactions in submodel, determine species that are not consumed by any reaction, or are not produced by any reaction. Costs \(O(n*p)\), where \(n\) is the number of reactions in submodel and \(p\) is the maximum number of participants in a reaction.

Parameters:
  • submodel (Submodel) – a DFBA submodel
  • inactive_reactions (set of Reaction) – the inactive reactions in submodel
Returns:

  • set of Species: the species that are not consumed
  • set of Species: the species that are not produced

Return type:

tuple

static get_inactive_reactions(submodel, dead_end_species)[source]

Find the inactive reactions in a reaction network

Given the dead end species in a reaction network, find the reactions that must eventually become inactive. Reactions that consume species which are not produced must become inactive. And reactions that produce species which are not consumed must become inactive to prevent the copy numbers of those species from growing without bound. Costs \(O(n*p)\), where \(n\) is the number of reactions in submodel and \(p\) is the maximum number of participants in a reaction.

Parameters:
  • submodel (Submodel) – a DFBA submodel
  • dead_end_species (tuple) –
    • set of Species: the Species that are not consumed by any Reaction in submodel
    • set of Species: the Species that are not produced by any Reaction in submodel
Returns:

the inactive reactions in submodel’s reaction network

Return type:

set of Reaction

identify_dfba_submodel_rxn_gaps(submodel)[source]

Identify gaps in a dFBA submodel’s reaction network

Species that are not consumed or not produced indicate gaps in the reaction network. These can be found by a static analysis of the model. Reactions that use species that are not produced or produce species that are not consumed must eventually have zero flux. A reaction network can be reduced to a minimal network of reactions that can all have positive fluxes.

Algorithm:

all_gap_species = get_gap_species([])
delta_gap_species = all_gap_species
while delta_gap_species:
    all_gap_reactions = get_gap_reactions(all_gap_species)
    tmp_gap_species = all_gap_species
    all_gap_species = get_gap_species(all_gap_reactions)
    delta_gap_species = all_gap_species - tmp_gap_species
return (all_gap_species, all_gap_reactions)
Parameters:submodel (Submodel) – a DFBA submodel
Raises:ValueError – if submodel is not a dFBA submodel
Returns:
  • set of Species: Species not in the minimal reaction network
  • set of Reaction: `Reaction`s not in the minimal reaction network
Return type:tuple
static path_bounds_analysis(submodel)[source]

Perform path bounds analysis on submodel

To be adequately constrained, a dFBA metabolic model should have the property that each path from an extracellular species to a component in the objective function contains at least one reaction constrained by a finite flux upper bound.

Analyze the reaction network in submodel and return all paths from extracellular species to objective function components that lack a finite flux upper bound.

Parameters:submodel (Submodel) – a DFBA submodel
Returns:obj:: paths from extracellular species to objective function components that lack a finite flux upper bound. Keys in the dict are the ids of extracellular species; the corresponding values contain the unbounded paths for the extracellular species, as returned by unbounded_paths.
Return type:dict of list of list of
static unbounded_paths(rxn_network, ex_species, obj_fn_species, min_non_finite_ub=1000.0)[source]

Find the unbounded paths from an extracellular species to some objective function species

Return all paths in a reaction network that lack a finite flux upper bound and go from ex_species to an objective function component.

Parameters:
  • rxn_network (DiGraph) – a NetworkX directed graph representing a reaction network,
  • by digraph_of_rxn_network (created) –
  • ex_species (Species) – an extracellular Species that is a node in rxn_network
  • obj_fn_species (list of Species) – objective function Species that are
  • nodes in rxn_network (also) –
  • finite_upper_bound_limit (float, optional) – the maximum value of a finite flux
  • bound (upper) –
  • min_non_finite_ub (float, optional) – flux upper bounds less than min_non_finite_ub
  • considered finite (are) –
Returns:

obj:: a list of the reaction paths from ex_species to objective function components that lack a finite flux upper bound. A path is a list of Species, Reaction, Species, …, Species, starting with ex_species and ending with an objective function component.

Return type:

list of list of

class wc_lang.prepare.CheckModel(model)[source]

Bases: object

Statically check a model

A Model which validates in wc_lang may fail to satisfy global properties that must hold for the Model to be used. CheckModel evaluates these properties.

Currently checked properties:

  • DFBA submodels contain a biomass reaction and an objective function
  • Rate laws transcode and evaluate without error
  • All reactants in each submodel’s reactions are in the submodel’s compartment
  • All species types have positive molecular weights
  • The network of Observable depencencies is acyclic

Other properties to be checked:

  • The model does not contain dead-end species which are only consumed or produced
  • The model uses water consistently - either in all compartments or in none
  • Reactions are balanced
  • Reactions in dynamic submodels contain fully specified rate laws
  • A reaction’s rate laws uses only species that are in the reaction’s reactants
  • All Species used in reactions have concentration values
  • Consider the reactions modeled by a submodel – all modifier species used by the rate laws for the reactions participate in at least one reaction in the submodel
  • Ensure that Reaction and BiomassReaction ids don’t overlap; can then simplify ObjectiveFunction.deserialize()

# TODO: implement these, and expand the list of properties

check_dfba_submodel(submodel)[source]

Check the inputs to a DFBA submodel

Ensure that:

  • All DFBA reactions have min flux and max flux with appropriate values
  • The DFBA submodel contains a biomass reaction and an objective function
  • All species used in biomass reactions are defined
Parameters:submodel (Submodel) – a DFBA submodel
Returns:if no errors, returns an empty list; otherwise a list of error messages
Return type:list of str
check_dynamic_submodel(submodel)[source]

Check the inputs to a dynamic submodel

Ensure that:

  • All reactions have rate laws for the appropriate directions
Parameters:submodel (Submodel) – a dynamic (SSA or ODE) submodel
Returns:if no errors, returns an empty list; otherwise a list of error messages
Return type:list of str
run()[source]

Run all tests in CheckModel

Raises:ValueError – if any of the tests return an error
transcode_and_check_rate_law_equations()[source]

Transcode and evaluate all rate law equations in a model

Ensure that all rate law equations can be transcoded and evaluated. Rate laws that succesfully transcode are stored in rate_law.equation.transcoded.

Returns:if no errors, returns an empty list; otherwise a list of error messages
Return type:list of str
verify_acyclic_dependencies(model_types)[source]

Verify that the network of depencencies for model types in model_types are acyclic

Ensure that:
  • The model types in model_types do not make recursive calls; tested types
    include Observable and FunctionExpression
Parameters:model_types (list of type) – model types (subclasses of obj_model.Model) to test
Returns:if no errors, returns an empty list; otherwise a list of error messages
Return type:list of str
verify_species_types()[source]

Verify all species types

Ensure that:

  • All species types have positive molecular weights
Returns:if no errors, returns an empty list; otherwise a list of error messages
Return type:list of str
class wc_lang.prepare.PrepareModel(model)[source]

Bases: object

Statically prepare a model

Models which validate usually lack data needed to use them. PrepareModel automates the addition of default and statically computed data to a Model.

Currently added data:

  • Missing concentrations
  • Create implicit exchange reactions for dFBA submodels
  • Ensure that dFBA submodels have objective functions
  • Apply default flux bounds to the reactions in dFBA submodels
apply_default_dfba_submodel_flux_bounds(submodel)[source]

Apply default flux bounds to a dFBA submodel’s reactions

The FBA optimizer needs min and max flux bounds for each dFBA submodel reaction. If some reactions lack bounds and default bounds are provided in a config file, then apply the defaults to the reactions. Specifically, min and max default bounds are applied as follows:

reversible reactions:

  • min_flux = -default_max_flux_bound
  • max_flux = default_max_flux_bound

irreversible reactions:

  • min_flux = default_min_flux_bound
  • max_flux = default_max_flux_bound
Parameters:submodel (Submodel) – a dFBA submodel
Raises:ValueError – if submodel is not a dFBA submodel
Returns:
  • obj:int: number of min flux bounds set to the default
  • obj:int: number of max flux bounds set to the default
Return type:tuple
static assign_linear_objective_fn(submodel, reactions, biomass_reactions)[source]

Assign a linear objective function to a submodel

Assign a linear objective function parsed by parse_dfba_submodel_obj_func to a submodel’s attributes.

Parameters:
  • submodel (Submodel) – a dFBA submodel
  • reactions (list of (float, str)) – list of (coeff, id) pairs for reactions
  • biomass_reactions (list of (float, str)) – list of (coeff, id) pairs for biomass reactions
Raises:

ValueError – if submodel is not a dFBA submodel

confirm_dfba_submodel_obj_func(submodel)[source]

Ensure that a dFBA submodel has an objective function

If the submodel definition does not provide an objective function, then use the biomass reaction.

Parameters:

submodel (Submodel) – a dFBA submodel

Raises:
  • ValueError – if submodel is not a dFBA submodel
  • ValueError – if submodel cannot use its biomass reaction ‘{}’ as an objective function
create_dfba_exchange_rxns(submodel, extracellular_compartment_id)[source]

Create exchange reactions for a dFBA submodel’s reaction network.

To represent FBA’s mathematical assumption that it models a closed system, create ‘implicit’ forward exchange reactions that synthesize all extracellular metabolites.

# TODO: To model how other pathways consume metabolites generated by metabolism, create ‘implicit’ reactions which exchange these metabolites between a dFBA metabolism submodel and the other pathway(s)/submodel(s).

Algorithm to synthesize extracellular metabolites:

E = the set of all extracellular metabolites used by the submodel
generate a "-> e" reaction for each e in E in the submodel
Parameters:
  • submodel (Submodel) – a DFBA submodel
  • extracellular_compartment_id (str) – the id of the extracellular compartment
Raises:

ValueError – if submodel is not a dFBA submodel

Returns:

the number of reactions created

Return type:

int

init_concentrations()[source]

Initialize missing concentration values to 0

parse_dfba_submodel_obj_func(submodel)[source]

Parse a dFBA submodel’s objective function into a linear function of reaction fluxes

The SBML FBC only handles objectives that are a linear function of reaction fluxes. This method uses Python’s parser to parse an objective function.

The general form for an objective is \(c_1*id_1 + c_2*id_2 + ... + c_n*id_n\), where \(c_i\) is a numerical coefficient and \(id_i\) is a reaction id. The ids may represent reactions or biomass reactions. Coefficients may also appear after an id, as in \(id_j*c_j\). Coefficients equal to 1.0 are not needed. And negative coefficients are supported.

Parameters:

submodel (Submodel) – a dFBA submodel

Returns:

a pair of lists representing the objective’s linear form

  • obj:list: (coeff, id) pairs for reactions
  • obj:list: (coeff, id) pairs for biomass reactions

Return type:

tuple

Raises:
  • ValueError – if submodel is not a dFBA submodel
  • ValueError – if submodel.objective_function is not a legal python expression, does not have the form above, is not a linear function of reaction ids, uses an unknown reaction id, or uses an id multiple times
run()[source]

Statically prepare a model by executing all Prepare methods.

2.1.8. wc_lang.util module

Utilities

Author:Jonathan Karr <karr@mssm.edu>
Date:2016-11-10
Copyright:2016, Karr Lab
License:MIT
wc_lang.util.get_model_size(model)[source]

Get numbers of model components

Parameters:model (core.Model) – model
Returns:dictionary with numbers of each type of model component
Return type:dict
wc_lang.util.get_model_summary(model)[source]

Get textual summary of a model

Parameters:model (core.Model) – model
Returns:textual summary of the model
Return type:str
wc_lang.util.get_models(inline=True)[source]

Get list of models :param inline: if true, return inline models :type inline: bool, optional

Returns:list of models
Return type:list of class
wc_lang.util.get_reaction_string(reaction)[source]

Generate string representation of reaction stoichometry.

Returns:string representation of reaction stoichometry
Return type:str
wc_lang.util.set_git_repo_metadata_from_path(model, path='.')[source]

Use Git to set the Git repository URL, branch, and revision metadata for a model

Parameters:
  • model (core.Model) – model
  • path (str, optional) – path to the Git repository for the model

2.1.9. Module contents