Meta-model

Template model (mira.metamodel.template_model)

class Annotations(name=None, description=None, license=None, authors=None, references=None, time_scale=None, time_start=None, time_end=None, locations=None, pathogens=None, diseases=None, hosts=None, model_types=None)[source]

Bases: object

A metadata model for model-level annotations.

Examples in this metadata model are taken from https://www.ebi.ac.uk/biomodels/BIOMD0000000956, a well-annotated SIR model in the BioModels database.

name

A human-readable label for the model. Example: “SIR model of scenarios of COVID-19 spread in CA and NY”

Type:

Optional[str]

description

A description of the model.

Type:

Optional[str]

license

Information about the licensing of the model artifact. Ideally given as an SPDX identifier like CC0 or CC-BY-4.0. Models from the BioModels databases are all licensed under CC0. Example: “CC0”

Type:

Optional[str]

authors

A list of authors/creators of the model. This is not the same as the people who e.g., submitted the model to BioModels.

Type:

list of Author

references

A list of CURIEs (i.e., <prefix>:<identifier>) corresponding to literature references that describe the model. Do not duplicate the same publication with different CURIEs (e.g., using pubmed, pmc, and doi). Example: [“pubmed:32616574”]

Type:

list of str

time_scale

The granularity of the time element of the model, typically on the scale of days, weeks, or months for epidemiology models. Example: “day”

Type:

Optional[str]

time_start

The start time of the applicability of a model, given as a datetime. When the time scale is not so granular, leave the less granular fields as default, i.e., if the time scale is on months, give dates like YYYY-MM-01 00:00.

Type:

Optional[datetime.datetime]

time_end

The end time of the applicability of a model, given as a datetime.

Type:

Optional[datetime.datetime]

locations

Locations where this model is applicable, ideally annotated using CURIEs referencing a controlled vocabulary such as GeoNames. Example: [“geonames:5128581”, “geonames:5332921”]

Type:

list of str

pathogens

Pathogens present in the model, given with CURIEs referencing vocabulary for taxa, ideally NCBI Taxonomy. Do not confuse with terms for annotating the disease caused by the pathogen. Example: [“ncbitaxon:2697049”]

Type:

list of str

diseases

Diseases caused by pathogens in the model, given with CURIEs referencing vocabulary for diseases, such as DOID, EFO, or MONDO. Example: [“doid:0080600”]

Type:

list of str

hosts

Hosts present in the model, given with CURIEs referencing vocabulary for taxa, ideally NCBI Taxonomy. Note that some models have multiple hosts. Example: [“ncbitaxon:9606”]

Type:

list of str

model_types

Type(s) of the model using the Mathematical Modeling Ontology (MAMO), which has terms like ‘ordinary differential equation model’, ‘population model’, etc. Annotated as CURIEs in the form of mamo:<local unique identifier>. Example: [“mamo:0000028”, “mamo:0000046”]

Type:

list of str

classmethod from_json(data)[source]

Return an Annotations from a dictionary.

to_json()[source]

Return a JSON-compatible dict.

class TemplateModel(templates, parameters=None, initials=None, observables=None, annotations=None, time=None)[source]

Bases: object

A template model.

templates

A list of any child class of Templates.

Type:

list of Template

parameters

A dict of parameter values where keys correspond to how the parameter appears in rate laws.

Type:

dict of str to Parameter

initials

A dict of initial condition values where keys correspond to concept names they apply to.

Type:

dict of str to Initial

observables

A dict of observables that are readouts from the model.

Type:

dict of str to Observable

annotations

A structure containing model-level annotations. Note that all annotations are optional.

Type:

Optional[Annotations]

time

A structure containing time-related annotations. Note that all annotations are optional.

Type:

Optional[Time]

to_json()[source]

Return a JSON-compatible dict.

get_parameters_from_expression(expression)[source]

Given a symbolic expression, find its elements that are model parameters.

Expressions such as rate laws consist of some combination of participants, rate parameters and potentially other factors. This function finds those elements of expressions that are rate parameters.

Parameters:

expression (sympy.Symbol | sympy.Expr) – A sympy expression or symbol, whose parameters are extracted.

Return type:

Set[str]

Returns:

A set of parameter names (as strings).

get_parameters_from_rate_law(rate_law)[source]

Given a rate law, find its elements that are model parameters.

Rate laws consist of some combination of participants, rate parameters and potentially other factors. This function finds those elements of rate laws that are rate parameters.

Parameters:

rate_law (sympy.Symbol | sympy.Expr) – A sympy expression or symbol, whose parameters are extracted.

Return type:

Set[str]

Returns:

A set of parameter names (as strings).

update_parameters(parameter_dict)[source]

Update parameter values.

Parameters:

parameter_dict (Dict[str,float]) – Mapping of parameter name to value.

get_all_used_parameters()[source]

Get all parameters that are actually used in the model

Usages include rate laws of templates, observable expressions and initial expressions.

Return type:

Set[str]

Returns:

A set of parameter names.

eliminate_unused_parameters()[source]

Remove parameters that are not used in rate laws.

eliminate_duplicate_parameter(redundant_parameter, preserved_parameter)[source]

Eliminate a duplicate parameter from the model.

This happens when there are two redundant parameters only one of which is actually used in the model. This function removes the redundant parameter and updates the rate laws to use the preserved parameter.

Parameters:
  • redundant_parameter (str) – The name of the parameter to remove.

  • preserved_parameter (str) – The new name of the parameter to preserve.

classmethod from_json(data)[source]

Return a template model from a dictionary

Parameters:

data (Dict[str,Any]) – Mapping of template model attributes to their values.

Return type:

TemplateModel

Returns:

Returns the newly created template model.

generate_model_graph(use_display_name=False, concepts_only=False)[source]

Generate a graph based off the template model.

Parameters:

use_display_name (bool) – Whether to use the display_name attribute of the concepts as the label in the graph.

Return type:

DiGraph

Returns:

A graph

set_rate_law(template_name, rate_law, local_dict=None)[source]

Set the rate law of a template with a given name.

draw_graph(path, use_display_name=False, prog='dot', args='', format=None)[source]

Draw a pygraphviz graph of the TemplateModel.

Parameters:
  • path (str) – The path to the output file.

  • use_display_name (bool) – Whether to use the display_name attribute of the concepts as the label in the graph.

  • prog (str) – The graphviz layout program to use, such as “dot”, “neato”, etc.

  • format (Optional[str]) – Set the file format explicitly.

  • args (str) – Additional arguments to pass to the graphviz bash program as a string. Example: args=”-Nshape=box -Edir=forward -Ecolor=red”.

draw_jupyter(path='model.png', use_display_name=False, prog='dot', args='', format=None)[source]

Display in jupyter.

Parameters:
  • path (str) – The path to the output file.

  • use_display_name (bool) – Whether to use the display_name attribute of the concepts as the label in the graph.

  • prog (str) – The graphviz layout program to use, such as “dot”, “neato”, etc.

  • format (Optional[str]) – Set the file format explicitly.

  • args (str) – Additional arguments to pass to the graphviz bash program as a string. Example: args=”-Nshape=box -Edir=forward -Ecolor=red”.

Returns:

The image of the graph.

Return type:

Image

graph_as_json()[source]

Serialize the TemplateModel graph as node-link data.

Return type:

Dict

Returns:

The node-link data as a dictionary.

print_params_table()[source]

Print the table full of parameters.

get_concepts_map()[source]

Return a mapping from concept keys to concepts that appear in this template model’s templates.

Returns:

