booldog.io

Read Boolean or regulatory networks from various formats.

Submodules

Attributes

logger

Classes

BoolDogModelIOFromMixin

Mixin providing BoolDogModel.from_XXX constructors

BoolDogModelIOToMixin

Mixin providing to_XXX export methods for supported Boolean / regulatory network formats.

Functions

booldog2networkx(model[, as_logic_circuit])

Export a BoolDog Boolean model to Networkx DiGraph

booldog2igraph(model[, as_logic_circuit])

Export a BoolDog Boolean model to an igraph graph object.

booldog2cytoscape(model[, as_logic_circuit, title, ...])

Display a BoolDog Boolean model in Cytoscape.

read_bnet(bnet[, node_names])

Generate a BoolDogModel object from a Boolean network in boolnet

write_bnet(model[, outfile, from_primes, header, minimize])

Write a BoolDogModel object to a Boolean network in boolnet (bnet) format.

read_sif(file[, delim, source_col, target_col, ...])

Reads in a SIF file of interactions

read_graphml(file[, edge_type_key, node_id_key, ...])

Extract relavent parts for a Boolean network from a graphml file.

read_igraph(g[, node_id_key, edge_type_key, node_name_key])

Create BooleanNetwork from a igraph Graph object.

read_networkx(g[, edge_type_key, node_name_key])

Create BooleanNetwork from a networkx (Di)Graph object.

read_interactions(interactions_input[, node_names])

Create Network from interactions (list)

read_sbmlqual(file)

Create Network from a SBML-qual file

write_sbmlqual(model, outfile, **kwargs)

read_primes(primes_input)

Read primes from a dictionary or a json file

write_primes(network, outfile)

Save primes as formatted JSON file.

read_tabularqual(model_path)

Read a TabularQual file and return a BoolDogModel.

file_writable(path)

Checks if path is writeable. If not, attempts to provide reason, and raises

Package Contents

booldog.io.booldog2networkx(model, as_logic_circuit=True)

Export a BoolDog Boolean model to Networkx DiGraph

