Executable PySB models (indra.assemblers.pysb.assembler)

PySB Assembler (indra.assemblers.pysb.assembler)

class indra.assemblers.pysb.assembler.Param(name, value, unique=False)[source]

Represent a parameter as an input to the assembly process.


The name of the parameter


The value of the parameter


If True, a suffix is added to the end of the parameter name upon assembly to make sure the parameter is unique in the model. If False, the name attribute is used as is. Default: False

class indra.assemblers.pysb.assembler.Policy(name, parameters=None, sites=None)[source]

Represent a policy that can be associated with a speficic Statement.


The name of the policy, e.g. one_step


A dict of parameters where each key identifies the role of the parameter with respect to the policy, e.g. ‘Km’, and the value is a Param object.

Type:dict[str, Param]

A dict of site names corresponding to the interactions induced by the policy.

class indra.assemblers.pysb.assembler.PysbAssembler(statements=None)[source]

Assembler creating a PySB model from a set of INDRA Statements.

Parameters:statements (list[indra.statements.Statement]) – A list of INDRA Statements to be assembled.

A dictionary of policies that defines assembly policies for Statement types. It is assigned in the constructor.


A list of INDRA statements to be assembled.


A PySB model object that is assembled by this class.


A set of BaseAgents used during the assembly process.


Set default initial conditions in the PySB model.

Parameters:value (Optional[float]) – Optionally a value can be supplied which will be the initial amount applied. Otherwise a built-in default is used.

Add INDRA Statements to the assembler’s list of statements.

Parameters:stmts (list[indra.statements.Statement]) – A list of indra.statements.Statement to be added to the statement list of the assembler.
export_model(format, file_name=None)[source]

Save the assembled model in a modeling formalism other than PySB.

For more details on exporting PySB models, see http://pysb.readthedocs.io/en/latest/modules/export/index.html

  • format (str) – The format to export into, for instance “kappa”, “bngl”, “sbml”, “matlab”, “mathematica”, “potterswheel”. See http://pysb.readthedocs.io/en/latest/modules/export/index.html for a list of supported formats. In addition to the formats supported by PySB itself, this method also provides “sbgn” output.
  • file_name (Optional[str]) – An optional file name to save the exported model into.

exp_str – The exported model string or object

Return type:

str or object

make_model(policies=None, initial_conditions=True, reverse_effects=False, model_name='indra_model')[source]

Assemble the PySB model from the collected INDRA Statements.

This method assembles a PySB model from the set of INDRA Statements. The assembled model is both returned and set as the assembler’s model argument.

  • policies (Optional[Union[str, dict]]) –

    A string or dictionary that defines one or more assembly policies.

    If policies is a string, it defines a global assembly policy that applies to all Statement types. Example: one_step, interactions_only

    A dictionary of policies has keys corresponding to Statement types and values to the policy to be applied to that type of Statement. For Statement types whose policy is undefined, the ‘default’ policy is applied. Example: {‘Phosphorylation’: ‘two_step’}

  • initial_conditions (Optional[bool]) – If True, default initial conditions are generated for the Monomers in the model. Default: True
  • reverse_effects (Optional[bool]) – If True, reverse rules are added to the model for activity, modification and amount regulations that have no corresponding reverse effects. Default: False
  • model_name (Optional[str]) – The name attribute assigned to the PySB Model object. Default: “indra_model”

model – The assembled PySB model object.

Return type:



Print the assembled model as a PySB program string.

This function is useful when the model needs to be passed as a string to another component.


Save the assembled model as a PySB program file.

Parameters:file_name (Optional[str]) – The name of the file to save the model program code in. Default: pysb-model.py
save_rst(file_name='pysb_model.rst', module_name='pysb_module')[source]

Save the assembled model as an RST file for literate modeling.

  • file_name (Optional[str]) – The name of the file to save the RST in. Default: pysb_model.rst
  • module_name (Optional[str]) – The name of the python function defining the module. Default: pysb_module

Set protein expression amounts from CCLE as initial conditions.

This method uses indra.databases.context_client to get protein expression levels for a given cell type and set initial conditions for Monomers in the model accordingly.

  • cell_type (str) – Cell type name for which expression levels are queried. The cell type name follows the CCLE database conventions.
  • Example (LOXIMVI_SKIN, BT20_BREAST) –

Set protein expression amounts as initial conditions

Parameters:expression_dict (dict) – A dictionary in which the keys are gene names and the values are numbers representing the absolute amount (count per cell) of proteins expressed. Proteins that are not expressed can be represented as nan. Entries that are not in the dict or are in there but resolve to None, are set to the default initial amount. Example: {‘EGFR’: 12345, ‘BRAF’: 4567, ‘ESR1’: nan}
exception indra.assemblers.pysb.assembler.UnknownPolicyError[source]
indra.assemblers.pysb.assembler.add_rule_to_model(model, rule, annotations=None)[source]

Add a Rule to a PySB model and handle duplicate component errors.

indra.assemblers.pysb.assembler.complex_monomers_default(stmt, agent_set)

