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_typetoto_typevia a node list.Extra
kwargsare forwarded to the destination exporter (e.g.adjust_no_input/one_symbol_schematafor 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
kwargsare forwarded to format-specific exporters (e.g.adjust_no_inputfor cnet,warnfor expression formats).- Parameters:
nodes (Sequence[BooleanNode])
fmt (str)
kwargs (Any)
- 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
Noneif 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:
nodes (Sequence[BooleanNode])
warn (bool)
- Return type:
str
- cana.io.nodes_to_bnet(nodes, *, warn=True)[source]
Export a node list to BoolNet
targets,factorstext.Prefers stored expression, then one-symbol schemata, then LUT DNF. Soft-warns when verification flags are not
True(never blocks).- Parameters:
nodes (Sequence[BooleanNode])
warn (bool)
- 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:
nodes (Sequence[BooleanNode])
warn (bool)
- 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
.cnettext.- 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**kLUT rows.
- Return type:
str
Dense export materializes
bit_lutviaBooleanFunction.get_bit_lut()when only expression/schemata are present. Schemata export materializesone_symbol_schematasimilarly. If a representation cannot be derived, raisesValueError.
- 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:
nodes (Sequence[BooleanNode])
warn (bool)
- Return type:
str
- cana.io.bit_lut_to_expression(input_names, lut, style='python')[source]
Build a DNF expression for a
BitLutusinginput_names.Positional vs named is chosen by
input_names: passpositional_names()(k)for positional IR, or input names for a named expression. Callers with a plain 0/1 sequence should convert viaBitLut.from_sequence()first.- Parameters:
input_names (Sequence[str]) – Input variable names in LUT bit order (MSB first).
lut (BitLut) – Dense truth table (
lut.kmust equallen(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/notor&/|/!.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"(forpositional_expression_to_bit_lut()/named_expression_to_bit_lut()) or"symbolic".
- Return type:
str
- cana.io.parse_aeon(text)[source]
Parse AEON
*.aeoninto a node list.- Parameters:
text (str)
- Return type:
List[BooleanNode]
- cana.io.parse_aeon_update_rule(line)[source]
Parse one
$var: named_expressionline, orNoneif 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
*.bnetinto a node list.- Parameters:
text (str)
- Return type:
List[BooleanNode]
- cana.io.parse_bnet_update_rule(line)[source]
Parse one
target, named_expressionline, orNoneif not a rule.Skips blanks, comments, and the
targets,factorsheader.- Parameters:
line (str)
- Return type:
Tuple[str, str] | None
- cana.io.parse_booleannet(text)[source]
Parse BooleanNet /
*.booleannet.txtrules into a node list.- Parameters:
text (str)
- Return type:
List[BooleanNode]
- cana.io.parse_booleannet_update_rule(line)[source]
Parse one
name* = named_expressionline, orNoneif not a rule.- Parameters:
line (str)
- Return type:
Tuple[str, str] | None
- cana.io.parse_cnet(text)[source]
Parse BNS / Cell Collective
.cnettext 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 asone_symbol_schemataonly; otherwise import as a densebit_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
textof the given format into alist[BooleanNode].- Parameters:
text (str)
fmt (str)