Parameters:
  • model (booldog:BoolDogModel) – A BoolDog object representing a Boolean network.

  • as_logic_circuit (bool) – If True, the graph is exported as a logic circuit (Boolean rules are represented as “logical” nodes (and, or, not) and edges. Otherwise, it is exported as a directed interaction graph. Default is False.

Returns:

graph – A networkx graph with the same nodes as the input network. If as_logic_circuit is True, Boolean rules are represented as “logical” nodes (and, or, not) and edges.

Return type:

networkx.DiGraph

Notes

See also pyboolnet.interaction_graphs.primes2igraph.

booldog.io.booldog2igraph(model, as_logic_circuit=True)

Export a BoolDog Boolean model to an igraph graph object.

Parameters:
  • model (booldog:BoolDogModel) – A BoolDog object representing a Boolean network.

  • as_logic_circuit (bool) – If True, the graph is exported as a logic circuit (Boolean rules are represented as “logical” nodes (and, or, not) and edges. Otherwise, it is exported as a directed interaction graph. Default is False.

Returns:

graph – A igraph.Graph object with the same nodes as the input network. If as_logic_circuit is True, Boolean rules are represented as “logical” nodes (and, or, not) and edges.

Return type:

igraph.Graph

Notes

See also pyboolnet.interaction_graphs.primes2igraph.

Implemented via conversion to Networkx DiGraph, then to igraph Graph, to reuse pyboolet function and logic circuits code.

booldog.io.booldog2cytoscape(model, as_logic_circuit=False, title=None, collection='Booldog Network', layout=None, style=None)

Display a BoolDog Boolean model in Cytoscape.

Parameters:
  • model (booldog:BoolDogModel) – A BoolDog object representing a Boolean network.

  • as_logic_circuit (bool) – If True, the graph is exported as a logic circuit (Boolean rules are represented as “logical” nodes (and, or, not) and edges. Otherwise, it is exported as a interaction graph. Default is False.

  • title (str or None) – The title of the Cytoscape network. Default is ‘{model_id} interaction network’ if as_logic_circuit is False and ‘{model_id} logic circuit’ else.

  • collection (str) – The name of the Cytoscape collection to add the network to. Default is “Booldog Network”.

  • layout (str or None) – The name of the Cytoscape layout to apply to the network. Default is None (no layout).

  • style (str or None) – The name of the Cytoscape visual style to apply to the network. If None, a default style will be applied. Default is None.

Returns:

suid – The SUID of the created Cytoscape network.

Return type:

int

booldog.io.read_bnet(bnet, node_names=None)

Generate a BoolDogModel object from a Boolean network in boolnet (bnet) format.

For complete documentation, see file_exchange.

Parameters:

file (str) – Path to the bnet file

Returns:

rn – An object of type py:class:BoolDogModel.

Return type:

BoolDog

Notes

The format of the output file is described at boolnet_format.

booldog.io.write_bnet(model, outfile=None, from_primes=False, header=True, minimize=False)

Write a BoolDogModel object to a Boolean network in boolnet (bnet) format.

Parameters:
  • model (BoolDogModel) – A BoolDog object representing a Boolean network.

  • outfile (str) – Path to the output file. If None, the output is returned as a string.

  • from_primes (bool, default False) – If True, rules are obtained by converting prime implicants to bnet format. Otherwise, node rules are written directly.

  • header (bool, default True) – If True, include a header line (“target, factors”).

  • minimize (bool, default False) – If True, minimize rules when converting from primes. Only relevant if from_primes is True.

Returns:

Returns the bnet string if outfile is None, otherwise None.

Return type:

str or None

Notes

The output file will be overwritten if it already exists.

The format of the output file is described at boolnet_format.

booldog.io.read_sif(file, delim='\t', source_col=0, target_col=1, interaction_col=2, header=True, **kwargs)

Reads in a SIF file of interactions

Parameters:
  • file (str) – Path to the SIF file

  • delim (str, optional) – Delimiter used in the SIF file (default=” “)

  • header (bool, optional) – If the first line of the file is a header (default=True)

  • source_col (int or str, optional) – Column index (if int) or column name (if str) of source node (default=0)

  • target_col (int or str, optional) – Column index (if int) or column name (if str) of target node (default=1)

  • interaction_col (int, optional) – Column index (if int) or column name (if str) of interaction type (symbol) (default=2)

  • activator_symbol (str, optional) – Symbol of activation edges in interaction_col (default=”1”)

  • inhibitor_symbol (str, optional) – Symbol of inhibition edges in interaction_col (default=”-1”)

  • **kwargs (dict) – Additional keyword arguments (ignored).

Notes

Uses SQUAD logic to obtain Boolean network.

booldog.io.read_graphml(file, edge_type_key='interaction', node_id_key='name', node_name_key='name', yEd_labels=False, yEd_arrow_head=False, use_labels=True, **kwargs)

Extract relavent parts for a Boolean network from a graphml file.

Since graphml is not well defined for Boolean networks (or even standard for interaction networks), this read functionality has limited support.

Parameters:
  • file (str) – Path to the graphml file

  • edge_type_key (str, optional) – The edge attribute key to use for interaction type (e.g., weight, type). Default is “interaction”. Only if yEd=False (yEd uses the arrow head symbol).

  • node_id_key (str, optional) – The vertex attribute key that contains the primary identifier to use for node names. Default is “name”.

  • node_name_key (str, optional) – The vertex attribute key that contains the node name (e.g. display label). Default is “name”.

  • yEd_labels (bool, optional) – If graphml file originates as a yEd export, the node attribute “y:NodeLabel” is used to determine node names (default=False)

  • yEd_arrow_head (bool, optional) – If graphml file originates as a yEd export, the edge attribute “y:Arrows” is used to determine interaction type (default=False)

  • activator_symbol (int or str, optional) – Symbol or value of activation edges. If yEd=True, default=”standard”, else default is 1.

  • inhibitor_symbol (int or str, optional) – Symbol or value of inhibition edges. If yEd=True, default=”t_shape”, else default is -1.

Returns:

n – A BoolDogModel object representing the Boolean network.

Return type:

booldog.BoolDogModel

Notes

Uses igraph to parse the graphml file, and extracts node and edge attributes to determine interactions.

If yEd_label=True, it also parses the yEd-specific attributes to extract node labels (y:NodeLabel) for node names.

If yEd_arrow_head=True, it parses the yEd-specific edge arrow types (arrow head symbols of y:Arrows) to determine interaction types (activation/inhibition).

booldog.io.read_igraph(g, node_id_key='name', edge_type_key='interaction', node_name_key='name', **kwargs)

Create BooleanNetwork from a igraph Graph object.

Parameters:
  • g (igraph.Graph) – The input graph object from the igraph library.

  • node_id_key (str, optional) – The vertex attribute key that contains the primary identifier to use for node names. Default is “name”.

  • node_name_key (str, optional) – The vertex attribute key that contains the node name (e.g. display label). Default is “name”.

  • edge_type_key (str, optional) – The edge attribute key to use for interaction values (e.g., weight, type). Default is “interaction”.

  • activator_symbol (str, optional) – Symbol or value of activation edges in edge_type_key of g (default=”1”)

  • inhibitor_symbol (str, optional) – Symbol or value of inhibition edges in edge_type_key of g (default=”-1”)

  • **kwargs (dict) – Additional keyword arguments (ignored).

Notes

Uses SQUAD logic to obtain Boolean network.

booldog.io.read_networkx(g, edge_type_key='interaction', node_name_key='name', **kwargs)

Create BooleanNetwork from a networkx (Di)Graph object.

Parameters:
  • g (networkx.(Di)Graph) – The input graph object from the networkx library.

  • edge_type_key (str, optional) – The edge attribute key to use for interaction values (e.g., weight, type). Default is “interaction”.

  • activator_symbol (str, optional) – Symbol or value of activation edges in edge_type_key of g (default=”1”)

  • inhibitor_symbol (str, optional) – Symbol or value of inhibition edges in edge_type_key of g (default=”-1”)

  • node_name_key (str, optional) – The vertex attribute key that contains the node name (display label). Default is “name”.

  • **kwargs (dict) – Additional keyword arguments (ignored).

Returns:

n – A BoolDogModel object representing the Boolean network.

Return type:

booldog.BoolDogModel

Notes

Uses SQUAD logic to obtain Boolean network.

booldog.io.read_interactions(interactions_input, node_names=None, **kwargs)

Create Network from interactions (list)

Parameters:
  • interactions_input (list or str) – 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. Or a path to a JSON file containing such a list of interactions.

  • 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.

  • **kwargs (dict) – Additional keyword arguments (ignored).

Returns:

n – A BoolDogModel object representing the Boolean network.

Return type:

booldog.BoolDogModel

Notes

Uses SQUAD logic to obtain Boolean network.

booldog.io.read_sbmlqual(file)

Create Network from a SBML-qual file

Parameters:

file (str) – Path to SBML-qual file.

Notes

The SBML-qual file is converted to a Boolean network using libsbml, via the bnet format. To access the bnet format directly, you can use py:booldog.io.sbmlqual2bnet.

booldog.io.write_sbmlqual(model, outfile, **kwargs)
booldog.io.read_primes(primes_input)

Read primes from a dictionary or a json file

Parameters:

primes_input (str or dict) – Dictionary of primes, or a file path to primes saved in JSON format.

Returns:

rn – A BoolDog BoolDogModel object.

Return type:

:py:class:BoolDogModel

booldog.io.write_primes(network, outfile)

Save primes as formatted JSON file. See also pyboolnet.file_exchange.write_primes.

Parameters:

outfile (Path) – File name/path to write primes to.

booldog.io.read_tabularqual(model_path)

Read a TabularQual file and return a BoolDogModel.

Parameters:

model_path (str) – Path to the TabularQual file.

Returns:

The BoolDogModel generated from the TabularQual file.

Return type:

BoolDogModel

booldog.io.file_writable(path)

Checks if path is writeable. If not, attempts to provide reason, and raises an Exception.

Parameters:

path (str or Path) – Path to file to check for writability. If the file does not exist, the function will check if it can be created.

Return type:

None

booldog.io.logger
class booldog.io.BoolDogModelIOFromMixin

Mixin providing BoolDogModel.from_XXX constructors for supported Boolean / regulatory network formats.

classmethod _from_reader(reader, *args, **kwargs)

Generic constructor wrapper around a reader function.

Reader functions should take *args and **kwargs as input and return a dictionary of “nodes”, “modelinfo” and “primes” (primes and modelinfo are optional, but “nodes” is required).

classmethod from_bnet(*args, **kwargs)

Create model from BoolNet .bnet format.

classmethod from_primes(*args, **kwargs)

Create model from prime implicants format.

classmethod from_sbmlqual(*args, **kwargs)

Create model from SBML-qual file.

classmethod from_tabularqual(*args, **kwargs)

Create model from tabular-qual format.

classmethod from_interactions(*args, **kwargs)

Create model from generic interaction table.

classmethod from_sif(*args, **kwargs)

Create model from SIF interaction network.

classmethod from_networkx(*args, **kwargs)

Create model from networkx graph.

classmethod from_igraph(*args, **kwargs)

Create model from igraph object or file.

classmethod from_graphml(*args, **kwargs)

Create model from GraphML file.

class booldog.io.BoolDogModelIOToMixin

Mixin providing to_XXX export methods for supported Boolean / regulatory network formats.

classmethod _to_writer(writer, *args, **kwargs)

Generic constructor wrapper around a writer function.

Writer functions should take *args and **kwargs as input and return a string or write to a file. The first argument should always be the model instance (self). An optional keyword argument “outfile” can be used to specify an output file path.

This constructor presents a consistent interface for exporting models to various formats, and centralizes any common logic needed.

to_bnet(*args, **kwargs)

Export model to BoolNet .bnet format.

to_primes(*args, **kwargs)

Export model to prime implicants format.

to_sbmlqual(*args, **kwargs)

Export model to SBML-qual file.

to_networkx(*args, **kwargs)

Export model to Networkx DiGraph

to_igraph(*args, **kwargs)

Export model to igraph Graph.

to_cytoscape(*args, **kwargs)

Export model to Cytoscape (via py4cytoscape).