booldog.io.interaction_logic

Convert interactions into Boolean functions

Attributes

logger

Classes

LogicBuilder

Abstract base class for Boolean logic builders.

SquadLogic

SQUAD logic (the default LogicBuilder of interactions2rules).

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 convention (see SquadLogic for the rule built in each case: no regulators, activators only, inhibitors only, or both).

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

Notes

Every interaction must be signed (activation or inhibition); edges of unknown monotonicity are not supported. Interactions whose sign matches neither activator_symbol nor inhibitor_symbol are dropped and a warning is logged. If the same (source, target) pair appears more than once, the last occurrence wins and a warning is logged (noting whether the signs conflict).

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 (with a recognized sign), only the last occurrence is kept and a warning is logged, stating whether the signs conflict (an edge cannot be both activating and inhibiting).

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 (the default LogicBuilder of interactions2rules).

The rule for a node depends on which kinds of regulators it has:

  • no regulators: constant 0

  • activators only: OR of the activators, e.g. A | B

  • inhibitors only: AND of the negated inhibitors, e.g. !C & !D (the node is on unless an inhibitor is active)

  • both: (activators OR-ed) & (negated inhibitors AND-ed), e.g. (A | B) & (!C & !D)

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