phievo package

Networks module

classes_eds2

Defines the main class used to describe the evolved networks The class hierarchy is the following:

Network

Types: Should be just the class, but for Species we have mutliple types (eg TF, Complex, Kinase, Phosphatase, Input, Output), several of which can apply at once, so the class defn in python not general enough.

IO: species of type = ‘Input’ has a defined time course supplied within the integrator.c. Type = ‘Output’ are the species whos time course is used by the fitness function, they are numbered and created as genes ie with TModule and CorePromoter nodes attached to them.

Grammar: the rules as for what can interact with what, depends on the type of interaction and the types of inputs and outputs. All the data for checking grammar given in the class defn of interaction. The grammar also enters the function, Network.remove_Node().

Class Network: defines a bipartite graphs with adjacent nodes either ‘physical-objects, segments of the genome (eg Species or TModule) or interactions. Network class then has lots of methods to add and remove nodes and edges, check the grammar rules, and output the network either as C-code or as dot diagram .

Caps: Classes begin as caps, abbreviations eg TF in CAPS. Functions within classes lc, ‘_’ to separate names, retain Caps for embedded class names.

Arguments to functions are in order implied by directed graph, eg check_grammar( nodes_in, node_tested, nodes_out) add_interaction( upstream_species, interaction, downstream species)


class phievo.Networks.classes_eds2.Interaction

Bases: phievo.Networks.classes_eds2.Node

Interaction class derived from Node, defines interaction between Species or TModule

check_grammar(input_list, output_list)

checks the grammar for the interactions

Parameters:
  • input_list (list) – nodes to be checked
  • output_list (list) – nodes to be checked
Returns:

Boolean for the consistency of up and downstream grammar

class phievo.Networks.classes_eds2.Network

Bases: object

Complete description of a network of interactions.

It is represented as a bipartite graph between the biochemical species and the interactions. The very description is stored in the graph attribute.

Note that each interaction import add new methods to the Network class.

graph

networkx.MultiDiGraph – the network properly speaking

order_node

int – index to keep track of the order of the nodes

dict_types

dict – a dictionary indicating the Nodes of a given type (types are the keys)

hash_topology

int – to index the topologies (see __hash_net_topology__)

title

str – for graphing network and to hold misc info

Cseed

int – random seed for the integration in C

remove_output_when_duplicate

bool – if you want to remove Output tag when duplicating genes

activator_required

bool – if an activator is required to get any gene product

fixed_activity_for_TF

bool – if a TF either an activator or repressor (if False, they can do both)

Main functions:
add_* methods just add objects to the graph new_* create and add objects (usually by calling add_* method)
add_CorePromoter2Species(inter, output)

Add a CorePromoter Interaction and its output to the network

Parameters:
  • inter (CorePromoter) – the CorePromoter to be added
  • output (Species) – the CorePromoter output
add_Node(node)

add_node to graph unless already present

Parameters:node (Node) – The node to be added
Returns:boolean indicating if the node has effectively been added
add_TFHill(tf, inter, module)

Add a TF, a TModule and a TFHill interaction to the network

Parameters:
  • tf (Species) – with the ‘TF’ tag
  • inter (TFHill) – will link tf and module
  • module (TModule) – TModule to link the TFHill to
add_TModule2CorePromoter(module, inter)

Add a CorePromoter Interaction and its TModule to the network

Parameters:
  • module (TModule) – the CorePromoter module
  • inter (CorePromoter) – the CorePromoter to be added
catal_data(interaction)

Find the reactants, catalysors, products for a catalytic interaction

Parameters:interaction – the Interaction you are interested in
Returns:list of the form [catalyst,reactants,products]
check_Node(node, list_nodes_loop)

Check if a Node can be removed from the network

Delegate to Node.isremovable check if node is not an input/output or a node uniquely and directly upstream of a nonremovable species (eg part of output gene)

Parameters:
  • node (Node) – the node to be checked
  • list_node_loops (list) – to handle non tree like network

Return: Boolean indicates if node can be safely removed

check_existing_Degradation(i1, i2)

Check if a Degradation exists between species i1 and i2

Parameters:
  • i1 (Species) – the ‘enzyme’
  • i2 (Species) – the species degraded
Returns:

True if i1 is known to degrade i2

check_existing_Phosphorylation(signature)

check if a particular phosphorylation exists in the network

Parameters:signature (list) – The signature of the phospho in the form [Kinase,Input]

Return: True if this phosphorylation exist

check_existing_binary(list, Type)

Check if a specific binary interaction of type Type already exists

typically used for PPI

Parameters:
  • list (list) – the reactants (Nodes) you are looking for
  • Type (str) – the type of Interaction you are looking for

Return: bool

Check if a specific interaction of type Type already exists between the elements of list

Parameters:
  • list (list) – the reactant/product couple (Nodes) you are looking for
  • Type (str) – the type of Interaction you are looking for

Return: bool

clean_Nodes(verbose=False)

remove nodes from the network until all nodes pass the check_grammar test

Parameters:verbose (bool) – Flag to activate the prolix mode

Return: Boolean indicating the completion of the process

Delete any node with incorrect grammar until all remaining nodes pass test Currently implemented to check grammar on interaction nodes only, thus need remove_Node function that kills species and other phys objects that are not defined in absence of interaction

delete_clean(id, target='interaction', verbose=False)

Remove a node according to its id and clean the network Warning: This operation renames all the nodes (and changes the id)

Parameters:
  • id – integer id of the node
  • target – string either interaction or species, the type of the node to delete
draw(file=None, edgeLegend=False, extended=False, display=True, return_graph=False)

Draw the network in a matplotlib framework

Delegate to pretty_graph

Parameters:
  • file (str) – save the picture in file, or print it on screen if file is None
  • edgeLegend (bool) – Label the graph edges
  • extended (bool) – Display inner modules (ex: TModules)
  • display (bool) – Display the figure
  • return_graph (bool) – Returns a graph object rather than a figure

Examples

my_Network.draw(‘my_lovely_network.pdf’)

duplicate_PPI(species, D_species, interaction, module, D_module)

function to duplicate a PPI interaction

Parameters:
  • species (Species) – the original species
  • D_species (Species) – the new species
  • interaction (PPI) – the interaction you want to duplicate
  • module (TModule) – the original module
  • D_module (TModule) – the new module
duplicate_TFHill(D_species, interaction, module, D_module)

duplicate a TFHill interaction

Parameters:
  • D_species (Species) – the new species
  • interaction (TFHill) – the interaction you want to duplicate
  • module (TModule) – the original module
  • D_module (TModule) – the new module
duplicate_downstream_interactions(species, D_species, module, D_module)

Called in case of gene duplication to copy the downstream interactions

Parameters:
  • species (Species) – the ‘mother’ species
  • D_species (Species) – the ‘daughter’ species
  • module (TModule) – the ‘father’ module
  • D_module (TModule) – the ‘son’ module
duplicate_gene(species)

Duplicate a gene, i.e. a triplet Tmodule/CorePromoter/Species

Parameters:species (Species) – Species to duplicate
Returns:
list of the form [new_TModule, new_CorePromoter, new_Species, old_TModule]

or None if an error occured

duplicate_species_and_interactions(species)

Called to duplicate a species with its interactions

Right now only duplicates downstream TFHills and PPI and upstream TFHills. The input&output tags are removed from duplicate gene (see self.remove_output_when_dulicate)

Parameters:species (Species) – the mother species
Returns:A list [D_module,D_promoter,D_species] D_module (TModule): the duplicate TModule D_promoter (CorePromoter): the duplicate CorePromoter D_species (Species): the duplicate Species
get_node(id, target='interaction')

Return the node correspoding to the specified id and target

Parameters:
  • id – integer id of the node
  • target – string either interaction or species, the type of the node to search
list_possible_Degradation()

Return the list of all possible new degradations

new_Degradation(Input1, Input2, rate)

Create a new Degradation and add it to the network

Parameters:
  • Input1 (Species) – the ‘enzyme’
  • Input2 (Species) – the species degraded (have to be Degradable)
  • rate (float) – the degradation rate
Returns:

list of the form [Degradation] or None if an error occured

new_PPI(P1, P2, assoc, dissoc, types)

Create a new Networks.PPI.PPI, its associated complex and add then to the network.

Parameters:
  • P1 (Species) – First Protein
  • P2 (Species) – Second Protein
  • assoc (float) – the association rate
  • dissoc (float) – the dissociation rate of the complex
  • types (list) – the types of the complex species
Returns:

Return type:

list of the form [ppi,`complex created`] with

new_Phosphorylation(kinase, species, rate, threshold, hill, dephospho)

Create a new Phosphorylation, its associated product and add them to the network.

Parameters:
  • kinase (Species) –
  • species (Species) –
  • rate (float) – the association rate
  • threshold (float) – the Michaelis-Menten constant
  • hill (float) – the hill coefficient of the reaction
  • dephospho (float) – the dephosphorylation rate of the product
Returns:

list of the form [Phosphorylation , Species] or None if an error occured

new_Species(types)

Create a new Species instance and add it to the network

