quantgen.core package

Submodules

quantgen.core.chromosome module

class quantgen.core.chromosome.chromosome[source]

Bases: object

Represents a chromosome (linkage group). Nodes in the chromosome are loci, with edges in between representing some type of distance (genetic or physical)

Methods

add_locus(locus[, pos, locus_id]) Adds the locus at a given genetic position
get_bordering_loci(pos) Gets the loci that surround a given genetic position
get_bordering_loci_inds(pos) Gets the indices of the loci that surround a given genetic position
get_chrom_length() Gets the length of the chromosome in centimorgans
get_locus(locus_ind) Gets a locus object by index
get_locus_by_name(locus_name) Gets a locus object by name
get_locus_ind(locus_name) Gets the index of a locus object by name
get_recomb_points([obligate]) Gets recombination point(s) in centimorgans using the exponential
__init__()[source]

Initializes chromosome object

add_locus(locus, pos=0, locus_id=None)[source]

Adds the locus at a given genetic position

Parameters:

locus : locus object

A locus object

pos : float

The location of the locus in cM

locus_id : hashable, optional

The name of the locus. If left as None, will be given an integer id

Raises:

ValueError

If trying to put in a position > 0 when there are no loci in the chromosome yet or if trying to add a locus at the exact position of another locus

get_bordering_loci(pos)[source]

Gets the loci that surround a given genetic position

Parameters:

pos : float

The position to query, in centimorgans

Returns:

locus1, locus2

Raises:

ValueError

If the position is past the end of the chromosome

get_bordering_loci_inds(pos)[source]

Gets the indices of the loci that surround a given genetic position

Parameters:

pos : float

The position to query, in centimorgans

Returns:

locus ind 1, locus2 ind 2

Raises:

ValueError

If the position is past the end of the chromosome

get_chrom_length()[source]

Gets the length of the chromosome in centimorgans

Returns:The length of the chromosome, in centimorgans
get_locus(locus_ind)[source]

Gets a locus object by index

Parameters:

locus_ind : int

The index of the locus

Returns:

The locus object at the index

get_locus_by_name(locus_name)[source]

Gets a locus object by name

Parameters:

locus_name : hashable

The name of the locus

Returns:

The locus object for the name

get_locus_ind(locus_name)[source]

Gets the index of a locus object by name

Parameters:

locus_name : hashable

The name of the locus

Returns:

The index of the locus

get_recomb_points(obligate=True)[source]

Gets recombination point(s) in centimorgans using the exponential distribution

Parameters:

obligate : boolean

If true, requires at least 1 crossover to take place

Returns:

List of recombination breakpoints in centimorgans

quantgen.core.diploidIndividual module

class quantgen.core.diploidIndividual.diploidIndividual(haplotype_dict=None)[source]

Bases: object

Represents an individual composed of 1 or more chromosomes, each of which has 2 haplotypes

Methods

get_raw_nonepistatic_G() Gets the value of G for the individual, without taking into
mate(other) Mates 2 diploidIndividuals to produce a new diploidIndividual
__init__(haplotype_dict=None)[source]

Instantiates an individual

Parameters:

haplotype_dict : dict

Dictionary of ‘chromosome_name’ -> (haplotype1, haplotype2), where each haplotype is a haplotype object

get_raw_nonepistatic_G()[source]

Gets the value of G for the individual, without taking into account any epistatic interactions, by adding up the contributions from a and k in each locus

Returns:

The value of G, taken by adding up the contributions from a and k

at each locus

mate(other)[source]

Mates 2 diploidIndividuals to produce a new diploidIndividual

Parameters:

other: diploidIndividual

The individual to mate with

Returns:

The new diploidIndividual resulting from the mating

class quantgen.core.diploidIndividual.individual[source]

Bases: object

quantgen.core.haplotype module

class quantgen.core.haplotype.haplotype(chromosome, genos=None)[source]

Bases: quantgen.core.chromosome.chromosome

Represents the alleles along a single phased haplotype

Methods

