BNMPy.model_parser¶
The model_parser module provides functions for merging, converting, and extending Boolean and Probabilistic Boolean Networks.
- BNMPy.model_parser.simplify_expression(expression)[source]¶
Simplifies the Boolean expression by removing redundant parentheses using boolean.py package.
- Parameters:
expression – The Boolean expression as a string.
- Returns:
The simplified expression.
- BNMPy.model_parser.parse_expression(expression: str)[source]¶
Parses a Boolean expression to separate activators and inhibitors.
- BNMPy.model_parser.check_inhibitor_wins_rule(expression)[source]¶
Ensures that the “Inhibitor Wins” rule is respected within a single expression.
- BNMPy.model_parser.merge_networks(BNs, method='OR', prob=0.9, descriptive=False)[source]¶
Merge multiple Boolean-network models using one of four strategies.
- Parameters:
- BNslist[BooleanNetwork]
List of Boolean-network objects
- method{“OR”, “AND”, “Inhibitor Wins”, “PBN”}
Merge strategy.
- probfloat, default 0.9
Only used for PBN. Probability given to equations from the first model
- descriptivebool, default False
If True, prints a human-readable merge log.
- Returns:
- str
A newline-separated network definition string suitable for writing to file. • deterministic modes: gene = Boolean-expression • PBN mode: gene = expr1, p1
gene = expr2, p2 … (one line per rule)
- BNMPy.model_parser.BN2PBN(bn_string, prob=0.5, fixed_nodes=None)[source]¶
Expand the boolean network to a PBN by adding a self-loop as alternative function prob: probability of the equations from the original BN fixed_nodes: list of nodes that are fixed (e.g., output nodes)
- Returns:
pbn_string: string of the PBN nodes_to_optimize: list of nodes excludes input nodes
- BNMPy.model_parser.extend_networks(original_network, new_network, nodes_to_extend, prob=0.5, descriptive=True)[source]¶
Extend the original network by adding the nodes_to_extend (and their rules) from the new network. This will return a PBN where: - rules for the nodes_to_extend are added to the original network with a probability of prob. - rules for the nodes_to_extend from the original network will have a probability of 1-prob. - in case the new rules for nodes_to_extend include new nodes, they will also be added with a probability of 1. - The direct targets of nodes_to_extend are also extended with both rules and probabilities. - The rest of the rules are kept the same with a probability of 1.
Key Functions¶
merge_networks¶
Merge multiple Boolean Networks or convert them to Probabilistic Boolean Networks.
- BNMPy.model_parser.merge_networks(BNs, method='OR', prob=0.9, descriptive=False)[source]¶
Merge multiple Boolean-network models using one of four strategies.
- Parameters:
- BNslist[BooleanNetwork]
List of Boolean-network objects
- method{“OR”, “AND”, “Inhibitor Wins”, “PBN”}
Merge strategy.
- probfloat, default 0.9
Only used for PBN. Probability given to equations from the first model
- descriptivebool, default False
If True, prints a human-readable merge log.
- Returns:
- str
A newline-separated network definition string suitable for writing to file. • deterministic modes: gene = Boolean-expression • PBN mode: gene = expr1, p1
gene = expr2, p2 … (one line per rule)
BN2PBN¶
Convert a Boolean Network to a Probabilistic Boolean Network by adding a self-loop as alternative function.
- BNMPy.model_parser.BN2PBN(bn_string, prob=0.5, fixed_nodes=None)[source]¶
Expand the boolean network to a PBN by adding a self-loop as alternative function prob: probability of the equations from the original BN fixed_nodes: list of nodes that are fixed (e.g., output nodes)
- Returns:
pbn_string: string of the PBN nodes_to_optimize: list of nodes excludes input nodes
extend_networks¶
Extend an existing Boolean Network by adding nodes and rules informed by a Knowledge Graph.
- BNMPy.model_parser.extend_networks(original_network, new_network, nodes_to_extend, prob=0.5, descriptive=True)[source]¶
Extend the original network by adding the nodes_to_extend (and their rules) from the new network. This will return a PBN where: - rules for the nodes_to_extend are added to the original network with a probability of prob. - rules for the nodes_to_extend from the original network will have a probability of 1-prob. - in case the new rules for nodes_to_extend include new nodes, they will also be added with a probability of 1. - The direct targets of nodes_to_extend are also extended with both rules and probabilities. - The rest of the rules are kept the same with a probability of 1.
Example Usage¶
Merging Networks¶
import BNMPy
# Load two networks
network1 = BNMPy.load_network_from_file("network1.txt")
network2 = BNMPy.load_network_from_file("network2.txt")
# Merge into a single Boolean Network
merged_bn = BNMPy.merge_networks([network1, network2], output_type='BN')
# Or merge into a Probabilistic Boolean Network
merged_pbn = BNMPy.merge_networks([network1, network2], output_type='PBN')
Converting BN to PBN¶
import BNMPy
# Load a Boolean Network
bn = BNMPy.load_network_from_file("network.txt")
# Convert to PBN with equal probabilities for existing rules and a self-loop
pbn = BNMPy.BN2PBN(bn, prob=0.5)
Extending Networks¶
import BNMPy
# Load original network and KG-derived network
original_bn = BNMPy.load_network_from_file("original.txt")
kg_network = BNMPy.load_signor_network(gene_list=['GENE1', 'GENE2'])
# Extend original network with KG information
extended_pbn = BNMPy.extend_networks(
original_bn,
kg_network,
nodes_to_extend=['GENE1', 'GENE2'],
prob=0.5, # probability of the rules from the KG
descriptive=True
)