Executable PySB models (indra.assemblers.pysb_assembler)

class indra.assemblers.pysb_assembler.PysbAssembler(policies=None)[source]

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

Parameters: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: contact_only, one_step

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’}


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


list – A list of INDRA statements to be assembled.


pysb.Model – A PySB model object that is assembled by this class.


_BaseAgentSet – 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

Return type:


make_model(policies=None, initial_conditions=True, reverse_effects=False)[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 of policies, as defined in indra.assemblers.PysbAssembler. This set of policies locally supersedes the default setting in the assembler. This is useful when this function is called multiple times with different policies.
  • initial_conditions (Optional[bool]) – If True, default initial conditions are generated for the Monomers in the 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 data 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) –
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.


Return an SBGN model string corresponding to the PySB model.

This function first calls generate_equations on the PySB model to obtain a reaction network (i.e. individual species, reactions). It then iterates over each reaction and and instantiates its reactants, products, and the process itself as SBGN glyphs and arcs.

Parameters:model (pysb.core.Model) – A PySB model to be exported into SBGN
Returns:sbgn_str – An SBGN model as string
Return type:str

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/.


Return a binding site name from a given agent.

indra.assemblers.pysb_assembler.get_create_parameter(model, name, value, unique=True)[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.

indra.assemblers.pysb_assembler.get_mod_site_name(mod_type, residue, position)[source]

Return site names for a modification.

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)[source]

Get monomer patterns for the agent accounting for grounding information.


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.