Parameters:types (list) – the list types of the Species (see Species.__init__)
Returns:The Species which have been created
new_TFHill(tf, hill, threshold, module, activity=0)

Create a new TFHill with given parameters and link it to the network.

Parameters:
  • tf (Species) – the upstrem Species
  • hill (float) – the hill coefficient of the reaction
  • threshold (float) – the Michaelis-Menten constant
  • module (TModule) – the downstream TModule
  • activity (int) – if fixed_activity_for_TF is True, always use the activity of tf
Returns:

return the new interaction or None if an error occured

Return type:

TFHill

new_custom_random_gene(ltypes)
new_enhancer(species, rate, delay, parameters, basal=0.0)

Create a complete new gene (TModule, CorePromoter and Species)

Parameters:
  • species (Species) –
  • rate (float) – the rate production of the TModule
  • delay (int) – the delay of the CorePromoter
  • parameters (list) – the species parameter (see Network.new_Species)
  • basal (float) – the basal production of the TModule (default to 0.)
Return: list of the form [Networks.classes_eds2.TModule, Networks.CorePromoter.CorePromoter]
or None if an error occured
new_gene(rate, delay, parameters, basal=0.0)

Create a complete new gene (TModule, CorePromoter and Species)

Parameters:
  • rate (float) – the rate production of the TModule
  • delay (int) – the delay of the CorePromoter
  • parameters (list) – the species parameter (see Network.new_Species)
  • basal (float) – the basal production of the TModule (default to 0.)
Return: list of the form [Networks.classes_eds2.TModule, Networks.CorePromoter.CorePromoter, Networks.classes_eds2.Species]
or None if an error occured
number_Degradation()

Computes the number of possible Degradations

number_PPI()

Return the number of possible PPI in network

number_Phosphorylation()

Return the number of possible Phosphorylations

number_TFHill()

Return the number of possible TFHill

number_nodes(Type)

count the number of Nodes of type Type

Parameters:Type (str) – the type you are looking for

Return: The number of Nodes of types Type in dict_types

propagate_activity_TFHill()

Ensure that TFHill activity correspond to the one of their predecessor - done for compatibility with older versions

remove_Node(Node)

remove node from the network graph

In case of interactions, also remove any phys objects (eg species, TModule) that are no more defined in absence of this interaction In the course of evolution, only interactions should be explicitly removed, then the other nodes are managed with the help of clean_nodes

Parameters:
  • node (Node) – The node to be removed
  • verbose (bool) – Flag to activate the prolix mode

Return: Boolean indicating the completion of the process

store_to_pickle(filename)

Save the whole network in a pickle object named filename

Parameters:filename (str) – the directory where the object is saved
verify_IO_numbers()

Redetermine all the input/output index

label_them run through the list and give the correct index to all the items

write_id()

Update all indexations of the network

Return: a number comprise between 0 and sys.maxint

class phievo.Networks.classes_eds2.Node

Bases: object

Superclass for all nodes object

id = 'None'
int_id()

extract the integer identifer computed in Network.write_id()

Returns:int - the identifier of the Node None when valid int not found eg if write_id not called
isinstance(name)

check the type of a node

Customed the builtin isinstance(derived_class, base_class) for the general case

Parameters:name – the type to be tested
Returns:returns True if self is of type name
isremovable(net, list_nodes_loop, verbose=False)

Check if a Node can be removed from the network

Parameters:
  • net (Network) – the network self belongs to
  • list_nodes_loop (list) – to handle non tree like network
  • debug (bool) – Flag to activate a prolix version
Returns:

Boolean removable or not

list_types()

Return the list of types associated to a node

outputs_to_delete(net)

Indicates a list of objects to delete when removing the node from the network

Needs to be tuned specifically by all derived classes.

Parameters:net (Network) – the network self belongs to
Returns:list - default empty list
print_node()

print a full description of the current node

rand_modify(random_generator)

modify every parameters of the node self

This subroutine is then export to the Node class and used as a method Called the sample_dictionary_ranges subroutine when needed

Parameters:
  • self (Node) – the node you want to modify
  • random_generator – a random number generator (.random() called here)
Returns:

in place modification

Return type:

None

string_param()

Returns a function with parameters for the nodes

Mainly here to be customized in subclasses

Returns:string , default ‘.’
class phievo.Networks.classes_eds2.Species(listtypes=[])

Bases: phievo.Networks.classes_eds2.Node

Class for any type of species, or list of species of various types Input list of lists eg [ [Degradation, degradation], [TF, activity], [Complex,], [Kinase],.. [Output, n_put], [Input, n_put] ] where n_put is an integer enumerating IO The first tag of [‘Species’] is assumed and should not be input

Tags_Species = {'Complexable': [], 'Receptor': [], 'Phosphorylable': [], 'Ligand': [], 'Diffusible': ['diffusion'], 'TF': ['activity'], 'Phospho': ['n_phospho'], 'Complex': [], 'Linear_Producer': [], 'Output': ['n_put'], 'Species': [], 'pMHC': [], 'Kinase': [], 'Input': ['n_put'], 'Degradable': ['degradation'], 'Phosphatase': []}
add_type(Type)

add Type and its corresponding parameters

Several layer of check are done before the core function to insure that Type is correctly added Also used to add the output/input tag to species. e.g.:species.add_type([‘Output’,n_put])

Parameters:
  • Type (list) – must be provided in a list of the form
  • as defined in Tags_Species (['Tag',parameter1,parameter2]) –
Returns:

1 if everything is done properly None if an error occur during the process

change_type(Type, parameters)

Change the parameters of a type

Parameters:
  • Type (string) – name of the type to modify
  • parameters (list) – list of the new parameters as defined in the Tag_Species
clean_type(Type)

Removes a type and corresponding attributes from a species

def_label()

Function to write labels for graphical representation

default_tags = ['Degradable', 'Phosphorylable', 'Diffusible']
isinstance(name)

check the type of a node

Customed the builtin isinstance(derived_class, base_class) for the Species class

Parameters:name – the type to be tested

Return: return True if self is of type name

label = 'Generic Species'
list_types()

Return the list of types associated to a node (custom for Species)

parameters = ['Degradable', 'Phosphorylable', 'Diffusible']
class phievo.Networks.classes_eds2.TModule(rate=0, basal=0)

Bases: phievo.Networks.classes_eds2.Node

A TModule regulate the production of a Species, it generally binds upstream to a CorePromoter (direct production) or a TFHill (regulation) and downstream to another TFHill which point to the product Species.

Parameters:
  • rate (float) – the production rate to be regulated
  • basal (float) – the basal production rate
string_param()
phievo.Networks.classes_eds2.check_consistency(lTypes, lNodes)

Check the consistency between a list of types and a list of nodes

Typically used when constructing an interaction to check the biochemical grammar. For each type, it recursively checks if there is a corresponding node in list_nodes.

Parameters:
  • lTypes – the desired type of each node
  • lNodes – the list of nodes
Returns:

Boolean indicating if the consistency is OK

phievo.Networks.classes_eds2.compare_node(x)

Used to order nodes in arbitrary but deterministic order when needed

Definition of CorePromoter Interaction. The CorePromoter is part of a gene system
and binds a TModule to a Species.

class phievo.Networks.CorePromoter.CorePromoter(delay=0)

Bases: phievo.Networks.classes_eds2.Interaction

Core promoter for transcription of one species

The CorePromoter serve as a link between the TModule and the Species to preserve the bipartite nature of the network.

delay

int

label

str – ‘transcription’ by default

input

list – list of input types: [‘TModule’]

output

list – list of output types: [‘Species’]

outputs_to_delete(net)

indicate the Nodes to remove when deleting the CorePromoter

Parameters:net (Network) – The network to which the CP belongs

Return: list of all the predec. and succ. of self in net

string_param()

Self description of the Interaction

phievo.Networks.CorePromoter.add_CorePromoter2Species(self, inter, output)

Add a CorePromoter Interaction and its output to the network

Parameters:
  • inter (CorePromoter) – the CorePromoter to be added
  • output (Species) – the CorePromoter output
phievo.Networks.CorePromoter.add_TModule2CorePromoter(self, module, inter)

Add a CorePromoter Interaction and its TModule to the network

Parameters:
  • module (TModule) – the CorePromoter module
  • inter (CorePromoter) – the CorePromoter to be added
phievo.Networks.CorePromoter.duplicate_gene(self, species)

Duplicate a gene, i.e. a triplet Tmodule/CorePromoter/Species

Parameters:species (Species) – Species to duplicate
Returns:
list of the form [new_TModule, new_CorePromoter, new_Species, old_TModule]

or None if an error occured

phievo.Networks.CorePromoter.new_custom_random_gene(self, ltypes)
phievo.Networks.CorePromoter.new_enhancer(self, species, rate, delay, parameters, basal=0.0)

Create a complete new gene (TModule, CorePromoter and Species)

Parameters:
  • species (Species) –
  • rate (float) – the rate production of the TModule
  • delay (int) – the delay of the CorePromoter
  • parameters (list) – the species parameter (see Network.new_Species)
  • basal (float) – the basal production of the TModule (default to 0.)