The mapping of concept keys to concepts that appear in this template model’s templates.

Return type:

Dict[tuple, Concept]

get_concepts_name_map()[source]

Return a mapping from concept names to concepts that appear in this template model’s templates.

Returns:

Mapping of concept names to concepts that appear in this template model’s templates.

Return type:

Dict[str,Concept]

get_concept(name)[source]

Return the first concept that has the given name.

Parameters:

name (str) – The name to be queried for.

Return type:

Optional[Concept]

Returns:

The first concept that has the given name if it’s present in the TemplateModel.

reset_base_names()[source]

Reset the base names of all concepts in this model to the current name.

get_concepts_by_name(name)[source]

Return a list of all concepts that have the given name.

Warning

this could give duplicates if there are nodes with compositional grounding.

Parameters:

name (str) – The name to be queried for.

Return type:

List[Concept]

Returns:

A list of concepts that have the given name.

extend(template_model, parameter_mapping=None, initial_mapping=None)[source]

Extend this template model with another template model.

Parameters:
Returns:

The template model with added templates from the added template model

Return type:

TemplateModel

add_template(template, parameter_mapping=None, initial_mapping=None)[source]

Add a template to the model.

Parameters:
  • template (Template) – The template to add.

  • parameter_mapping (Optional[Mapping[str, Parameter]]) – A mapping from parameter names in the template to Parameters in the model.

  • initial_mapping (Optional[Mapping[str, Initial]]) – A mapping from concept names in the template to Initials in the model.

Return type:

TemplateModel

Returns:

A new model with the additional template

add_transition(transition_name=None, subject_concept=None, outcome_concept=None, rate_law_sympy=None, params_dict=None, mass_action_parameter=None)[source]

Add a transition to a template model. Only Natural templates between a source and an outcome are supported. Multiple parameters can be added explicitly or implicitly.

Parameters:
  • transition_name (str) – Name of the new transition to be added.

  • subject_concept (Concept) – The subject of the new transition.

  • outcome_concept (Concept) – The outcome of the new transition.

  • rate_law_sympy – The rate law associated with the new transition.

  • params_dict (Mapping) – Mapping of parameter attribute to their respective values.

  • mass_action_parameter (Optional[Parameter]) – The mass action parameter that will be set to the transition’s mass action rate law if provided.

Return type:

TemplateModel

Returns:

The new template model with the added transition.

substitute_parameter(name, value=None)[source]

Substitute a parameter with the value argument if supplied, else substitute the parameter with the parameter’s value.

Parameters:
  • name (str) – The name of the parameter to substitute.

  • value – The value to substitute.

Returns:

None if there does not exist a parameter with the given name. Else not return value.

add_parameter(parameter_id, name=None, description=None, value=None, distribution=None, units_mathml=None)[source]

Add a parameter to the template model.

Parameters:
  • parameter_id (str) – The id of the parameter.

  • name (str) – The name of the parameter.

  • description (str) – The description of the parameter.

  • value (float) – The value of the newly added parameter.

  • distribution (Dict[str,Any]) – Dictionary of distribution attributes to their values to be passed into the Distribution constructor.

  • units_mathml (str) – The unit of the parameter in mathml form.

eliminate_parameter(name)[source]

Eliminate a parameter from the model by substituting 0.

Parameters:

name (str) – The name of the parameter to be eliminated.

set_parameters(param_dict)[source]

Set the parameters of this model to the values in the given dict. If a parameter in the given dict is not a part of the model, we create a new parameter out of it.

Parameters:

param_dict (Dict[str,float]) – Mapping of parameter name to its new value.

set_initials(initial_dict)[source]

Set the initials of this model to the expression in the given dict.

Parameters:

initial_dict (dict) – Mapping of initial name to its new expression.

class Initial(concept, expression)[source]

Bases: object

Initial conditions for parameters in the model.

concept

The concept associated with the initial.

Type:

Concept

expression

The expression for the initial.

Type:

sympy.Expr or float or int

to_json()[source]

Return a JSON-compatible dict.

classmethod from_json(data, locals_dict=None)[source]

Return an Initial from a dictionary.

Parameters:
  • data (dict) – Mapping of Initial attributes to values.

  • locals_dict (dict) – Mapping of string symbols to their sympy equivalent.

Returns:

The newly created initial.

substitute_parameter(name, value)[source]

Substitute a parameter value into the initial expression.

Parameters:
  • name (str) – The name of the parameter to substitute.

  • value – The value to substitute.

get_parameter_names(known_param_names)[source]

Get the names of all parameters in the expression.

Parameters:

known_param_names (list of str) – List of symbols that are known to be parameters, typically from the list of parameters of a model.

Returns:

The set of parameter names.

class Parameter(name, value=None, distribution=None, display_name=None, description=None, identifiers=None, context=None, units=None)[source]

Bases: Concept

A Parameter is a special type of Concept that carries a value.

name

The name of the parameter.

Type:

str

value

Value of the parameter.

Type:

Optional[float]

distribution

A distribution of values for the parameter.

Type:

Optional[Distribution]

display_name

An optional display name for the parameter.

Type:

Optional[str]

description

An optional description of the parameter.

Type:

Optional[str]

identifiers

A mapping of namespaces to identifiers.

Type:

dict

context

A mapping of context keys to values.

Type:

dict

units

The units of the parameter.

Type:

Optional[Unit]

classmethod from_json(data)[source]

Return a Parameter from a dictionary.

to_json()[source]

Return a JSON-compatible dict.

class Distribution(type, parameters)[source]

Bases: object

A distribution of values for a parameter.

type

The type of distribution as provided by ProbOnto, e.g. ‘StandardUniform1’, ‘Beta1’, etc.

Type:

str

parameters

The parameters of the distribution keyed by parameter names controlled by ProbOnto and values that are either floating point values or symbolic expressions over other parameters.

Type:

dict

to_json()[source]

Return a JSON-compatible dict.

get_expression_parameter_names(known_param_names)[source]

Get the names of all parameters used in expressions, if any.

Note this only applies to parameters that are referenced in custom expressions defining the distribution parameters.

Parameters:

known_param_names (list of str) – List of symbols that are known to be parameters, typically from the list of parameters of a model.

Returns:

The set of parameter names.

substitute_parameter(name, value)[source]

Substitute a value into the distribution parameter expressions.

Parameters:
  • name (str) – The name of the parameter to substitute.

  • value – The value to substitute.

class Observable(name, expression, display_name=None, description=None, identifiers=None, context=None, units=None)[source]

Bases: Concept

An observable is a special type of Concept that carries an expression.

Observables are used to define the readouts of a model, useful when a readout is not defined as a state variable but is rather a function of state variables.

name

The name of the observable.

Type:

str

expression

The expression for the observable.

Type:

sympy.Expr

display_name

An optional display name for the observable.

Type:

Optional[str]

description

An optional description of the observable.

Type:

Optional[str]

identifiers

A mapping of namespaces to identifiers.

Type:

dict

context

A mapping of context keys to values.

Type:

dict

units

The units of the observable.

Type:

Optional[Unit]

to_json()[source]

Return a JSON-compatible dict.

substitute_parameter(name, value)[source]

Substitute a parameter value into the observable expression.

Parameters:
  • name (str) – The name of the parameter to substitute.

  • value – The value to substitute.

get_parameter_names(known_param_names)[source]

Get the names of all parameters in the expression.

Parameters:

known_param_names (list of str) – List of symbols that are known to be parameters, typically from the list of parameters of a model.

Returns:

The set of parameter names.