In this (very simple) implementation, proteins in a complex are each given site names corresponding to each of the other members of the complex (lower case). So the resulting complex can be “fully connected” in that each member can be bound to all the others.

indra.assemblers.pysb.assembler.complex_monomers_one_step(stmt, agent_set)[source]

In this (very simple) implementation, proteins in a complex are each given site names corresponding to each of the other members of the complex (lower case). So the resulting complex can be “fully connected” in that each member can be bound to all the others.


Construct a string from an Agent as part of a PySB rule name.

indra.assemblers.pysb.assembler.get_annotation(component, db_name, db_ref)[source]

Construct model Annotations for each component.

Annotation formats follow guidelines at http://identifiers.org/.

indra.assemblers.pysb.assembler.get_create_parameter(model, param)[source]

Return parameter with given name, creating it if needed.

If unique is false and the parameter exists, the value is not changed; if it does not exist, it will be created. If unique is true then upon conflict a number is added to the end of the parameter name.

  • model (pysb.Model) – The model to add the parameter to
  • param (Param) – An assembly parameter object
indra.assemblers.pysb.assembler.get_monomer_pattern(model, agent, extra_fields=None)[source]

Construct a PySB MonomerPattern from an Agent.


Construct a dictionary of Monomer site states from an Agent.

This crates the mapping to the associated PySB monomer from an INDRA Agent object.


Construct the unconditional state of an Agent.

The unconditional Agent is a copy of the original agent but without any bound conditions and modification conditions. Mutation conditions, however, are preserved since they are static.

indra.assemblers.pysb.assembler.grounded_monomer_patterns(model, agent, ignore_activities=False)[source]

Get monomer patterns for the agent accounting for grounding information.

  • model (pysb.core.Model) – The model to search for MonomerPatterns matching the given Agent.
  • agent (indra.statements.Agent) – The Agent to find matching MonomerPatterns for.
  • ignore_activites (bool) – Whether to ignore any ActivityConditions on the agent when determining the required site conditions for the MonomerPattern. For example, if set to True, will find a match for the agent MAPK1(activity=kinase) even if the corresponding MAPK1 Monomer in the model has no site named kinase. Default is False (more stringent matching).

Return type:

generator of MonomerPatterns


Parse an identifiers.org URL into (namespace, ID) tuple.

indra.assemblers.pysb.assembler.set_base_initial_condition(model, monomer, value)[source]

Set an initial condition for a monomer in its ‘default’ state.

indra.assemblers.pysb.assembler.set_extended_initial_condition(model, monomer=None, value=0)[source]

Set an initial condition for monomers in “modified” state.

This is useful when using downstream analysis that relies on reactions being active in the model. One example is BioNetGen-based reaction network diagram generation.

PySB PreAssembler (indra.assemblers.pysb.preassembler)

class indra.assemblers.pysb.preassembler.PysbPreassembler(stmts=None)[source]

Pre-assemble Statements in preparation for PySB assembly.

Parameters:stmts (list[indra.statements.Statement]) – A list of Statements to assemble

Add Statements for the reverse effects of some Statements.

For instance, if a protein is phosphorylated but never dephosphorylated in the model, we add a generic dephosphorylation here. This step is usually optional in the assembly process.


Add a list of Statements for assembly.


Replace ative flags with Agent states when possible.

Base Agents (indra.assemblers.pysb.base_agents)

class indra.assemblers.pysb.base_agents.BaseAgentSet[source]

Container for a dict of BaseAgents with their names as keys.


Return base agent with given name, creating it if needed.


Return items for the set of BaseAgents that this class wraps.

class indra.assemblers.pysb.base_agents.BaseAgent(name)[source]

A BaseAgent aggregates the global properties of an Agent.

The BaseAgent class aggregates the name, sites, site states, active forms, inactive forms and database references of Agents from individual INDRA Statements. This allows the PySB Assembler to correctly assemble the Monomer signatures in the model.

add_activity_form(activity_pattern, is_active)[source]

Adds the pattern as an active or inactive form to an Agent.

  • activity_pattern (dict) – A dictionary of site names and their states.
  • is_active (bool) – Is True if the given pattern corresponds to an active state.

Adds an activity type to an Agent.

Parameters:activity_type (str) – The type of activity to add such as ‘activity’, ‘kinase’, ‘gtpbound’
add_site_states(site, states)[source]

Create new states on an agent site if the state doesn’t exist.


Create modification site for the BaseAgent from a ModCondition.

create_site(site, states=None)[source]

Create a new site on an agent if it doesn’t already exist.

A utility to get graphs from kappa (indra.assemblers.pysb.kappa_util)


Return pygraphviz Agraph from Kappy’s contact map JSON.

Parameters:im_json (dict) – A JSON dict which contains a contact map generated by Kappy.
Returns:graph – A graph representing the contact map.
Return type:pygraphviz.Agraph

Return networkx graph from Kappy’s influence map JSON.

Parameters:im_json (dict) – A JSON dict which contains an influence map generated by Kappy.
Returns:graph – A graph representing the influence map.
Return type:networkx.MultiDiGraph