Return: list of the form [Networks.classes_eds2.TModule, Networks.CorePromoter.CorePromoter]
or None if an error occured
phievo.Networks.CorePromoter.new_gene(self, rate, delay, parameters, basal=0.0)

Create a complete new gene (TModule, CorePromoter and Species)

Parameters:
  • rate (float) – the rate production of the TModule
  • delay (int) – the delay of the CorePromoter
  • parameters (list) – the species parameter (see Network.new_Species)
  • basal (float) – the basal production of the TModule (default to 0.)
Return: list of the form [Networks.classes_eds2.TModule, Networks.CorePromoter.CorePromoter, Networks.classes_eds2.Species]
or None if an error occured
phievo.Networks.CorePromoter.random_enhancer(self, Type='TModule')

Create a new random enhancer. It includes a TModule and a CorePromoter.

Parameters:Type (list) – following the traditional template [‘type’, param]
Returns:
Return type:list of the form [tmodule, core_promoter] with
phievo.Networks.CorePromoter.random_gene(self, Type='Species')

Create a new random gene with a species of type Type

Parameters:Type (list) – following the traditional template [‘type’, param]
Returns:
Return type:list of the form [tmodule, core_promoter, species] with

Mutation

This module adds a layer to the elements defined in classes_eds2 and creates an extended version of Species called Mutable_Network. The addon adds a set of tools for node mutations. For mutation/removal, effective mutation rate will be the reference mutation rate times the number of instances of the considered Type.

Attributes
  • C,L,T (float):
  • dictionary_mutation (dict): referenced mutation rates and associated command as key
  • dictionary_ranges (dict): referenced parameters that can change and their ranges
  • list_create (list): list of Nodes subject to creation
  • list_mutate (list): list of Nodes subject to mutation
  • list_remove (list): list of Nodes subject to removal
  • list_types_output (list): list of the possible types for the output

class phievo.Networks.mutation.Mutable_Network(generator=<random.Random object at 0x25dcc18>)

Bases: phievo.Networks.classes_eds2.Network

Expand the Network class with all functions related to mutation

the random_Type() routines are the only ones called by evolution to sample all possible links on graph that can give rise to given interaction Type and then choses one. The assignment of random interaction parametes and types of output, packaged in separate routines new_random_Type(), that can be used independently to generate specific topologies with random parameters .. attribute:: fitness

float – the fitness of the Network, None by default (worst than everyother number)
dlt_fitness

float – the change of fitness at the last generation

data_evolution

list – keep various information such as fitness variance, average…

data_next_mutation

list – field to keep the data on the next mutation

Random

Random – defines the local random generator number

Main functions:

build_mutations()

builds a dictionary with relative mutation rates for a specific network

This method is based on dictionary_mutation

Returns:dict with the rates of each events for the network
compute_Cseed()

Return a random integer to determine the integrator seed

compute_next_mutation()

determine the time and type of next mutation for the gillespie algo.

Returns:float time to next mutation

given a network, computes the time of the next mutation and the command to execute to perform the mutation for the gillispie algorithm

mutate_Node(Type)

randomly selects then mutates a Node of a given Type

Parameters:Type (str) – the Type to mutate (e.g. Species: Species, TFHill: TFHill, Node: Node <phievo.Networks.classes_eds2.Node>…)
Returns:boolean if something is mutated
mutate_and_integrate(prmt, nnetwork, tgeneration, mutation=True)

function to mutate, integrate and update the fitness

Note that compile_and_integrate is defined in Networks/deriv2.py

Parameters:
  • prmt (dict) –
  • nnetwork (int) – an id for the C-file
  • tgeneration (float) – the time before the next gen.
  • mutation (bool) – if False, no mutation will be made
Returns:

  • n_mutations (int): the numbre of mutation performed
  • nnetwork (int): same as args
  • self (Mutable_Network): the Mutable_Network object itself
  • result (list): output of treatment_fitness (see compile_and_integrate)

Return type:

List [n_mutations,nnetwork,self,result] where

new_random_Degradation(Input1, Input2)

Creates a Degradation with random parameters between the Species

Parameters:
  • Input1 (Species) – the ‘enzyme’
  • Input2 (Species) – the species degraded (have to be Degradable)
Returns:

list of of the form [Degradation]

new_random_PPI(P1, P2)

Creates a PPI with random parameters between the Species

Parameters:
Returns:

  • ppi: PPI
  • complex created: Species

Return type:

list of the form [ppi,`complex created`] with

new_random_Phosphorylation(kinase, species)

Creates a Phosphorylation of species by kinase with random parameters

Parameters:
  • kinase (Species) – the kinase
  • species (Species) – the species to Phosphorylate
Returns:

list of the form [Phosphorylation , Species] or None if an error occured

new_random_TFHill(tf, module)

Creates a TFHill between tf and module with random parameters

Parameters:
  • tf (Species) – must have the ‘TF’ tag
  • module (TModule) – TModule associated to the TFHill
Returns:

return the new interaction or None if an error occured

Return type:

TFHill

random_Degradation()

Create new random Degradation among all possible ones

Returns:of the form [Degradation] or None if an error occured
Return type:list
random_Interaction(Interaction_Type)

create a new (and unique) interaction

Parameters:Interaction_Type (str) – the type of interaction you want
Returns:None
random_PPI()

Create new random PPI among all those possible

Returns:
Return type:list of the form [ppi,`complex created`] with
random_Phosphorylation()

Creates a new Phosphorylation among all possibles

Returns:list of the form [Phosphorylation , Species] or None if an error occured
random_Species(Type='Species')

Create a new random species instance of a given type

Parameters:Type (str) – the desired type of the new Species instance
Returns:note that it is automatically added to the network
Return type:Species
random_TFHill()

Creates a new TFHill among all possibles

Returns:return the new interaction or None if an error occured
Return type:TFHill
random_add_output()

Randomly adds an output tag to a random species

random_change_output()

Function that changes one output by adding then removing a TAG output

random_duplicate()

Routine to duplicate gene and its interactions

Currently the classes_eds2.duplicate_* only implemented for TF & PPI interactions If duplicating an output gene, add a new output tag to duplicated species, irrespective of other dictionary_mutation[‘output’] values in initialization.

Returns:boolean indicating if a duplication has been finally done
random_enhancer(Type='TModule')

Create a new random enhancer. It includes a TModule and a CorePromoter.

Parameters:Type (list) – following the traditional template [‘type’, param]
Returns:
Return type:list of the form [tmodule, core_promoter] with
random_gene(Type='Species')

Create a new random gene with a species of type Type

Parameters:Type (list) – following the traditional template [‘type’, param]
Returns:
Return type:list of the form [tmodule, core_promoter, species] with
random_remove_output()

Removes at random an output tag on some species

Outputs are always index 0,1,2…; not possible to have 0,1,3 for instance

remove_Interaction(Type)

Randomly removes a Node of a given Type

Parameters:Type (str) – the type you want to remove (e.g. ‘Interaction’, Species, …)
Returns:boolean indicating if something is effectively removed
phievo.Networks.mutation.build_lists(mutation_dict)

Construct the index of Species types subject to various operation

Parameters:mutation_dict (dict) – the dictionary listing the various operation (typically inits.dictionary_mutations)
phievo.Networks.mutation.ligand_fct(random_generator)
phievo.Networks.mutation.rand_modify(self, random_generator)

modify every parameters of the node self

This subroutine is then export to the Node class and used as a method Called the sample_dictionary_ranges subroutine when needed

Parameters:
  • self (Node) – the node you want to modify
  • random_generator – a random number generator (.random() called here)
Returns:

in place modification

Return type:

None

phievo.Networks.mutation.random_parameters(Types, random_generator)

Create a set of new random parameters for a Species instance of type Types

This used only for initialization and adds attributes to various types. Some of which may not be mutable later

Parameters:
  • Types (str) – a species type
  • random_generator – a random number generator (.random() called here)
Returns:

parameters a list of random parameters that can create a new Species or None if an error occured

phievo.Networks.mutation.sample_dictionary_ranges(key, random_generator)

Draw a random value for a parameter of type key

Look on dictionary_range, if the attribute to key is: a real number, a list or tuple of two reals defining min-max of range, and sample accordingly.

Parameters:
  • key (str) – the type of parameter you want
  • random_generator – a random number generator (.random() called here)
Returns:

float a random value or int if key is CorePromoter.delay or None if an error occured

TFHill

Definition of TFHill interaction TFHill are mainly a convenient link between TModule and their regulating species. It is used to conserve the bipartite nature of the network.


class phievo.Networks.TFHill.TFHill(hill=0, threshold=0, activity=0)

Bases: phievo.Networks.classes_eds2.Interaction

Implement the link between TModule and the TF

Parameters:
  • hill (float) – the hill coefficient of the reaction
  • threshold (float) – the Michaelis-Menten constant
  • activity (int) – flag for activation (1) or repression (0)
  • label (str) – ‘transcription’ by default
  • input (list) – list of input types: [‘TModule’]
  • output (list) – list of output types: [‘Species’]
