tracts.chromosome.Chropair#
- class Chropair(chroms=None, chropair_len=1, label='POP')#
Bases:
objectA pair of chromosomes. Using chromosome pairs allows modeling of diploid individuals.
- len#
The length of this chromosome pair, in Morgans. This is set to the length of the first chromosome copy, and the second copy is checked to have the same length.
- Type:
int
- __init__(chroms=None, chropair_len=1, label='POP')#
Can be instantiated either by explicitly providing two chromosomes as a tuple, or by specifying an ancestry label and length.
- Parameters:
chroms (
list[Chrom] |tuple[Chrom]) – The two chromosomes to form this chromosome pair. If None is given, then two identical chromosomes are created according to the other parameters.chropair_len (
int) – The length of this chromosome pair, in Morgans. This is used if chroms is None to create two identical chromosomes of the specified length.label (
str) – An identifier categorizing this chromosome pair. This is used if chroms is None to create two identical chromosomes with the specified label.
- applychrom(func)#
Apply func to chromosomes.
- Parameters:
func (
callable) – A function that takes a chromosome as input and returns some output. This function is applied to each copy of this chromosome pair, and the results are returned in a list.- Returns:
A list containing the results of applying func to each copy of this chromosome pair.
- Return type:
list
- plot(canvas, colordict, height=0)#
Plot the chromosome pair on a tkinter canvas.
- Parameters:
canvas (
Canvas) – The tkinter canvas on which to draw the chromosome pair.colordict (
dict) – A dictionary mapping chromosome types to colors.height (float) – The vertical position at which to plot the chromosome pair.
- recombine()#
Recombine this chromosome pair.
- Returns:
A new chromosome resulting from recombination of the two copies of this chromosome pair.
- Return type:
Notes
Recombination is modeled as a Poisson process along the chromosome, with the number of recombinations drawn from a Poisson distribution with mean equal to the chromosome’s length in Morgans. The positions of the recombinations are drawn uniformly at random along the chromosome. The resulting chromosome is formed by alternating between the two copies of this chromosome pair at each recombination point, starting with a randomly chosen copy.