cellsystem.simulation package¶
Submodules¶
cellsystem.simulation.cells module¶
Structures representing the biological entities.
-
class
cellsystem.simulation.cells.
Cell
(lineage, index)[source]¶ Bases:
object
A single cell.
It acts according to it’s state, and the states of nearby cells and sites.
-
+ Index
A label that identifies it among others in the same lineage.
-
+ Father
The index (lineage label) of it’s father.
-
+ CellLine
The lineage this cell belongs to.
-
+ Site
The place in the grid this cell inhabits in.
-
+ Mutations
The mutations in this cell relative to the cell lineage’s reference
-
add_mutation
(position, mutated)[source]¶ Add a mutation to the cell in the given position of the genome.
Note: The genome may not represent a nucleotide sequence, so these mutations may not represent SNPs.
-
ancestral_genome
¶ Ancestral genome of the cell lineage.
-
coordinates
¶ Coordinates of the site that the cell inhabits.
-
genome
¶ Genome of the cell.
It is assembled from the cell’s ancestral genome and it’s mutations.
-
genome_alphabet
¶ Genome alphabet of the cell line.
The set of characters a genome is composed of. (The genome characters may really represent genes, aminoacids, etc…)
-
initialize
(site=None, father=None, mutations=None)[source]¶ Initialize grid site, mutations and father.
-
mutations
¶ Record of the mutations the cell has had.
The mutations are relative to the ancestral genome.
-
-
class
cellsystem.simulation.cells.
CellLine
(*args, genome=None, genome_alphabet=None, recycle_dead=True, **kwargs)[source]¶ Bases:
object
Handles the specimens of a specific cell lineage.
A cell lineage is a group of cells that have a common ancestor, we represent the common ancestor by it’s ancestral genome. This structure is in charge of holding this ancestral code and managing the cells creating new cells when needed and cleaning up the dead ones.
- Atributes:
- Ancestral genome: A string-like object.
- Cells: The cells inherited from this cell line.
- Alive/Dead cells.
- Current cell index: Each cell has a unique index. This is the
- index to place in the next cell to be born.
-
add_behaviors
(behaviors, weights=None)[source]¶ Add the behaviors defining the cells from this cell line.
Params:
- behaviors (list of callables):
- The list of actions that the cells in this lineage will be able to perform.
- weights (optional list of numeric values):
- The list of relative weights for selecting each action. The bigger the weight of an action relative to the weights of the others, the more likely is that that action will be selected by the cell at each step. default is all actions have the same weights.
Raises: ValueError
– If the weights are not of the same length as the behaviors.
-
handle_death
(dying)[source]¶ Process a dying cell.
This means removing from the alive cells and adding to the dead ones, maybe to recycle it when another is born.
-
sample
(all=False, n=1)[source]¶ Take a sample of alive cells.
Parameters: - all – If True, return all alive cells, else, return a sample of size n.
- n – The size of the sample. If 1, return the cell without a container.
-
total_cells
¶
-
cellsystem.simulation.cells.
behavior
(actionname, actionfn=None, probability=None, prepare=True)[source]¶ Assemble a cell behavior.
Adds logging and asociates a name and a probability function to the raw action function. Allows to specify if the logging of the action requires to prepare the log.
Can be used as a function decorator or as a normal function.
cellsystem.simulation.logging module¶
cellsystem.simulation.system module¶
System-related classes.
This module defines a general system that can be used as the base of a computation graph.
A system is composed of entities and interactions btw them, it coordinates all processes.
-
class
cellsystem.simulation.system.
Entity
[source]¶ Bases:
object
An entity is something that resides in the system.
It processes information according to it’s internal state and the information flowing through the links it shares with other entities.
- An entity registers the following methods:
- process(time)
-
class
cellsystem.simulation.system.
Interaction
(entities, effect)[source]¶ Bases:
object
A structure representing flow of information btw entities.
-
class
cellsystem.simulation.system.
Process
(entities, effects)¶ Bases:
tuple
-
effects
¶ Alias for field number 1
-
entities
¶ Alias for field number 0
-
-
class
cellsystem.simulation.system.
System
(*args, **kwargs)[source]¶ Bases:
object
The global system and event dispatcher.
Aware of the passage of time (steps). A system is composed of entities and interactions between them, at each time step, the system triggers the proceses associated with them.
-
add_entity
(entity, name, procesable=True, inithook=None)[source]¶ Add an entity to the graph.
If procesable, the entity.process(time) method is called on each time step.
Inithooks are callables called at initialization.
-
add_interaction_to
(container, effect, entitynames)[source]¶ Add an interaction btw named entities to a dict-like container.
-
cellsystem.simulation.world module¶
Classes associated with physical space where entities live and interact.
-
class
cellsystem.simulation.world.
Site
(world, coordinates)[source]¶ Bases:
object
A unit of space.
Cells inhabitate in these spaces and interact with their neighborhood.
- Is aware of:
- World: The world it forms a part of.
- Coordinates <i,j>: Coordinates in the matrix.
- Guests: <List>: The guests currently inhabiting this site.
-
coordinates
¶ Getter for the site’s coordinates.
-
class
cellsystem.simulation.world.
World
(shape=(10, 10), wrap=<function toroidal_wrap>)[source]¶ Bases:
object
The space in which cells inhabit.
It represents physical space and enforces rules and properties like distance and closeness.
- A world is aware of:
- Grid: The sites the action develops in.
- Neighborhood: How many and which sites may directly influence or
- be influenced by another.
-
middle
¶ Get the site at the middle of the world.
-
cellsystem.simulation.world.
toroidal_wrap
(grid, coord)[source]¶ Return the coordinates wrapped on the grid dimensions.
-
cellsystem.simulation.world.
wrap
(n, maxValue)[source]¶ Auxiliary function to wrap an integer on maxValue.
Examples
>>> # For positives: wrap(n, maxValue) = n % maxValue >>> [ wrap(i,3) for i in range(9) ] [0, 1, 2, 0, 1, 2, 0, 1, 2]
>>> # For negatives, the pattern is continued in a natural way >>> for i in range(-5, 5+1): print(f'{i} : {wrap(i, 3)}') ... -3 : 0 -2 : 1 -1 : 2 0 : 0 1 : 1 2 : 2
Module contents¶
-
class
cellsystem.simulation.
System
(*args, **kwargs)[source]¶ Bases:
object
The global system and event dispatcher.
Aware of the passage of time (steps). A system is composed of entities and interactions between them, at each time step, the system triggers the proceses associated with them.
-
add_entity
(entity, name, procesable=True, inithook=None)[source]¶ Add an entity to the graph.
If procesable, the entity.process(time) method is called on each time step.
Inithooks are callables called at initialization.
-
add_interaction_to
(container, effect, entitynames)[source]¶ Add an interaction btw named entities to a dict-like container.
-
-
class
cellsystem.simulation.
CellLine
(*args, genome=None, genome_alphabet=None, recycle_dead=True, **kwargs)[source]¶ Bases:
object
Handles the specimens of a specific cell lineage.
A cell lineage is a group of cells that have a common ancestor, we represent the common ancestor by it’s ancestral genome. This structure is in charge of holding this ancestral code and managing the cells creating new cells when needed and cleaning up the dead ones.
- Atributes:
- Ancestral genome: A string-like object.
- Cells: The cells inherited from this cell line.
- Alive/Dead cells.
- Current cell index: Each cell has a unique index. This is the
- index to place in the next cell to be born.
-
add_behaviors
(behaviors, weights=None)[source]¶ Add the behaviors defining the cells from this cell line.
Params:
- behaviors (list of callables):
- The list of actions that the cells in this lineage will be able to perform.
- weights (optional list of numeric values):
- The list of relative weights for selecting each action. The bigger the weight of an action relative to the weights of the others, the more likely is that that action will be selected by the cell at each step. default is all actions have the same weights.
Raises: ValueError
– If the weights are not of the same length as the behaviors.
-
handle_death
(dying)[source]¶ Process a dying cell.
This means removing from the alive cells and adding to the dead ones, maybe to recycle it when another is born.
-
sample
(all=False, n=1)[source]¶ Take a sample of alive cells.
Parameters: - all – If True, return all alive cells, else, return a sample of size n.
- n – The size of the sample. If 1, return the cell without a container.
-
total_cells
¶
-
class
cellsystem.simulation.
Action
(action, probability=None, name=None)[source]¶ Bases:
object
Objects of this class represent actions with an associated probability.
-
class
cellsystem.simulation.
World
(shape=(10, 10), wrap=<function toroidal_wrap>)[source]¶ Bases:
object
The space in which cells inhabit.
It represents physical space and enforces rules and properties like distance and closeness.
- A world is aware of:
- Grid: The sites the action develops in.
- Neighborhood: How many and which sites may directly influence or
- be influenced by another.
-
middle
¶ Get the site at the middle of the world.
-
cellsystem.simulation.
behavior
(actionname, actionfn=None, probability=None, prepare=True)[source]¶ Assemble a cell behavior.
Adds logging and asociates a name and a probability function to the raw action function. Allows to specify if the logging of the action requires to prepare the log.
Can be used as a function decorator or as a normal function.