string_param()

Self description of the Interaction

phievo.Networks.TFHill.add_TFHill(self, tf, inter, module)

Add a TF, a TModule and a TFHill interaction to the network

Parameters:
  • tf (Species) – with the ‘TF’ tag
  • inter (TFHill) – will link tf and module
  • module (TModule) – TModule to link the TFHill to
phievo.Networks.TFHill.compute_transcription(net, module)

Determine the transcription rate of a given module

Used for integration in transcription_deriv_inC

Parameters:module (TModule) – TModule to compute .
Returns:string the algebraic transcription rate of module
phievo.Networks.TFHill.duplicate_TFHill(self, D_species, interaction, module, D_module)

duplicate a TFHill interaction

Parameters:
  • D_species (Species) – the new species
  • interaction (TFHill) – the interaction you want to duplicate
  • module (TModule) – the original module
  • D_module (TModule) – the new module
phievo.Networks.TFHill.new_TFHill(self, tf, hill, threshold, module, activity=0)

Create a new TFHill with given parameters and link it to the network.

Parameters:
  • tf (Species) – the upstrem Species
  • hill (float) – the hill coefficient of the reaction
  • threshold (float) – the Michaelis-Menten constant
  • module (TModule) – the downstream TModule
  • activity (int) – if fixed_activity_for_TF is True, always use the activity of tf
Returns:

return the new interaction or None if an error occured

Return type:

TFHill

phievo.Networks.TFHill.new_random_TFHill(self, tf, module)

Creates a TFHill between tf and module with random parameters

Parameters:
  • tf (Species) – must have the ‘TF’ tag
  • module (TModule) – TModule associated to the TFHill
Returns:

return the new interaction or None if an error occured

Return type:

TFHill

phievo.Networks.TFHill.number_TFHill(self)

Return the number of possible TFHill

phievo.Networks.TFHill.propagate_activity_TFHill(self)

Ensure that TFHill activity correspond to the one of their predecessor - done for compatibility with older versions

phievo.Networks.TFHill.random_TFHill(self)

Creates a new TFHill among all possibles

Returns:return the new interaction or None if an error occured
Return type:TFHill
phievo.Networks.TFHill.transcription_deriv_inC(net)

gives the string corresponding to transcription for integration

Return: A single string for all transcriptions in the network

PPI

Definition of Protein-Protein-Interaction Creation: unknown Last edition: 2016-10-26

class phievo.Networks.PPI.PPI(association=0, disassociation=0)

Bases: phievo.Networks.classes_eds2.Interaction

Protein-protein interaction between two species

Parameters:
  • association (float) – the association rate
  • disassociation (float) – the dissociation rate fo the complex
  • label (str) – ‘PP Interaction’ by default
  • input (list) – list of input types: [‘Complexable’,’Complexable’]
  • output (list) – list of output types: [‘Species’]
check_grammar(input_list, output_list)

checks the grammar for the interactions (custom for PPI)

Parameters:
  • input_list (list) – nodes to be checked
  • output_list (list) – nodes to be checked
Returns:

Boolean for the consistency of up and downstream grammar

outputs_to_delete(net)

Return the complex to delete when removing the LR

phievo.Networks.PPI.PPI_deriv_inC(net)

gives the string corresponding to Networks.PPI.PPI for integration

Returns:str a single string for all Networks.PPI.PPI in the network
phievo.Networks.PPI.duplicate_PPI(self, species, D_species, interaction, module, D_module)

function to duplicate a PPI interaction

Parameters:
  • species (Species) – the original species
  • D_species (Species) – the new species
  • interaction (PPI) – the interaction you want to duplicate
  • module (TModule) – the original module
  • D_module (TModule) – the new module
phievo.Networks.PPI.new_PPI(self, P1, P2, assoc, dissoc, types)

Create a new Networks.PPI.PPI, its associated complex and add then to the network.

Parameters:
  • P1 (Species) – First Protein
  • P2 (Species) – Second Protein
  • assoc (float) – the association rate
  • dissoc (float) – the dissociation rate of the complex
  • types (list) – the types of the complex species
Returns:

Return type:

list of the form [ppi,`complex created`] with

phievo.Networks.PPI.new_random_PPI(self, P1, P2)

Creates a PPI with random parameters between the Species

Parameters:
Returns:

  • ppi: PPI
  • complex created: Species

Return type:

list of the form [ppi,`complex created`] with

phievo.Networks.PPI.number_PPI(self)

Return the number of possible PPI in network

phievo.Networks.PPI.random_PPI(self)

Create new random PPI among all those possible

Returns:
Return type:list of the form [ppi,`complex created`] with

Phosphorylation

Definition of Phosphorylation interaction

! WARNING: IF USING THIS CLASS PUT config.multiple_phospho to 0, otherwise you might have bugs (for now) TODO: in New Phosphorylation, test on n_phospho; if it is 1 (or higher than something) then remove Phosphorylable. Also update n_phospho accordingly when phosphorylated

phievo.Networks.Phosphorylation.Phospho_deriv_inC(net)

gives the string corresponding to Phosphorylation for integration

Returns:A single string for all Phosphorylations in the network
class phievo.Networks.Phosphorylation.Phosphorylation(rate=0, threshold=1, hill_coeff=1, dephospho_rate=1)

Bases: phievo.Networks.classes_eds2.Interaction

Phosphorylation interaction

rate

float – the phosphorylation rate

threshold

float – the Michaelis-Menten constant

hill

float – the hill coefficient of the reaction

dephosphorylation

float – the dephosphorylation rate

label

str – ‘Phosphorylation’ by default

input

list – list of input types: [‘Kinase’,’Phosphorylable’]

output

list – list of output types: [‘Kinase’,’Phospho’]

check_grammar(input_list, output_list)

checks the grammar for the interactions (custom for Phosphorylation)

Parameters:
  • input_list (list) – nodes to be checked
  • output_list (list) – nodes to be checked
Returns:

Boolean for the consistency of up and downstream grammar

outputs_to_delete(net)

Return the phosphorylated species to delete when deleting a Phosphorylation

phievo.Networks.Phosphorylation.check_existing_Phosphorylation(self, signature)

check if a particular phosphorylation exists in the network

Parameters:signature (list) – The signature of the phospho in the form [Kinase,Input]

Return: True if this phosphorylation exist

phievo.Networks.Phosphorylation.new_Phosphorylation(self, kinase, species, rate, threshold, hill, dephospho)

Create a new Phosphorylation, its associated product and add them to the network.

Parameters:
  • kinase (Species) –
  • species (Species) –
  • rate (float) – the association rate
  • threshold (float) – the Michaelis-Menten constant
  • hill (float) – the hill coefficient of the reaction
  • dephospho (float) – the dephosphorylation rate of the product
Returns:

list of the form [Phosphorylation , Species] or None if an error occured

phievo.Networks.Phosphorylation.new_random_Phosphorylation(self, kinase, species)

Creates a Phosphorylation of species by kinase with random parameters

Parameters:
  • kinase (Species) – the kinase
  • species (Species) – the species to Phosphorylate
Returns:

list of the form [Phosphorylation , Species] or None if an error occured

phievo.Networks.Phosphorylation.number_Phosphorylation(self)

Return the number of possible Phosphorylations

phievo.Networks.Phosphorylation.random_Phosphorylation(self)

Creates a new Phosphorylation among all possibles

Returns:list of the form [Phosphorylation , Species] or None if an error occured

Degradation

Definition of catalysed degradations.


class phievo.Networks.Degradation.Degradation(rate=0.0)

Bases: phievo.Networks.classes_eds2.Interaction

Catalyse the degradation of a given species

rate

float – the degradation constant

label

str – ‘Degradation’ by default

input

list – list of input types: [‘Species’,’Degradable’]

output

list – list of output types: [‘Species’]

check_grammar(input_list, output_list)

checks the grammar for the interactions (custom for degradation)

Parameters:
  • input_list (list) – nodes to be checked
  • output_list (list) – nodes to be checked
Returns:

Boolean of the consistency of up and downstream grammar

outputs_to_delete(net)

indicate the Nodes to remove when deleting the Degradation

Parameters:net (Mutable_Network) – The network to which the interaction belongs
Returns:here an empty list
Return type:list
phievo.Networks.Degradation.Degradation_deriv_inC(net)

gives the string corresponding to degradations for integration

Return:A single string for all degradation in the network

phievo.Networks.Degradation.check_existing_Degradation(self, i1, i2)

Check if a Degradation exists between species i1 and i2

Parameters:
  • i1 (Species) – the ‘enzyme’
  • i2 (Species) – the species degraded
Returns:

True if i1 is known to degrade i2

phievo.Networks.Degradation.list_possible_Degradation(self)

Return the list of all possible new degradations

phievo.Networks.Degradation.new_Degradation(self, Input1, Input2, rate)

Create a new Degradation and add it to the network

Parameters:
  • Input1 (Species) – the ‘enzyme’
  • Input2 (Species) – the species degraded (have to be Degradable)
  • rate (float) – the degradation rate
Returns:

list of the form [Degradation] or None if an error occured