class Time(name='t', units=None)[source]

Bases: object

A special type of Concept that represents time.

name

The symbol of the time variable in the model.

Type:

str

units

The units of the time variable.

Type:

Optional[Unit]

to_json()[source]

Return a JSON-compatible dict.

model_has_grounding(template_model, prefix, identifier)[source]

Returns true or false if a given search curie is present within the TemplateModel.

Parameters:
  • template_model (TemplateModel) – The TemplateModel to query.

  • prefix (str) – The prefix of the search curie.

  • identifier (str) – The identifier of the search curie.

Return type:

bool

class Concept(name, display_name=None, description=None, identifiers=None, context=None, units=None)[source]

Bases: object

A concept is specified by its identifier(s), name, and - optionally - its context.

name

The name of the concept.

Type:

str

display_name

An optional display name for the concept. If not provided, the name can be used for display purposes.

Type:

Optional[str]

description

An optional description of the concept.

Type:

Optional[str]

identifiers

A mapping of namespaces to identifiers.

Type:

dict

context

A mapping of context keys to values.

Type:

dict

units

The units of the concept.

Type:

Optional[Unit]

to_json()[source]

Return a JSON-compatible dict.

with_context(do_rename=False, curie_to_name_map=None, inplace=False, **context)[source]

Return this concept with extra context.

Parameters:
  • do_rename – If true, will modify the name of the node based on the context introduced

  • curie_to_name_map – Use to set a name different from the context values provided in the **context kwarg when do_rename=True. Useful if the context values are e.g. curies or longer names that should be shortened, like {“New York City”: “nyc”}. If not provided ( default behavior), the context values will be used as names.

  • inplace (bool) – If True, modify the concept in place. Default: False.

  • **context – The context to add to the concept.

Return type:

Concept

Returns:

A new concept containing the given context.

get_curie(config=None)[source]

Get the priority prefix/identifier pair for this concept.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Return type:

Tuple[str, str]

Returns:

A tuple of the priority prefix and identifier for this concept.

get_curie_str(config=None)[source]

Get the priority prefix/identifier as a CURIE string.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Return type:

str

Returns:

A CURIE string for this concept.

get_included_identifiers(config=None)[source]

Get the identifiers for this concept that are not excluded.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Return type:

Dict[str, str]

Returns:

A dict of identifiers for this concept that are not excluded as defined by the config.

get_key(config=None)[source]

Get the key for this concept.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Returns:

A tuple of the priority prefix and identifier together with the sorted context of this concept.

is_equal_to(other, with_context=False, config=None)[source]

Test for equality between concepts

Parameters:
  • other (Concept) – Other Concept to test equality with

  • with_context (bool) – If True, do not consider the two Concepts equal unless they also have exactly the same context. If there is no context, with_context has no effect.

  • config (Config) – Configuration defining priority and exclusion for identifiers.

Return type:

bool

Returns:

True if other is the same Concept as this one

refinement_of(other, refinement_func, with_context=False, config=None)[source]

Check if this Concept is a more detailed version of another

Parameters:
  • other (Concept) – The other Concept to compare with. Assumed to be less detailed.

  • with_context (bool) – If True, also consider the context of the Concepts for the refinement.

  • refinement_func (Callable[[str, str], bool]) – A function that given a source/more detailed entity and a target/less detailed entity checks if they are in a child-parent and returns a boolean.

  • config (Config) – Configuration defining priority and exclusion for identifiers.

Return type:

bool

Returns:

True if this Concept is a refinement of another Concept

classmethod from_json(data)[source]

Create a Concept from its JSON representation.

Parameters:

data – The JSON representation of the Concept.

Return type:

Concept

Returns:

The Concept object.

class Author(name)[source]

Bases: object

A metadata model for an author.

name

The name of the author.

Type:

str

to_json()[source]

Return a JSON-compatible dict.

Templates (mira.metamodel.templates)

Data models for metamodel templates.

Regenerate the JSON schema by running python -m mira.metamodel.schema.

class Template(rate_law=None, name=None, display_name=None, **kwargs)[source]

Bases: object

The Template is a parent class for model processes.

rate_law

The rate law for the template.

Type:

Optional[sympy.Expr]

name

The name of the template.

Type:

Optional[str]

display_name

The display name of the template.

Type:

Optional[str]

classmethod from_json(data, rate_symbols=None)[source]

Create a Template from a JSON object

Parameters:
  • data – The JSON object to create the Template from

  • rate_symbols – A mapping of symbols to use for the rate law. If not provided, the rate law will be parsed without any symbols.

Return type:

Template

Returns:

A Template object

to_json()[source]

Return a JSON-compatible dict.

is_equal_to(other, with_context=False, config=None)[source]

Check if this template is equal to another template

Parameters:
  • other (Template) – The other template to check for equality with this one with

  • with_context (bool) – If True, the contexts are taken into account when checking for equality. Default: False.

  • config (Config) – Configuration defining priority and exclusion for identifiers.

Return type:

bool

Returns:

True if the other Template is equal to this Template

refinement_of(other, refinement_func, with_context=False, config=None)[source]

Check if this template is a more detailed version of another

Parameters:
  • other (Template) – The other template to compare with. Is assumed to be less detailed than this template.

  • with_context (bool) – If True, also consider the context of Templates’ Concepts for the refinement.

  • refinement_func (Callable[[str, str], bool]) – A function that given a source/more detailed entity and a target/less detailed entity checks if they are in a child-parent relationship and returns a boolean.

Return type:

bool

Returns:

True if this Template is a refinement of the other Template.

with_context(do_rename=False, exclude_concepts=None, curie_to_name_map=None, **context)[source]

Return a copy of this template with context added

Parameters:
  • do_rename – If True, rename the names of the concepts

  • exclude_concepts – A set of concept names to keep unchanged.

  • curie_to_name_map – A mapping of context values to names. Useful if the context values are e.g. curies. Will only be used if do_rename is True.

Returns:

A copy of this template with context added

get_concepts()[source]

Return the concepts in this template.

Return type:

List[Union[Concept, List[Concept]]]

Returns:

A list of concepts in this template.

get_concepts_flat(exclude_controllers=False, refresh=False)[source]

Return the concepts in this template as a flat list.

Attributes where a list of concepts is expected are flattened.

Return type:

List[Concept]

get_concepts_by_role()[source]

Return the concepts in this template as a dict keyed by role.

Return type:

Dict[str, Concept]

Returns:

A dict of concepts in this template keyed by role.

get_concept_names()[source]

Return the concept names in this template.

Return type:

Set[str]

Returns:

The set of concept names in this template.

get_interactors()[source]

Return the interactors in this template.

Return type:

List[Concept]

Returns:

A list of interactors in this template.

get_controllers()[source]

Return the controllers in this template.

Return type:

List[Concept]

Returns:

A list of controllers in this template.

get_interactor_rate_law(independent=False)[source]

Return the rate law for the interactors in this template.

This is the part of the rate law that is the product of the interactors but does not include any parameters.

Parameters:

independent – If True, the controllers will assume independent action.

Return type:

Expr

Returns:

The rate law for the interactors in this template.

get_mass_action_rate_law(parameter, independent=False)[source]

Return the mass action rate law for this template.

Parameters:
  • parameter (str) – The parameter to use for the mass-action rate law.

  • independent – If True, the controllers will assume independent action.

Return type:

Expr

Returns:

The mass action rate law for this template.

get_independent_mass_action_rate_law(parameter)[source]

Return the mass action rate law for this template with independent action.

Parameters:

parameter (str) – The parameter to use for the mass-action rate.

Return type:

Expr

Returns:

The mass action rate law for this template with independent action.

set_mass_action_rate_law(parameter, independent=False)[source]

Set the rate law of this template to a mass action rate law.

Parameters:
  • parameter – The parameter to use for the mass-action rate.

  • independent – If True, the controllers will assume independent action.

with_mass_action_rate_law(parameter, independent=False)[source]

Return a copy of this template with a mass action rate law.

Parameters:
  • parameter – The parameter to use for the mass-action rate.

  • independent – If True, the controllers will assume independent action.

Return type:

Template

Returns:

A copy of this template with the mass action rate law.

set_rate_law(rate_law, local_dict=None)[source]

Set the rate law of this template.

get_parameter_names()[source]

Get the set of parameter names.

Return type:

Set[str]

Returns:

The set of parameter names.

update_parameter_name(old_name, new_name)[source]

Update the name of a parameter in the rate law.

Parameters:
  • old_name (str) – The old name of the parameter.

  • new_name (str) – The new name of the parameter.

get_mass_action_symbol()[source]

Get the symbol for the mass action rate parameter.

Return type:

Optional[Symbol]

Returns:

The symbol for the parameter associated with this template’s rate law, assuming it’s mass action. Returns None if the rate law is not mass action or if there is no rate law.

substitute_parameter(name, value)[source]

Substitute a parameter in this template’s rate law.

Parameters:
  • name (str) – The name of the parameter to substitute.

  • value – The value to substitute.

deactivate()[source]

Deactivate this template by setting its rate law to zero.

get_key(config=None)[source]

Get the key for this template.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Return type:

Tuple

Returns:

A tuple of the type and concepts in this template.

class ControlledConversion(controller, subject, outcome, provenance=None, **kwargs)[source]

Bases: Template

Controlled conversion from subject to outcome.

controller

The controller of the conversion.

Type:

Concept

subject

The subject of the conversion.

Type:

Concept

outcome

The outcome of the conversion.

Type:

Concept

provenance

The provenance of the conversion.

Type:

list of Provenance

with_context(do_rename=False, exclude_concepts=None, curie_to_name_map=None, **context)[source]

Return a copy of this template with context added

Parameters:
  • do_rename – If True, rename the names of the concepts

  • exclude_concepts – A set of concept names to keep unchanged.

  • curie_to_name_map – A mapping of context values to names. Useful if the context values are e.g. curies. Will only be used if do_rename is True.

Return type:

ControlledConversion

Returns:

A copy of this template with context added

add_controller(controller)[source]

Add a controller to this template.

Parameters:

controller (Concept) – The controller to add.

Return type:

GroupedControlledConversion

Returns:

A new template with the additional controller.

with_controller(controller)[source]

Return a copy of this template with the given controller.

Parameters:

controller – The controller to use for the new template.

Return type:

ControlledConversion

Returns:

A copy of this template with the given controller.

get_key(config=None)[source]

Get the key for this template.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Returns:

A tuple of the type and concepts in this template.

class ControlledProduction(controller, outcome, provenance=None, **kwargs)[source]

Bases: Template

Production controlled by one controller.

controller

The controller of the production.

Type:

Concept

outcome

The outcome of the production.

Type:

Concept

provenance

Provenance of the template.

Type:

list of Provenance

get_key(config=None)[source]

Get the key for this template.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Returns:

A tuple of the type and concepts in this template.

add_controller(controller)[source]

Add a controller to this template.

Parameters:

controller (Concept) – The controller to add.

Return type:

GroupedControlledProduction

Returns:

A GroupedControlledProduction template with the additional controller.

with_controller(controller)[source]

Return a copy of this template with the given controller.

Parameters:

controller – The controller to use for the new template.

Return type:

ControlledProduction

Returns:

A copy of this template with the given controller replacing the existing controller.

with_context(do_rename=False, exclude_concepts=None, curie_to_name_map=None, **context)[source]

Return a copy of this template with context added

Parameters:
  • do_rename – If True, rename the names of the concepts

  • exclude_concepts – A set of concept names to keep unchanged.

  • curie_to_name_map – A mapping of context values to names. Useful if the context values are e.g. curies. Will only be used if do_rename is True.

Return type:

ControlledProduction

Returns:

A copy of this template with context added

class ControlledDegradation(controller, subject, provenance=None, **kwargs)[source]

Bases: Template

Degradation controlled by one controller.

controller

The controller of the degradation.

Type:

Concept

subject

The subject of the degradation.

Type:

Concept

provenance

The provenance of the degradation.

Type:

list of Provenance

get_key(config=None)[source]

Get the key for this template.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Returns:

A tuple of the type and concepts in this template.

add_controller(controller)[source]

Add a controller to this template.

Parameters:

controller (Concept) – The controller to add.

Return type:

GroupedControlledDegradation

Returns:

A new template with the additional controller.

with_controller(controller)[source]

Return a copy of this template with the given controller.

Parameters:

controller – The controller to use for the new template.

Return type:

ControlledDegradation

Returns:

A copy of this template as a ControlledDegradation template with the given controller replacing the existing controllers.

with_context(do_rename=False, exclude_concepts=None, curie_to_name_map=None, **context)[source]

Return a copy of this template with context added

Parameters:
  • do_rename – If True, rename the names of the concepts

  • exclude_concepts – A set of concept names to keep unchanged.

  • curie_to_name_map – A mapping of context values to names. Useful if the context values are e.g. curies. Will only be used if do_rename is True.

Return type:

ControlledDegradation

Returns:

A copy of this template with context added

class NaturalConversion(subject, outcome, provenance=None, **kwargs)[source]

Bases: Template

Natural conversion from subject to outcome.

subject

The subject of the conversion.

Type:

Concept

outcome

The outcome of the conversion.

Type:

Concept

provenance

The provenance of the conversion.

Type:

list of Provenance

with_context(do_rename=False, exclude_concepts=None, curie_to_name_map=None, **context)[source]

Return a copy of this template with context added

Parameters:
  • do_rename – If True, rename the names of the concepts

  • exclude_concepts – A set of concept names to keep unchanged.

  • curie_to_name_map – A mapping of context values to names. Useful if the context values are e.g. curies. Will only be used if do_rename is True.

Return type:

NaturalConversion

Returns:

A copy of this template with context added

get_key(config=None)[source]

Get the key for this template.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Returns:

A tuple of the type and concepts in this template.

class NaturalProduction(outcome, provenance=None, **kwargs)[source]

Bases: Template

Production of a species at a constant rate.

outcome

The outcome of the production.

Type:

Concept

provenance

The provenance of the production.

Type:

list of Provenance

get_key(config=None)[source]

Get the key for this template.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Returns:

A tuple of the type and concepts in this template.

with_context(do_rename=False, exclude_concepts=None, curie_to_name_map=None, **context)[source]

Return a copy of this template with context added

Parameters:
  • do_rename – If True, rename the names of the concepts

  • exclude_concepts – A set of concept names to keep unchanged.

  • curie_to_name_map – A mapping of context values to names. Useful if the context values are e.g. curies. Will only be used if do_rename is True.

Return type:

NaturalProduction

Returns:

A copy of this template with context added

class NaturalDegradation(subject, provenance=None, **kwargs)[source]

Bases: Template

Degradation of a species at a rate proportional to its amount.

subject

The subject of the degradation.

Type:

Concept

provenance

The provenance of the degradation.

Type:

list of Provenance

get_key(config=None)[source]

Get the key for this template.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Returns:

A tuple of the type and concepts in this template.

with_context(do_rename=False, exclude_concepts=None, curie_to_name_map=None, **context)[source]

Return a copy of this template with context added

Parameters:
  • do_rename – If True, rename the names of the concepts

  • exclude_concepts – A set of concept names to keep unchanged.

  • curie_to_name_map – A mapping of context values to names. Useful if the context values are e.g. curies. Will only be used if do_rename is True.

Return type:

NaturalDegradation

Returns:

A copy of this template with context added

class GroupedControlledConversion(controllers, subject, outcome, provenance=None, **kwargs)[source]

Bases: Template

Conversion controlled by multiple controllers.

controllers

The controllers of the conversion.

Type:

list of Concept

subject

The subject of the conversion.

Type:

Concept

outcome

The outcome of the conversion.

Type:

Concept

provenance

The provenance of the conversion.

Type:

list of Provenance

with_context(do_rename=False, exclude_concepts=None, curie_to_name_map=None, **context)[source]

Return a copy of this template with context added

Parameters:
  • do_rename – If True, rename the names of the concepts

  • exclude_concepts – A set of concept names to keep unchanged.

  • curie_to_name_map – A mapping of context values to names. Useful if the context values are e.g. curies. Will only be used if do_rename is True.

Return type:

GroupedControlledConversion

Returns:

A copy of this template with context added

with_controllers(controllers)[source]

Return a copy of this template with the given controllers.

Parameters:

controllers – The controllers to use for the new template.

Return type:

GroupedControlledConversion

Returns:

A copy of this template with the given controllers.

get_key(config=None)[source]

Get the key for this template.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Returns:

A tuple of the type and concepts in this template.

get_concepts()[source]

Return the concepts in this template.

Returns:

A list of concepts in this template.

add_controller(controller)[source]

Add an additional controller.

Return type:

GroupedControlledConversion

class GroupedControlledProduction(controllers, outcome, provenance=None, **kwargs)[source]

Bases: Template

Production controlled by several controllers.

controllers

The controllers of the production.

Type:

list of Concept

outcome

The outcome of the production.

Type:

Concept

provenance

The provenance of the production.

Type:

list of Provenance

get_key(config=None)[source]

Get the key for this template.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Returns:

A tuple of the type and concepts in this template.

get_concepts()[source]

Return the concepts in this template.

Returns:

A list of concepts in this template.

add_controller(controller)[source]

Add a controller to this template.

Parameters:

controller (Concept) – The controller to add.

Return type:

GroupedControlledProduction

Returns:

A new template with the additional controller.

with_controllers(controllers)[source]

Return a copy of this template with the given controllers.

Parameters:

controllers – The controllers to use for the new template.

Return type:

GroupedControlledProduction

Returns:

A copy of this template with the given controllers replacing the existing controllers.

with_context(do_rename=False, exclude_concepts=None, curie_to_name_map=None, **context)[source]

Return a copy of this template with context added

Parameters:
  • do_rename – If True, rename the names of the concepts

  • exclude_concepts – A set of concept names to keep unchanged.

  • curie_to_name_map – A mapping of context values to names. Useful if the context values are e.g. curies. Will only be used if do_rename is True.

Return type:

GroupedControlledProduction

Returns:

A copy of this template with context added

class GroupedControlledDegradation(controllers, subject, provenance=None, **kwargs)[source]

Bases: Template

Degradation controlled by several controllers.

controllers

The controllers of the degradation.

Type:

list of Concept

subject

The subject of the degradation.

Type:

Concept

provenance

The provenance of the degradation.

Type:

list of Provenance

get_key(config=None)[source]

Get the key for this template.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Returns:

A tuple of the type and concepts in this template.

get_concepts()[source]

Return the concepts in this template.

Returns:

A list of concepts in this template.

add_controller(controller)[source]

Add a controller to this template.

Parameters:

controller (Concept) – The controller to add.

Return type:

GroupedControlledDegradation

Returns:

A new template with the additional controller added.

with_controllers(controllers)[source]

Return a copy of this template with the given controllers.

Parameters:

controllers – The controllers to use for the new template.

Return type:

GroupedControlledDegradation

Returns:

A copy of this template with the given controllers replacing the existing controllers.

with_context(do_rename=False, exclude_concepts=None, curie_to_name_map=None, **context)[source]

Return a copy of this template with context added

Parameters:
  • do_rename – If True, rename the names of the concepts

  • exclude_concepts – A set of concept names to keep unchanged.

  • curie_to_name_map – A mapping of context values to names. Useful if the context values are e.g. curies. Will only be used if do_rename is True.

Return type:

GroupedControlledDegradation

Returns:

A copy of this template with context added

class MultiConversion(subjects, outcomes, provenance=None, **kwargs)[source]

Bases: Template

Conversion of multiple subjects and outcomes.

subjects

The subjects of the conversion.

Type:

list of Concept

outcomes

The outcomes of the conversion.

Type:

list of Concept

provenance

The provenance of the conversion.

Type:

list of Provenance

get_key(config=None)[source]

Get the key for this template.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Returns:

A tuple of the type and concepts in this template.

get_concepts()[source]

Return the concepts in this template.

Returns:

A list of concepts in this template.

with_context(do_rename=False, exclude_concepts=None, curie_to_name_map=None, **context)[source]

Return a copy of this template with context added

Parameters:
  • do_rename – If True, rename the names of the concepts

  • exclude_concepts – A set of concept names to keep unchanged.

  • curie_to_name_map – A mapping of context values to names. Useful if the context values are e.g. curies. Will only be used if do_rename is True.

Return type:

MultiConversion

Returns:

A copy of this template with context added

class NaturalReplication(subject, provenance=None, **kwargs)[source]

Bases: Template

Natural replication of a subject.

subject

The subject of the replication.

Type:

Concept

provenance

The provenance of the template.

Type:

list of Provenance

with_context(do_rename=False, exclude_concepts=None, curie_to_name_map=None, **context)[source]

Return a copy of this template with context added

Parameters:
  • do_rename – If True, rename the names of the concepts

  • exclude_concepts – A set of concept names to keep unchanged.

  • curie_to_name_map – A mapping of context values to names. Useful if the context values are e.g. curies. Will only be used if do_rename is True.

Return type:

NaturalReplication

Returns:

A copy of this template with context added

get_key(config=None)[source]

Get the key for this template.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Returns:

A tuple of the type and concepts in this template.

class ControlledReplication(controller, subject, provenance=None, **kwargs)[source]

Bases: Template

Replication controlled by one controller.

controller

The controller of the replication.

Type:

Concept

subject

The subject of the replication.

Type:

Concept

provenance

The provenance of the replication.

Type:

list of Provenance

get_key(config=None)[source]

Get the key for this template.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Returns:

A tuple of the type and concepts in this template.

with_controller(controller)[source]

Return a copy of this template with the given controller.

Parameters:

controller – The controller to use for the new template.

Return type:

ControlledReplication

Returns:

A copy of this template with the given controller replacing the existing controller.

with_context(do_rename=False, exclude_concepts=None, curie_to_name_map=None, **context)[source]

Return a copy of this template with context added

Parameters:
  • do_rename – If True, rename the names of the concepts

  • exclude_concepts – A set of concept names to keep unchanged.

  • curie_to_name_map – A mapping of context values to names. Useful if the context values are e.g. curies. Will only be used if do_rename is True.

Return type:

ControlledReplication

Returns:

A copy of this template with context added

class ReversibleFlux(left, right, provenance=None, **kwargs)[source]