add_locus(locus[, pos, locus_id]) Adds the locus at a given genetic position
get_bordering_loci(pos) Gets the loci that surround a given genetic position
get_bordering_loci_inds(pos) Gets the indices of the loci that surround a given genetic position
get_chrom_length() Gets the length of the chromosome in centimorgans
get_locus(locus_ind) Gets a locus object by index
get_locus_by_name(locus_name) Gets a locus object by name
get_locus_ind(locus_name) Gets the index of a locus object by name
get_recomb_points([obligate]) Gets recombination point(s) in centimorgans using the exponential
recombine2(haplo1, haplo2) Recombines 2 haplotypes
__init__(chromosome, genos=None)[source]

Instantiates the haplotype

Parameters:

chromosome : chromosome

The chromosome giving the structure of the haplotype

genos : list

List of the alleles, with one for each locus. 0 represents allele 1 and 1 represents allele 2. If None, all alleles instantiated to 0

Raises:

ValueError

If the number of loci doesn’t match the number of genotypes

static recombine2(haplo1, haplo2)[source]

Recombines 2 haplotypes

Parameters:

haplo1 : haplotype

The first haplotype

haplo2 : haplotype

The second haplotype

Returns:

first recombined haplotype, second recombined haplotype

Raises:

ValueError

If the haplotype chromosomes are not compatible

quantgen.core.locus module

class quantgen.core.locus.locus(a, k, genetic_loc=0.0)[source]

Bases: object

Represents a diallelic locus on a chromosome.

Note that the comparison functions only compare positions.

Methods

get_a_d_values() Gets the values of a and d under that allele configuration See Lynch/Walsh pg.
get_alpha(p1) Gets the average effect of allelic substitution, alpha.
get_alpha_vals(p1) Gets the slope of the number of alleles on the phenotypic values
get_mu_G(p1) Gets the theoretical average phenotype assuming the locus
get_raw_G(allele1, allele2) Gets the value of G for this locus, given a genotype
set_a(a) Sets the value of a for the locus
set_cM(location) Sets the genetic location of the locus
set_k(k) Sets the value of k for the locus
__init__(a, k, genetic_loc=0.0)[source]

Instantiates the locus. See Lynch/Walsh pg. 62

Parameters:

a : float

Half the genotypic value of the homozygote for the second allele

k : float

The dominance value, where k=0 is no dominance, k=1 is dominance of second allele, and k=-1 is dominance of first allele

get_a_d_values()[source]

Gets the values of a and d under that allele configuration See Lynch/Walsh pg. 62

Returns:a, d
get_alpha(p1)[source]

Gets the average effect of allelic substitution, alpha. See Lynch/Walsh ph. 68. Under the assumption of random mating, this represents the average change in genotypic value that results when a B2 allele is randomly substituted for a B1 allele.

Parameters:

p1 : float

The frequency of allele 1 in the population

Returns:

alpha, the average effect of allelic substitution

get_alpha_vals(p1)[source]

Gets the slope of the number of alleles on the phenotypic values (the average effects)

Parameters:

p1 : float

The frequency of allele 1 in the population

Returns:

alpha1, alpha2

get_mu_G(p1)[source]

Gets the theoretical average phenotype assuming the locus is the only locus affecting the phenotype

Parameters:

p1 : float

The frequency of allele 1 in the population

Returns:

mu_G for the locus

get_raw_G(allele1, allele2)[source]

Gets the value of G for this locus, given a genotype

Parameters:

allele1 : int

0 or 1 for the first allele

allele2 : int

0 or 1 for the second allele

Returns:

The value of G

set_a(a)[source]

Sets the value of a for the locus

Parameters:

a : float

Half the genotypic value of the homozygote for the second allele

set_cM(location)[source]

Sets the genetic location of the locus

Parameters:

location : float

The location of the locus in centimorgans

set_k(k)[source]

Sets the value of k for the locus

Parameters:

k : float

The dominance value, where k=0 is no dominance, k=1 is dominance of second allele, and k=-1 is dominance of first allele

Module contents