phievo.Networks.Degradation.new_random_Degradation(self, Input1, Input2)

Creates a Degradation with random parameters between the Species

Parameters:
  • Input1 (Species) – the ‘enzyme’
  • Input2 (Species) – the species degraded (have to be Degradable)
Returns:

list of of the form [Degradation]

phievo.Networks.Degradation.number_Degradation(self)

Computes the number of possible Degradations

phievo.Networks.Degradation.random_Degradation(self)

Create new random Degradation among all possible ones

Returns:of the form [Degradation] or None if an error occured
Return type:list

deriv2

Here are the tools to convert a Network object to a C-file that will be compiled and run. The C-file goes into workplace_dir/built_integrator*.c along with executable The C-file is assembled with several pieces:

  • header, utilities, geometry, integrator and main: see initialization_code.init_deriv2
  • for each interaction: see interaction.interaction_deriv_inC (bottom of file)
  • see also Networks.interaction.py and the cfile dictionary

All these pieces are assembled by compute_program(), and then compiled with compile_and_integrate().

The c-code files passed only once in form of dictionary cfile. The numerical parameters need to find dimensions of arrays, integration steps, input as argments to functions

phievo.Networks.deriv2.workplace_dir

str – the directory where build_integrator*.c will go

phievo.Networks.deriv2.Ccompiler

str – ‘gcc’ by default

phievo.Networks.deriv2.cfile

dict – where the generic c-code are found (can be reset to fit problem)

phievo.Networks.deriv2.noise_flag

bool – flag to know if we integrate or not with noise

TODO: it would be nice to include in header.h declaration of all C functions used so that they can then be loaded in any order, currently order constrained by declare before use.

phievo.Networks.deriv2.all_params2C(net, prmt, print_buf, Cseed=0)

Collect all the numerical constants and format them to C like

neelocalneig,diff,index_ligand,ded

Parameters:
  • net (Mutable_Network) –
  • prmt (dict) – dictionary from initialization file
  • print_buf (bool) – control printing of time history by C codes
  • Cseed (int) – seed for the integrator random number generator
Returns:

A C formated string of parameters

phievo.Networks.deriv2.compile_and_integrate(network, prmt, nnetwork, print_buf=False, Cseed=0)

Compile and integrate a network

Wait for process completion before launching another integration See https://www.python.org/dev/peps/pep-0324/ for interface to run C code

Parameters:
  • network (Mutable_Network) –
  • prmt (dict) – dictionary from initialization file
  • nnetwork (int) – an id to separate the different C-file
  • print_buf (bool) – control printing of time history by C codes to a file
  • Cseed (int) – seed for the integrator random number generator
Returns:

list of corresponding to the different line of the output of treatment_fitness (see your fitness.c file) or None if an error occured

phievo.Networks.deriv2.compute_leap(list_input_id, list_output_id, rate)

Routine to compute strings for derivative in C associated to an interaction

if noise_flag, adds a Langevin noise term which scaled with concentration

Parameters:
  • list_input_id (list) – contains id of the input, i.e. the depleted species
  • list_output_id (list) – contains id of the created species
  • rate (str) – the rate, should be positive
Returns:

a C-formatted string

phievo.Networks.deriv2.degrad_deriv_inC(net)

gives the string corresponding to the degradation integration

Returns:A single string for all degradations in the network
phievo.Networks.deriv2.track_changing_variable(net, name)

Return a list of the indices of the species with type name

Use this function when Output or Input may be added (we do not care about their order)

Parameters:
  • net (Mutable_Network) –
  • name (str) – a Species tag, usually ‘Input’ or ‘Output’
Returns:

list of the id species list ordered by growing n_put

phievo.Networks.deriv2.track_variable(net, name)

Return a list of the indices of the species with type name

This is way of keeping track of fixed IO variables. Use this function only if the output or input are fixed in the algorithm, otherwise, use track_changing_variable

Parameters:
  • net (Mutable_Network) –
  • name (str) – a Species tag, usually ‘Input’ or ‘Output’
Returns:

list of the id species list ordered by growing n_put

phievo.Networks.deriv2.write_program(programm_file, net, prmt, print_buf, Cseed=0)

Write the built_integrator of the network in the C file

Collect python encoded C and the stored files selected via cfile dictionary and write them in the correct order.

Parameters:
  • programm_file (TextIOWrapper) – the built_integrator file
  • net (Mutable_Network) –
  • prmt (dict) – passed to all_params2C
  • print_buf (bool) – passed to all_params2C
  • Cseed (int) – passed to all_params2C
Returns:

The C programm as a python string

lovelyGraph

The lovelyGraph modules contains a set of utilities to plot a network. It uses the homemade package PlotGraph.

phievo.Networks.lovelyGraph.gettype(node, type_list)
phievo.Networks.lovelyGraph.pretty_graph(net, extended=True, layout='graphviz')

Creates a ready-to-plot graph object from a network.

Parameters:net (Mutable_Network) –
Returns:returns a PlotGraph graph
phievo.Networks.lovelyGraph.produce_CorePromoter_name(node_reac)
phievo.Networks.lovelyGraph.produce_Degradation_name(node_reac)
phievo.Networks.lovelyGraph.produce_PPI_name(node_PPI)
phievo.Networks.lovelyGraph.produce_Phospho_name(node_reac, cat=False)
phievo.Networks.lovelyGraph.produce_TFHill_name(node_reac)
phievo.Networks.lovelyGraph.produce_TModule_name(node_species)
phievo.Networks.lovelyGraph.produce_species_name(node_species)
phievo.Networks.lovelyGraph.short_label(species)

PlotGraph

Graph

class phievo.Networks.PlotGraph.Graph.Graph(layout)

Bases: object

Container of a directed graph. It contains mainly two types of objects: nodes and edges.

add_edge(*argv, **kwargs)

Add an edge to the graph.

Parameters:
  • argv (list(str)) – Is handled if it contains only two elements corresponding to the edge’s starting and ending nodes.
  • kwargs (dict) – The function handles only the keys style, label that respectively correspond to the edge’s style and its label. It can also deal with nodeFrom and nodeFrom if it was not defined in argv. The other keys are passed for latter use by the plotting function.
Returns
Networks.PlotGraph.Components.Edge:The edge reference.
add_node(*argv, **kwargs)

Add a node to the graph.

Parameters:
  • argv (list(str)) – Is handled if it contains only one element corresponding to the node label.
  • kwargs (dict) – The function handles only the keys size, marker that respectively correspond to the node’s area and its shape. It can also deal with label if it was not defined in argv. The other keys are passed for latter use by the plotting function.
Returns
Networks.PlotGraph.Components.Node: The node reference.
draw(file=None, edgeLegend=False, display=True)

Draw the graph in a matplib framework. The node and edges are generated using patches.

Parameters:file (str) – Optional. When defined, the figure will be saved under the file name. Otherwise the program pops up a window with the graph.
Returns:None
edge_list()

Generate a list of the node edges

Returns:Each tuple in the list contains the starting and ending node labels.
Return type:list((str,str))
get_networkx()
layout(recursion=500)

Compute a layout for the node and set the node positions.

node_list()

Generate a list of the node labels

Returns:of the labels for the node contained in the graph
Return type:list(str)
set_node_size(size)

Homogenise the node area in the network.

Parameters:size (float) – Relative node area as compare to the default area.
Returns:None

Graph components

class phievo.Networks.PlotGraph.Components.Arrow(**kwargs)

Bases: phievo.Networks.PlotGraph.Components.Edge

The class arrow is inherited from Networks.PlotGraph.Components.Edge. It adds extra fonctionalities to generate Matplolib patches.

get_autoPatch(offsets=(0, 0), num=0)

Generates a matplotlib patch for the arrow between two nodes. It takes into account the offset to keep between the ends of the arrow and the node given the node shape. This is an implementation of get_vector for a edge that start and ends at the same node.

Parameters:offsets (float,float) – offset between node and the start of the arrow and offset between node and the end of the arrow
Returns:Matplotlib.Patches
get_patch(offsets=(0, 0), angle=0.2)

Generates a matplotlib patch for the arrow between two nodes. It takes into account the offset to keep between the ends of the arrow and the nodes given the node shapes.

Parameters:offsets (float,float) – offset between node1 and the start of the arrow and offset between node2 and the end of the arrow
Returns:Matplotlib.Patches
class phievo.Networks.PlotGraph.Components.BarB(widthB=0.4, angleB=None)

Bases: matplotlib.patches._Bracket

An arrow with a bar(|) at the B end. The class is added to matplotlib to allow “-|” style of arrow.

phievo.Networks.PlotGraph.Components.Bezier(P0, P1, P2)
class phievo.Networks.PlotGraph.Components.Circle(*args, **kwargs)

Bases: phievo.Networks.PlotGraph.Components.Node

Circle is inherited from Networks.PlotGraph.Components.Node and represents a node with a circular shape (⬤).

get_patch()

Draw of a matplotlib patch to be added to the graph plot.

Returns:Matplotlib.Patch
radius(theta)

Every point on the node’s boundary is refered to by an angle in rad. Given the shape of the node, compute the radius of the boundary for a angle.

