Explanation (indra.explanation)

Check whether a rule-based model satisfies a property (indra.explanation.model_checker)

class indra.explanation.model_checker.ModelChecker(model, statements=None, agent_obs=None, do_sampling=False, seed=None)[source]

Check a PySB model against a set of INDRA statements.

Parameters:
  • model (pysb.Model) – A PySB model to check.
  • statements (Optional[list[indra.statements.Statement]]) – A list of INDRA Statements to check the model against.
  • agent_obs (Optional[list[indra.statements.Agent]]) – A list of INDRA Agents in a given state to be observed.
  • do_sampling (bool) – Whether to use breadth-first search or weighted sampling to generate paths. Default is False (breadth-first search).
  • seed (int) – Random seed for sampling (optional, default is None).
add_statements(stmts)[source]

Add to the list of statements to check against the model.

Parameters:stmts (list[indra.statements.Statement]) – The list of Statements to be added for checking.
check_model(max_paths=1, max_path_length=5)[source]

Check all the statements added to the ModelChecker.

Parameters:
  • max_paths (Optional[int]) – The maximum number of specific paths to return for each Statement to be explained. Default: 1
  • max_path_length (Optional[int]) – The maximum length of specific paths to return. Default: 5
Returns:

Each tuple contains the Statement checked against the model and a PathResult object describing the results of model checking.

Return type:

list of (Statement, PathResult)

check_statement(stmt, max_paths=1, max_path_length=5)[source]

Check a single Statement against the model.

Parameters:
  • stmt (indra.statements.Statement) – The Statement to check.
  • max_paths (Optional[int]) – The maximum number of specific paths to return for each Statement to be explained. Default: 1
  • max_path_length (Optional[int]) – The maximum length of specific paths to return. Default: 5
Returns:

True if the model satisfies the Statement.

Return type:

boolean

generate_im(model)[source]

Return a graph representing the influence map generated by Kappa

Parameters:model (pysb.Model) – The PySB model whose influence map is to be generated
Returns:graph – A MultiDiGraph representing the influence map
Return type:networkx.MultiDiGraph
get_im(force_update=False)[source]

Get the influence map for the model, generating it if necessary.

Parameters:force_update (bool) – Whether to generate the influence map when the function is called. If False, returns the previously generated influence map if available. Defaults to True.
Returns:The influence map can be rendered as a pdf using the dot layout program as follows:
im_agraph = nx.nx_agraph.to_agraph(influence_map)
im_agraph.draw('influence_map.pdf', prog='dot')
Return type:networkx MultiDiGraph object containing the influence map.
prune_influence_map()[source]

Remove edges between rules causing problematic non-transitivity.

First, all self-loops are removed. After this initial step, edges are removed between rules when they share all child nodes except for each other; that is, they have a mutual relationship with each other and share all of the same children.

Note that edges must be removed in batch at the end to prevent edge removal from affecting the lists of rule children during the comparison process.

score_paths(paths, agents_values, loss_of_function=False, sigma=0.15, include_final_node=False)[source]

Return scores associated with a given set of paths.

Parameters:
  • paths (list[list[tuple[str, int]]]) – A list of paths obtained from path finding. Each path is a list of tuples (which are edges in the path), with the first element of the tuple the name of a rule, and the second element its polarity in the path.
  • agents_values (dict[indra.statements.Agent, float]) – A dictionary of INDRA Agents and their corresponding measured value in a given experimental condition.
  • loss_of_function (Optional[boolean]) – If True, flip the polarity of the path. For instance, if the effect of an inhibitory drug is explained, set this to True. Default: False
  • sigma (Optional[float]) – The estimated standard deviation for the normally distributed measurement error in the observation model used to score paths with respect to data. Default: 0.15
  • include_final_node (Optional[boolean]) – Determines whether the final node of the path is included in the score. Default: False
class indra.explanation.model_checker.PathMetric(source_node, target_node, polarity, length)[source]

Describes results of simple path search (path existence).

class indra.explanation.model_checker.PathResult(path_found, result_code, max_paths, max_path_length)[source]

Describes results of running the ModelChecker on a single Statement.

Parameters:
  • path_found (bool) –
  • result_code (string) – STATEMENT_TYPE_NOT_HANDLED SUBJECT_MONOMERS_NOT_FOUND OBSERVABLES_NOT_FOUND NO_PATHS_FOUND MAX_PATH_LENGTH_EXCEEDED PATHS_FOUND INPUT_RULES_NOT_FOUND MAX_PATHS_ZERO
path_found

boolean

result_code

string

path_metrics

list of PathMetric

paths

list of paths

max_paths
max_path_length
indra.explanation.model_checker.remove_im_params(model, im)[source]

Remove parameter nodes from the influence map.

Parameters:
  • model (pysb.core.Model) – PySB model.
  • im (networkx.MultiDiGraph) – Influence map.
Returns:

Influence map with the parameter nodes removed.

Return type:

networkx.MultiDiGraph

indra.explanation.model_checker.stmt_from_rule(rule_name, model, stmts)[source]

Return the source INDRA Statement corresponding to a rule in a model.

Parameters:
  • rule_name (str) – The name of a rule in the given PySB model.
  • model (pysb.core.Model) – A PySB model which contains the given rule.
  • stmts (list[indra.statements.Statement]) – A list of INDRA Statements from which the model was assembled.
Returns:

stmt – The Statement from which the given rule in the model was obtained.

Return type:

indra.statements.Statement