VirtualMicrobes.virtual_cell package

Submodules

VirtualMicrobes.virtual_cell.Cell module

class VirtualMicrobes.virtual_cell.Cell.Cell(params, environment, rand_gen, toxicity_function=None, toxicity_effect_function=None, time_birth=-1, **kwargs)[source]

Bases: VirtualMicrobes.virtual_cell.PhyloUnit.PhyloUnit

GRN(genes=None, prot_color_func=<function <lambda>>, with_gene_refs=False, with_self_marker=False)[source]

Make Gene Regulatory Network representation of the regulated genome.

First, the lists of nodes and edges is generated for the given genes. Then, nodes are added to a Directed Graph (networkx.DiGraph) object with attributes that distinguish the gene type and other characteristics. Finally, edges are added with attributes that indicate e.g. binding strength.

Returns:
Return type:networkx.Digraph
add_gene_copy(gene, concentration=0.0, diff_constant=None, degr_constant=None)[source]

Add gene product to the cell. If the ‘gene’ is already present as a key in the subdictionary, adding it again means we have to increase the multiplicity of the gene product, since there are multiple genes coding for this gene product. Otherwise, we add an entry for this gene product.

Parameters:
  • gene (VirtualMicrobes.virtual_cell.Gene.Gene) – The gene for which copy number is increased.
  • concentration (float) – Initial concentration of gene product.
  • diff_constant (float) – Diffusion constant of gene product over the cell membrane. (If None, no diffusion is modeled)
  • degr_constant (float) – Degradation constant of gene product.
add_gene_product(gene, concentration=None)[source]

Initialize gene products from the genes in the genome.

Gene products have a concentration and degradation rate. ODE system integration will use the gene products as input variables.

Parameters:concentration (float) – initial concentration of gene products
add_small_molecule(mol, env, concentration, diff_const, degr_const)[source]

Add a metabolite to the internal Cell molecules and set its state.

Parameters:
add_small_molecules(env, conc, degr_const, ene_degr_const, bb_degr_const)[source]

Add the metabolites in the environment as internal variables to this individual.

Set a membraned diffusion rate and degradation rate for the molecules. Diffusion rates come from a dictionary of the environment. Degradation rates also come from a dictionary in the environment, but may be scaled with an ‘internal’ degr_const parameter to cause degradation rates to be different inside and outside of the cell.

Parameters:
  • env (VirtualMicrobes.environment.Environment.Environment) – environment containing metabolites
  • conc (float) – start concentration of all metabolites
  • degr_const (float) – degradation constant of metabolites
  • ene_degr_const (float) – degradation constant of energy metabolites
  • bb_degr_const (float) – degradation constant of building block metabolites
ancestral_mutations

Cumulative mutations in the line(s) of descent.

For each LOD of this individual concatenate all mutations in each mutation category that happened in the ancestors of this individual. Because multiple LODs might exist, return a list of dictionaries that hold all mutations that this lineage acumulated, per mutation category.

Returns:
Return type:list of mutation dictionaries of LODs
apply_hgt(time, gp, environment, rand_gene_params=None, mutation_rates=None, global_mut_mod=None, rand_gen=None, rand_gen_np=None, verbose=False)[source]

Applies HGT to a cell, and updates the GRN.

If applied HGT is applied, the gp updated flag is set to True, to inform integrator update in next timestep.

Parameters:
  • time (int) – time point in the simulation
  • gp (VirtualMicrobes.environment.Grid.GridPoint) – location of cell on the grid
  • environment (VirtualMicrobes.environment.Environment.Environment) – simulation environment containing all possible reactions to draw a random gene for external HGT
  • rand_gene_params (dict) – parameter space for properties of externally HGTed genes
  • mutation_rates (dict) – contains rates for eHGT and iHGT
  • global_mut_mod (double) – scaling factor for all mutation rates
  • rand_gen (RNG) –
  • rand_gen_np (RNG numpy) –
Returns:

Return type:

The applied mutations are returned

asexual(time)[source]

Asexual reproduction.

Parameters:time (int) – simulation time point
Returns:
Return type:VirtualMicrobes.virtual_cell.Cell.Cell
avrg_promoter_strengths
building_blocks

Building Blocks in metabolism of this individual.

calculate_raw_death_rate(base_rate, toxicity_scaling, toxic_effect_func=None)[source]

Raw death rate based on a base rate and the toxic effects of internal molecule concentrations.

Parameters:
  • base_rate (float) – base death rate
  • toxicity_scaling (float) – scaling constant for toxic effect
  • toxic_effect_func (func) – calculates surplus death rate due to toxicity
cap_lineage_marker(max_lin_marker)[source]
chromosomal_mut

List of chromosomal mutations of this individual.

chromosomal_mut_count

Number of chromosomal mutations of this individual.

chromosome_count
chromosome_del

List of chromosome deletions of this individual.

chromosome_del_count

Number of chromosomal deletions of this individual.

chromosome_dup

List of chromosome duplications of this individual.

chromosome_dup_count

Number of chromosomal duplications of this individual.

chromosome_fiss_count

Number of chromosomal fissions of this individual.

chromosome_fission

List of chromosome fissions of this individual.

chromosome_fuse_count

Number of chromosomal fusions of this individual.

chromosome_fusion

List of chromosome fusions of this individual.

chromosome_mutate_genome(time, mutation_rates, global_mut_mod, rand_gen, rand_gen_np, verbose)[source]

Apply chromosomal mutations to the genome.

Each type of chromosome mutation is applied independently. When a mutation is selected, one or two random chromosomes are chosen for the mutation. The mutation method return a Mutation instance, that is appended to a list of chromosome mutations. This list is returned.

Parameters:
  • time (int) – simulation time
  • mutation_rates (attr_dict) – dict with all mutation rates
  • global_mut_mod (float) – modifier for Cell wide mutation rate
  • rand_gen (RNG) –
  • rand_gen_np (RNG) – numpy random number generator
  • verbose (bool) – verbosity
Returns:

Return type:

list of Mutation objects

class_version = '3.0'
clear_mol_time_courses()[source]

Set time course arrays to None.

Notes

Reduces memory footprint of cell, for example before saving cell objects.

clone(time)[source]

Make a clone of this cell.

Clones are identical, having no mutations, and maintain a reference to the parent.

Parameters:time (int) – simulation time point
Returns:
Return type:VirtualMicrobes.virtual_cell.Cell
compute_product_toxicity(toxicity_func=None)[source]

Set toxicity effect of product.

consumer_type

Return the set of all metabolic classes consumed in enzymatic reactions by this cell.

consumes

Set of consumed metabolic species.

consuming_count

Number of metabolic classes consumed by this individual.

conversions_type

The set of conversion reactions in the genome.

copy_numbers
copy_numbers_eff_pumps
copy_numbers_enzymes
copy_numbers_inf_pumps
copy_numbers_tfs
delete_chromosome(chrom, time)[source]

Chromosome deletion.

