pybool package

Submodules

pybool.analysis module

Code to analyse the consistent networks.

pybool.analysis.aggregate_possible_inputs(meta_data, networks)

Aggregate the possible input parameters.

pybool.analysis.aggregate_possible_regulations(meta_data, networks)

Aggregate the possible regulatory relationships in the networks.

pybool.analysis.aggregate_possible_thetas(meta_data, networks)

Aggregate the possible theta parameters.

pybool.analysis.analyse_dependencies(networks)

Analyse the dependencies between pairs of network features.

pybool.analysis.count_possible_inputs(meta_data, networks)

Count how often each possible input parameters occurs.

pybool.analysis.count_possible_regulations(meta_data, networks)

Count the possible regulatory relationships in the networks.

pybool.analysis.count_possible_thetas(meta_data, networks)

Count the possible theta parameters.

pybool.chow_liu_trees module

Chow-Liu Trees

Chow-Liu trees were originally defined in Chow, C. K.; Liu, C. N. (1968), “Approximating discrete probability distributions with dependence trees”, IEEE Transactions on Information Theory IT-14 (3): 462-467.

In this module, each data point is presented as a sequence of discrete-valued features. For example suppose we have data, X = {X}, where each x has n=4 features.

>>> X = [
...     'AACC',
...     'AAGC',
...     'AAGC',
...     'GCTC',
...     'ACTC',
... ]
>>> n = len(X[0])

We can calculate the marginal distribution of each feature

>>> import pybool.chow_liu_trees as CLT
>>> for u in xrange(n):
...     print CLT.marginal_distribution(X, u)
defaultdict(<type 'float'>, {'A': 0.80000000000000004, 'G': 0.20000000000000001})
defaultdict(<type 'float'>, {'A': 0.60000000000000009, 'C': 0.40000000000000002})
defaultdict(<type 'float'>, {'C': 0.20000000000000001, 'T': 0.40000000000000002, 'G': 0.40000000000000002})
defaultdict(<type 'float'>, {'C': 1.0})

and also the marginal distribution of a pair of features

>>> print CLT.marginal_pair_distribution(X, 0, 1)
defaultdict(<type 'float'>, {('A', 'A'): 0.60000000000000009, ('G', 'C'): 0.20000000000000001, ('A', 'C'): 0.20000000000000001})
>>> print CLT.marginal_pair_distribution(X, 1, 2)
defaultdict(<type 'float'>, {('A', 'G'): 0.40000000000000002, ('C', 'T'): 0.40000000000000002, ('A', 'C'): 0.20000000000000001})

We can calculate the mutual infomation between all pairs of features

>>> for v in xrange(n):
...     for u in xrange(v):
...         print u, v, CLT.calculate_mutual_information(X, u, v)
0 1 0.223143551314
0 2 0.223143551314
1 2 0.673011667009
0 3 0.0
1 3 0.0
2 3 0.0

Finally we can build a Chow-Liu tree

>>> T = CLT.build_chow_liu_tree(X, n)
>>> print T.edges(data=True)
[(0, 1, {'weight': -0.22314355131420974}), (0, 3, {'weight': -0}), (1, 2, {'weight': -0.6730116670092563})]
pybool.chow_liu_trees.build_chow_liu_tree(X, n)

Build a Chow-Liu tree from the data, X. n is the number of features. The weight on each edge is the negative of the mutual information between those features. The tree is returned as a networkx object.

pybool.chow_liu_trees.calculate_mutual_information(X, u, v)

X are the data points. u and v are the indices of the features to calculate the mutual information for.

pybool.chow_liu_trees.marginal_distribution(X, u)

Return the marginal distribution for the u’th features of the data points, X.

pybool.chow_liu_trees.marginal_pair_distribution(X, u, v)

Return the marginal distribution for the u’th and v’th features of the data points, X.

pybool.constraints module

Code to help implement constraints in Boolean networks.

pybool.constraints.CHECK_ALL_DIFFERENT = 2

