Class for low-dimensional population genetics (short genomes ~20 loci).
The class offers a number of functions, but an example will explain the basic idea:
#####################################
# EXAMPLE SCRIPT #
#####################################
import numpy as np
import matplotlib.pyplot as plt
import FFPopSim as h
c = h.haploid_lowd(5) # 5 loci
# initialize with 300 individuals with genotype 00000,
# and 700 with genotype 00010
c.set_genotypes([0, 2], [300, 700])
# set an additive fitness landscape with these coefficients
c.set_fitness_additive([0.02,0.03,0.04,0.02, -0.03])
# Note: we are in the -/+ basis, so
# F[10000] - F[00000] = 2 * 0.02
# Hence the coefficients are half of the effect of mutation on fitness
c.evolve(100) # evolve for 100 generations
c.plot_diversity_histogram()
plt.show()
#####################################
Construct a low-dimensional population with certain parameters.
Copy population into new instance.
Print a status list of the population parameters
Number of loci (read-only)
Number of loci (read-only)
Population size (read-only)
Population size (read-only)
Current generation (read-only)
is the genome circular?
current carrying capacity of the environment
Model of recombination to use
Available values:
- FFPopSim.FREE_RECOMBINATION: free shuffling between parents
- FFPopSim.CROSSOVERS: block recombination with crossover probability
- FFPopSim.SINGLE_CROSSOVER: block recombination with crossover probability
outcrossing rate (probability of sexual reproduction per generation)
Initialize the population in linkage equilibrium with specified allele frequencies.
Note
the population size is only used for resampling and has therefore no effect on the speed of the simulation.
Initialize population with fixed counts for specific genotypes.
from 00...0 that is 0, up to 11...1 that is 2^L-1.
counts: list of counts for those genotypes
Note
the population size and, if unset, the carrying capacity will be set as the sum of the counts.
Note
you can use Python binary notation for the indices, e.g. 0b0110 is 6.
Initialize population of N individuals with the - allele at all loci (wildtype)
Note
the carrying capacity is set to the same value if still unset.
Set the recombination rate(s).
Note
if locus-specific rates are specified, the array must have length (L-1) for linear chromosomes and length L for circular ones. The i-th element is the crossover rate between the i-th site and the (i+1)-th site.
Note
if the recombination model is not specified, the current model will be kept or, if the current model is FREE_RECOMBINATION, then CROSSOVERS will be set.
Get recombination rates.
Note
if the recombination model if FREE_RECOMBINATION, an error is raised.
Set the mutation rate(s).
rates:if a double, the mutation rate at any locus in both directions or, if rates_back is not None, only in the forward direction
if a vector, the mutation rate is specified for each locus, the same in both directions or, if rates_back is not None, only in the forward direction
rates_back: mutation rate in the backward direction (global or locus-specific)
Get one or several mutation rates.
locus: get only the mutation rate(s) of this locus
is a Boolean, 0/False for forward rates, 1/True for backward rates.
Note: if the mutation rates for all loci and/or directions are the same, this function will try to be smart and give you the answer you are looking for. In case of doubt, you will get a matrix (L x 2) with the full mutation rate landscape.
Evolve for some generations
Evolve for some generations deterministically (skips the resampling)
Evolve for some generations without recombination
Get the frequency of a genotype
Get the frequency of each genotype.
Get the frequency of the + allele
- Parameters:
- locus: locus, at which the frequency of the + allele is to be computed
- Returns:
- the frequency of the + allele, :math:`
u_i := rac{1 + left<s_i ight>}{2}`, where \(s_i \in \{-1, 1\}\).
Get the frequencies of all + alleles
Get the frequency of genotypes with the + allele at both loci.
Get chi of an allele in the -/+ basis
- Parameters:
- locus: locus whose chi is to be computed
- Returns:
- the chi of that allele, :math:`chi_i := left<s_i
ight>`, where \(s_i \in \{-1, 1\}\).
Get \(\chi_{ij}\)
- Parameters:
- locus1: first locus
- locus2: second locus
- Returns:
- the linkage disequilibiurm between them, i.e. :math:`chi_{ij} := left<s_i s_j
ight> - chi_i cdot chi_j`.
Get linkage disequilibrium
- Parameters:
- locus1: first locus
- locus2: second locus
- Returns:
- the linkage disequilibiurm between them, i.e. :math:`D_{ij} := 1 / 4 left[left<s_i s_j
ight> - chi_i cdot chi_j ight]`.
Get moment of two alleles in the -/+ basis
- Parameters:
- locus1: first locus
- locus2: second locus
- Returns:
- the second moment, i.e. :math:`left<s_i s_j
ight>`, where \(s_i, s_j \in \{-1, 1\}\).
Get random genomes according sampled from the population.
Get fitness values of a genotype
Get the fitness of all possible genotypes.
Get the histogram of the fitness of a sample from the population.
Plot the histogram of the fitness of a sample from the population.
Get the mean and variance of the divergence of a population sample – same as mean and variance of allele frequencies.
Get the histogram of the divergence of a population sample.
Note: to get a normalized histogram, use the density keyword.
Plot the histogram of the divergence of a population sample.
Get the mean and variance of the diversity of a population sample
Get the histogram of the diversity in a sample from the population.
Note: to get a normalized histogram, use the density keyword.
Plot the histogram of the diversity of a population sample.
Set the fitness landscape for individual genotypes.
from 00...0 that is 0, up to 11...1 that is 2^L-1.
values: fitness values to assign
Note
you can use Python binary notation for the genotypes, e.g. 0b0110 is 6.
Set the fitness landscape in Fourier space for individual Fourier coefficients.
as integers, from 00...0 that is 0, up to 11...1 that is 2^L-1.
values: values to assign
Note
you can use Python binary notation for the coefficients, e.g. 0b0110 is 6.
Set an additive fitness landscape. Coefficients obey +/- convention.
Get the genotype entropy of the population
Note
the genotype entropy is defined as \(-\sum_{i=0}^{2^L} p_i \log p_i\).
get the allele entropy of the population
Note
the allele entropy is defined as \(-\sum_{i=0}^{L} \left[\nu_i\log \nu_i + (1-\nu_i)\log(1-\nu_i)\right]\).