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.

name

str – The name of the parameter

value

float – The value of the parameter

unique

Optional[bool] – 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.

name

str – The name of the policy, e.g. one_step

parameters

dict[str, Param] – 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.

sites

dict – 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.
policies

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

statements

list[indra.statements.Statement] – A list of INDRA statements to be assembled.

model

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

agent_set

BaseAgentSet – A set of BaseAgents used during the assembly process.

add_default_initial_conditions(value=None)[source]

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

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

Parameters:
  • 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.
Returns:

exp_str – The exported model string

Return type:

str

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.

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: 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”
Returns:

model – The assembled PySB model object.

Return type:

pysb.Model

print_model()[source]

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_model(file_name='pysb_model.py')[source]

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.

Parameters:
  • 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_context(cell_type)[source]

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.

Parameters:
  • 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_expression(expression_dict)[source]

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.

indra.assemblers.pysb.assembler.get_agent_rule_str(agent)[source]

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.

Parameters:
  • 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.

indra.assemblers.pysb.assembler.get_site_pattern(agent)[source]

Construct a dictionary of Monomer site states from an Agent.

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

indra.assemblers.pysb.assembler.get_uncond_agent(agent)[source]

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.

indra.assemblers.pysb.assembler.parse_identifiers_url(url)[source]

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

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

Add a list of Statements for assembly.

replace_activities()[source]

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.

get_create_base_agent(agent)[source]

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

items()[source]

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.

Parameters:
  • 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.
add_activity_type(activity_type)[source]

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

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.