Check each pair on genes in the list have different on/off patterns.

pybool.constraints.CHECK_CONSECUTIVE_DIFFERENT = 1

Check that no consecutive genes in the list have the same on/off pattern.

pybool.constraints.CHECK_DIFFERENT = 0

Check that two genes do not have the same on/off pattern.

pybool.constraints.CHECK_EXPRESSES_BEFORE = 3

Check the first gene expresses before the second.

pybool.constraints.CHECK_NULL_EXPRESSION = 5

Check there is no expression for the given gene.

pybool.constraints.CHECK_OFF_TO_ON_SWITCH = 7

Check that the gene starts off, switches on and remains on.

pybool.constraints.CHECK_ON_TO_OFF_SWITCH = 6

Check that the gene starts on, switches off and remains off.

pybool.constraints.CHECK_ORDER_OF_EXPRESSION = 4

Check the genes in the list are expressed in the same order they are given.

class pybool.constraints.ChangePointChecker(R)

Bases: object

Given a set of change points, offers various functions to check that genes are going on and off in the correct temporal order.

R = None

Realisation.

check_all_different(genes)

Check that no genes in the list have the same on/off pattern.

check_consecutive_different(genes)

Check that no consecutive genes in the list have the same on/off pattern.

check_different(g1, g2)

Check that gene1 and gene2 do not have the same on/off pattern.

check_expresses_before(g1, g2)

Check gene1 is expressed before gene2.

check_null_expression(g)

Check there is no expression for the given gene.

check_off_to_on_switch(g)

Check that the gene starts off, switches on and remains on.

check_on_to_off_switch(g)

Check that the gene starts on, switches off and remains off.

check_order_of_expression(genes)

Check the genes in the list are expressed in order.

cp = None

Change points for a realisation.

class pybool.constraints.Condition

Bases: tuple

Condition(name, inputs, constraints, merged_inputs)

constraints None

Alias for field number 2

inputs None

Alias for field number 1

merged_inputs None

Alias for field number 3

name None

Alias for field number 0

class pybool.constraints.Gene

Bases: tuple

Gene(name, color, position)

color None

Alias for field number 1

name None

Alias for field number 0

position None

Alias for field number 2

class pybool.constraints.MetaData(allow_X=True)

Bases: object

Base meta-data functionality for regulatory networks.

G None
add_condition(name, inputs, constraints)

Add a condition to the network.

add_external_input(name, color, position, input_function, input_params=(None, ))

Add an external input gene to the network.

add_gene(name, color, position, initial_state, constitutive)

Add a non-external input gene to the network.

pybool.constraints.combinations(iterable, r)

combinations(‘ABCD’, 2) –> AB AC AD BC BD CD combinations(range(4), 3) –> 012 013 023 123

pybool.constraints.combine(c1, c2, union=True)

Take 2 constraints and combine them. If union is False, then take the intersection.

pybool.constraints.consecutive(iterable)

@return: Yield consecutive items from the iterable as a tuple.

pybool.constraints.gene_off(t, p)

External input function to turn a gene off.

pybool.constraints.gene_on(t, p)

External input function to turn a gene on.

pybool.io module

I/O for boolean regulatory networks.

class pybool.io.GraphBuilder(meta_data, options)

Bases: object

Builds graphs representing the information in the meta data.

add_edge(src, dst, activatory)
class pybool.io.NetworkXGraphBuilder(meta_data, options)

Bases: object

Builds graphs representing the information in the meta data using Python package networkx.

add_edge(src, dst, activatory, dashed)
pybool.io.add_gene_headers_to_matrix(genes, matrix, width=5)

Takes a matrix and creates a new one with headers for rows and columns.

pybool.io.centre_string(s, width)

Pad and centre a string to the given width.

pybool.io.configure_matplotlib_for_tex()

Set up matplotlib parameters for plotting using TeX.

pybool.io.ensure_dir_exists(dir)