\[\theta \rightarrow R\]
Parameters:theta (float) – Angle a which to compute the distance between the center and the boundary.
Returns:corresponding to the radius.
Return type:float
class phievo.Networks.PlotGraph.Components.Edge(nodeFrom, nodeTo, label, **kwargs)

Bases: object

Directed graph edge between two nodes.

compute_center(A, B, angle)
get_vector(offsets=(0, 0), angle=0)

Generate a starting and ending point of the edge’s arrow that accomodates the desired space and between the arrow and the nodes given the node shapes.

Parameters:
  • offsets (float,float) – offsets between the arrow and the two nodes
  • angle (float) – If angle is 0, the arrow follows a straigh line between two nodes. Otherwise it is a curved line starting and arriving to the node with two opposite angles with respect to the freeAngle value
Returns:

tuple containing:
  • start (numpy.array): Start of the arrow
  • end (numpy.array): End of the arrow

Return type:

(tuple)

get_vector_auto(offsets=(0, 0), num=0)

Generate a starting and ending point of the edge’s arrow that accomodates the desired space and between the arrow and the node given the node shapes. This is an implementation of get_vector for a edge that start and ends at the same edge.

Parameters:
  • offsets (float,float) – offsets between the arrow and the two nodes
  • angle (float) – Here the angle cannot be 0. The arrow is a curved line starting and arriving to the node with two opposite angles with respect to the freeAngle value.
Returns:

tuple containing:
  • start (numpy.array): Start of the arrow
  • end (numpy.array): End of the arrow

Return type:

(tuple)

radius(theta)
record_angle(angle)
setReceiveEdge()
set_center(center)
class phievo.Networks.PlotGraph.Components.HouseDown(*args, **kwargs)

Bases: phievo.Networks.PlotGraph.Components.Node

Node with a pentagon shape (⯂).

get_patch()

Draw of a matplotlib patch to be added to the graph plot.

Returns:Matplotlib.Patch
radius(theta)

Every point on the node’s boundary is refered to by an angle in rad. Given the shape of the node, compute the radius of the boundary for a angle.

\[\theta \rightarrow R \times \frac{\cos \pi/5}{\cos((5\theta - 3\pi/2)\%(2pi)/5 - \pi/5)}\]
Parameters:theta (float) – Angle a which to compute the distance between the center and the boundary.
Returns:corresponding to the radius.
Return type:float
class phievo.Networks.PlotGraph.Components.HouseUp(*args, **kwargs)

Bases: phievo.Networks.PlotGraph.Components.Node

Node with a pentagon shape (⬟)

get_patch()

Draw of a matplotlib patch to be added to the graph plot.

Returns:Matplotlib.Patch
radius(theta)

Every point on the node’s boundary is refered to by an angle in rad. Given the shape of the node, compute the radius of the boundary for a angle.

\[\theta \rightarrow R \times \frac{\cos \pi/5}{\cos((5\theta + 3\pi/2)\%(2pi)/5 - \pi/5)}\]
Parameters:theta (float) – Angle a which to compute the distance between the center and the boundary.
Returns:corresponding to the radius.
Return type:float
class phievo.Networks.PlotGraph.Components.Interaction(node1, node2)

Bases: object

In the module Graph, an iteraction between node A and node B stands for at least one edge between those two node. It is a mean to keep tracks of all the edges that exist between A and B.

add_edge(edge)

Add an edge to an the existing interaction

Parameters:edge (Edge) – edge to be added to the list of edge references
Returns:None
get_patches(offsets=(0, 0))

Run through the interactions edges to create a Matplotlib patch for each of them

Parameters:offsets (float,float) – Size 2 tuple containing the offset to leave between the edges an the node1 and node2.
Returns:list of Matplotlib patches
Return type:[Matplotlib.Patches]
class phievo.Networks.PlotGraph.Components.Line(**kwargs)

Bases: phievo.Networks.PlotGraph.Components.Edge

class phievo.Networks.PlotGraph.Components.Node(label, size, *args, **kwargs)

Bases: object

Directed graph node or vertex.

find_freeAngle()

Searches for the best position where to add a new edge to the node. It is used only for looping edges. It tries to increase the angle between the new angle and the already plotted edges.

Parameters:angle (float) – Value between 0 and 2π where an new edge arrives or leaves the node.
Returns:the function returns the optimal angle
Return type:float
plot_label()

Write the node label on the plot a the node’s center.

record_angle(angle)

Every point on boundary of the Node is refered to by an angle. This function records the postition each time a new edge is drawn. The list of angle is used to choose the optimal position where to add looping edges.

Parameters:angle (float) – Value between 0 and 2π where an new edge arrives or leaves the node.
Returns:None
set_center(pos)

Set the coordinates of the node’s center.

Parameters:pos (list(float)) – Coordinates of the node’s center
Returns:None
class phievo.Networks.PlotGraph.Components.RoundedRectangle(*args, **kwargs)

Bases: phievo.Networks.PlotGraph.Components.Node

Node with a RoundedRectangle shape (▢).

get_patch()

Draw of a matplotlib patch to be added to the graph plot.

Returns:Matplotlib.Patch
radius(theta)

Every point on the node’s boundary is refered to by an angle in rad. Given the shape of the node, compute the radius of the boundary for a angle.

Parameters:theta (float) – Angle a which to compute the distance between the center and the boundary.
Returns:corresponding to the radius.
Return type:float
class phievo.Networks.PlotGraph.Components.Square(*args, **kwargs)

Bases: phievo.Networks.PlotGraph.Components.Node

Node with a square shape (◼).

get_patch()

Draw of a matplotlib patch to be added to the graph plot.

Returns:Matplotlib.Patch
radius(theta)

Every point on the node’s boundary is refered to by an angle in rad. Given the shape of the node, compute the radius of the boundary for a angle.

\[\theta \rightarrow R \times \frac{\cos \pi/4}{\cos((4\theta + 2\pi/2)\%(2pi)/4 - \pi/4)}\]
Parameters:theta (float) – Angle a which to compute the distance between the center and the boundary.
Returns:corresponding to the radius.
Return type:float
class phievo.Networks.PlotGraph.Components.TriangleDown(*args, **kwargs)

Bases: phievo.Networks.PlotGraph.Components.Node

Node with a triangle shape (▼).

get_patch()

Draw of a matplotlib patch to be added to the graph plot.

Returns:Matplotlib.Patch
radius(theta)

Every point on the node’s boundary is refered to by an angle in rad. Given the shape of the node, compute the radius of the boundary for a angle.

\[\theta \rightarrow R \times \frac{\cos \pi/3}{\cos((3\theta + 3\pi/2)\%(2pi)/3 - \pi/3)}\]
Parameters:theta (float) – Angle a which to compute the distance between the center and the boundary.
Returns:corresponding to the radius.
Return type:float
class phievo.Networks.PlotGraph.Components.TriangleUp(*args, **kwargs)

Bases: phievo.Networks.PlotGraph.Components.Node

Node with a triangle shape (▲).

get_patch()

Draw of a matplotlib patch to be added to the graph plot.

Returns:Matplotlib.Patch
radius(theta)

Every point on the node’s boundary is refered to by an angle in rad. Given the shape of the node, compute the radius of the boundary for a angle.

\[\theta \rightarrow R \times \frac{\cos \pi/3}{\cos((3\theta - 3\pi/2)\%(2pi)/3 - \pi/3)}\]
Parameters:theta (float) – Angle a which to compute the distance between the center and the boundary.
Returns:corresponding to the radius.
Return type:float

Layout

phievo.Networks.PlotGraph.Layout.hierarchical_layout(node_list)
phievo.Networks.PlotGraph.Layout.layout(node_list, interaction_list, radius=1, layout='graphviz')

Use networkx layout function to compute the node centers

Parameters:
  • node_list (list) – List of all the nodes in the nework
  • interaction_list (list) – List of tuple describing the nodes in interaction
  • radius (float) – Order of magnitude for a node radius. used to scale the minimal distance.
  • layout (str) – Use a networkx layout. Choose between: - circular - spring - shell - random - spectral - circular - fruchterman_reingold - pygraphviz
Returns:

indexed by nodes names and containing their (x,y) position (for use with draw_networkx pos argument typically)

Return type:

dict

Populations

Default evolution

Defines the Class Population with her principal method, evolution, which evolve a set of networks. All initialization done from an initialization.py file. All the modules are initialized through run_evolution.py.

The initial networks to evolve, can be built from just the input/output genes, a predefined newtork, or restarted from any saved population from a previous run. (See initialization file for details)

The time between generations is variable, and about the same for all species, we sample the mutation rates with a gillespie like algorithm, hence the name

The evolution method will write the following files in the namefolder given as argument to Population.__init__ stdout basic info each generation: * Bests = for generation, the network with best fitness in text form to edit or process with stat_best_net.py * Restart* = binary dbm type file with data to restart evolution at selected generation numbers * graphic files with time course and best network diagram at selected generations

class phievo.Populations_Types.evolution_gillespie.Population(namefolder)

Bases: object