Bases: Template

A reversible flux between a left and right side.

left

The left hand side of the flux.

Type:

list of Concept

right

The right hand side of the flux.

Type:

list of Concept

provenance

The provenance of the flux.

Type:

list of Provenance

get_concepts()[source]

Return the concepts in this template.

Returns:

A list of concepts in this template.

get_key(config=None)[source]

Get the key for this template.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Returns:

A tuple of the type and concepts in this template.

with_context(do_rename=False, exclude_concepts=None, curie_to_name_map=None, **context)[source]

Return a copy of this template with context added

Parameters:
  • do_rename – If True, rename the names of the concepts

  • exclude_concepts – A set of concept names to keep unchanged.

  • curie_to_name_map – A mapping of context values to names. Useful if the context values are e.g. curies. Will only be used if do_rename is True.

Return type:

ReversibleFlux

Returns:

A copy of this template with context added

class StaticConcept(subject, provenance=None, **kwargs)[source]

Bases: Template

A standalone Concept that is not part of a process.

subject

The subject.

Type:

Concept

provenance

The provenance.

Type:

list of Provenance

get_key(config=None)[source]

Get the key for this template.

Parameters:

config (Optional[Config]) – Configuration defining priority and exclusion for identifiers.

Returns:

A tuple of the type and concepts in this template.

get_concepts()[source]

Return the concepts in this template.

Returns:

A list of concepts in this template.

with_context(do_rename=False, curie_to_name_map=None, exclude_concepts=None, **context)[source]

Return a copy of this template with context added

Parameters:
  • do_rename – If True, rename the names of the concepts

  • exclude_concepts – A set of concept names to keep unchanged.

  • curie_to_name_map – A mapping of context values to names. Useful if the context values are e.g. curies. Will only be used if do_rename is True.

Return type:

StaticConcept

Returns:

A copy of this template with context added

templates_equal(templ, other_templ, with_context, config)[source]

Check if two Template objects are equal

Parameters:
  • templ (Template) – A template to compare.

  • other_templ (Template) – The other template to compare.

  • with_context (bool) – If True, also check the contexts of the contained Concepts of the Template.

  • config (Config) – Configuration defining priority and exclusion for identifiers.

Return type:

bool

Returns:

True if the two Template objects are equal.

context_refinement(refined_context, other_context)[source]

Check if one Concept’s context is a refinement of another Concept’s

Parameters:
  • refined_context – The assumed more detailed context

  • other_context – The assumed less detailed context

Return type:

bool

Returns:

True if the Concept refined_concept truly is strictly more detailed than other_concept

match_concepts(self_concepts, other_concepts, with_context=True, config=None, refinement_func=None)[source]

Return true if there is an exact match between two lists of concepts.

Parameters:
  • self_concepts (List[Concept]) – The list of concepts to compare to the second list.

  • other_concepts (List[Concept]) – The second list of concepts to compare the first list to.

  • with_context (bool) – If True, also consider the contexts of the contained Concepts of the Template when comparing the two lists. Default: True.

  • config (Config) – Configuration defining priority and exclusion for identifiers. If None, the default configuration will be used.

  • refinement_func (Callable[[str, str], bool]) – A function to use to check if one concept is a refinement of another. If None, the default is to check for equality.

Return type:

bool

Returns:

True if there is an exact match between the two lists of concepts.

is_production(template)[source]

Return True if the template is a form of production.

is_degradation(template)[source]

Return True if the template is a form of degradation.

is_conversion(template)[source]

Return True if the template is a form of conversion.

is_replication(template)[source]

Return True if the template is a form of replication.

is_reversible(template)[source]

Return True if the template is a reversible process.

has_subject(template)[source]

Return True if the template has a subject.

has_outcome(template)[source]

Return True if the template has an outcome.

has_controller(template)[source]

Check if the template has a controller.

Parameters:

template (Template) – The template to check. The template must be representing a controlled process.

Return type:

bool

Returns:

True if the template has a controller

num_controllers(template)[source]

Return the number of controllers in the template.

get_binding_templates(a, b, c, kf, kr)[source]

Return a list of templates emulating a reversible binding process.

conversion_to_deg_prod(conv_template)[source]

Given a conversion template, compile into degradation/production templates.

Operations (mira.metamodel.ops)

Operations for template models.

stratify(template_model, key, strata, strata_curie_to_name=None, strata_name_lookup=False, structure=None, directed=False, conversion_cls=<class 'mira.metamodel.templates.NaturalConversion'>, cartesian_control=False, modify_names=True, params_to_stratify=None, params_to_preserve=None, concepts_to_stratify=None, concepts_to_preserve=None, param_renaming_uses_strata_names=False)[source]

Multiplies a model into several strata.

E.g., can turn the SIR model into a two-city SIR model by splitting each concept into two derived concepts, each with the context for one of the two cities

Parameters:
  • template_model (TemplateModel) – A template model

  • key (str) – The (singular) name of the stratification, e.g., "city"

  • strata (Collection[str]) – A list of the values for stratification, e.g., ["boston", "nyc"] or [geonames:4930956, geonames:5128581].

  • strata_curie_to_name (Optional[Mapping[str, str]]) – If provided, should map from a key used in strata to a name. For example, {"geonames:4930956": "boston", "geonames:5128581": "nyc"}.

  • strata_name_lookup (bool) – If true, will try to look up the entity names of the strata values under the assumption that they are curies. This flag has no impact if strata_curie_to_name is given.

  • structure (Optional[Iterable[Tuple[str, str]]]) – An iterable of pairs corresponding to a directed network structure where each of the pairs has two strata. If none given, will assume a complete network structure. If no structure is necessary, pass an empty list.

  • directed (bool) – Should the reverse direction conversions be added based on the given structure?

  • conversion_cls (Type[Template]) – The template class to be used for conversions between strata defined by the network structure. Defaults to NaturalConversion

  • cartesian_control (bool) –

    If true, splits all control relationships based on the stratification.

    This should be true for an SIR epidemiology model, the susceptibility to infected transition is controlled by infected. If the model is stratified by vaccinated and unvaccinated, then the transition from vaccinated susceptible population to vaccinated infected populations should be controlled by both infected vaccinated and infected unvaccinated populations.

    This should be false for stratification of an SIR epidemiology model based on cities, since the infected population in one city won’t (directly, through the perspective of the model) affect the infection of susceptible population in another city.

  • modify_names (bool) – If true, will modify the names of the concepts to include the strata (e.g., "S" becomes "S_boston"). If false, will keep the original names.

  • params_to_stratify (Optional[Collection[str]]) – A list of parameters to stratify. If none given, will stratify all parameters.

  • params_to_preserve (Optional[Collection[str]]) – A list of parameters to preserve. If none given, will stratify all parameters.

  • concepts_to_stratify (Optional[Collection[str]]) – A list of concepts to stratify. If none given, will stratify all concepts.

  • concepts_to_preserve (Optional[Collection[str]]) – A list of concepts to preserve. If none given, will stratify all concepts.

  • param_renaming_uses_strata_names (Optional[bool]) – If true, the strata names will be used in the parameter renaming. If false, the strata indices will be used. Default: False

Return type:

TemplateModel

Returns:

A stratified template model

simplify_rate_laws(template_model)[source]

Return a template model after rewriting templates by simplifying rate laws.

Parameters:

template_model (TemplateModel) – A template model

Returns:

A template model with simplified rate laws.

check_simplify_rate_laws(template_model)[source]

Return a summary of what changes upon rate law simplification

Parameters:

template_model (TemplateModel) – A template model

Return type:

Mapping[str, Union[str, int, TemplateModel]]

Returns:

A dictionary with the result of the check under the result key. The result can be one of the following: - {‘result’: ‘NO_GROUP_CONTROLLERS’}: If there are no templates with

grouped controllers

  • {‘result’: ‘NO_CHANGE’}: If the model does contain templates with

    grouped controllers but simplification does not change the model.

  • {‘result’: ‘NO_CHANGE_IN_MAX_CONTROLLERS’,

    ’max_controller_count’: n}: If the model is simplified but the maximum number of controllers remains the same so it might not be worth doing the simplification. In this case the max controller count in the model is returned. The simplified model itself is also returned.

  • {‘result’: ‘MEANINGFUL_CHANGE’,

    ’max_controller_decrease’: n}: If the model is simplified and the maximum number of controllers also meaningfully changes. In this case the decrease in the maximum controller count is returned. The simplified model itself is also returned.

aggregate_parameters(template_model)[source]

Return a template model after aggregating parameters for mass-action rate laws.

Parameters:

template_model (TemplateModel) – A template model whose rate laws will be aggregated.

Return type:

TemplateModel

Returns:

A template model with aggregated parameters.

get_term_roles(term, template, parameters)[source]

Return terms in a rate law by role.

Parameters:
  • term – A sympy expression.

  • template (Template) – A template.

  • parameters (Mapping[str, Parameter]) – A dict of parameters in the template model, needed to interpret the semantics of rate laws.

Return type:

Mapping[str, List[str]]

Returns:

A dict of lists of symbols in the term by role.

counts_to_dimensionless(tm, counts_unit, norm_factor)[source]

Convert all quantities using a given counts unit to dimensionless units.

Parameters:
  • tm (TemplateModel) – A template model.

  • counts_unit (str) – The unit of the counts.

  • norm_factor (float) – The normalization factor to convert counts to dimensionsionless.

Return type:

TemplateModel

Returns:

A template model with all entity concentrations converted to dimensionless units.

deactivate_templates(template_model, condition)[source]

Deactivate templates that satisfy a given condition.

Parameters:
add_observable_pattern(template_model, name, identifiers=None, context=None)[source]

Add an observable for a pattern of concepts.

Parameters:
  • template_model (TemplateModel) – A template model.

  • name (str) – The name of the observable.

  • identifiers (Mapping) – Identifiers serving as a pattern for concepts to observe.

  • context (Mapping) – Context serving as a pattern for concepts to observe.

Model comparison (mira.metamodel.comparison)

class ModelComparisonGraphdata(template_models, concept_nodes=None, template_nodes=None, inter_model_edges=None, intra_model_edges=None)[source]

Bases: object

A graph representation of TemplateModel delta.

template_models

A mapping of template model keys to template models.

Type:

Dict[int, TemplateModel]

concept_nodes

A mapping of model identifiers to a mapping of node identifiers to concept nodes. Node identifiers have the structure of ‘mXnY’ where X is the model id and Y is the node id within the model.

Type:

Dict[int, Dict[int, Concept]]

template_nodes

Same structure as concept_nodes but for template nodes.

Type:

Dict[int, Dict[int, Template]]

inter_model_edges

List of edges as tuples of (source node lookup, target node lookup, role) where role describes if the edge is a refinement of or equal to another node in another model. Edges are directed for refinements and undirected for equalities. Node lookups are tuples of (model id, node id).

Type:

list of tuple

intra_model_edges

List of edges as tuples of (source node lookup, target node lookup, role) where role describes if the edge is incoming to, outgoing from or controls a template/process in the same model. Edges are directed. Node lookups are tuples of (model id, node id).

Type:

list of tuple

to_json()[source]

Return a JSON-compatible dict representation.

get_similarity_score(model1_id, model2_id)[source]

Get the similarity score of the model comparison

Parameters:
  • model1_id (int) – The id of the first model

  • model2_id (int) – The id of the second model

Return type:

float

Returns:

The similarity score

get_similarity_scores()[source]

Get the similarity scores for all model comparisons

Returns:

A list of dictionaries with the model ids and the similarity score

classmethod from_template_models(template_models, refinement_func)[source]

Create a ModelComparisonGraphdata from a list of TemplateModels

Parameters:
  • template_models (List[TemplateModel]) – The list of TemplateModels to compare

  • refinement_func (Callable[[str, str], bool]) – The refinement function to use when comparing concepts

Return type:

ModelComparisonGraphdata

Returns:

The ModelComparisonGraphdata

class TemplateModelComparison(template_models, refinement_func, tags=None, run_on_init=True)[source]

Bases: object

Compares TemplateModels in a graph friendly structure

Create a ModelComparisonGraphdata from a list of TemplateModels

Parameters:
  • template_models (List[TemplateModel]) – The list of TemplateModels to compare

  • refinement_func (Callable[[str, str], bool]) – The refinement function to use when comparing concepts

compare_models()[source]

Run model comparison

class TemplateModelDelta(template_model1, template_model2, refinement_function, tag1='1', tag2='2', tag1_color='blue', tag2_color='green', merge_color='orange', concepts_only=False)[source]

Bases: object

Defines the differences between TemplateModels as a networkx graph

Create a TemplateModelDelta

Parameters:
  • template_model1 (TemplateModel) – The first template model

  • template_model2 (TemplateModel) – The second template model

  • refinement_function (Callable[[str, str], bool]) – The refinement function to use when comparing concepts

  • tag1 (str) – The tag for the first template model. Default: “1”

  • tag2 (str) – The tag for the second template model. Default: “2”

  • tag1_color (str) – The color for the first template model. Default: “blue”

  • tag2_color (str) – The color for the second template model. Default: “green”

  • merge_color (str) – The color for the merged template model. Default: “orange”

draw_graph(path, prog='dot', args='', format=None)[source]

Draw a pygraphviz graph of the differences using

Parameters:
  • path (str) – The path to the output file

  • prog (str) – The graphviz layout program to use, such as “dot”, “neato”, etc.

  • format (Optional[str]) – Set the file format explicitly

  • args (str) – Additional arguments to pass to the graphviz bash program as a string. Example: “args=”-Nshape=box -Edir=forward -Ecolor=red “

graph_as_json()[source]

Return the comparison graph json serializable node-link data

Return type:

Dict

classmethod for_jupyter(template_model1, template_model2, refinement_function, name='model.png', tag1='1', tag2='2', tag1_color='blue', tag2_color='green', merge_color='orange', prog='dot', args='', format=None, concepts_only=False, **kwargs)[source]

Display in jupyter

Parameters:
  • template_model1 – The first template model

  • template_model2 – The second template model

  • refinement_function – The refinement function to use

  • name – The name of the output file

  • tag1 – The tag for the first template model

  • tag2 – The tag for the second template model

  • tag1_color – The color for the first template model

  • tag2_color – The color for the second template model

  • merge_color – The color for the merged template model

  • prog (str) – The graphviz layout program to use, such as “dot”, “neato”, etc.

  • format (Optional[str]) – Set the file format explicitly

  • args (str) – Additional arguments to pass to the graphviz bash program as a string. Example: “args=”-Nshape=box -Edir=forward -Ecolor=red”

  • kwargs – Keyword arguments to pass to IPython.display.Image

Returns:

The IPython Image object

class RefinementClosure(transitive_closure)[source]

Bases: object

A wrapper class for storing a transitive closure and exposing a function to check for refinement relationship.

