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:
objectA 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]
- 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.
- 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”]
- 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”]
- 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”]
- diseases
Diseases caused by pathogens in the model, given with CURIEs referencing vocabulary for diseases, such as DOID, EFO, or MONDO. Example: [“doid:0080600”]
- 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”]
- 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”]
- class TemplateModel(templates, parameters=None, initials=None, observables=None, annotations=None, time=None)[source]
Bases:
objectA template model.
- 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]
- 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.
- 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.
- 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.
- 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.
- 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:
- 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.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.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:
- Returns:
The node-link data as a dictionary.
- get_concepts_map()[source]
Return a mapping from concept keys to concepts that appear in this template model’s templates.
- get_concepts_name_map()[source]
Return a mapping from concept names to concepts that appear in this template model’s templates.
- 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.
- 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:
- add_template(template, parameter_mapping=None, initial_mapping=None)[source]
Add a template to the model.
- Parameters:
- Return type:
- 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:
- 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.
- class Initial(concept, expression)[source]
Bases:
objectInitial conditions for parameters in the model.
- class Parameter(name, value=None, distribution=None, display_name=None, description=None, identifiers=None, context=None, units=None)[source]
Bases:
ConceptA Parameter is a special type of Concept that carries a value.
- distribution
A distribution of values for the parameter.
- Type:
Optional[Distribution]
- class Distribution(type, parameters)[source]
Bases:
objectA distribution of values for a parameter.
- type
The type of distribution as provided by ProbOnto, e.g. ‘StandardUniform1’, ‘Beta1’, etc.
- Type:
- 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:
- class Observable(name, expression, display_name=None, description=None, identifiers=None, context=None, units=None)[source]
Bases:
ConceptAn 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.
- expression
The expression for the observable.
- Type:
sympy.Expr
- class Time(name='t', units=None)[source]
Bases:
objectA special type of Concept that represents time.
- 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:
- class Concept(name, display_name=None, description=None, identifiers=None, context=None, units=None)[source]
Bases:
objectA concept is specified by its identifier(s), name, and - optionally - its context.
- display_name
An optional display name for the concept. If not provided, the name can be used for display purposes.
- Type:
Optional[str]
- 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:
- Returns:
A new concept containing the given context.
- get_included_identifiers(config=None)[source]
Get the identifiers for this concept that are not excluded.
- 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 withwith_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_contexthas no effect.config (
Config) – Configuration defining priority and exclusion for identifiers.
- Return type:
- Returns:
True if
otheris 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:
- Returns:
True if this Concept is a refinement of another Concept
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:
objectThe Template is a parent class for model processes.
- rate_law
The rate law for the template.
- Type:
Optional[sympy.Expr]
- 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:
- Returns:
A Template object
- is_equal_to(other, with_context=False, config=None)[source]
Check if this template is equal to another template
- Parameters:
- Return type:
- 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:
- 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_renameis True.
- Returns:
A copy of this template with context added
- 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.
- 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:
- Returns:
A copy of this template with the mass action rate law.
- 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.
- class ControlledConversion(controller, subject, outcome, provenance=None, **kwargs)[source]
Bases:
TemplateControlled conversion from subject to outcome.
- 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_renameis True.
- Return type:
- 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:
- Returns:
A new template with the additional controller.
- class ControlledProduction(controller, outcome, provenance=None, **kwargs)[source]
Bases:
TemplateProduction controlled by one 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.
- add_controller(controller)[source]
Add a controller to this template.
- Parameters:
controller (
Concept) – The controller to add.- Return type:
- 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:
- 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_renameis True.
- Return type:
- Returns:
A copy of this template with context added
- class ControlledDegradation(controller, subject, provenance=None, **kwargs)[source]
Bases:
TemplateDegradation controlled by one 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.
- add_controller(controller)[source]
Add a controller to this template.
- Parameters:
controller (
Concept) – The controller to add.- Return type:
- 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:
- 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_renameis True.
- Return type:
- Returns:
A copy of this template with context added
- class NaturalConversion(subject, outcome, provenance=None, **kwargs)[source]
Bases:
TemplateNatural conversion from subject to outcome.
- 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_renameis True.
- Return type:
- Returns:
A copy of this template with context added
- class NaturalProduction(outcome, provenance=None, **kwargs)[source]
Bases:
TemplateProduction of a species at a constant rate.
- 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_renameis True.
- Return type:
- Returns:
A copy of this template with context added
- class NaturalDegradation(subject, provenance=None, **kwargs)[source]
Bases:
TemplateDegradation of a species at a rate proportional to its amount.
- 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_renameis True.
- Return type:
- Returns:
A copy of this template with context added
- class GroupedControlledConversion(controllers, subject, outcome, provenance=None, **kwargs)[source]
Bases:
TemplateConversion controlled by multiple 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_renameis True.
- Return type:
- 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:
- 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.
- class GroupedControlledProduction(controllers, outcome, provenance=None, **kwargs)[source]
Bases:
TemplateProduction controlled by several 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 a controller to this template.
- Parameters:
controller (
Concept) – The controller to add.- Return type:
- 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:
- 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_renameis True.
- Return type:
- Returns:
A copy of this template with context added
- class GroupedControlledDegradation(controllers, subject, provenance=None, **kwargs)[source]
Bases:
TemplateDegradation controlled by several 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 a controller to this template.
- Parameters:
controller (
Concept) – The controller to add.- Return type:
- 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:
- 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_renameis True.
- Return type:
- Returns:
A copy of this template with context added
- class MultiConversion(subjects, outcomes, provenance=None, **kwargs)[source]
Bases:
TemplateConversion of multiple subjects and outcomes.
- 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_renameis True.
- Return type:
- Returns:
A copy of this template with context added
- class NaturalReplication(subject, provenance=None, **kwargs)[source]
Bases:
TemplateNatural replication of a subject.
- 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_renameis True.
- Return type:
- Returns:
A copy of this template with context added
- class ControlledReplication(controller, subject, provenance=None, **kwargs)[source]
Bases:
TemplateReplication controlled by one 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.
- 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:
- 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_renameis True.
- Return type:
- Returns:
A copy of this template with context added
- class ReversibleFlux(left, right, provenance=None, **kwargs)[source]
Bases:
TemplateA reversible flux between a left and right side.
- 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_renameis True.
- Return type:
- Returns:
A copy of this template with context added
- class StaticConcept(subject, provenance=None, **kwargs)[source]
Bases:
TemplateA standalone Concept that is not part of a process.
- 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_renameis True.
- Return type:
- 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:
- Return type:
- 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:
- 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:
- Returns:
True if there is an exact match between the two lists of concepts.
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 modelkey (
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 instratato 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 ifstrata_curie_to_nameis 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 toNaturalConversioncartesian_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:
- 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:
- Returns:
A template model with aggregated parameters.
- 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:
- 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:
template_model (
TemplateModel) – A template model.condition (
Callable[[Template],bool]) – A function that takes a template and returns a boolean.
- 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:
objectA 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.
- template_nodes
Same structure as concept_nodes but for template nodes.
- 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).
- 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).
- get_similarity_score(model1_id, model2_id)[source]
Get the similarity score of the model comparison
- 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
- class TemplateModelComparison(template_models, refinement_func, tags=None, run_on_init=True)[source]
Bases:
objectCompares TemplateModels in a graph friendly structure
Create a ModelComparisonGraphdata from a list of TemplateModels
- Parameters:
- 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:
objectDefines the differences between TemplateModels as a networkx graph
Create a TemplateModelDelta
- Parameters:
template_model1 (
TemplateModel) – The first template modeltemplate_model2 (
TemplateModel) – The second template modelrefinement_function (
Callable[[str,str],bool]) – The refinement function to use when comparing conceptstag1 (
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
- 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.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:
objectA 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
- get_dkg_refinement_closure()[source]
Return a refinement closure from the DKG
- Return type:
- 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 modelmodel2 (
TemplateModel) – The second template modelrefinement_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:
- 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:
- 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.
Units (mira.metamodel.units)
Utilities (mira.metamodel.utils)
- get_parseable_expression(s)[source]
Return an expression that can be parsed using sympy.
- Return type:
Decapodes (mira.metamodel.decapodes)
- class Decapode(variables, op1s, op2s, summations, tangent_variables)[source]
Bases:
objectMIRA’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:
- class Variable(id, type, name, expression=None, identifiers=<factory>)[source]
Bases:
objectDataclass that represents a variable in MIRA’s internal representation of a Decapode.
- expression
The expression of the variable.
- Type:
sympy.Expr
- class TangentVariable(id, incl_var)[source]
Bases:
objectDataclass that represents a tangent variable in MIRA’s internal representation of a Decapode.
- class Summation(id, summands, sum)[source]
Bases:
objectDataclass that represents a summation in MIRA’s internal representation of a decapode.
- class Op1(id, src, tgt, function_str)[source]
Bases:
objectDataclass that represents unary operations in MIRA’s internal representation of a decapode.
- class Op2(id, proj1, proj2, res, function_str)[source]
Bases:
objectDataclass that represents binary operations in MIRA’s internal representation of a decapode.
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