Define a population as a list of networks called Population. Genus and a principal method evolution. object means it is a newstyle class ! See the web for distinction between new and olds style class, important for inheritance

best_fitness

float – keep trace of the best fitness in the population

genus

list – the list of individuals(Network) of the population

same_seed

bool – indicate if the file is a restart or not

tgeneration

float – starting hop time for the gillespie algorithm

npopulation

int – size of te population

bests_file

str – directory to save the data of evolution

Main methods:
evolution: launch the evolutionary algorithm pop_mutate_and_integrate: update the whole population
evolution(prmt)

Main method to evolve population

Returns:None
genus_mutate_and_integrate(prmt, nnetwork, mutation=True)

mutate, and update the fitness of one individual

Parameters:
  • prmt (dict) – the inits parameters for integration
  • nnetwork (int) – the index of the network in the population
  • mutation (bool) – a flag to activate mutation
Returns:

the number of mutation int: the index of the network in the population Network: The resulting network after mutation

Return type:

int

increment_identifier(network)

Test whether the network was mutated. If so the network identifier is updated with a new index.

initialize_identifier()

Set an unique index to every network of the initial population an set the max_network_identifier value. If the run restarts an existing simulation, only max_network_identifier is computed.

pop_mutate_and_integrate(initial, first_mutated, last_mutated, prmt, net_stat)

Recompute the fitness for half the population and mutate/compute the fitness for the rest. Save all the data in net_stat

Parameters:
  • initial (int) – index of the first individual in population
  • first_mutated (int) – index of the first mutated individual in population
  • last_mutated (int) – index of the last mutated individual in population
  • prmt (dict) – the inits parameters for integration
  • net_stat (NetworkStat) – to store the population data
Returns:

in place modification

Return type:

None

pop_sort()

Sort the population with respect to fitness

save_restart_file(kgeneration, header, tgeneration)

Save a dbm file, keyed by the generation number (a string!) and with value a [parameter dictionary, genus]. Might be more transparent to write out Poulation instance and forget header, and be sure to update tgeneration

storing(t_gen, net)

Store the work and various data for later analysis

Network object are stored in individual pickle file in Seed{}/data Data are stored in a shelve called the Seed{}/Bests_{}.net

Parameters:
  • t_gen – the key (normally the generation number)
  • net (Network) – the object to be saved
Returns:

None

update_fitness(nnetwork, integration_result)

Update (in place) the fitness and the dlt_fitness

Parameters:
  • nnetwork (int) – the index of the network in the population
  • integration_result (list) – the output of compile_and_integrate
Returns:

in place modification

Return type:

None

phievo.Populations_Types.evolution_gillespie.fitness_treatment(population)

default function for fitness treatment

If necessary, should be implemented in the init*.py file

phievo.Populations_Types.evolution_gillespie.init_network(mutation)

Default function to create network

It must be overwritten with function from the init*.py file otherwise stop the programm

phievo.Populations_Types.evolution_gillespie.restart(directory, generation, verbose=True)

Allow the user to restart an old run

Parameters:
  • directory (str) – the directory of the restart file
  • generation (int) – the generation number
Returns:

the parameters of the run genus (list): the list of individuals(Network) of the population

Return type:

rprmt (dict)

Pareto evolution

This module provide a pareto_Population class to perform a Pareto evolution, that is, a general frame to evolve Networks according to more than one fitness function.

See: Warmflash, A., Francois, P., & Siggia, E. D. (2012). Pareto Evolution of Gene Networks: An Algorithm to Optimize Multiple Fitness Objectives. Physical Biology, 9(5), 56001.

Coder: A. Warmflash, P. François

phievo.Populations_Types.pareto_population.compdist(x, y, n_functions)

Compute the distance between the fitness of x and y

class phievo.Populations_Types.pareto_population.pareto_Population(namefolder, nfunctions, rshare)

Bases: phievo.Populations_Types.evolution_gillespie.Population

Update the Population to manage a Pareto evolution

Note that we dynamically change the fitness of the individuals to give them a list-like fitness.

nfunctions

int – number of functions taken into account by pareto

rshare

float – parameter for the fitness sharing

pop_fitness_share()

Use fitness sharing to increase the diversity of the population.

That is, it augment the rank of inidividual to close from each other to promote diversity in the population. The implementation is a variant on the basic fitness sharing algorithm in section II of Cioppa et al. IEEE Trans. Evol Comp. 11:453

pop_print_pareto(f_pop, f_best)

Write various information about population in files f_pop and

Parameters:
  • f_pop (str) – short description of all individuals
  • f_best (str) – complete description of the first rank only
pop_sort(verbose=False)

Perform a pareto sorting of the population using the Goldberg algorithm.

See Van Velhuizen and Lamont. Evol Computation. 8:125 (2000) for details To avoid having population dominated by 0,0 function assigns lowest rank to networks with this score.

update_fitness(nnetwork, integration_result)

Update (in place) all the fitnesses and the corresponding dlt_fitness

Parameters:
  • nnetwork (int) – the index of the network in the population
  • integration_result (list) – the output of compile_and_integrate
class phievo.Populations_Types.pareto_population.pareto_thread_Population(namefolder, nfunctions, rshare)

Bases: phievo.Populations_Types.pareto_population.pareto_Population, phievo.Populations_Types.thread_population.thread_Population

Update the pareto_Population class to allow threading

Note, when looking for inherited method, python always choose the right most first (here pareto_Population).

pop_mutate_and_integrate(initial, first_mutated, last_mutated, prmt, net_stat)

Recompute the fitness for half the population and mutate/compute the fitness for the rest. Save all the data in net_stat

Parameters:
  • initial (int) – index of the first individual in population
  • first_mutated (int) – index of the first mutated individual in population
  • last_mutated (int) – index of the last mutated individual in population
  • prmt (dict) – the inits parameters for integration
  • net_stat (NetworkStat) – to store the population data
Returns:

in place modification

Return type:

None

phievo.Populations_Types.pareto_population.pcompare(x, y, n_functions)

Perform a pareto comparison of two networks based on their different fitness

Parameters:
  • x,y (Network) – the object to compare
  • n_functions (int) – the number of function taken into account
Returns:

the comparison of x & y (1 if x>y), 0 indicates that they are pareto equivalent

phievo.Populations_Types.pareto_population.single_comparison(x, y)

Compare two numbers and return 1 if x>y, -1 if x<y and 0 otherwise

Analysis tools

Simulation

class phievo.AnalysisTools.Simulation.Genealogy(seed)

Bases: object

compare_ss_wrt_parent(sim, child, parent)
get_network_from_identifier(net_ind)
load_sort_networks()

Loads an existing network classification

plot_compare_multiple_networks(sim, indexes, cell=0)

Print a svg figure of the cell profile,time series and the network layout in the seed folder.

plot_front_genealogy(generations, extra_networks_info=[], filename='')

Uses the seed plot_pareto_fronts function to display the pareto fronts. In addition, the function allows to plots extra networks in the fitness plan

Parameters:
  • generations – list of generation indexes
  • extra_networks_indexes – list of extra network informatino dictionaries.
plot_lineage_fitness(line, formula='{}', highlighted_mutations=[])
plot_mutation_fitness_deviation(only_one_mutation=True, networks=None, ploted_ratio=1)

Plot the deviation of fitness in the fitness space caused by a generation’s mutation.

Arg:
only_one_mutation (bool): If True, plot only the networks that undergone only a single mutation durign a generation.
scatter_pareto_accross_generations(generation, front_to_plot, xrange, yrange, step=1)
search_ancestors(network)
sort_networks(verbose=False, write_pickle=True)

Order the networks, by the label_ind, in a dictionary. The dictonary contains the most useful information but takes last space. The information dictionaries is easier to handle than the actual networks.

Parameters:
  • verbose – print information during sorting
  • write_pickle – backup the sorting information in a pickle file
Returns:

dictionary. A key is associated to each network

class phievo.AnalysisTools.Simulation.Seed(path)

Bases: object

This is a container to load the information about a Simulation seed. It contains mainly the indexes of the generations and some extra utilities to analyse them.

compute_best_fitness(generation)
custom_plot(X, Y)
Plot the Y as a function of X. X and Y can be chosen in the keys of
self.observables.
Parameters:
  • seed (int) – number of the seed to look at
  • X (str) – x-axis observable
  • Y (list) – list (or string) of y-axis observable
get_backup_net(generation, index)

Get network from the backup file(or restart). In opposition to the best_net file the restart file is note stored at every generation but it contains a full population. This funciton allows to grab any individual of the population when the generation is stored

Parameters:
  • generation – index of the generation (must be a stored generation)
  • index – index of the network within its generation
Returns:

the selected network object

get_backup_pop(generation)

Cf get_backup_net. Get the complete population of networks for a generation that was backuped.

Parameters:generation – index of the generation (must be a stored generation)
Returns:List of the networks present in the population at the selected generation
get_best_net(generation)

The functions returns the best network of the selected generation

Parameters:seed (int) – number of the seed to look at
Returns:the best network for the selected generation
Return type:Networks
show_fitness(smoothen=0, **kwargs)