Typical usage would involve: >>> from mira.dkg.web_client import get_transitive_closure_web >>> rc = RefinementClosure(get_transitive_closure_web()) >>> rc.is_ontological_child(‘doid:0080314’, ‘bfo:0000016’)

Initialize the RefinementClosure

Parameters:

transitive_closure (Set[Tuple[str, str]]) – The transitive closure of the refinement relationship

is_ontological_child(child_curie, parent_curie)[source]

Check if the child is a refinement of the parent

Parameters:
  • child_curie (str) – The child curie

  • parent_curie (str) – The parent curie

Return type:

bool

Returns:

True if the child is a refinement of the parent, False otherwise

get_dkg_refinement_closure()[source]

Return a refinement closure from the DKG

Return type:

RefinementClosure

Returns:

The refinement closure

get_concept_comparison_table(model1, model2, refinement_func=None, name_only=False)[source]

Compare two template models by their concepts and return a table

Parameters:
  • model1 (TemplateModel) – The first template model

  • model2 (TemplateModel) – The second template model

  • refinement_func (Callable[[str, str], bool]) – The refinement function to use when comparing concepts. Default: the default DKG refinement closure’s is_ontological_child method.

Return type:

DataFrame

Returns:

A table comparing the two models. The table has one model’s concepts on one axis and the other model’s concepts on the other axis. The table shows the relationship between the concepts. Possible relationships are:

  • ”is_equal”: The concepts are equal Todo: distinguish curie vs name equality

  • ”X refinement_of Y”: The first concept is a refinement of the second

  • NaN/no value: The concepts are not equal

Meta-model schema (mira.metamodel.schema)

Model search (mira.metamodel.search)

find_models_with_grounding(template_models, prefix, identifier)[source]

Filter a dict of models to ones containing a given grounding in any role.

Parameters:
  • template_models (Mapping[str, TemplateModel]) – A dict of template models.

  • prefix (str) – A prefix of a CURIE.

  • identifier (str) – An identifier of a CURIE.

Return type:

Mapping[str, TemplateModel]

Returns:

A dict of template models containing the given grounding.

Model I/O (mira.metamodel.io)

Input/output functions for metamodels.

model_from_json_file(fname)[source]

Return a TemplateModel from a JSON file.

Parameters:

fname (str or Path) – A file path.

Return type:

TemplateModel

Returns:

A TemplateModel deserialized from the JSON file.

model_to_json_file(model, fname)[source]

Dump a TemplateModel into a JSON file.

Parameters:
  • model (TemplateModel) – A template model to dump to a JSON file.

  • fname (str or Path) – A file path to dump the model into.

expression_to_mathml(expression, *args, **kwargs)[source]

Convert a sympy expression to MathML string.

Here we pay attention to not style underscores and numeric suffixes in special ways.

Parameters:
  • expression (Expr) – A sympy expression to convert.

  • args (list) – Additional arguments to pass to sympy.mathml.

  • kwargs (dict) – Additional keyword arguments to pass to sympy.mathml.

Return type:

str

Returns:

A MathML string representing the sympy expression.

mathml_to_expression(xml_str)[source]

Convert a MathML string to a sympy expression.

Parameters:

xml_str (str) – A MathML string.

Return type:

Expr

Returns:

A sympy expression.

Notes

This function is a wrapper around the SBMLMathMLParser class from the sbmlmath package, which has to be installed.

Units (mira.metamodel.units)

class Unit(expression)[source]

Bases: object

A unit of measurement.

expression

The expression for the unit.

Type:

sympy.Expr

Utilities (mira.metamodel.utils)

get_parseable_expression(s)[source]

Return an expression that can be parsed using sympy.

Return type:

str

revert_parseable_expression(s)[source]

Return an expression to its original form.

Return type:

str

safe_parse_expr(s, local_dict=None)[source]

Parse an expression that may contain lambda functions.

Return type:

Expr

sanity_check_tm(tm)[source]

Apply a short sanity check to a template model.

Decapodes (mira.metamodel.decapodes)

class Decapode(variables, op1s, op2s, summations, tangent_variables)[source]

Bases: object

MIRA’s internal representation of a decapode compute graph or decaexpr JSON.

Create a Decapode based off multiple mappings of different parts of a Decapode.

Parameters:
  • variables (Dict[int,Variable]) – Mapping of Variables.

  • op1s (Dict[int,Op1]) – Mapping of Op1s (Operation 1s).

  • op2s (Dict[int,Op2]) – Mapping of Op2s (Operation 2s).

  • summations (Dict[int,Summation]) – Mapping of Summations.

  • tangent_variables (Dict[int,TangentVariable]) – Mapping of TangentVariables.

class Variable(id, type, name, expression=None, identifiers=<factory>)[source]

Bases: object

Dataclass that represents a variable in MIRA’s internal representation of a Decapode.

id

The id of the tangent variable

Type:

int

type

The type of the variable.

Type:

str

name

The name of the variable.

Type:

str

expression

The expression of the variable.

Type:

sympy.Expr

identifiers

The mapping of namespaces to identifiers associated with the Variable.

Type:

Mapping[str,str]

class TangentVariable(id, incl_var)[source]

Bases: object

Dataclass that represents a tangent variable in MIRA’s internal representation of a Decapode.

id

The id of the tangent variable.

Type:

int

incl_var

The variable that is the result of a derivative operation associated with the tangent variable.

Type:

Variable

class Summation(id, summands, sum)[source]

Bases: object

Dataclass that represents a summation in MIRA’s internal representation of a decapode.

id

The id of the summation.

Type:

int

summands

A list of Variables that are a part of the summation.

Type:

list[Variable]

sum

The Variable that is the result of the summation.

Type:

Variable

class Op1(id, src, tgt, function_str)[source]

Bases: object

Dataclass that represents unary operations in MIRA’s internal representation of a decapode.

id

The id of the operation.

Type:

int

src

The Variable that is the source of the operation.

Type:

Variable

tgt

The Variable that is the target of the operation.

Type:

Variable

function_str

The operator of the operation.

Type:

str

class Op2(id, proj1, proj2, res, function_str)[source]

Bases: object

Dataclass that represents binary operations in MIRA’s internal representation of a decapode.

id

The id of the operation.

Type:

int

proj1

The Variable that is the first input to the operation.

Type:

Variable

proj2

The Variable that is the second input to the operation.

Type:

Variable

res

The variable that is the result of the operation.

Type:

Variable

function_str

The operator of the operation.

Type:

str

class RootVariable(id, type, name, expression=<factory>, identifiers=<factory>)[source]

Bases: Variable

Dataclass that represents a variable that is the output of a unary ( derivative) operation and the output of a series of unary and binary operations as well.

expression

A list containing both expressions associated with a RootVariable: One expression built up from a unary operation (derivative) and one built up from a series of unary and binary operations.

Type:

list[sympy.Expr]

Composition (mira.metamodel.composition)

Compose input template models into a single template model

compose(tm_list)[source]

Compose a list of template models into a single template model

This method composes two template models iteratively. For the initial composition of the first two template models in the list, this method prioritizes attributes (parameters, initials, templates, annotation time, model time, etc.) of the first template model in the list.

Parameters:

tm_list – The list of template models to compose

Returns:

The composed template model derived from the list of template models

compose_two_models(tm0, tm1)[source]

Compose two template models into one

The method prioritizes attributes (parameters, initials, templates, annotation time, model time, etc.) of the first template model passed in.

Parameters:
  • tm0 – The first template model to be composed

  • tm1 – The second template model to be composed

Returns:

The composed template model