1. 1LocusSim is a simple and adaptable (mobile-friendly) simulator to visualize the effect of genetic drift, selection and mutation on allele frequency.
  2. It is programmed in Python based on the NumPy library.


If you have any questions please contact me .



Back to AC-R home
Simulator parameters
The simulator defines an ideal population model with a constant population size and diploid individuals without distinction of sex (hermaphrodites). Each individual consists of a gene (locus) with 2 alleles (normal and mutant). Allows simulation of deviations from the ideal population generated by mutation and selection.


Number of populations
It corresponds to the number (n) of isolated populations or independent replicas where the gene evolves. They can also be considered as different independent genes (loci) in a population. The maximum is 100 but with restrictions. The computational complexity of the program depends mainly on the number of populations and generations. To avoid long simulation times, limits are imposed for both parameters. With 50 populations or less, the maximum allowed for the product of both is 2×105. With more than 50 populations, the limit drops to 2×104.


Population size
It is the number of individuals (N) in each population. The maximum is 104.


Initial frequency
Initial frequency of the mutant allele (q0). Between 0 and 1 both included.


Mutation rate μ from normal to mutant allele per generation and haploid gene. That is, the probability that a specific individual will mutate will be 2μ because they are diploid.


Backmutation rate ν. It corresponds to the probability of mutating from the mutant to the normal allele. If it is not checked, it is 0. If it is checked and the model is neutral, it is equal to the mutation rate (ν=μ). If there is selection, it is an order of magnitude less than the mutation rate (ν=μ/10). In the absence of other forces the equilibrium frequency is qeq=μ/(μ+ν).


If it is checked, it allows self-fertilization, otherwise it is not allowed. An exception to the latter is the case of populations with only one individual (N=1), in which self-fertilization is mandatory whether or not the option is checked.


Selection coefficient (s) with values between -1 and 1 (both included). The value 0 corresponds to absence of selection (neutral gene). Positive values of the selection coefficient indicate that the mutant allele is deleterious (fitness 1-s) and negative values (fitness 1+|s|) indicate that the mutant allele is beneficial (see Selection menu for more information).


Dominance coefficient (h). It only has effect in the presence of selection. Indicates the allelic interaction in the heterozygote. If it is 0, the mutant allele is completely recessive and the heterozygote has the same selective value as the normal homozygote. If it is 0.5, the relationship is additive and the heterozygote has an intermediate value between both homozygotes. If it is 1, the mutant allele is completely dominant and the heterozygous has the same value as the homozygous mutant. Values of h greater than 1 or less than 0 indicate overdominance or subdominance depending on the sign of s (see Selection menu for more information).


Number of generations
Indicates the number T of generations of evolution. The maximum is Tmax=104 if the number of populations n is 20 or less. If n>20 to 50, then Tmax=2×105/n. Finally, if n>50, Tmax=2×104/n. For example, with 50 populations Tmax corresponds to 4000 generations and with 100 populations Tmax is 200 generations. The reason for these restrictions is to ensure that in the worst case, the simulation time does not exceed a few minutes (3-5 minutes at most).


Ideal population
The ideal population model is defined by the following characteristics:
1.- Census population N, constant between generations, with diploid individuals without separation of sexes.
2.- Random mating between gametes including self-fertilization.
3.- The genetic characterization of the population involves a biallelic autosomal locus with initial frequencies p0 and q0 in Hardy-Weinberg equilibrium, that is, with genotypic frequencies p02, 2p0q0 and q02.
4.- Absence of other forces of change of the allelic frequency (there is no mutation, migration or selection).

Effective population size (Ne)
Number of individuals that the current population would have if it were ideal. It is usually less than the actual census. It is related to the expected frequency of heterozygotes (heterozygosity) and genetic diversity, such that the greater the effective population size, the greater the genetic diversity and vice versa. The effective population size is a very relevant parameter in evolutionary terms because it determines the magnitude of genetic drift and consanguinity in the population. For example, in a population of 1000 individuals where there is 1 individual of one sex and 999 of the other, so that the first reproduces with the rest, the population size is 1000 but obviously the effective size is lower (approximately 4 individuals of an ideal population).

Genetic drift
Random fluctuations in allele frequencies that occur due to random sampling of gametes in reproduction. These fluctuations are inversely proportional to the effective population size. That is, the smaller Ne is, the greater the fluctuations, and vice versa. One way to measure these fluctuations is through the variance σ2 of the gene frequency between different subpopulations or replicates.

Natural selection
In the basic model of a biallelic locus, selection acts directly on genotypes. So, one homozygote has maximum fitness 1, the other homozygote has fitness 1-s, and the heterozygote has fitness 1-sh, where s and h are the selection and dominance coefficients, respectively (see Selection menu for more information).
Based on the fact that the equilibrium frequency between mutation and retromutation, if there is no selection or other forces of change, is qeq=μ/(μ+ν), do the following exercises.


Exercise 1
We have 10 populations of 100 individuals each with initial frequency q0=0.5. After 1000 generations equilibrium is reached and the frequency is q1000=1, if the mutation rate was μ=0.01 what was the value of the backmutation rate ν? Check it out with a simulation.


Since qeq=μ/(μ+ν) we have that q1000=1=0.01/(0.01+ν) and therefore 0.01+ν=0.01=>ν=0.

Exercise 2
We have 50 populations of 100 individuals each and the initial mutant is not present in any of them (q0=0). After 1000 generations equilibrium is reached and the mean frequency of the mutant is approximately 0.5. If the mutation rate was 0.01, what will be the backmutation rate? Why? Test your hypothesis with a simulation. What would be the frequency if the backmutation rate were 0? Why? What if the mutation rate had been 0?


q1000=0.5=0.01/(0.01+ν) solving we get ν=0.02-0.01=0.01. The mutation and backmutation rates must be equal to obtain an equilibrium frequency of 0.5. If ν=0 and assuming a model of only 2 alleles (wild type and mutant), then the equilibrium frequency is 1 because given enough time all genes will have mutated. If μ=0 the frequency of the mutant at equilibrium is 0.



A. Carvajal-Rodriguez - Departamento de Bioquímica Genética e Inmunología - Universidad de Vigo. (Updated: May 2023)