Creates a mutation object that is then responsible for calling the appropriate genomic operations (deletion methods of chromosome and genome updation functions of genome. The Cell then updates its gene product counts accordingly.

Parameters:
Returns:

Return type:

VirtualMicrobes.mutation.Mutation.ChromosomeDeletion

delete_genes(genes, time)[source]
delete_stretch(chrom, start_pos, end_pos, time, verbose=False)[source]

Delete a stretch of genes in the genome.

The chromosome, start position and end position (exclusive) uniquely determine a sequence of genes that will be deleted. The copy number of gene products in the cell is reduced. A Mutation object will be returned.

Parameters:
  • chrom (VirtualMicrobes.virtual_cell.Chromosome.Chromosome) – target chromosome
  • start_pos (int) – position index of the start of the stretch
  • end_pos (int) – position index of the end of the stretch
  • time (int) – simulation time
  • verbose (bool) – verbosity
Returns:

Return type:

VirtualMicrobes.mutation.Mutation.StretchDeletion

die(time, verbose=False, clear_time_courses=False, wiped=False)[source]

Cell death.

Informs genomic units of cell death.

Parameters:
  • time (float) – simulation time point
  • verbose (mol : VirtualMicrobes.event.Molecule.Molecule) – metabolitebool report on cell death
  • clear_time_courses (bool) – set time courses to None
  • wiped (bool) – set if cell death was due to wiping of (a fraction of) the population
divide_volume(factor=2.0)[source]

Divide the volume of the cell.

Parameters:factor (float) – division factor
duplicate_chromosome(chrom, time)[source]

Chromosome duplication.

Creates a mutation object that is then responsible for calling the appropriate genomic operations (duplication methods in chromosome and genome updation functions of genome. The Cell then updates its gene product counts accordingly.

Parameters:
Returns:

Return type:

VirtualMicrobes.mutation.Mutation.ChromosomeDuplication

eff_pump_count
enz_avrg_promoter_strengths
enz_promoter_strengths
enz_subs_differential_ks
enz_subs_ks
enz_sum_promoter_strengths
enz_vmaxs
enzyme_count
enzymes

Enzyme products in the Cell.

Notes

Can include gene products of genes that are no longer in the genome.

exploiting

Return the set of metabolic classes that are imported and consumed.

exploiting_count

Number of metabolic classes imported and consumed by this individual.

export_type

Return the set of all metabolic classes exported by this cell.

exporter_type

The set of export reactions in the genome.

exporting_count

Number of metabolic classes exported by this individual.

external_hgt

List of external Horizontal Gene Transfers of this individual.

external_hgt_count

Number of external Horizontal Gene Transfers of this individual.

fiss_chromosome(chrom, pos, time)[source]

Chromosome fission.

Breaks apart a chromosome at a given position. The two resulting parts will become new chromosome replacing the original in the genome. Creates a mutation object that is then responsible for calling the appropriate genomic operations.

Parameters:
Returns:

Return type:

VirtualMicrobes.mutation.Mutation.Fission

classmethod from_file(parameter_dict, environment, init_rand_gen, file_path)[source]
classmethod from_params(parameter_dict, environment, init_rand_gen)[source]
fuse_chromosomes(chrom1, chrom2, end1, end2, time)[source]

Fusion of two chromosomes.

Two chromosomes are fused end to end. The new product replaces the original two chromosomes in the genome.

chrom1 : VirtualMicrobes.virtual_cell.Chromosome.Chromosome
first chromosome to be fused
chrom2 : VirtualMicrobes.virtual_cell.Chromosome.Chromosome
second chromosome to be fused
end1 : bool
indicate end or start of the first chromosome will be fused
end2 : bool
indicate end or start of the second chromosome will be fused
Returns:
Return type:VirtualMicrobes.mutation.Mutation.Fusion
gene_substrate_differential_ks(ks_param, genes)[source]

Calculate differences between K parameters per substrate for a list of genes.

Parameters:
  • ks_param (str) – type of parameter
  • genes (list) – list of genes for which to calculate the diffs
Returns:

Return type:

array of diffs per gene

gene_substrate_ks(ks_param, genes)[source]
gene_type_counts
generate_enzymes(nr_enzymes, env, rand_gen, metabolic_pathway_dict, prioritize_influxed=True)[source]

Generate the set of enzymes of the cell.

Uses heuristics for constructing ‘viable’ initial metabolic pathways for the production of building blocks and energy metabolites.

Parameters:
  • nr_enzymes (int) – number of enzymes to generate
  • env (VirtualMicrobes.environment.Environment.Environment) – environment provides the set of metabolites and possible metabolic reactions
  • rand_gen (RNG) –
  • metabolic_pathway_dict (dict) – dictionary to keep track of metabolites consumed and produced by the cell.
  • prioritize_influxed (bool) – first create enzymes that can utilize metabolites that are present (influxed) in environment
Returns:

Return type:

list of :class:`VirtualMicrobes.virtual_cell.Gene.MetabolicGene`s

generate_pumps(nr_pumps, env, rand_gen, metabolic_pathway_dict, import_first=True, prioritize_influxed=True)[source]

Generate set of transporters of the cell.

Use heuristics for connecting to the metabolic pathways formed so far by the enzymes present in the cell.

Parameters:
  • nr_pumps (int) – number of transporters to generate
  • env (VirtualMicrobes.environment.Environment.Environment) – environment provides the set of metabolites and possible metabolic reactions
  • rand_gen (RNG) –
  • metabolic_pathway_dict (dict) – dictionary to keep track of metabolites consumed and produced by the cell.
  • import_first (bool) – first create import enzymes for all metabolites that can be consumed in metabolism
  • prioritize_influxed (bool) – first create transporters that can import metabolites that are present (influxed) in environment
Returns:

Return type:

list of :class:`VirtualMicrobes.virtual_cell.Gene.Transporter`s

See also

generate_enzymes

generate_tfs(nr_tfs, env, rand_gen, metabolic_pathway_dict, bb_ene_only=False)[source]

Create TFs of the cell.

Prioritizes TFs that sense metabolites that are relevant for the cell, i.e. metabolites that are actively consumed or produced by the cell’s enzymes (or production function).

Parameters:
  • nr_tfs (int) – number of tfs to generate
  • env (VirtualMicrobes.environment.Environment.Environment) – environment provides the set of metabolites and possible metabolic reactions
  • rand_gen (RNG) –
  • metabolic_pathway_dict (dict) – dictionary to keep track of metabolites consumed and produced by the cell.
  • bb_ene_only (bool) – create TFs with either a building block or an energy carrier as ligand exclusively
Returns:

Return type:

list of :class:`VirtualMicrobes.virtual_cell.Gene.TranscriptionFactor`s

genes_get_prop_vals(genes, get_prop)[source]

Construct array of values of a gene property for all duplicates of a list of genes.

Parameters:
  • genes (list of VirtualMicrobes.virtual_cell:Gene:Gene objects) – The genes for which to list the proprty
  • get_prop (func [VirtualMicrobes.virtual_cell:Gene:Gene] -> value) – A function that takes a gene as argument and returns a value
Returns:

Return type:

numpy array

genome_size
genotype

Construct frozen set of the genotype classification of this cell.

The genotype represents the gene functionality that the cell is capable of. It is expressed as the total set of transport, enzymatic and transcription sensing capabilities of the cell.

Returns:
Return type:frozenset
genotype_vector(env)[source]

Construct boolean vector of gene-type presence-absence.

Parameters:env (VirtualMicrobes.environment.Environment.Environment) – environment relative to which the gene type presence absence is determined
Returns:
get_ancestor(gen_back, verbose=False)[source]
get_ancestor_at_time(time)[source]
get_cell_size_time_course()[source]

Time course of cell size.

get_gene_concentration_dict()[source]

Mapping of gene products to current concentration.

get_gene_degradation_dict()[source]

Mapping of gene products to degradation rates.

get_gene_diffusion_dict()[source]

Mapping of gene products to diffusion rates.

get_gene_multiplicities_dict()[source]

Mapping of gene products to copy numbers in the genome.

get_gene_prod_conc(gene)[source]

Get current gene product concentration.

Parameters:gene (VirtualMicrobes.virtual_cell.Gene.Gene) – gene product
Returns:
Return type:concentration value (float)
get_gene_time_course_dict()[source]

Fetches time courses for gene products (proteins)

Returns:
Return type:dictionary of all time courses
get_gene_type_time_course_dict()[source]

Return a dictionary of concentration time course data for different gene types.

get_mol_concentration_dict()[source]

Mapping of internal molecule species to current concentrations.

get_mol_degradation_dict()[source]

Mapping of internal molecule species to degradation rates.

get_mol_diffusion_dict()[source]

Mapping of internal molecule species to diffusion rates.

get_mol_time_course_dict()[source]

Mapping of internal molecule species to concentration time course.

get_pos_prod_time_course()[source]

Time course of positive component of production rate.

get_raw_production_time_course()[source]

Time course of raw production value.

get_small_mol_conc(mol)[source]

Get current metabolite concentration.

Parameters:mol (VirtualMicrobes.event.Molecule.Molecule) – metabolite
Returns:
Return type:concentration value (float)
get_time_points()[source]

Array of (data) time points stored.

get_total_expression_level(reaction, exporting=False)[source]

Get total expression of a certain type of reaction

Parameters:
  • reaction (VirtualMicrobes.event.Reaction) –
    or
    VirtualMicrobes.event.MoleculeClass

    reaction or moleculeclass for TFs

  • exporting – whether pump is exporting
Returns:

Return type:

concentration valule (float)

get_total_reaction_type_time_course_dict()[source]

Return a dictionary of summed time courses per reaction type.

Gets the time courses per gene type and then sums concentrations of gene products with the same reaction (enzymes/pumps) or ligand (tfs).

get_toxicity_time_course()[source]

Time course of cell toxicity.

grow_time_course_arrays(factor=1.5)[source]

Grow time course arrays if they cannot hold enough new time points.

Parameters:factor (float) – increase capacity with this factor
hgt_external(hgt_rate, global_mut_mod, environment, time, rand_gene_params, rand_gen)[source]

Insert a randomly generated (external) gene into the genome.

Gene is created with random parameters and inserted (as a stretch) into a randomly picked chromosome and position.

Parameters:
  • hgt_rate (float) – probability external hgt
  • global_mut_mod (float) – mutation scaling parameter of all mutation rates
  • environment (VirtualMicrobes.environment.Environment.Environment) – simulation environment containing all possible reactions to draw a random gene for external HGT.
  • time (int) – simulation time
  • rand_gene_params (dict) – parameter space for properties of externally HGTed genes
  • rand_gen (RNG) –
Returns:

Return type:

VirtualMicrobes.mutation.Mutation.Insertion

hgt_internal(hgt_rate, global_mut_mod, gp, time, rand_gene_params, rand_gen, rand_gen_np)[source]

Insert a randomly chosen gene (stretch) from a neighboring individual into the genome.

Potential donor individuals come from the neighbourhood of a focal grid point. Once a donor individual is selected, a random gene is chosen to be transferred to this individual.

Parameters:
  • hgt_rate (float) – probability external hgt
  • global_mut_mod (float) – mutation scaling parameter of all mutation rates
  • gp (VirtualMicrobes.environment.Grid.GridPoint) – focal grid point to select donor individual
  • time (int) – simulation time
  • rand_gene_params (dict) – parameter space for properties of externally HGTed genes
  • rand_gen (RNG) –
Returns:

Return type:

VirtualMicrobes.mutation.Mutation.Insertion

hybridize(second_parent, time)[source]
import_type

Return the set of all metabolic classes imported by this cell.

importer_type

The set of import reactions in the genome.

importing_count

Number of metabolic classes imported by this individual.

inf_pump_count
init_building_blocks_dict(nr_blocks, rand_gen, stois)[source]

Initialize the dictionary of cellular building blocks and their stoichiometry.

Parameters:
  • nr_blocks (int) – number of different metabolic building blocks of the cell.
  • rand_gen (RNG) –
  • stois (tuple of int) – (lower, higher) range of stoichiometric constants from which to randomly draw stoichiometries.
init_cell_params()[source]

Set cell parameters based on simulation parameter settings.

init_cell_time_courses(length=None)[source]

Initialize arrays to hold time course data.

Parameters:length (int) – initial length of array
init_energy_mols(environment)[source]

Store the energy molecules of the cell.

Parameters:environment (VirtualMicrobes.environment.Environment.Environment) – simulation environment that contains metabolic universe

Notes

energy_mols are used in odes.pyx

init_gene_products(concentration=None)[source]

Initialize gene products from the genes in the genome.

Gene products have a concentration and degradation rate. ODE system integration will use the gene products as input variables.

Parameters:concentration (float) – initial concentration of gene products
init_genome(environment, chrom_compositions=None, min_bind_score=None, prioritize_influxed=None, rand_gene_params=None, circular_chromosomes=None, better_tf_params=None, rand_gen=None, randomize=True)[source]

Iniitialize the genome of the cell.

The genome is constructed according to a list of chromosome composition descriptions. These descriptions specify the number of each gene type a set of chromosomes. Sets of metabolic , transport and transcription factor genes are initialized using heuristic functions that guarantee basic viability of the cell and a basic logic in transported and sensed metabolites, by taking into account the set of indispensible metabolites (building blocks and energy carriers). Finally, kinetic and other parameters of all genes are randomized and the genes distributed over the chromosomes.

Parameters:
  • environment (VirtualMicrobes.environment.Environment.Environment) – simulation environment that determines metabolic universe
  • chrom_compositions (list of VirtualMicrobes.my_tools.utility.GeneTypeNumbers) – per chromosome composition of different gene types
  • min_bind_score (float) – parameter for minimal binding score for transcription regulation
  • prioritize_influxed (bool) – first choose enzymatic reactions that use substrates that are influxed in environment
  • rand_gene_params (VirtualMicrobes.my_tools.utility.ParamSpace) – range from which to draw randomized gene parameters
  • circular_chromosomes (bool) – make the chromosomes circular
  • rand_gen (RNG) –
  • randomize (bool) – whether gene parameters should be randomized after creation
Returns:

Return type:

VirtualMicrobes.virtual_cell.Genome.Genome

init_mol_time_course(mol_struct, length=None)[source]

Initialize an array for time course data in a molecule structure SmallMol or GeneProduct.

Parameters:
  • mol_struct (VirtualMicrobes.my_tools.utility.SmallMol) – simple c-struct like object that holds data on small molecules or gene products
  • length (int) – initial length of time course array
init_mol_views()[source]

Initialize ‘aliases’ for the set of small molecules and that of gene products in the cell.

init_mutations_dict()[source]

Initialize a dictionary for storing the mutations in the life time of this cell.

init_time_courses()[source]

Initialize arrays that hold time course data for molecules and cell variables

insert_stretch(chrom, insert_pos, stretch, time, is_external, verbose=False)[source]

Insert a stretch of exogenous genomic material. Also adds product to the dict of to proteins made by the cell

internal_hgt

List of internal Horizontal Gene Transfers of this individual.

internal_hgt_count

Number of internal Horizontal Gene Transfers of this individual.

invert_stretch(chrom, start_pos, end_pos, time, verbose=False)[source]

Invert a stretch of genes in the genome in place.

The chromosome, start position and end position (exclusive) uniquely determine a sequence of genes that will be inverted. A Mutation object will be returned.

Parameters:
  • chrom (VirtualMicrobes.virtual_cell.Chromosome.Chromosome) – target chromosome
  • start_pos (int) – position index of the start of the stretch
  • end_pos (int) – position index of the end of the stretch
  • time (int) – simulation time
  • verbose (bool) – verbosity
Returns:

Return type:

VirtualMicrobes.mutation.Mutation.Inversion

is_autotroph(env)[source]

Determine if cell is autotrophic within an environment.

Autotrophy is defined as the ability to produce building blocks from precursors that are present ‘natively’ in the environment. This may be done in a multistep pathway in which the cell produces intermediates with its own metabolic enzymes.

Parameters:env (VirtualMicrobes.environment.Environment.Environment) – the environment relative to which autotrophy is tested

See also

is_heterotroph()

is_clone(ref_cell)[source]

Is clone

Using string representation of genome to see if cells have the same genome

Parameters:ref_cell (VirtualMicrobes.virtual_cell.Cell.Cell) –
Returns:
Return type:bool
is_heterotroph(env)[source]

Determine if cell is heterotrophic within an environment.

Heterotrophy is defined as the ability to produce the building blocks from precursors that could only be present as (by)products from metabolism of other individuals in the environment, but not natively present (through influx).

Parameters:env (VirtualMicrobes.environment.Environment.Environment) – the environment relative to which autotrophy is tested

See also

is_autotroph()

mean_life_time_cell_size

Average cell size over the life time of the individual.

mean_life_time_pos_production

Average positive production value over the life time of the individual.

mean_life_time_production

Average production value over the life time of the individual.

mean_life_time_toxicity

Average toxicity value over the life time of the individual.

metabolic_type

Return a set of sets that uniquely defines the metabolic functions of this cell.

metabolic_type_vector(env)[source]

Construct boolean vector of metabolic capacity of the cell.

Based on the complete set of environmental molecule classes, write out a cells metabolism in terms of produced, consumed, imported and exported molecule classes by the cells metabolism.

Parameters:env (VirtualMicrobes.environment.Environment.Environment) – environment relative to which the metabolic capacity is determined
Returns:
  • mapping of metabolic-function to
  • :class:`VirtualMicrobes.event.Molecule.MoleculeClass`s presence/absence.
mutate(time, environment, rand_gene_params=None, mutation_rates=None, mutation_param_space=None, global_mut_mod=None, excluded_genes=None, point_mutation_dict=None, point_mutation_ratios=None, regulatory_mutation_dict=None, regulatory_mutation_ratios=None, rand_gen=None, rand_gen_np=None, verbose=False)[source]

Apply mutations to the genome.

In turn, chromosome mutations, gene stretch mutations, point mutations and regulatory region mutations are applied. Mutations happen with probabilities supplied in a mutation_rates dict. The parameter spaces of the different types of mutations are supplied in the mutation_param_space

Parameters:
  • time (int) – simulation time
  • environment (VirtualMicrobes.environment.Environment.Environment) – environment holds Metabolites that can be potential ligands
  • rand_gene_params (VirtualMicrobes.my_tools.utility.ParamSpace) – parameter space to draw new random parameter values
  • mutation_rates (attr_dict) – dict with all mutation rates
  • mutation_param_space (VirtualMicrobes.my_tools.utility.MutationParamSpace) – parameter space and bounds for mutation effect
  • global_mut_mod (float) – modifier for Cell wide mutation rate
  • point_mutation_dict (dict) – maps gene types to type specific parameter-> modifier-function mapping
  • point_mutation_ratios (dict) – mapping from parameter type to type specific relative mutation ratio
  • regulatory_mutation_dict (dict) – maps gene types to type specific parameter-> modifier-function mapping
  • regulatory_mutation_ratios (dict) – mapping from parameter type to type specific relative mutation ratio
  • rand_gen (RNG) –
  • rand_gen_np (RNG) – numpy random number generator
  • verbose (bool) – verbosity
Returns:

Return type:

list of mutations

mutate_neigh(p_mutate, mutation_param_space, global_mut_mod, rand_gen)[source]

Evolvable chance to ALWAYS take up a gene from a neighbour (1.0), OR, duplicate your own gene (0.0)

p_mutate : float
mutation probability
mutation_param_space : VirtualMicrobes.my_tools.utility.MutationParamSpace
parameter space and bounds for mutation effect
global_mut_mod : float
modifier for Cell wide mutation rate

rand_gen : RNG

Returns (void for now)

mutate_uptake(p_mutate, mutation_param_space, global_mut_mod, rand_gen)[source]

Apply mutations to rate of uptake of eDNA. Currently this uptake is a multiplier modulating the already existing natural occurence of transformation.

p_mutate : float
mutation probability
mutation_param_space : VirtualMicrobes.my_tools.utility.MutationParamSpace
parameter space and bounds for mutation effect
global_mut_mod : float
modifier for Cell wide mutation rate

rand_gen : RNG

Returns (void for now)

nodes_edges(genes=None)[source]

Returns a list of nodes and edges of the individual’s gene regulatory network.

Nodes are simply all the genes. Edges are TF binding site to operator interactions between genes in the nodes list.

Parameters:genes (list of :class:`VirtualMicrobes.virtual_cell.Gene.Gene`s) – genes for which to find nodes and edges. If None (default) all gene products in the cell that have copy nr > 0.
Returns:
Return type:nodes(list),edges(list of tuples)
point_mut

List of point mutations of this individual.

point_mut_count

Number of point mutations of this individual.

point_mutate_gene(chrom, pos, mut_dict, point_mut_ratios, environment, mutation_param_space, rand_gene_params, time, rand_gen)[source]

Mutate a gene at a particular position of a chromosome.

Depending on the ‘type’ of the gene, a different set of parameters may be mutated. One parameter of the gene randomly selected to be mutated, according to a weighted roulette wheel draw, with the probabilities given by the point_mut_ratios associated with each parameter. The selected parameter for the gene will be modified using a particular mut_modifier function for this parameter type. A VirtualMicrobes.mutate.Mutation.PointMutation object is constructed that holds references to the original and mutated gene and the old and new parameter value, and allowing for reversal of the mutation operation. Finally, append the mutation in the Cell’s list of single gene mutations.

Parameters:
  • chrom (VirtualMicrobes.virtual_cell.Chromosome.Chromosome) – chromosome that holds the gene to be mutated
  • pos (int) – position index of the gene to mutate
  • mut_dict (dict) – maps gene types to type specific parameter-> modifier-function mapping
  • point_mut_ratios (dict) – mapping from parameter type to type specific relative mutation ratio
  • environment (VirtualMicrobes.environment.Environment.Environment) – environment holds Metabolites that can be potential ligands
  • mutation_param_space (VirtualMicrobes.my_tools.utility.MutationParamSpace) – parameter space and bounds for mutation effect
  • rand_gene_params (VirtualMicrobes.my_tools.utility.ParamSpace) – parameter space to draw new random parameter values
  • time (int) – simulation time point that mutation is applied
  • rand_gen (RNG) –
Returns:

Return type:

VirtualMicrobes.mutation.Mutation.PointMutation

point_mutate_gene_param(chrom, pos, param, mut_modifier, environment, mutation_param_space, rand_gene_params, time, rand_gen)[source]

Mutate a particular parameter of a gene at a particular position.

A random new value is drawn for the parameter. Then the point mutation is initialized and applied. The Cell’s gene products are updated to reflect the introduction of a new, mutated protein.

Parameters:
  • chrom (VirtualMicrobes.virtual_cell.Chromosome.Chromosome) – chromosome that holds the gene
  • pos (int) – position index of the gene to mutate
  • param (str) – name of parameter to mutate
  • mut_modifier (func) – function that from parameter value to new parameter value
  • environment (VirtualMicrobes.environment.Environment.Environment) – environment holds Metabolites that can be potential ligands
  • mutation_param_space (VirtualMicrobes.my_tools.utility.MutationParamSpace) – parameter space and bounds for mutation effect
  • rand_gene_params (VirtualMicrobes.my_tools.utility.ParamSpace) – parameter space to draw new random parameter values
  • time (int) – simulation time point that mutation is applied
  • rand_gen (RNG) –
Returns:

Return type:

VirtualMicrobes.mutation.Mutation.PointMutation

point_mutate_genome(p_mutate, mut_dict, global_mut_mod, point_mut_ratios, excluded_genes, environment, mutation_param_space, rand_gene_params, time, rand_gen)[source]

Apply point mutations to genes in the genome, according to point mutation rate.

p_mutate : float
point mutation probability
mut_dict : dict
maps gene types to type specific parameter-> modifier-function mapping
global_mut_mod : float
modifier for Cell wide mutation rate
point_mut_ratios : dict
mapping from parameter type to type specific relative mutation ratio
environment : VirtualMicrobes.environment.Environment.Environment
environment holds Metabolites that can be potential ligands
mutation_param_space : VirtualMicrobes.my_tools.utility.MutationParamSpace
parameter space and bounds for mutation effect
rand_gene_params : VirtualMicrobes.my_tools.utility.ParamSpace
parameter space to draw new random parameter values
time : int
simulation time point that mutation is applied

rand_gen : RNG

Returns:
Return type:list of mutations applied in this round
pos_production

Current bruto production value.

producer_type

Return the set of all metabolic classes produced in enzymatic reactions by this cell.

produces

Set of produced metabolic species.

producing_count

Number of metabolic classes produced by this individual.

promoter_strengths
providing

Return the set of metabolic classes that are produced AND exported.

providing_count

Number of metabolic classes produced and exported by this individual.

prune_dead_phylo_branches()[source]

Prune branches of phylogenetic trees of all phylogenetically tracked entities.

Recursively, prunes phylogenetic branches of this individual if it is not alive. Also prunes phylogenies of phylogenetic entities in the genome.

Returns:
Return type:pruned cells (set), pruned chromosomes (set), pruned genes (set)
pump_avrg_promoter_strengths
pump_count
pump_ene_differential_ks
pump_ene_ks
pump_promoter_strengths
pump_subs_differential_ks
pump_subs_ks
pump_sum_promoter_strengths
pump_vmaxs
pumps

Transporter products in the Cell.

Notes

Can include gene products of genes that are no longer in the genome.

qual_expr_diff(ref_cell)[source]

Calculate a qualitative expression difference with a reference cell.

Parameters:ref_cell (VirtualMicrobes.virtual_cell.Cell.Cell) – reference cell to compare gene expression.
Returns:
Return type:mean positive (relative) difference of all gene expression values.
raw_production

Current production value.

raw_production_change_rate

Current production change rate value.

reaction_genotype

Construct frozen set of the reaction genotype classification of this cell.

The genotype represents the enzyme functionality that the cell is capable of. It is expressed as the total set of transport, enzymatic capabilities of the cell, but excluding the tf sensing capabilities.

Returns:
Return type:frozenset

See also

func
genotype
reaction_set_dict

Dictionary of enzymatic reaction types to reactions.

Reactions of genes are mapped to their reaction types (Conversion, Transport).

reaction_set_dict2

Dictionary of enzymatic reaction types to reactions.

Reactions of genes are mapped to their reaction types (Conversion, Transport).

Notes

Different formatting from reaction_set_dict.

read_genome(environment, gene_dict, genome_order, verbose=False)[source]

Reads and sets genome based on genes dictionary and a list of gene indexes representing the genome order.

Parameters:
  • environment (VirtualMicrobes.environment.Environment.Environment) – environment provides the reactions to match to the genes
  • gene_dict (dict) – dictionary that contains all properties of the gene most are just values such as v_max, prom_str, type etc. ene_ks and subs_ks are themselves dicts for each mol
  • genome_order (list) – a list of indexes that represent in what order the genes should be put into the genome
Returns:

Return type:

class:`VirtualMicrobes.virtual_cell.Genome

reduce_gene_copies(gene)[source]

Reduce the copy number for a gene.

Parameters:gene (VirtualMicrobes.virtual_cell.Gene.Gene) – The gene for which copy number is reduced.
regulatory_region_mutate(chrom, genome, pos, mut_dict, mut_ratios, stretch_exp_lambda, time, rand_gen, rand_gen_np)[source]

Mutate part of the sequence of a regulatory region of a gene.

The mutation may be either a copying and translocation of an existing sequence somewhere in the genome to new position, or the insertion of a random sequence.

chrom : VirtualMicrobes.virtual_cell.Chromosome.Chromosome
chromosome that holds the gene to be mutated
genome : VirtualMicrobes.virtual_cell.Genome.Genome
full genome to find donor sequence
pos : int
position on chromosome of gene to be mutated
mut_dict : dict
maps gene types to type specific parameter-> modifier-function mapping
mut_ratios : dict
mapping from parameter type to type specific relative mutation ratio
stretch_exp_lambda : float
geometric distribution parameter that determines expected stretch length
time : int
simulation time

rand_gen : RNG rand_gen_np : RNG

numpy random number generator
Returns:
Return type:VirtualMicrobes.mutation.Mutation.OperatorInsertion
regulatory_region_mutate_genome(mutation_rates, mut_dict, global_mut_mod, reg_mut_ratios, time, rand_gen, rand_gen_np)[source]

Apply regulatory region mutations to genes in the genome.

mutation_rates : attr_dict
dict with all mutation rates
mut_dict : dict
maps gene types to type specific parameter-> modifier-function mapping
global_mut_mod : float
modifier for Cell wide mutation rate
reg_mut_ratios : dict
mapping from parameter type to type specific relative mutation ratio
time : int
simulation time point that mutation is applied

rand_gen : RNG rand_gen_np : RNG

numpy random number generator
Returns:
Return type:list of mutations applied in this round
remove_unproduced_gene_products(conc_cutoff=None)[source]

Remove gene products when they are no longer produced and have a below threshold concentrations.

Parameters:conc_cutoff (float) – threshold concentration below which gene product is removed
Returns:True if any product was removed
Return type:bool
reproduce(spent_production, time, second_parent=None)[source]

Create a new child of this cell.

Copies all relevant properties, including the genome. Divides the original cell volume between the parent and child.

Parameters:
  • spent_production (float) – amount of the production variable spent for reproduction
  • time (int) – simulation time point
  • second_parent (VirtualMicrobes.virtual_cell.Cell.Cell) – an (optional) second parent that contributes to reproduction
Returns:

Return type:

VirtualMicrobes.virtual_cell.Cell.Cell

reset_grn(min_bind_score=None)[source]

Recalculate and reset all binding interactions in the genome.

Parameters:min_bind_score (float) – minimum identity score to set a regulatory interaction.
resize_time_courses(new_max_time_points)[source]

Set a new size for arrays that hold time course data.

Parameters:new_max_time_points (int) – max number of time points
scale_mol_degr_rate(mol, env, degr_const, ene_degr_const, bb_degr_const)[source]

Return scaled internal rate of metabolite degradation, relative to its external rate.

The base rate is the metabolite specific external degradation rate. If internal rates have been chosen (not None), the base rate will be scaled with the ratio of internal/external. Rates can be different for building block and energy metabolites.

Parameters:
Returns:

Return type:

scaled degradation rate (float)

sequence_mut

List of sequence mutations of this individual.

sequence_mut_count

Number of sequence mutations of this individual.

set_gene_prod_conc(gene, conc)[source]

Set the new concentration of a gene product.

The last concentration time point will be overwritten.

Parameters:
set_mol_concentrations_from_time_point()[source]

Record cellular concentrations and values from time course arrays.

During the integration step, for each molecule or other variable time course data is stored in an array. The position that was last filled is the new concentration. The value stored under index pos will be copied to a dedicated concentration or ‘value’ member.

Parameters:pos – position in array to
set_molconcs(concdict)[source]

Set molecule concentrations based on dict.

Parameters:concdict (dict) – dict with values for mol concentrations
set_properties(celldict)[source]

Set cell properties based on dict.

Parameters:celldict (dict) – dict with values for cell properties
set_small_mol_conc(mol, conc)[source]

Set the new concentration of a metabolite.

The last concentration time point will be overwritten.

Parameters:
set_small_mol_degr(mol, reac, rate)[source]

Set metabolite degradation parameter.

Parameters:
set_small_mol_diff(mol, reac, rate)[source]

Set metabolite diffusion parameter.

Parameters:
set_state_from_file(environment, filename)[source]

Set the state of the cell based on a configuration file.

Parameters:
set_state_from_ref_cell_tp(ref_cell, tp_index=0, verbose=False)[source]

Reset cell properties to the state of a reference cell at a chosen time point.

Parameters:
  • ref_cell (VirtualMicrobes.virtual_cell.Cell.Cell) – take values from this reference individual
  • tp_index (int) – index of reference time point to take reset value
  • verbose (bool) – verbosity flag
stretch_del

List of stretch deletions of this individual.

stretch_del_count

Number of stretch deletions of this individual.

stretch_invert

List of stretch inversions of this individual.

stretch_invert_count

Number of stretch inversions of this individual.

stretch_mut

List of stretch mutations of this individual.

stretch_mut_count

Number of stretch mutations of this individual.

stretch_mutate_genome(time, mutation_rates, global_mut_mod, rand_gen, rand_gen_np, mut_types=['tandem_dup', 'stretch_del', 'stretch_invert', 'stretch_translocate'], verbose=True)[source]

Iterate over chromosomes and positions to select stretches of genes for mutational events.

For every chromosome, iterate over positions and select front and end positions of stretch mutations. The direction of iteration is randomly chosen (back-to-front or front-to-back). Multiple mutations per chromosome may occur. Every position may be independently selected as the front site of a stretch mutation. The length of the stretch is a geometrically distributed random variable, using a lambda parameter. The end position is the minimum of the remaining chromosome length and the randomly drawn stretch length. If any positions remain in the chromosome after the stretch mutation, these positions are then iterated over in a random direction (direction of iteration is reversed at random after the application of the stretch mutation). Reversing direction is significant, because it randomizes the locations of ‘truncated’ stretches when reaching the end of a chromosome.

Parameters:
  • time (int) – simulation time
  • mutation_rates (attr_dict) – dict with all mutation rates
  • mut_dict (dict) – maps gene types to type specific parameter-> modifier-function mapping
  • global_mut_mod (float) – modifier for Cell wide mutation rate
  • rand_gen (RNG) –
  • rand_gen_np (RNG) – numpy random number generator
  • mut_types (list of str) – mutation types to apply
strict_exploiting

Return exploited resources classes that are not produced by self.

See also

exploiting()

strict_exploiting_count

Number of metabolic classes imported and consumed, but not produced by this individual.

strict_providing

Return provided resources classes that are not imported by self.

See also

providing()

strict_providing_count

Number of metabolic classes produced, exported but not consumed by this individual.

sum_promoter_strengths
tandem_dup

List of stretch duplications of this individual.

tandem_dup_count

Number of stretch duplications of this individual.

tandem_duplicate_stretch(chrom, start_pos, end_pos, time, verbose=False)[source]

Duplicate a stretch of genes in the genome in place.

The chromosome, start position and end position (exclusive) uniquely determine a sequence of genes that will be duplicated and inserted immediately behind the original stretch. A Mutation object will be returned.

Parameters:
  • chrom (VirtualMicrobes.virtual_cell.Chromosome.Chromosome) – target chromosome
  • start_pos (int) – position index of the start of the stretch
  • end_pos (int) – position index of the end of the stretch
  • time (int) – simulation time
  • verbose (bool) – verbosity
Returns:

Return type:

VirtualMicrobes.mutation.Mutation.TandemDuplication

tf_avrg_promoter_strengths
tf_count
tf_differential_reg
tf_k_bind_ops
tf_ligand_differential_ks
tf_ligand_ks
tf_promoter_strengths
tf_sensed

The set of molecule classes that are sensed by TFs.

tf_sum_promoter_strengths
tfs

TF products in the Cell.

Notes

Can include gene products of genes that are no longer in the genome.

toxicity

Current toxicity value.

toxicity_change_rate

Current toxicity value change rate.

tp_index

Index of last time point stored.

translocate

List of stretch translocations of this individual.

translocate_count

Number of stretch translocations of this individual.

translocate_stretch(chrom, start_pos, end_pos, target_chrom, insert_pos, invert, time, verbose=False)[source]

Translocate a stretch of genes in the genome in place.

The chromosome, start position and end position (exclusive) uniquely determine a sequence of genes that will be excised and inserted at a new position in target chromosome. A Mutation object will be returned.

Parameters:
Returns:

Return type:

VirtualMicrobes.mutation.Mutation.Translocation

trophic_type(env)[source]

Trophic type classification of individual’s metabolic capacities.

Based on the metabolic reactions present in the individual’s genome an individual can be classified as being ‘autotrophic’ and/or ‘heterotrophic’. Facultative mixotrophs are defined as having both autotrophic and heterotrophic metabolic capacities, while obligate mixotroph are neither self-sufficient autotrophs, nor heterotrophs.

Parameters:env (VirtualMicrobes.environment.Environment.Environment) – the environment trophic type is determined in
truncate_time_courses(max_tp=None)[source]

Truncate the time course data.

If no maximum is supplied, truncates time courses to the parts of the arrays that have actually been filled with time points, discarding the empty last part of the array.

Intended to be called when a cell dies and no additional data points are expected to be stored.

Parameters:max_tp (int) – maximum number of time points retained
uid = 0

A Cell in the Simulation.

Initializes the state of the cell (without genome); notably:
  • internal molecule dictionaries
  • arrays to hold time course data of internal molecule concentrations
  • mutation dictionary, a record of mutations that occured during reproduction
  • internal state variables for volume, toxicity etc
Parameters:
  • params (attrdict.AttrDict) – mapping object that holds global simulation parameters
  • environment (VirtualMicrobes.environment.Environment) – environment that cell lives in; determines molecular and reaction universe
  • rand_gen (RNG) –
  • fromfile (path to .cell-file to reproduce cell from) –
  • toxicity_function (func) – calculates toxicity based on actual and threshold level of a concentration
  • toxicity_effect_function (func) – calculates added death rate from toxicity
update(state)[source]
update_grn(min_bind_score=None)[source]

Update the regulatory network, by finding (new) matches between TF binding sites and gene operators.

min_bind_score : float
minimum identity score to set a regulatory interaction.
update_mutated_gene_product(old, new)[source]

Decrease the copy number of the old gene and increase/initialize the new gene.

Parameters:
update_small_molecules(env, conc)[source]

Used when a new molecule enters the game

update_small_molecules_degr(env, degr_const, ene_degr_const, bb_degr_const)[source]

Update membrane degradation parameter of metabolites.

env : VirtualMicrobes.environment.Environment.Environment
environment containing reactions and base degradation rates.
update_small_molecules_diff(env)[source]

Update membrane diffusion parameter of metabolites.

env : VirtualMicrobes.environment.Environment.Environment
environment containing reactions and membrane diffusion rates.
upgrade()[source]

Upgrading from older pickled version of class to latest version. Version information is saved as class variable and should be updated when class invariants (e.g. fields) are added.

volume

Current cell volume.

VirtualMicrobes.virtual_cell.Cell.make_inherited_hgt_dict()[source]
VirtualMicrobes.virtual_cell.Cell.make_mutations_dict()[source]

VirtualMicrobes.virtual_cell.Chromosome module

class VirtualMicrobes.virtual_cell.Chromosome.Chromosome(gene_list=None, positions=None, time_birth=0, circular=False, **kwargs)[source]

Bases: VirtualMicrobes.virtual_cell.PhyloUnit.PhyloBase

A chromosome contains genes in spatial order.

The chromosome class defines methods for chromosomal mutations * duplication * deltion * fission * fusion and mutations on the level of gene stretches * stretch deltion * stretch duplication * stretch inversion * stretch insertions

append_gene(g)[source]

Append gene at end of chromosome.

Parameters:g (class virtual_cell.Gene.Gene) – gene to add
delete_stretch(start_pos, end_pos)[source]

Deletes a stretch of genes.

Parameters:
  • start_pos (int) – first position of stretch
  • end_pos (int) – last position (exclusive) of stretch
Returns:

Return type:

iterable of genes; the deleted stretch

duplicate(time)[source]

Duplicate the chromosome.

Creates two identical copies of the chromosome. The original version is deleted.

Parameters:time (int) – simulation time
Returns:
Return type:Returns tuple of two chromosomes
fiss(pos, time)[source]

Chromosome fission.

A fission splits a chromosome, creating two new chromosomes.

Parameters:
  • pos (int) – position of fission
  • time (int) – simulation time
Returns:

Return type:

returns tuple of two chromosomes

classmethod fuse(chrom1, chrom2, time, end1=True, end2=True)[source]

Fuse two chromosomes.

Parameters:
Returns:

Return type:

returns the new fused chromosome

init_positions(circular=False)[source]

Initialize chromosome positions.

Parameters:circular (boolean) – if true define as circular list
insert_stretch(stretch, pos)[source]

Insert a stretch of genes at position.

Parameters:
  • stretch (iterable) – stretch of genes to insert
  • pos (int) – insert position
invert(start_pos, end_pos)[source]

Invert a stretch of genes.

Parameters:
  • start_pos (int) – first position of stretch
  • end_pos (int) – last position (exclusive) of stretch
Returns:

Return type:

iterable of genes; the inverted stretch

positions
tandem_duplicate(start_pos, end_pos)[source]

Duplicates a stretch of genes ‘in place’, and insert after end_pos.

Parameters:
  • start_pos (int) – first position of stretch
  • end_pos (int) – last position (exclusive) of stretch
Returns:

Return type:

iterable of genes; the duplicated stretch

toJSON(index, *args, **kwargs)[source]

Create JSON representation of chromosome.

Parameters:index (int) – a position index of the chromosome
Returns:
Return type:json dict
translocate_stretch(start_pos, end_pos, target_pos, target_chrom)[source]

Translocate a stretch of genes to a target chromosome and position.

Parameters:
  • start_pos (int) – first position of stretch
  • end_pos (int) – last position (exclusive) of stretch
  • target_pos (int) – position to insert stretch
  • target_chrom (VirtualMicrobes.virtual_cell.Chromosome.Chromosome) – target chromosome for insertion
uid = 0

VirtualMicrobes.virtual_cell.Gene module

class VirtualMicrobes.virtual_cell.Gene.Gene(type_, pr_str=1.0, operator_seq_len=10, operator=None, fixed_length=None, is_enzyme=False, promoter_phylo_type='base', operator_phylo_type='base', **kwargs)[source]

Bases: VirtualMicrobes.virtual_cell.GenomicElement.GenomicElement

Representation of gene in the genome.

Gene is the base class for various types of genes in the genome. A gene has * a set of type specific parameters * a promoter that determines basal gene expression level * an operator that allows interaction and expression modulation by

transcription factors
Parameters:
  • type (string) – type of gene
  • pr_str (float) – promoter strength
  • operator_seq_len (int) – sequence length of operator
  • operator (iterable) – operator sequence as bitstring
  • fixed_length (bool) – if false, operator length can change
  • is_enzyme (bool) – if true, is an enzyme type
is_enzyme
mutated(param, new_val, time, verbose=False)[source]

Mutates a parameter of the gene.

To maintain a full ancestry, the mutation should be applied to a (shallow) copy of the gene and this copy reinserted in the original ancestral position. The shallow copy will however have a new deepcopied version of the parameter dictionary so that the mutation will not affect the ancestral gene state.

Parameters:
  • param (string) – parameter to mutate
  • new_val (new parameter value) –
Returns:

Return type:

Returns the mutated copy of the gene.

operator
params
promoter
randomize(rand_gene_params, rand_gen, better_tfs=False, **kwargs)[source]

Randomizes gene properties.

Parameters:
  • rand_gene_params (dict) – parameters of randomization function
  • rand_gen (RNG) –
randomize_params(rand_gene_params, rand_generator)[source]
toJSON(attr_mapper, index, d=None, *args, **kwargs)[source]

Create JSON representation of gene.

Parameters:attr_mapper (dict) – mapping from properties to colours
Returns:
Return type:JSON dict
class VirtualMicrobes.virtual_cell.Gene.MetabolicGene(reaction, substrates_ks=10.0, v_max=1.0, forward=True, **kwargs)[source]

Bases: VirtualMicrobes.virtual_cell.Gene.Gene

Version:
Author:
ode_params()[source]

Returns a list of dictionaries of parameters necessary and sufficient to parameterize an ODE for all the sub-reactions associated with this Gene.

randomize_params(rand_gene_params, rand_generator)[source]
reaction
simple_str()[source]
toJSON(*args, **kwargs)[source]

Create JSON representation of gene.

Parameters:attr_mapper (dict) – mapping from properties to colours
Returns:
Return type:JSON dict
class VirtualMicrobes.virtual_cell.Gene.Promoter(pr_str, time_birth=0, **kwargs)[source]

Bases: VirtualMicrobes.virtual_cell.PhyloUnit.PhyloBase

A promoter sequence object.

A promoter is exclusively associated with a genomic element. It encodes a basal promoter strength that is a factor in the gene expresion level.

mutate(mut_modifier, rand_gen)[source]

Mutates the promoter.

Parameters:
  • mut_modifier (func) – a function that changes the promoter parameters.
  • rand_gen (RNG) –
randomize(rand_gene_params, rand_generator)[source]

Randomize the promoter parameters.

Parameters:
  • rand_gene_params (dict) – parameters for the randomization function
  • rand_generator (RNG) –
strength
toJSON(attr_mapper, *args, **kwargs)[source]

Creates JSON representation of promoter.

Parameters:attr_mapper (dict) – mapping from attributes to colors
Returns:
Return type:A JSON dictionary.
uid = 0
class VirtualMicrobes.virtual_cell.Gene.TranscriptionFactor(ligand_mol_class, ligand_ks=10.0, ligand_cooperativity=1.0, binding_seq_len=10, binding_seq=None, eff_apo=1.0, eff_bound=1.0, k_bind_op=1.0, binding_cooperativity=2, sense_external=False, **kwargs)[source]

Bases: VirtualMicrobes.virtual_cell.Gene.Gene

Version:
Author:
binding_sequence
init_ligand(ligand_class, ligand_ks=10)[source]

Set ligand class and the kinetic (K) constants of binding affinity for individual molecule species.

Parameters:
ligand_class
randomize(rand_gene_params, rand_gen, **kwargs)[source]

Randomizes gene properties.

Parameters:
  • rand_gene_params (dict) – parameters of randomization function
  • rand_gen (RNG) –
randomize_good_params(rand_gene_params, rand_generator)[source]
randomize_params(rand_gene_params, rand_generator)[source]
simple_str()[source]
toJSON(*args, **kwargs)[source]

Create JSON representation of gene.

Parameters:attr_mapper (dict) – mapping from properties to colours
Returns:
Return type:JSON dict
class VirtualMicrobes.virtual_cell.Gene.Transporter(reaction, ene_ks=10.0, substrates_ks=10.0, v_max=1.0, exporting=False, **kwargs)[source]

Bases: VirtualMicrobes.virtual_cell.Gene.Gene

Transporter gene class.

Transporters can transport metabolites across the cell membrane. The class defines the kinetic parameters of the transport reaction. The exporting parameter determines the direction of transport.

Parameters:
  • reaction (VirtualMicrobes.virtual_cell.event.Reaction.Reaction) – the transport reaction of the gene
  • ene_ks (float or list of floats) – energy molecule binding constant
  • subtrate_ks (float or list of floats) – substrate binding constants
  • v_max (float) – max reaction flux constant
  • exporting (bool) – if true, set to exporting
ode_params()[source]

Returns a list of dictionaries of parameters necessary and sufficient to parameterize an ODE for all the sub-reactions associated with this Gene.

randomize_params(rand_gene_params, rand_generator, rand_direction=False)[source]

Randomizes gene properties.

Parameters:
  • rand_gene_params (dict) – parameters of randomization function
  • rand_generator (RNG) –
  • rand_direction (bool) – if true, randomize the direction of transport
reaction
simple_str()[source]
toJSON(*args, **kwargs)[source]

Create JSON representation of gene.

Parameters:attr_mapper (dict) – mapping from properties to colours
Returns:
Return type:JSON dict
VirtualMicrobes.virtual_cell.Gene.convert_rates(enzyme, enzyme_conc, metabolite_conc_dict)[source]

Estimate of conversion rates per substrate

Parameters:
  • enzyme – enzyme gene
  • enzyme_conc – internal enzyme concentrations
  • metabolite_conc_dict – concentrations of metabolites
VirtualMicrobes.virtual_cell.Gene.init_molecule_ks(mol_class, mol_ks, external=False)[source]

Initialize the ordered mapping from molecules to Ks.

Each molecule in a moleculeclass has an associated K value, that is the binding affinity.

Parameters:
Returns:

Return type:

mapping from VirtualMicrobes.event.Molecule.Molecule to K values (float)

VirtualMicrobes.virtual_cell.Gene.init_substrates_ks(reaction, kss)[source]

Initialize the ordered mapping from substrate molecules to Ks for a Conversion reaction.

Each molecule in a moleculeclass has an associated K value, that is the binding affinity.

Parameters:
  • reaction (VirtualMicrobes.event.Reaction.Conversion) –
  • mol_ks (float or list) – the K values for individual molecules
Returns:

Return type:

mapping from VirtualMicrobes.event.Molecule.Molecule to K values (float)

VirtualMicrobes.virtual_cell.Gene.pump_rates(pump, pump_conc, metabolite_conc_dict)[source]

Estimate of pumping rates for each substrate

Parameters:
  • pump – pump gene
  • pump_conc – internal pump concentration
  • metabolite_conc_dict – concentrations of metabolites
VirtualMicrobes.virtual_cell.Gene.random_gene(environment, rand_gene_params, rand_gen, params, keep_transport_direction=True)[source]
VirtualMicrobes.virtual_cell.Gene.randomized_param(rand_gene_params, rand_generator)[source]
VirtualMicrobes.virtual_cell.Gene.read_gene(environment, gene, gene_index, verbose=False)[source]

VirtualMicrobes.virtual_cell.Genome module

class VirtualMicrobes.virtual_cell.Genome.Genome(chromosomes, min_bind_score)[source]

Bases: object

add_chromosome(chrom, verbose=False)[source]

Add a chromosome to the list of chromosomes.

binding_sequences
binding_tfs_scores(op)[source]

Return tfs that bind this operator and their scores.

Parameters:op (VirtualMicrobes.virtual_cell.Sequence.Operator) – operator sequence
Returns:
Return type:list of VirtualMicrobes.virtual_cell.Gene.TranscriptionFactor, float tuples
bs_to_tfs_dict()[source]

Create mapping from binding sequences to tfs.

For each binding sequence in the genome map to the set of tfs that contain this binding sequence

Returns:
class_version = '1.0'
copy_number_dist
copy_numbers
copy_numbers_eff_pumps
copy_numbers_enzymes
copy_numbers_inf_pumps
copy_numbers_tfs
del_chromosome(chrom, remove_genes=True, verbose=False)[source]

Delete a chromosome.

Remove a chromosome from the list of chromosomes. If remove_genes is True the genome will be further updated to reflect deletion of genes. E.g. the sequence bindings should be updated when genes are removed from the genome. It may be useful to defer updating if it is already known that the genes will be readded immediately. This may be the case when a chromosome is split (fission) or fused and no genes will be actually lost from the genome.

Parameters:
die(time)[source]

Record death of phylogenetic units in the genome.

Typically called from the cell when it dies. All phylogenetic units in the genome are instructed to record their death. When phylogenetic units are no longer alive, they may be pruned from their respective phylogenetic trees if there are no more living descendants of the phylogenetic unit.

Parameters:time (float) – simulation time
eff_pumps
enzymes
inf_pumps
init_chromosomes(chromosomes)[source]

Initialize chromosomes.

Add preinitialized chromosomes to the genome.

Parameters:chromosomes (iterable of VirtualMicrobes.virtual_cell.Chromosome.Chromosome) – chromosomes to add
init_regulatory_network(min_bind_score)[source]

Initialize the binding state of the regulatory network.

Iterate over all :class:`VirtualMicrobes.virtual_cell.Sequence.Operator`s in the genome and match them against all :class:`VirtualMicrobes.virtual_cell.Sequence.BindingSequence`s.

Parameters:min_bind_score (float) – minimum binding score for sequence matching
op_to_tfs_scores_dict()[source]

Create mapping from operators to the tfs that bind them, with their scores.

For each operator in the genome map the set of tfs, together with their binding scores.

Returns:
operators
prune_genomic_ancestries()[source]

Prune the phylogenetic trees of phylogenetic units in the genome.

Returns:
pumps
reset_regulatory_network(min_bind_score)[source]

Reset the binding state of the regulatory network.

Iterate over all Sequences in the genome and clear all bindings. Then re-initialize the regulatory network.

Parameters:min_bind_score (float) – minimum binding score for sequence matching
size
tf_connections_dict()[source]

A dictionry of TFs to sets of downstream bound genes.

tfs
toJSON(*args, **kwargs)[source]
update(state)[source]
update_genome_removed_gene(gene)[source]

Remove a gene from the genome if no more copies exist in the genome.

Updates the genome

Parameters:gene (VirtualMicrobes.virtual_cell.GenomicElement.GenomicElement) – gene to be removed
update_genome_removed_genes(genes)[source]

Update the genome to reflect gene deletions.

After the deletion of (part of) a chromosome, the genome has to be updated to reflect the change. Because exact copies of deleted genes may still be present in another part of the genome a check has to be performed before definitive removal.

Parameters:genes (iterable of VirtualMicrobes.virtual_cell.GenomicElement.GenomicElement) – genes that were targeted by a deletion operation.
update_regulatory_network(min_bind_score)[source]

Update the binding state of the regulatory network.

Iterate over all Sequences in the genome and if their check_binding flag is set, match the sequence against all potential binders in the genome.

Parameters:min_bind_score (float) – minimum binding score for sequence matching
upgrade()[source]

VirtualMicrobes.virtual_cell.GenomicElement module

class VirtualMicrobes.virtual_cell.GenomicElement.GenomicElement(time_birth=0, **kwargs)[source]

Bases: VirtualMicrobes.virtual_cell.PhyloUnit.PhyloBase

Version:
Author:
types = ['tf', 'pump', 'enz']
uid = 0

VirtualMicrobes.virtual_cell.Identifier module

class VirtualMicrobes.virtual_cell.Identifier.Identifier(obj, versioned_id=1, increment_func=None)[source]

Bases: object

clear_offspring()[source]
classmethod count_class_types(obj)[source]
from_parent(parent, flat=True, pos=-1)[source]

Set an Identifier from a parent id.

If id is incremented in a ‘flat’ way, the new id is the unique count of objects of the (parent) type that this id belongs to. Else, the id increment is done in a ‘versioned’ manner. If parent has 0 offspring ids so far, the parent id is simply copied and no increment is done. If parent already has > 0 offspring ids, then a version element is added that indicates this id as the “n’th” offspring of the parent id. E.g. if parent id is 2.3 and it has 2 offspring already: from_parent(parent, flat=False) -> 2.3.2

Parameters:
  • parent (object with an Identifier attribute) – The parent of this Identifier.
  • flat (bool) – If True, set versioned id position as the total number of counted objects of a the type of parent. Else, add versioned id information.
  • pos (int (index)) – index of the version bit to update
increment_func
increment_offspring()[source]
is_copy(identifier)[source]

Test if identifier and self are different copies of the same major_id.

identifier : Identifier
Identifier to compare to.
Returns:
Return type:bool
major_id

Return the first part (highest order) of identifier.

Returns:
Return type:int (or other id format)
minor_id

Return version part of the identifier.

Returns:
Return type:list of int (or other id format)
offspring_count
parse(versioned_id)[source]
unique_unit_dict = {}
versioned_id
VirtualMicrobes.virtual_cell.Identifier.increment(x)[source]

VirtualMicrobes.virtual_cell.PhyloUnit module

class VirtualMicrobes.virtual_cell.PhyloUnit.AddInheritanceType[source]

Bases: type

A metaclass that can set a class instances base type to support phylogenetic linking

The base type of the instantiated class can be either a PhyloBase or a PhyloUnit, depending on its _phylo_type class attribute. This enables an at run-time decision (via a program options) to fix the ancestry structure the class supports. PhyloBase instances keep references to neither parents nor children and hence do not need use a linker dict or unique_key generator. PhyloUnit does support ancestry. Phylogenetic linking is delegated to a global linker dict.

class VirtualMicrobes.virtual_cell.PhyloUnit.PhyloBase(time_birth)[source]

Bases: object

Base class for all classes that can behave as phylogenetic units of inheritance.

Phylogenetic Base units record their time of birth and death and have an identifier field that can indicate a relation to parents and offspring. PhyloBase object may come into existence when a mother cell gives rise to a daughter cell and all units of inheritance that it contains (i.e. when a genome get’s copied), but also when a phylogenetic unit (such as a gene or chromosome) mutates and the ancestral version will be kept intact for analysis purposes.

alive
die(time)[source]

Death of a phylo unit happens either when a cell dies and all its genetic material with it, or when a mutation gives rise to a new variant of the unit.

Parameters:time – Time of death in simulation time units.
id
living_offspring()[source]
mark(marker, mark)[source]

Set a marker on the phylo unit.

Parameters:
  • marker – marker type
  • mark – value
marker_dict
prune_dead_branch()[source]

Return self to be removed from the global phylo linker dict if not alive.

This is the degenerate base version of pruning. See the version in Phylo Unit for the case when units keep track of parent-child relationships.

time_birth
time_death
class VirtualMicrobes.virtual_cell.PhyloUnit.PhyloUnit(time_birth)[source]

Bases: VirtualMicrobes.virtual_cell.PhyloUnit.PhyloBase

Extended Base class for all classes that can be represented in phylogenies. These classes should support ancestor and child retrieval and setting time of birth and death.

child_of(phylo_unit)[source]

Return whether this PhyloUnit is the child of another PhyloUnit.

phylo_unit : PhyloUnit

children
common_ancestors(phylo_unit)[source]
die(*args, **kwargs)[source]

Death of a phylo unit happens either when a cell dies and all its genetic material with it, or when a mutation gives rise to a new variant of the unit.

Parameters:time – Time of death in simulation time units.
has_living_offspring(exclude_set=set([]), depth=1)[source]

Returns True if any of the phylo units descendants are alive

init_phylo_dicts()[source]
living_offspring()[source]

Returns a list of all offspring of this phylo unit that are currently alive.

lod_down_single()[source]

Proceed down a single branch on the line of descent until there is a branch point or terminal node.

lod_up_single()[source]

Proceed up a single branch on the line of descent until there is a branch point or terminal node.

lods_down()[source]

Composes all the lines of descent leading down (forward in time) from phylo unit in a non- recursive way (compare lods_up).

lods_up()[source]

Composes all the lines of descent leading up (back in time) from phylo unit (compare lods_down).

parent_of(phylo_unit)[source]

Return whether this PhyloUnit is the parent of another PhyloUnit.

phylo_unit : PhyloUnit

parents
prune_dead_branch(exclude_offspring_check_set=set([]), depth=1)[source]

Return a set of phylogenetically related units that represent a dead phylogenetic branch.

Recursively checks for parent nodes whether the nodes descendants are all dead. In that case, the node can be pruned and its parents may additionally be checked for being part of the extended dead branch. The exclude is used to prevent superfluous checks of living offspring when it is already known that the current phylo_unit has no living_offspring.

Parameters:exclude_offspring_check_set (set of VirtualMicrobes.virtual_cell.PhyloUnit.PhyloUnit) –
set_ancestor(ge)[source]
set_unique_key()[source]

Generate a unique key that can be used for mapping in a global linker dict.

VirtualMicrobes.virtual_cell.Population module

class VirtualMicrobes.virtual_cell.Population.Population(params, environment)[source]

Bases: object

add_cell(cell)[source]

Add an individual to the population.

A cell that is added is stored in a dictionary that maps the individual to a dictionary of properties, e.g. the numer of offspring.

Increase the population size.

Parameters:cell (VirtualMicrobes.virtual_cell.Cell.Cell) – the individual to add
ages(cells=None)[source]

Return array of individual death rate parameters.

average_death_rate(cells=None)[source]
average_production(cells=None)[source]
average_promoter_strengths(cells=None)[source]

Return array of individual average genomic promoter strength.

best_producer()[source]

Return the individual and the value of highest production in the population.

calculate_death_rates(base_death_rate=None, max_die_off_fract=None, death_rate_scaling=None, toxicity_scaling=None, no_death_frac=None, cells=None)[source]

Calculate and store death rates of individuals.

Uses a base_death_rate and toxicity_scaling parameter to calculate the death rate of individuals.

Parameters:
  • base_death_rate (float, optional) – base death rate for all individuals
  • max_die_off_fract (float, optional) – maximum fraction of individuals that can die (stochastically)
  • toxicity_scaling (float, optional) – scaling parameter for toxicity death rate effect
  • cells (sequence of VirtualMicrobes.virtual_cell.Cell.Cell) – individuals in calculation
Returns:

Return type:

returns mapping of cells to death rates

calculate_reference_production(pressure=None, historic_production_weight=None)[source]

Calculates a reference production value for competition.

Reference production is used to scale the reproductive potential of cells during competition to reproduce.

Parameters:
  • pressure (str) – type of selection pressure scaling
  • historic_production_weight (float, optional) – weighting of historic production values
cell_death(cell, time, wiped=False)[source]

Kill an individual.

Updates the population size. Sets the time of death of individual.

Parameters:
cell_markers(marker, cells=None)[source]
cell_sizes(cells=None)[source]

Return array of individual cell volumes.

chromosomal_mut_counts(cells=None)[source]

Return array of individual counts of life time chromosomal mutations.

chromosome_counts(cells=None)[source]

Return array of individual chromosome counts.

class_version = '1.2'

A population of individual Cells that reproduce and die during a Simulation.

The class defines methods for life history events of the cell population:
  • death of individuals
  • competition and reproduction
  • population level gene exchange (HGT)

Phylogenetic relationships between individuals in the population are tracked and a phylogenetic tree is maintained and pruned when individuals reproduce and die.

Parameters:
  • params (dict) – a dictionary of simulation parameters
  • environment (VirtualMicrobes.environment.Environment) – environment that is home to the population; determines molecular and reaction universe
params

reference of Simulation parameters

Type:dict
historic_production_max

historic maximum of production value in the population

Type:float
production_val_history

history of all population production maxima

Type:list of floats
pop_rand_gen

RNG for drawing population events

Type:RNG
evo_rand_gen

RNG for drawing evolutionary events

Type:RNG
markers_range_dict

stores ranges for cell markers used in plotting

Type:dict
value_range_dict

ranges of attributes on phylogenetic tree

Type:dict
current_pop_size

population size

Type:int
died

individuals that have died in the current simulation step

Type:sequence of VirtualMicrobes.virtual_cell.Cell.Cell s
cell_dict

mapping from VirtualMicrobes.virtual_cell.Cell.Cell to attributes

Type:dict
cells

the living VirtualMicrobes.virtual_cell.Cell.Cell s in the population

Type:view on keys
new_offspring

individuals born in current time step

Type:sequence of VirtualMicrobes.virtual_cell.Cell.Cell s
pruned_cells

individuals that are dead and do not have living offspring

Type:set of VirtualMicrobes.virtual_cell.Cell.Cell s
current_ancestors

living individuals and ancestors that contribute offspring to current population

Type:sequence of VirtualMicrobes.virtual_cell.Cell.Cell s
roots

first common ancestors of current population

Type:sequence of VirtualMicrobes.virtual_cell.Cell.Cell s
phylo_tree

represent phylogenetic tree of current population

Type:VirtualMicrobes.Tree.PhyloTree.PhyloTree
pruned_cells

cell phylo units to be pruned from global phylo dict

Type:set of VirtualMicrobes.virtual_cell.PhyloUnit.PhyloUnit
pruned_chromosomes

chromosome phylo units to be pruned from global phylo dict

Type:set of VirtualMicrobes.virtual_cell.PhyloUnit.PhyloUnit
pruned_genes

gene phylo units to be pruned from global phylo dict

Type:set of VirtualMicrobes.virtual_cell.PhyloUnit.PhyloUnit
clear_mol_time_courses()[source]
clear_pop_changes()[source]

Reset population change containers.

cloned_pop(pop_size, environment, params_dict, time=0)[source]

Creates a single ancestor VirtualMicrobes.virtual_cell.Cell.Cell individual and initialises its genomes. Genome initialisation depends on the environment, because this determines the set of possible gene types and minimum viable metabolism that can be constructed.

The population is then generated by cloning the ancestor individual. Clones are identical and store a reference to the ancestor.

Parameters:
  • pop_size (int) – population size
  • environment (VirtualMicrobes.environment.Environment) – environment that is home to the population; determines molecular and reaction universe
  • params_dict (dict, optional) – a dictionary of simulation parameters
  • time (int, optional) – time of birth of the clone
Returns:

common ancestor – the common ancestor of the cloned population

Return type:

VirtualMicrobes.virtual_cell.Cell.Cell

cloned_pop_from_files(pop_size, environment, cell_files=None, time=0)[source]

Create population of individuals initialised from cell parameter files.

Creates VirtualMicrobes.virtual_cell.Cell.Cell individuals and reads their genome and state from cell parameter files.

Parameters:
  • pop_size (int) – population size
  • environment (VirtualMicrobes.environment.Environment) – environment that is home to the population; determines molecular and reaction universe
  • time (int, optional) – time of birth of the clone
Returns:

common_ancestors – the common ancestors of the new population

Return type:

list of VirtualMicrobes.virtual_cell.Cell.Cell objects

consumer_type_counts(cells=None)[source]

Return counts of cell sets with equal consumption metabolomes.

death_rates(cells=None)[source]

Return array of individual death rate parameters.

die_off(time, cells=None)[source]

Kill individual cells.

Individuals die deterministically if their cell volume is too low, or stochastically, with a probability : death_rate .

Parameters:
  • time (int) – simulation time
  • max_die_off_frac (float, optional) – maximum fraction of individuals that can die
  • min_cell_volume (float, optional) – minimum cell volume for survival
  • stochastic_death (bool, optional) – if true, cells die stochastically, according to a death_rate
  • cells (sequence of VirtualMicrobes.virtual_cell.Cell.Cell) – individuals that can die
differential_regulation(cells=None)[source]

Return array of individual average differential regulation value.

enz_average_promoter_strengths(cells=None)[source]

Return array of individual average enzyme promoter strength.

enzyme_average_vmaxs(cells=None)[source]

Return array of individual average enzyme vmax values.

enzyme_counts(cells=None)[source]

Return array of individual enzyme gene counts.

enzyme_substrate_ks(cells=None)[source]

Return array of individual average enzyme substrate binding strength values.

export_type_counts(cells=None)[source]

Return counts of cell sets with equal export genotypes

exporter_counts(cells=None)[source]

Return array of individual exporting pump gene counts.

genome_sizes(cells=None)[source]

Return array of individual genome sizes.

genotype_counts(cells=None)[source]

Return counts of cell sets with equal genotypes

get_cell_age_dict(cells=None)[source]

Return dict of cell sizes.

get_cell_death_rate_dict(cells=None)[source]
get_cell_divided_dict(cells=None)[source]

Return dict of cell sizes.

get_cell_genome_size_dict(cells=None)[source]
get_cell_pos_production_dict(cells=None)[source]

Return dict of cell production values.

get_cell_production_dict(cells=None, life_time_prod=None)[source]

Return a mapping of cells and their last or life time production value.

Parameters:
  • cells (sequence of Cell objects) – individuals to map, default is the current population
  • life_time_prod (bool) – take life time mean production instead of current
get_cell_production_rate_dict(cells=None)[source]

Return dict of cell production rates.

get_cell_reproduction_dict(cells=None)[source]

Counts of the number of reproduction events for each cell (living and dead direct children)

get_cell_size_dict(cells=None)[source]

Return dict of cell sizes.

get_cell_toxicity_rate_dict(cells=None)[source]

Return dict of cell toxicity change rates.

grow_time_course_arrays()[source]
hgt_neighs(cells=None)[source]

Return array of individual hgt neighbourhoods.

horizontal_transfer(time, grid, environment, rand_gen=None, rand_gen_np=None)[source]

Applies HGT to all cells in the grid

Parameters:
  • grid (needed for internal HGT and setting the update-flags) –
  • environment (contains all possible reactions to draw a random gene for external HGT) –
  • rand_gen (RNG) –
Returns:

Return type:

import_type_counts(cells=None)[source]

Return counts of cell sets with equal import genotypes

importer_counts(cells=None)[source]

Return array of individual importing pump gene counts.

init_cells_view()[source]

Initialise the view on the keys of the cell dict.

init_current_ancestors(cells=None)[source]

Initialise the current ancestors.

init_evo_rand_gens(evo_rand_seed=None)[source]

Initialise random generator for evolutionary events

init_phylo_tree(supertree=False)[source]

Initialise the phylogenetic tree of the population.

Parameters:supertree (bool, optional) – if true create supertree of all independent phylogenetic lineages
init_pop(environment, pop_size=None, params_dict=None)[source]

Initialise the population.

Population initialisation is determined by the set of simulation parameters available in the params_dict or the params stored during construction of the VirtualMicrobes.virtual_cell.Population.Population. Several methods for creating a population are available:

  • a new population of unique individuals is created with randomised

cell parameters. * individuals are initialised from a set of cell configuration files, describing their parameters * a population of identical clones is generated from a single randomly initialised individual.

Initialise the phylogenetic tree.

Parameters:
  • environment (VirtualMicrobes.environment.Environment) – environment that is home to the population; determines molecular and reaction universe
  • pop_size (int, optional) – size of population
  • params_dict (dict, optional) – a dictionary of simulation parameters
Returns:

the newly created individuals

Return type:

iterator of VirtualMicrobes.virtual_cell.Cell.Cell objects

init_pop_rand_gen(pop_rand_seed=None)[source]

Initialise random generator for population events

init_range_dicts()[source]

Initialise mappings used in colour coding individuals in graphical output.

The markers_range_dict stores lower and upper bounds on discrete population statistics.

The metabolic_type_marker_dict maps metabolic types to markers that are used for colour coding.

The value_range_dict stores lower and upper limits on various celll properties that are represented on the phylogenetic tree.

init_roots(roots=None)[source]

Initialise the phylogenetic roots.

If no roots are given, initialise roots with the current_ancestors.

Parameters:roots (sequence of VirtualMicrobes.virtual_cell.Cell.Cell, optional) – roots ancestors of the population
iterages(cells=None)[source]

Return array of individual line of descent ages.

kill_cells_lineage(lineages, time, fract, cells=None)[source]
lineages(cells=None)[source]

Return array of individual linages

make_anc_clones(generations_ago, density)[source]
make_cell_clones(environment, list_of_cell_files, density)[source]
mark_cells_lineage(cells=None)[source]
mark_cells_metabolic_type(cells=None)[source]
mark_for_death(max_die_off_frac=None, min_cell_volume=None, stochastic_death=None, cells=None)[source]

Kill individual cells.

Individuals die deterministically if their cell volume is too low, or stochastically, with a probability : death_rate .

Parameters:
  • time (int) – simulation time
  • max_die_off_frac (float, optional) – maximum fraction of individuals that can die
  • min_cell_volume (float, optional) – minimum cell volume for survival
  • stochastic_death (bool, optional) – if true, cells die stochastically, according to a death_rate
  • cells (sequence of VirtualMicrobes.virtual_cell.Cell.Cell) – individuals that can die
marker_counts(marker, cells=None)[source]
classmethod metabolic_complementarity(cells, strict_providing=False, strict_exploiting=False)[source]

Determine for the list of cells what the overlap is in metabolites provided and exploited.

To provide a metabolite a cell should simultaneous produce and export the metabolite. To exploit, it should be imported and consumed in a reaction.

metabolic_complementarity_pop(strict=False)[source]

Return the set of metabolites that are provided and exploited simultaneously by the population.

See also

func()
metabolic_complementarity
metabolic_type_color(cell)[source]
metabolic_type_counts(cells=None)[source]

Return frequencies of cell sets with identical metabolic types.

A metabolic type is defined on the bases of the full set of metabolic reactions that an individual can perform using its metabolic gene set. A frequency spectrum of these types is than produced in the form of a collections.Counter object. From this object we can ask things like: most_common(N) N elements etc.

metabolic_types(cells=None)[source]

Return array of individual metabolic types

most_abundant_marker(marker_name, cells=None)[source]
most_offspring()[source]

Return individual and value of highest offspring count.

mutate_new_offspring(time, gp_dict, environment, rand_gen=None, rand_gen_np=None)[source]
offspring_counts(cells=None)[source]

Return array of individual offspring counts.

oldest_cell()[source]

Return oldest living individual.

pan_reactome_dict(cells=None)[source]

Return the pan reactome of the population.

The pan-reactome is the combined set of reactions present in the population.

Returns:

Notes

For historic reasons the set of all transport reactions, either importing or exporting are keyd under ‘import’. This type as stored in the type_ attribute of the VirtualMicrobes.event.Reaction.Reaction and should not be confused with the type_ attribute of the :class:VirtualMicrobes.virtual_cell.Gene.Gene` object.

point_mut_counts(cells=None)[source]

Return array of individual counts of life time point mutations.

pop_marker_counts(marker_name, cells=None)[source]
pos_production(cells=None)[source]

Return array of individual positive production rates.

print_state()[source]

Print population state.

producer_type_counts(cells=None)[source]

Return counts of cell sets with equal production metabolomes.

production_rates(cells=None)[source]

Return array of individual netto production rates.

production_values(cells=None)[source]

Return array of individual production values.

prune_metabolic_types(cells=None)[source]
pump_average_promoter_strengths(cells=None)[source]

Return array of individual average pump promoter strength.

pump_average_vmaxs(cells=None)[source]

Return array of individual average pump vmax values.

pump_energy_ks(cells=None)[source]

Return array of individual average pump energy binding strength values.

pump_substrate_ks(cells=None)[source]

Return array of individual average pump substrate binding strength values.

reaction_counts(cells=None)[source]

Return counts of all reactions found in the population.

reaction_counts_split(cells=None)[source]

Return counts of all reactions found in the population per reaction type.

reaction_genotype_counts(cells=None)[source]

Return counts of cell sets with equal reaction genotypes

regulator_score(cells=None)[source]
reproduce_at_minimum_production(time, competitors=None, max_reproduce=None, reproduction_cost=None)[source]
reproduce_cell(cell, time, spent_production=0.0, report=False)[source]

Reproduction of individual cell.

Parameters:
  • cell (VirtualMicrobes.virtual_cell.Cell.Cell) – reproducing individual
  • time (int) – simulation time
  • spent_production (float, optional) – production spent on reproducing
  • report (bool, optional) – reporting
Returns:

offspring – new individual

Return type:

VirtualMicrobes.virtual_cell.Cell.Cell

reproduce_neutral(time, competitors, max_reproduce=None)[source]

Individuals compete and reproduce proportional to NOTHING :) Note that cells would shrink if you keep doing this! Therefore we choose to reset the volumes continuously.

Parameters:
Returns:

new_offspring – new offspring produced in this function

Return type:

list of VirtualMicrobes.virtual_cell.Cell.Cell s

reproduce_on_grid(grid, max_pop_per_gp, time, neighborhood='competition', non=None, selection_pressure=None)[source]

Reproduction of the population on the spatial grid.

Parameters:
  • grid (VirtualMicrobes.Environment.Grid.Grid) – spatial grid environment
  • max_pop_per_gp (int) – maximum number of individuals per grid point
  • time (int) – simulation time
  • neighborhood (str, optional) – key to select neighborhood shape
  • non (float, optional) – chance of no competitor winning competition
  • selection_pressure (str) – type of selection pressure
Returns:

new_offspring_gp_dictVirtualMicrobes.environment.Grid.GridPoint mapping of new offspring to the spatial grid point that they are born in.

Return type:

VirtualMicrobes.virtual_cell.Cell.Cell ->

reproduce_production_proportional(time, competitors, max_reproduce=None, production_spending_fract=None, non=0.0)[source]

Individuals compete and reproduce proportional to their production value.

Parameters:
  • time (int) – simulation time
  • competitors (list of VirtualMicrobes.virtual_cell.Cell.Cell) – competing individuals
  • max_reproduce (int, optional) – maximum allowed reproduction events
  • production_spending_fract (float, optional) – fraction of cell production value spent on reproduction
  • non (float, optional) – chance of no competitor winning competition
Returns:

new_offspring – new offspring produced in this function

Return type:

list of VirtualMicrobes.virtual_cell.Cell.Cell s

reproduce_size_proportional(time, competitors, max_reproduce=None, non=0.0)[source]

Individuals compete and reproduce proportional to their cell size.

Parameters:
  • time (int) – simulation time
  • competitors (list of VirtualMicrobes.virtual_cell.Cell.Cell) – competing individuals
  • max_reproduce (int, optional) – maximum allowed reproduction events
  • non (float, optional) – chance of no competitor winning competition
Returns:

new_offspring – new offspring produced in this function

Return type:

list of VirtualMicrobes.virtual_cell.Cell.Cell s

reset_divided()[source]

Reset flag for recent cell division.

reset_production_toxicity_volume(cells=None)[source]
resize_time_courses(new_max_time_points)[source]

resize the arrays that can hold time course information of cellular concentrations etc.

Parameters:new_max_time_points – new length of time course array
scale_death_rates(max_die_off_fract, cells=None)[source]

Scale death rates to give a maximum rate of dieing individuals.

If individual death rate are too high, these are scaled to have a maximum fraction of deaths, on average, in the population.

Parameters:
Returns:

Return type:

returns mapping of cells to death rates

select_reproducing_cell(cells_competition_value, rand_nr, non=0.0, competition_scaling_fact=None)[source]

Select a competing individual for reproduction.

Parameters:
  • cells_competition_value (list of (class:VirtualMicrobes.virtual_cell.Cell.Cell, float)) – competing cells with competition values
  • rand_nr (float) – randomly drawn value between 0 and 1.
  • non (float, optional) – value between 0 and 1 that represents no individual is chosen
  • competition_scaling_fact (float, optional) – factor that can skew competition to be more or less severe
Returns:

Return type:

(chosen individual, competition_value, index in competition list)

store_pop_characters()[source]
tf_average_promoter_strengths(cells=None)[source]

Return array of individual average transcription factor promoter strength.

tf_counts(cells=None)[source]

Return array of individual transcription factor gene counts.

tf_k_bind_operators(cells=None)[source]

Return array of individual average transcription factor operator binding strength values.

tf_ligand_ks(cells=None)[source]

Return array of individual average transcription factor ligand binding strength values.

times_divided(cells=None)[source]

Return array of individual death rate parameters.

toxicity_rates(cells=None)[source]

Return array of individual toxicity change rates.

trophic_type_counts(env, cells=None)[source]

Return counts of trophic types in the population.

unique_pop(pop_size, environment, params_dict)[source]

Create population of unique, randomised individuals.

Creates new class:VirtualMicrobes.virtual_cell.Cell.Cell individuals and initialises their genomes. Genome initialisation depends on the environment, because this determines the set of possible gene types and minimum viable metabolism that can be constructed.

Parameters:
  • pop_size (int) – population size
  • environment (VirtualMicrobes.environment.Environment) – environment that is home to the population; determines molecular and reaction universe
  • params_dict (dict, optional) – a dictionary of simulation parameters
Returns:

the newly created individuals

Return type:

view keys of VirtualMicrobes.virtual_cell.Cell.Cell objects

update_cell_params(cells=None)[source]

Update the the cell parameters.

Sets cell parameters from the Simulation params dict.

Parameters:cells (sequence of VirtualMicrobes.virtual_cell.Cell.Cell, optional) – the cells to update
update_ete_tree()[source]

Update the ete tree representation of the phylo_tree.

update_lineage_markers(cells=None, min_nr_marks=None)[source]
update_offspring_regulatory_network(min_bind_score=None)[source]
update_phylogeny(new_roots=None, verbose=True, add_living=None)[source]

Update the phylogeny of the current population.

current_ancestors contains all living individuals and those that have contributed to the current population.

Individuals are only added to the phylo_tree representation after they have died, unless the add_living option is used. Nodes will only remain in the phylo_tree as long as the branch they’re on contains a living individual in the current population. If a lineage dies out, its corresponding branch (and its constituent tree nodes) is pruned from the phylogenetic tree.

  • Add new offspring to the current ancestors.
  • Prune extinct branches in the phylogeny and remove ancestors without living offspring
  • Update the phylogenetic tree structure:
    • add new root nodes
    • add new intermediate nodes
    • prune dead branches and nodes
Parameters:
Returns:

phylo_tree – phylogenetic tree representation of current population

Return type:

VirtualMicrobes.Tree.PhyloTree.PhyloTree

update_prod_val_hist(hist_prod_func=<function median>, historic_production_window=None, pop_size_scaling=None)[source]

Keep a sliding window view on historic production values.

Parameters:
  • hist_prod_func (func, optional) – calculates the population production value
  • historic_production_window (int, optional) – length of the sliding window
  • pop_size_scaling (bool, optional) – scale production value by population size
update_stored_variables()[source]

Syncs all local variables of class Cell.py (small_molecules) with the time course data

upgrade()[source]

Upgrading from older pickled version of class to latest version. Version information is saved as class variable and should be updated when class invariants (e.g. fields) are added.

uptake_rates(cells=None)[source]

Return array of individual uptake multipliers.

wipe_pop(fract, time, min_surv=None, cells=None)[source]

Kill a fraction of the individuals.

Sets a flag on individuals that were killed by wipe_pop.

Parameters:
  • fract (float) – fraction to kill
  • time (int) – simulation time
  • min_surv (int, optional) – minimum number of surviving individuals
  • cells (sequence of VirtualMicrobes.virtual_cell.Cell.Cell) – individuals in calculation
Returns:

Return type:

list of individuals that were killed

VirtualMicrobes.virtual_cell.Sequence module

class VirtualMicrobes.virtual_cell.Sequence.BindingSequence(sequence=None, length=None, elements=['0', '1'], flip_dict={'0': '1', '1': '0'}, **kwargs)[source]

Bases: VirtualMicrobes.virtual_cell.Sequence.Sequence

Binding sequence of a Transcription Factor

bound_operators
clear_bound_operators()[source]
inform_operators()[source]
init_bound_operators()[source]
match_operators(operators, minimum_score)[source]
remove_bound_operator(op)[source]
toJSON(*args, **kwargs)[source]
class VirtualMicrobes.virtual_cell.Sequence.Operator(sequence=None, length=None, elements=['0', '1'], flip_dict={'0': '1', '1': '0'}, **kwargs)[source]

Bases: VirtualMicrobes.virtual_cell.Sequence.Sequence

Version:
Author:
bind_to_bs(bs, minimum_score, report=False)[source]
binding_sequences
calc_score_for_bs(binding_site, minimum_score=1.0, report=False)[source]
calculate_regulation()[source]
clear_binding_sequences()[source]
inform_bss()[source]
init_binding_sequences()[source]

A dictionary from binding sequences that bind to this operator to binding scores

remove_binding_sequence(bs)[source]
toJSON(*args, **kwargs)[source]
update_binding_sequences(all_binding_sequences, minimum_score)[source]

Find the Binding Sequences that match this Operator and update dictionaries accordingly. Matching depends on a threshold “minimum_score”.

Parameters:
  • binding_sequences – set of BS
  • minimum_score – threshold for calling a match between this

Operator and a BS

class VirtualMicrobes.virtual_cell.Sequence.Sequence(sequence, elements, length, flip_dict, time_birth=0, **kwargs)[source]

Bases: VirtualMicrobes.virtual_cell.PhyloUnit.PhyloBase

Version:
Author:
best_match(s2, at_least=0, penalty=0.5, report=False)[source]

Finds the best match possible between self and s2 anywhere in both sequences, but only if the match score reaches at least a minimum threshold. If the returned score is below this threshold it is not guaranteed to be the best possible match. No gaps are allowed.

Parameters:
  • s2 – sequence to compare to
  • at_least – the minimum score that should still be attainable by

the scoring algorithm for it to proceed computing the scoring matrix :param penalty: mismatch penalty

bit_flip(bit, flip_dict=None)[source]
check_binding
elements
flip_dict
insert_mutate(pos, sequence_stretch, constant_length=True)[source]

Insert a sequence stretch into the current sequence.

Sets the check_binding flag to indicate that the sequence should be checked for changed binding status.

Parameters:
  • pos (int) – position in current sequence to insert
  • sequence_stretch (str) – stretch to be inserted
  • constant_length (bool) – whether to truncate after insertion to maintain the original sequence length
Returns:

Return type:

newly mutated sequences

match(sequence, func)[source]
mutate(rand_gen=None, change_magnitude=None)[source]

Mutates the sequence.

Number of bits to mutate is either 1 or an amount of bits determined by the probability per bit to be changed or a given number of bits, depending on the value of “change_magnitude”. Sets the check_binding flag to indicate that the sequence should be checked for changed binding status.

Parameters:
  • rand_gen (RNG) –
  • change_magnitude (float or int) – when < 1, it is a probability, otherwise it is assumed to be the number of bits that should be changed (rounded up to nearest integer).
Returns:

Return type:

newly mutated sequences

mutate_bits(nr=1, rand_gen=None)[source]

Mutates a given number of random bits in the sequence to new values, chosen from the set of elements (possible values) that a bit can take, randomly.

Parameters:
  • nr – number of bits to mutate
  • rand_gen – random generator
random_sequence(n, rand_gen)[source]

Create random sequence of length n from elements.

Parameters:
  • n (int) – length of sequence
  • rand_gen (RNG) –
Returns:

Return type:

sequence string

randomize(rand_gen=None)[source]
sequence
classmethod substring_scoring_matrix(s1, s2, at_least=0, penalty=0.5)[source]

Computes a scoring matrix for matching between 2 sequences. Starts with a matrix filled in with all -1 . Comparisons between the strings continue as long as it is still possible to obtain the ‘at_least’ score when comparing the remainder of the strings. When the score is too low and the remaining substring length that can still be matched too short, the algorithm will stop, leaving the rest of the scores uncomputed. In that case, the _max is not guaranteed to be the maximum attainable matching score.

example matrix when matching sequences 0000000000 and 0000010100 with the default mismatch penalty of 0.5 (penalty substracted from score attained up to that point).

0 0 0 0 0 0 0 0 0 0 <- sequence 1

0 0 0 0 0 0 0 0 0 0 0

0 0 1 1 1 1 1 1 1 1 1 1 0 0 1 2 2 2 2 2 2 2 2 2 0 0 1 2 3 3 3 3 3 3 3 3 0 0 1 2 3 4 4 4 4 4 4 4 0 0 1 2 3 4 5 5 5 5 5 5 1 0 0 0.5 1.5 2.5 3.5 4.5 4.5 4.5 4.5 4.5 0 0 1 1 1.5 2.5 3.5 4.5 5.5 5.5 5.5 5.5 1 0 0 0.5 0.5 1.0 2.0 3.0 4.0 5.0 5.0 5.0 0 0 1 1 1.5 1.5 2.0 3.0 4.0 5.0 6.0 6.0 0 0 1 2 2 2.5 2.5 3.0 4.0 5.0 6.0 7.0

sequence 2

sequence 1: 0000000000 sequence 2: 0000010100 match: 0.7

uid = 0
VirtualMicrobes.virtual_cell.Sequence.pretty_scoring_matrix(seq1, seq2, scoring_mat, width=4)[source]

Module contents