Make sure a directory exists, making it and its parents if necessary.

pybool.io.graph_network(net, options)

Create a BGL graph of the network.

pybool.io.graph_restrictions(meta_data, options, possible_Js=None)

Create a BGL graph of the possible networks.

pybool.io.output_file(options, filename)

Return a path to the named output file.

pybool.io.plot_network_realisation(net, X, xlabel=False, ylabel=False)

Plot the realisation of the network.

pybool.io.plot_network_realisations(*args, **kwds)

Plot the network realisations over all the conditions.

pybool.io.regulation_as_str(r)

Convert a regulatory value to a string.

pybool.io.regulatory_matrix_as_string(possible_regulations)
pybool.io.rgb_as_string(rgb)

@return: A string representing the rgb colour.

pybool.io.summarise_meta_data(meta_data)

Log some information about the network constraint meta data.

pybool.io.summarise_possible_networks(meta_data, networks)

Log some information about the possible networks.

pybool.io.write_graph(graph, name, options)

Write the graph as a DOT file and a SVG file.

pybool.network module

Code to describe and generate boolean networks.

class pybool.network.BooleanNetwork(meta_data)

Bases: object

A boolean regulatory network.

J = None

The regulatory connections.

execute_time_step(net, X, t, external_inputs, result)
generate_realisation(condition=None, X=None)

Generate an entire realisation of the network.

input_parameters = None

Parameters for external inputs.

meta_data = None

Meta-data for this type of network.

theta = None

The constitutive (default) gene states.

class pybool.network.BooleanNetworkGenerator(meta_data)

Bases: object

Generates boolean networks with all possible parameters.

pybool.network.c_calculate_change_points(X)
pybool.network.c_execute_time_step(net, X, t, external_inputs, result)
pybool.network.calculate_change_points(X)
pybool.network.calculate_gene_change_points(X)

Inspect the expression of a gene to find when it turns off and on.

pybool.network.combinations(possible_values, X=None)

Yield each possible combination of the values given.

@arg possible_values: Should be a sequence of sequences of possible values. @arg X: Object to store combinations in. If not given, a numpy array is used.

For example:

>>> possible_values = (
...     (-5, 0, 1),
...     (0, 1),
... )
>>> for X in combinations(possible_values):
...     print X
[-5  0]
[0 0]
[1 0]
[-5  1]
[0 1]
[1 1]
pybool.network.evaluate_all_conditions(net)

Evaluate the network under all the conditions until one does not match.

@return: The first condition that does not match (or None) and the number of mismatches as a tuple.

pybool.network.evaluate_condition(net, condition, X=None)

Evaluate the network under one condition.

pybool.network.feature_string(feature)
pybool.network.filter_unique_Js(iterable)

Filter those networks from the iterable that have the same J.

pybool.network.network_to_features(network)

Maps the features of a network (theta, J, input parameters) into a sequence.

pybool.network.number_possible_combinations(possible_values)

@return: The number of possible combinations of the values.

pybool.network.py_execute_time_step(self, X, t, external_inputs, result)

Use the current values of gene expression, X, to calculate the values at the next time point.

pybool.network.which_network_feature(meta_data, u)

Identifies which feature in the network u refers to.

Module contents

pybool: A python package that infers Boolean networks given a set of constraints.

Consider the common scenario of a biologist who is studying a particular regulatory network. They study a set of genes that are known to play a role in the network. They have some background knowledge of particular regulatory connections from his own studies or from the literature. In addition to this they have perturbation data that reveals the temporal order of expression of the genes under some conditions. For example, these could be derived from loss-of-function or over-expression experiments. The biologist would like to elucidate the entire network and to this end can perform various experiments to test particular regulatory connections. These experiments are costly and time-consuming. Which connections should they focus on? This is where the pybool package can help. By modelling candidate regulatory networks using Boolean logic, pybool evaluates which networks are consistent with the perturbation data and the known regulatory connections.

pybool.version_string()

Return the release and svn revision as a string.