Plot the fitness as a function of time

stored_generation_indexes()

Return the list of the stored generation indexes

Returns:list of the stored generation indexes
class phievo.AnalysisTools.Simulation.Seed_Pareto(path, nbFunctions)

Bases: phievo.AnalysisTools.Simulation.Seed

pareto_generate_fit_dict(generations, max_rank=1)

Load fitness data for the selected generations and format them to be understandable by plot_pareto_fronts

plot_pareto_fronts(generations, max_rank=1, with_indexes=False, legend=False, xlim=[], ylim=[], colors=[], gradient=[], xlabel='F_1', ylabel='F_2', s=50, no_popup=False)

Plot every the network of the selected generations in the (F_1,F_2) fitness space.

Parameters:
  • generations (list) – list of the selected generations
  • max_rank (int) – In given population plot only the network of rank <=max_rank
  • with_indexes (bool) – NotImplemented
  • legend (bool) – NotImplemented
  • xlim (list) – [xmax,xmin]
  • ylim (list) – [ymax,ymin]
  • colors (list) – List of html colors, one for each generation
  • gradient (list) – List of colors to include in the gradient
  • xlabel (str) – Label of the xaxis
  • ylabel (str) – Label of the yaxis
  • s (float) – marker size
  • no_popup (bool) – prevents the popup of the plot windows
Returns:

matplotlib figure

show_fitness(smoothen=0, index=None)

Plot the fitness as a function of time

Parameters:
  • seed (int) – the seed-number of the run
  • index (array) – index of of the fitness to plot. If None, all the fitnesses are ploted
Returns:

Matplolib figure

class phievo.AnalysisTools.Simulation.Simulation(path, mode='default')

Bases: object

The simulation class is a container in which the informations about a simulation are unpacked. This is used for easy access to a simulation results.

PlotData(data, xlabel, ylabel, select_genes=[], no_popup=False, legend=True, lw=1, ax=None)

Function in charge of the call to matplotlib for both Plot_TimeCourse and Plot_Profile.

Plot_Profile(trial_index, time=0, select_genes=[], no_popup=False, legend=True, lw=1, ax=None)

Searches in the data last stored in the Simulation buffer for the time course corresponding to the trial_index and plot the gene profile along the cells at the selected time point.

Parameters:
  • trial_index – index of the trial you. Refere to run_dynamics to know how
  • trials there are. (many) –
  • time – Index of the time to select
  • select_genes – list of gene indexes to plot
  • no_popup – False by default. Option used to forbid matplotlib popup windows Useful when saving figures to a file.
Returns:

figure

Plot_TimeCourse(trial_index, cell=0, select_genes=[], no_popup=False, legend=True, lw=1, ax=None)

Searches in the data last stored in the Simulation buffer for the time course corresponding to the trial_index and the cell and plot the gene time series

Parameters:
  • trial_index – index of the trial you. Refere to run_dynamics to know how
  • trials there are. (many) –
  • cell – Index of the cell to plot
  • select_genes – list of gene indexes to plot
  • no_popup – False by default. Option used to forbid matplotlib popup windows Useful when saving figures to a file.
Returns:

figure

clear_buffer()

Clears the variable self.buffer_data.

custom_plot(seed, X, Y)

Plot the Y as a function of X. X and Y can be chosen in the list [“fitness”,”generation”,”n_interactions”,”n_species”]

Parameters:
  • seed (int) – number of the seed to look at
  • X (str) – x-axis observable
  • Y (str) – y-axis observable
get_backup_net(seed, generation, index)

Get network from the backup file(or restart). In opposition to the best_net file the restart file is note stored at every generation but it contains a full population. This funciton allows to grab any individual of the population when the generation is stored

Parameters:
  • seed – index of the seed
  • generation – index of the generation (must be a stored generation)
  • index – index of the network within its generation
Returns:

The selected network object

get_backup_pop(seed, generation)

Cf get_backup_net. Get the complete population of networks for a generation that was backuped.

Parameters:
  • seed – index of the seed
  • generation – index of the generation (must be a stored generation)
Returns:

List of the networks present in the population at the selected generation

get_best_net(seed, generation)

The functions returns the best network of the selected generation

Parameters:
  • seed (int) – number of the seed to look at
  • generation (int) – number of the generation
Returns:

The best network for the selected generation

get_genealogy(seed)
load_Profile_data(trial_index, time)

Loads the data from the simulation and generate ready to plot data. :param trial_index: index of the trial you. Refere to run_dynamics to know how :param many trials there are.: :param time: Index of the time to select

run_dynamics(net=None, trial=1, erase_buffer=False, return_treatment_fitness=False)

Run Dynamics for the selected network. The function either needs the network as an argument or the seed and generation information to select it. If a network is provided, seed and generation are ignored.

Parameters:
  • net (Networks) – network to simulate
  • trial (int) – Number of independent simulation to run
Returns:

data (dict) dictionnary containing the time steps at the “time” key, the network at “net” and the corresponding time series for index of the trial.

  • net : Network

  • time : time list

  • outputs: list of output indexes

  • inputs: list of input indexes

  • 0 : data for trial 0
    • 0 : array for cell 0:

      g0 g1 g2 g3 ..

      t0 . t1 . t2 . . .

show_fitness(seed, smoothen=0, **kwargs)

Plot the fitness as a function of time

Parameters:seed (int) – the seed-number of the run
Returns:matplotlib figure
stored_generation_indexes(seed)

Return the list of the stored generation indexes

Parameters:seed (int) – Index of Seed, you want the stored generation for.
Returns:list of the stored generation indexes

Palette

phievo.AnalysisTools.palette.HSL_to_RGB(h, s, l)

Converts HSL colorspace (Hue/Saturation/Value) to RGB colorspace. Formula from http://www.easyrgb.com/math.php?MATH=M19#text19

Parameters:
  • h (float) – Hue (0…1, but can be above or below (This is a rotation around the chromatic circle))
  • s (float) – Saturation (0…1) (0=toward grey, 1=pure color)
  • l (float) – Lightness (0…1) (0=black 0.5=pure color 1=white)
Returns:

Corresponding RGB values

Return type:

(r,g,b) (integers 0…255)

Examples

>>> print HSL_to_RGB(0.7,0.7,0.6)
(110, 82, 224)
>>> r,g,b = HSL_to_RGB(0.7,0.7,0.6)
>>> print g
82
phievo.AnalysisTools.palette.color_generate(n, colormap=None)

Returns a palette of colors suited for charting.

Parameters:
Returns:

A list of colors in HTML notation (eg.[‘#cce0ff’, ‘#ffcccc’, ‘#ccffe0’, ‘#f5ccff’, ‘#f5ffcc’])

Return type:

list

Example

>>> print color_generate(5)
['#5fcbff','#e5edad','#f0b99b','#c3e5e4','#ffff64']
phievo.AnalysisTools.palette.floatrange(start, stop, steps)

Computes a range of floating value.

Parameters:
  • start (float) – Start value.
  • end (float) – End value
  • steps (integer) – Number of values
Returns:

A list of floats with fixed step

Return type:

list

Example

>>> print floatrange(0.25, 1.3, 5)
[0.25, 0.51249999999999996, 0.77500000000000002, 1.0375000000000001, 1.3]
phievo.AnalysisTools.palette.generate_gradient(values, seq)

Generates a desired list of colors along a gradient from a custom list of colors.

Parameters:
  • values – list of values that need to ba allocated to a color
  • seq – sequence of colors in the gradient
phievo.AnalysisTools.palette.make_colormap(seq)

Return a LinearSegmentedColormap seq: a sequence of floats and RGB-tuples. The floats should be increasing and in the interval (0,1).

phievo.AnalysisTools.palette.update_default_colormap(colormap)

Update the color map used by the palette modules

Arg:
colormap (str): name of the matplotlib colormap
http://matplotlib.org/examples/color/colormaps_reference.html

extra_functions

phievo.AnalysisTools.main_functions.download_example(example_name, directory=None)

Download an example seed or project.

phievo.AnalysisTools.main_functions.download_tools(run_evolution='run_evolution.py', AnalyseRun='AnalyseRun.ipynb', ProjectCreator='ProjectCreator.ipynb')
phievo.AnalysisTools.main_functions.download_zip(dir_name, url)

Download and extract zip file to dir_name.

phievo.AnalysisTools.main_functions.load_generation_data(generations, restart_file)

Searches in the restart file the the informations that has been backed up up about the individuals at a given generations.

Parameters:
  • generations (list) – index of the generations to load_generation_data
  • restart_file – path of the restart_file
Returns:

dictionary where each key contains the informations about one generation.

phievo.AnalysisTools.main_functions.read_network(filename, verbose=False)

Retrieve a whole network from a pickle object named filename

Parameters:filename (str) – the directory where the object is saved
Returns:The stored network
phievo.AnalysisTools.main_functions.smoothing(array, param)

Smoothen an array by averaging over the neighbourhood

Parameters:
  • array (list) – the to be smoothed array
  • param (int) – the distance of the neighbourhood
Returns:

list of same size as array