cana.io package

Import / export Boolean networks via a list[BooleanNode] hub.

File formats (booleannet, bnet, aeon, sbml, cnet) convert to/from a dense list of BooleanNode (invariant: nodes[i].id == i). Expression formats store a positional expression peer on BooleanFunction at import; exporters may materialize dense LUTs. Name-keyed LUT equivalence is the round-trip authority across formats. Single-rule import without hub wiring uses import_detached_rule().

Modules:

booleannet, bnet, aeon, sbml, cnet: per-format parse / export

Builders / equivalence live in cana.nodes_builder. Expression helpers live in cana.function_outputs.expression.

Format parsers/exporters are loaded lazily so importing a single helper does not pull every format module.

cana.io.convert(text, from_type, to_type, **kwargs)[source]

Convert a model string from from_type to to_type via a node list.

Extra kwargs are forwarded to the destination exporter (e.g. adjust_no_input / one_symbol_schemata for cnet).

Parameters:
  • text (str)

  • from_type (str)

  • to_type (str)

  • kwargs (Any)

Return type:

str

cana.io.export_string(nodes, fmt, **kwargs)[source]

Serialize a node list to the requested format string.

Extra kwargs are forwarded to format-specific exporters (e.g. adjust_no_input for cnet, warn for expression formats).

Parameters:
Return type:

str

cana.io.import_detached_rule(text, *, fmt='bnet', target=None)[source]

Parse a one-rule (or multi-rule) snippet into a DetachedRule.

Uses first-appearance input order and does not invent free-input identity siblings. When text has multiple update rules, target selects which one (required if more than one rule is present).

Parameters:
  • text (str)

  • fmt (str)

  • target (str | None)

cana.io.infer_format(path)[source]

Infer format from a file path suffix, or None if ambiguous.

Parameters:

path (str | Path)

Return type:

str | None

cana.io.nodes_to_aeon(nodes, *, warn=True)[source]

Export a node list to AEON text (regulations + update functions).

Prefers stored expression, then one-symbol schemata, then LUT DNF. Soft-warns when verification flags are not True (never blocks).

Parameters:
Return type:

str

cana.io.nodes_to_bnet(nodes, *, warn=True)[source]

Export a node list to BoolNet targets,factors text.

Prefers stored expression, then one-symbol schemata, then LUT DNF. Soft-warns when verification flags are not True (never blocks).

Parameters:
Return type:

str

cana.io.nodes_to_booleannet(nodes, *, warn=True)[source]

Export a node list to BooleanNet text (name* = expr).

Prefers stored expression, then one-symbol schemata, then LUT DNF. Soft-warns when verification flags are not True (never blocks).

Parameters:
Return type:

str

cana.io.nodes_to_cnet(nodes, *, adjust_no_input=False, one_symbol_schemata=False)[source]

Export a node list to BNS / Cell Collective .cnet text.

Parameters:
  • nodes (Sequence[BooleanNode]) – Dense list[BooleanNode] hub (nodes[i].id == i).

  • adjust_no_input (bool) – If True, rewrite empty-input nodes as self-loops with identity LUT [0, 1] (BNS compatibility).

  • one_symbol_schemata (bool) – If True, export one-symbol (wildcard) covers; if False (default), export dense 2**k LUT rows.

Return type:

str

Dense export materializes bit_lut via BooleanFunction.get_bit_lut() when only expression/schemata are present. Schemata export materializes one_symbol_schemata similarly. If a representation cannot be derived, raises ValueError.

cana.io.nodes_to_sbml(nodes, *, warn=True)[source]

Export a node list to SBML Level 3 qualitative XML.

Prefers stored expression, then one-symbol schemata, then LUT DNF for MathML update functions. Soft-warns when verification flags are not True (never blocks).

Parameters:
Return type:

str

cana.io.bit_lut_to_expression(input_names, lut, style='python')[source]

Build a DNF expression for a BitLut using input_names.

Positional vs named is chosen by input_names: pass positional_names() (k) for positional IR, or input names for a named expression. Callers with a plain 0/1 sequence should convert via BitLut.from_sequence() first.

Parameters:
  • input_names (Sequence[str]) – Input variable names in LUT bit order (MSB first).

  • lut (BitLut) – Dense truth table (lut.k must equal len(input_names)).

  • style (str) – "python" (and/or/not) or "symbolic" (&/|/!).

Return type:

str

cana.io.normalize_format(fmt)[source]

Map aliases to a canonical format name, or return None.

Parameters:

fmt (str | None)

Return type:

str | None

cana.io.normalize_operators(expr, style='python')[source]

Normalize boolean operators to and/or/not or &/|/!.

Works on positional or named expressions (operators only). Prefix ~ is treated as logical NOT (same as ! / not), not Python bitwise complement.

Parameters:
  • expr (str) – Boolean expression string.

  • style (str) – "python" (for positional_expression_to_bit_lut() / named_expression_to_bit_lut()) or "symbolic".

Return type:

str

cana.io.parse_aeon(text)[source]

Parse AEON *.aeon into a node list.

Parameters:

text (str)

Return type:

List[BooleanNode]

cana.io.parse_aeon_update_rule(line)[source]

Parse one $var: named_expression line, or None if not an update.

Regulation edge lines are ignored here (handled only in full-file parse).

Parameters:

line (str)

Return type:

Tuple[str, str] | None

cana.io.parse_bnet(text)[source]

Parse BoolNet / PyBoolNet *.bnet into a node list.

Parameters:

text (str)

Return type:

List[BooleanNode]

cana.io.parse_bnet_update_rule(line)[source]

Parse one target, named_expression line, or None if not a rule.

Skips blanks, comments, and the targets,factors header.

Parameters:

line (str)

Return type:

Tuple[str, str] | None

cana.io.parse_booleannet(text)[source]

Parse BooleanNet / *.booleannet.txt rules into a node list.

Parameters:

text (str)

Return type:

List[BooleanNode]

cana.io.parse_booleannet_update_rule(line)[source]

Parse one name* = named_expression line, or None if not a rule.

Parameters:

line (str)

Return type:

Tuple[str, str] | None

cana.io.parse_cnet(text)[source]

Parse BNS / Cell Collective .cnet text into a node list.

Format sketch:

.v <N>
.l <id> <name>
.n <id> <k> <in1> ... <ink>
<binstate> <out>   # don't-care bits are ``-`` (legacy ``2`` also accepted)
.e

Per-node heuristic: if any logic line uses don’t-care -/2, store that node’s cover as one_symbol_schemata only; otherwise import as a dense bit_lut (including ON-only minterm listings with implied 0s).

Import is faithful: missing peer representations are not filled. Call BooleanNetwork.fill_function_representation(...) (or the node helper) when you need the other slot.

Parameters:

text (str)

Return type:

List[BooleanNode]

cana.io.parse_sbml(text)[source]

Parse SBML-qual Boolean models into a node list.

Parameters:

text (str)

Return type:

List[BooleanNode]

cana.io.parse_string(text, fmt)[source]

Parse text of the given format into a list[BooleanNode].

Parameters:
  • text (str)

  • fmt (str)

Submodules