tracts.indiv
Classes
|
The class of diploid individuals. |
- class tracts.indiv.Indiv(Ls=None, label='POP', fname=None, labs=('_A', '_B'), selectchrom=None, chroms=None, allosomes=None, name=None)
Bases:
objectThe class of diploid individuals. An individual is thought of as a list of pairs of chromosomes. Equivalently, a diploid individual is a pair of haploid individuals. Thus, it is possible to construct instances of this class from a pair of instances of the haploid class, as well as directly from a sequence of chropair instances.
The interface for loading individuals from files uses the haploid-oriented approach, since individual .bed files describe only one haplotype. The loading process is the following:
Load haploid individuals for each haplotype,
Combine the haploid individuals into a diploid individual.
- __init__(Ls=None, label='POP', fname=None, labs=('_A', '_B'), selectchrom=None, chroms=None, allosomes=None, name=None)
Constructs a diploid individual. There are several ways to build individuals, either from files, from existing data, or programmatically. The most straightforward way to build an individual is from existing data, by supplying only the
Lsandchromsarguments.- Parameters:
migration_matrix (npt.ArrayLike)
Ls (list of floats) – Default is
None. The lengths of the chromosomes in the order in which they appear inchroms.chroms (list of chropair objects) – Default is
None. The chromosome pairs that make up this individual. See the documentation forchropair.label (string) – Default is
POP. The label to use for building single-tract chromosomes when no other data is given to buid this individual.fname (2-tuple of str) – Default is
None. Paths are generated by concatenating the first component of “fname”, each label from “labs” in turn, and the second component of “fname”.labs (2-tuple of str) – Default is
("_A", "_B"). The labels used to identify maternal and paternal haplotypes in the paths leading to .bed files.selectchrom (list of integers) – Default is
None. This argument is forwarded as-is to haploid.from_file. It acts as a filter on the chromosomes to load. The default value of “None” selects all chromosomes.name (string) – Default is
None. An identifier for this individual.
Notes
If
Lsis given, butchromsis not, then chromosomes consisting each of a single tract will be created with the labellabeland lengths drawn fromLs.If the “fname” argument is given, the constructor will perform path manipulation involving the components of “fname” and “labs” to generate file names that are commonly used when dealing with .bed files.
The facilities in this constructor for loading individuals from files are deprecated. It is recommended to instead use the static methods
from_filesorfrom_haploids.
- ancestryAmt(ancestry)
Calculates the total length of the genome in segments of the given ancestry.
- ancestryProps(ancestries, allosome_label=False, cutoff=0.0)
Calculates the proportion of the genome represented by the given ancestries.
- ancestryPropsByChrom(ancestries)
- applychrom(func)
Apply the function func to each chromosome of the individual.
- create_gamete()
- flat_imap(f)
Lazily map a function over the full underlying structure of this individual. The function must accept 3 parameters:
chrom, the chromosome pair containing the tract,copy, the chromosome containing the tract andtract, the tract itself.
- static from_files(paths, selectchrom=None, name=None, allosomes=None)
Constructs a diploid individual from two files, which describe the individuals haplotypes.
- static from_haploids(haps, name=None, allosome_labels=[])
- iflatten(allosome_label=False)
Lazily flatten this individual to the tract level.
- plot(colordict, win=None)
Plots an individual. colordict is a dictionary mapping population label to a set of colors. E.g.:
colordict = {"CEU":'r',"YRI":b}.