simplicity.evolution package
Submodules
simplicity.evolution.decoder module
simplicity.evolution.mutations module
Created on Thu Jun 1 11:15:10 2023
@author: pietro
- simplicity.evolution.mutations.assign_sub(unassigned_subst, sub_coord_dicmap)[source]
Update the substitution coordinates to include the substitutions that will be included (assign the substitutions to lineages with the positions in their genome)
- Parameters:
unassigned_subst (dic) – dict with a list of substitutions for each nitrogenous base.
sub_coord_dicmap (coordinates of the substitutions that will be introduced)
- Returns:
sub_coord_dicmap (list)
UPDATED coordinates of substitution
index of individual (in population.individuals) that hosts the lineage
index of lineage inside the host
position in the genome of lineage mutated
nitrogenous base that will be introduced at that position
- simplicity.evolution.mutations.fetch_bases(population, sub_coord_dicmap)[source]
Add base to be substituted to subst_coord. First it checks if the position is already mutated, if so it takes the mutated base. Otherwise fetches the base from the reference genome.
- Parameters:
population (instance of population class)
sub_coord_dicmap (list) – coordinates of substitution
- Returns:
sub_coord_dicmap (list)
coordinates of substitution
index of individual (in population.individuals) that hosts the lineage
index of lineage inside the host
position in the genome of lineage mutated
nitrogenous base of the lineage at that position
- simplicity.evolution.mutations.get_subst_numbers(sub_coord_dicmap, sub_number)[source]
Returns count of how many of each nitrogenous base will undergo substitution
- Parameters:
sub_coord_dicmap (list) – coordinates of substitutions
sub_number (int) – number of substitution events
- Raises:
ValueError – Raise error if the list of coordinates is not the same size as the number of substitution events
- Returns:
dic that counts the number of bases to be substituted. e.g. 4 A, 3 T, 0 C, 5 G
- Return type:
TYPE
- simplicity.evolution.mutations.map_to_dic(mutating_lineages, positions, L_lin)[source]
Map mutation positions onto dictionary of population.individuals
- Parameters:
mutating_lineages (list)
lineages( (list of selected lineages that will mutate (subset of active) – coord map onto individuals
positions (array) – positions that will undergo substitution
- Returns:
sub_coord_dicmap (list)
coordinates of substitution
index of individual (in population.individuals) that hosts the lineage
index of lineage inside the host
position in the genome of lineage to be mutated
- simplicity.evolution.mutations.map_to_lin(positions, L)[source]
Maps positions to be mutated onto active_lineages (lineages).
- Parameters:
positions (array) – positions that will undergo substitution
L (int) – lenght of lineage genome
- Returns:
sub_coord_linmap –
- lineages mutation coordinates:
- (LIST index of active_lineage to mutate,
position in the genome to mutate).
the index here does not refer to the index of the population.individuals dic
- Return type:
tuple
- simplicity.evolution.mutations.mutate(population, NSR, L, dt, phenotype_model, *args)[source]
Mutation model, mutates the viruses in the population.
- Parameters:
NSR (float) – nucleotide substitution rate.
dt (float) – delta t - extrande time step (in years)
- simplicity.evolution.mutations.select_positions(population, L, NSR, dt)[source]
Select genome positions to mutate using two parallel Poisson processes.
- Returns:
array of pooled genome indices to mutate mutating_lineages : list of [individual_id, lineage_id] per mutation sub_number : number of mutations this time step
- Return type:
positions
- simplicity.evolution.mutations.sub_events(rng, NSR, L, dt, IH_lineages)[source]
- Choose the number of substitutions that happen in a time step dt,
drawing random number sampled from Poisson distribution.
- Parameters:
rng (numpy method) – Random number generator.
NSR (float) – nucleotide substitution rate.
dt (float) – delta t - extrande time step.
IH_lineages (int) – number of active IH_lineages that can mutate in time step dt
- Returns:
number of substitutions that happen in a time step dt.
- Return type:
int
- simplicity.evolution.mutations.sub_matrix()[source]
Define substitution matrix. If you want to specify a different matrix, change the code here.
- simplicity.evolution.mutations.substitution(M, bases_count, rng)[source]
Generate substitutions for each base based on substitution matrix. These substitutions are not assigned to any genome position yet, the function returns a dict with a list of substitutions for each nitrogenous base.
- Parameters:
M (substitution matrix)
bases_count (dic) – dictionary with count of bases to substitute
- Returns:
dictionary that contain a list of substitutions for each base type. e.g A = [T,T,G,C,G,T,T,C,C,G]
- Return type:
dic
simplicity.evolution.reference module
@author: Pietro Gerletti