booldog.io.interaction_logic

Convert interactions into Boolean functions

Attributes

logger

Classes

LogicBuilder

Abstract base class for Boolean logic builders.

SquadLogic

SQUAD logic:

Functions

interactions2rules(→ Dict[str, str])

Convert a list of signed interactions into Boolean update rules.

_normalise_and_collect_regulators(interactions, ...)

Normalize signs and orient interactions as target -> regulators.

Module Contents

booldog.io.interaction_logic.logger
booldog.io.interaction_logic.interactions2rules(interactions: tuple[int | str, int | str, int | str], *, logic: LogicBuilder = None, activator_symbol: int | str = 1, inhibitor_symbol: int | str = -1) Dict[str, str]

Convert a list of signed interactions into Boolean update rules.

Interactions are first grouped by target node (see _normalise_and_collect_regulators), then each target’s Boolean rule string (bnet-format, e.g. “A | B & !C”) is built from its regulators by logic.

Parameters:
  • interactions (list) – A list of interactions in the network. Each interaction should be a tuple of (source, target, sign), where source and target are node identifiers and sign is either activator_symbol or inhibitor_symbol.

  • activator_symbol (int, optional) – The value representing activation in the network. Default is 1.

  • inhibitor_symbol (int, optional) – The value representing inhibition in the network. Default is -1.

  • logic (LogicBuilder, optional) –

    An optional logic builder to use for constructing the update functions. If not provided, the default is SquadLogic, which implements the SQUAD logic: A node is active iff:

    (any activator is active) AND (no inhibitor is active)
    

Returns:

A dictionary mapping each target node identifier to its Boolean update rule, as a bnet-format rule string (not a prime-implicant object) produced by logic.build.

Return type:

dict

booldog.io.interaction_logic._normalise_and_collect_regulators(interactions, activator_symbol, inhibitor_symbol)

Normalize signs and orient interactions as target -> regulators.

Parameters:
  • interactions (list of tuple) – Interactions as (source, target, sign) tuples.

  • activator_symbol (int or str) – The value of sign that represents activation; normalized to 1.

  • inhibitor_symbol (int or str) – The value of sign that represents inhibition; normalized to -1.

Returns:

A dictionary mapping each target node identifier to a dict of its regulators, i.e. {target: {regulator: 1 or -1, ...}, ...}. Interactions whose sign matches neither activator_symbol nor inhibitor_symbol are dropped (a warning is logged) rather than included in the result. If the same (source, target) pair appears more than once, only the last occurrence is kept.

Return type:

dict

class booldog.io.interaction_logic.LogicBuilder

Abstract base class for Boolean logic builders.

Subclasses implement build to turn a node’s set of signed regulators into a Boolean rule string (bnet format), pluggable into interactions2rules.

abstractmethod build(node: str, regulators: Mapping[str, int]) str

Return an update rule for node.

Parameters:
  • node (str) – Identifier of the target node the rule is being built for.

  • regulators (Mapping[str, int]) – Mapping of regulator node identifier to normalized sign (1 for activator, -1 for inhibitor).

Returns:

A Boolean rule string (bnet format) for node.

Return type:

str

class booldog.io.interaction_logic.SquadLogic

Bases: LogicBuilder

SQUAD logic:

A node is active iff:

(any activator is active) AND (no inhibitor is active)
build(node: str, regulators: Mapping[str, int]) str

Build the SQUAD-logic rule for node from its regulators.

Parameters:
  • node (str) – Identifier of the target node the rule is being built for (unused other than for interface compatibility with LogicBuilder.build).

  • regulators (Mapping[str, int]) – Mapping of regulator node identifier to normalized sign (1 for activator, -1 for inhibitor).

Returns:

A Boolean rule string (bnet format): "0" if there are no regulators; the activators OR-ed together if there are no inhibitors; the negated inhibitors AND-ed together if there are no activators; otherwise "(activators OR-ed) & (negated inhibitors AND-ed)".

Return type:

str