pydigree.simulation package¶
Subpackages¶
Submodules¶
pydigree.simulation.chromosomepool module¶
A pool of Chromosomes a simulation can draw from
-
class
pydigree.simulation.chromosomepool.ChromosomePool(population=None, chromosomes=None, size=0)¶ Bases:
objectA pool of Chromosomes a simulation can draw from
-
chromosome(chromindex)¶ Get a random chromomsome from the pool :param chromindex: which chromosome are we looking for? :type chromindex: int
Return type: AlleleContainer
-
evolve(growth_func, gens)¶ Iterates the pool according to a popuation growth model.
Parameters: - growth_func (Callable) – A function that takes a generation number as an argument and returns a generation size
- gens (int) – number of generations to advance
Rtype void:
-
fix(loc, value)¶ Sets all alleles at loc to value
-
static
from_population(pop)¶ Creates a pool from an existing population.
Parameters: pop (Population) – Base population Return type: ChromosomePool
-
get_genotype_set()¶ Gives a full set of genotypes drawn from the chromosome pool
-
initialize_pool(size=None)¶ Initializes a pool of chromosomes for simulation
-
iterate_pool(gensize)¶ Iterate pool simulates a generation of random mating between chromosomes instead of individuals. The pool of population chromosomes then contains chromosomes from the new generation.
Arguements: gensize: The size of the next generation (rounded down to the integer)
Returns: Nothing
-
size()¶ Returns the size of the pool of available chromosomes
-
-
pydigree.simulation.chromosomepool.richards(A, C, M, B, T)¶ Generates a population growth model function
A: Lower Asymptope C: Upper Asymptope M: Maximum growth time B: Growth Rate T: Maximum growth position
pydigree.simulation.mating module¶
Classes for specifying the mating structure in a population
-
class
pydigree.simulation.mating.MatingClique(pop, males=None, females=None)¶ Bases:
objectA class that holds a group of individuals that can form offspring
Variables: -
children_possible()¶ Are enough males and females to have a child
Return type: bool
-
get_female()¶ Chooses a random female from the clique
-
get_male()¶ Chooses a random male from the clique
-
mate(pop=None, sex=None, label=None)¶ Generate offspring from the clique. If more than one father or mother is available, they are randomly selected.
Parameters: - pop (Population) – Population for the new individual
- sex (0,1) – Sex of the offspring if specified, otherwise offspring randomly sex is chosen
- label – Label for the offspring individual
Returns: offspring individual
Return type:
-
-
class
pydigree.simulation.mating.MatingStructure¶ Bases:
objectA class representing how a population mates, for when fully random mating may not be desired.
-
next_generation(pop, gensize)¶ Create the next generation by mating people using the current structure
Pop: Population to be advanced Gensize: Number of children to generate Return type: list of Individuals Returns: progeny
-
-
class
pydigree.simulation.mating.MonogamousMating¶ Bases:
pydigree.simulation.mating.MatingStructureA mating structure where pairs of individals from the opposite sex pair up and form childen together, and not with anyone else
-
form_cliques(pop)¶ Creates the monogamous pairs
Parameters: pop – The population we’re working with Returns: The cliques Return type: List of MatingCliques
-
-
class
pydigree.simulation.mating.RandomMating¶ Bases:
pydigree.simulation.mating.MatingStructureA MatingStructure representing purely random mating
-
next_generation(pop, gensize)¶ Create individuals for the next generation by random mating
Parameters: - pop (Population) – Parent population
- gensize (int) – Size of next generation
-
pydigree.simulation.trait module¶
Synthetic quantitative genetic traits
-
class
pydigree.simulation.trait.QuantitativeGeneticEffect(locus, a, k=0, chromosomes=None)¶ Bases:
objectQuantitativeGeneticEffect is a class for objects that relate loci to phenotypes.
Variables: - a – the additive effect of an allele
- k – the deviation from additivity for the heterozygote
- chromosomes – Chromosomes to get frequencies from
-
alpha¶ Returns the average effect of allelic substitution for the locus, \(\alpha = a(1 + k(p - q))\).
“[alpha] represents the average change in genotypic value that results when a [minor allele] is randomly substituted for a major allele”
Lynch & Walsh, Genetics and Analysis of Quantitative Traits, p. 68
Return type: float
-
expected_genotypic_value¶ The expected genotypic value at the locus. This is the mean of the three genotype effects, weighted by their frequency.
Return type: float
-
genotypic_value(individual)¶ The value that this individual gets from this genotype:
Minor Alleles Effect 0 0 1 (1+k)a 2 2a Parameters: individual (Individual) –
-
locus_additive_variance¶ Returns the additive variance due to the locus, based on the frequencies in the chromosomeset
\(\sigma^2_a = 2pq lpha ^2\)
Returns: \(\sigma ^{2}_{A_{x}}\) Return type: float
-
locus_dominance_variance¶ Returns the dominance variance due to the locus, based on the frequencies in the chromosomeset
\(\sigma^2_d = (2pqak)^2\)
Returns: \(\sigma ^{2}_{D_{x}}\) Return type: float
-
class
pydigree.simulation.trait.QuantitativeTrait(name, traittype, h2=1.0, mean=0, chromosomes=None)¶ Bases:
objectQuantitativeTrait is a static class that relates genotypes to phenotypes.
For main (i.e non-epistatic) effects, you supply a tuple of (chromosome, position) to indicate location.
Then you would add the effect to the trait architecture with: t.add_effect(location, a, k)
When h2 is specified, phenotypes have an appropriate amount of random normal noise added to them so that the heritability of the trait in a population in Hardy-Weinberg equilibrium (infinitely large, randomly mating, no migration/selection, etc) equals h2.
The trait can be forced to have a mean at a desired location by computing trait_mean = intercept + expected_genotypic_value. The genotypic value can be directly calculated from the specified effects, and the intercept is automatically calculated by the formula.
Predicted phenotypes for individual objects can be given by t.predict_phenotype(individual)
-
add_dummy_polygene_chromosomes(population, nloc, mean=0, sd=1, freqs=None, polylabel='Polygene')¶ Creates many independently segregating chromosomes that additively influence the trait.
Parameters: - population – The population to add the chromosomes to
- nloc (integer) – The number of dummy chromosomes to create
- mean (float) – Mean locus additive effect
- sd (float) – Standard deviation of locus additive effect
- freqs (sequence of floats) – frequencies of each polygene
- polylabel (string) – Label to add give chromosome
Return type: void
-
add_effect(locus, a=0, k=0, effect=None)¶ Add a main genetic effect for a locus.
Parameters: - locus – a chromosome, index tuple
- a – The additive effect of each minor allele
- k – The dominance effect of at the locus, where k is the deviation from additivity (default 0)
- effect – a QuantitativeGeneticEffect object if a and k are not supplied
-
additive_genetic_variance¶ Total additive variance.
The sum of the additive variance of each effect.
Return type: float
-
environmental_variance¶ When h2 is fixed, this returns the corresponding environmental variance in the population that must be added to result in the specified h2 value.
Return type: float
-
expected_genotypic_value¶ The expected genotypic value for an individual in the population.
This is the sum of the expected genotypic values for each of the effect loci
Return type: float
-
static
from_file(filename)¶ Reads a trait from a file
Parameters: filename (string) – path to file Return type: QuantitativeTrait
-
intercept¶ The mean phenotypic value in the population
-
predict_phenotype(individual)¶ Generates a predicted phenotype for an individual based off their genotype
Parameters: individual – subject to have a phenotype prediected Returns: Trait value if quantitative, affectation status if dichotomous Return type: double (quantitative); 0 or 1 (dichotomous)
-
rescale(mean, sd)¶ Rescale trait to have the distribution N(mean, sd). Modifies genotype effects so that they sum to the appropriate variance.
Parameters: - mean – the desired mean
- sd – the desired sd
Return type: void
-
set_liability_threshold(threshold)¶ Sets value above which an individual is considered affected
Parameters: threshold (numeric) – liability threshold
-
total_variance¶ The total variance of the phenotype
Return type: float
-