tracts.hybrid_pedigree
This module implements the hybrid pedigree model for tract length distributions. It computes a mixture of Phase-Type distributions, each describing the tract length distribution conditioned on a pedigree structure. Dioecious admixture is considered on a finite chromosome.
See Appendix E of the manuscript for details on the model and the implementation.
Functions
|
Calculates the maximum-likelihood in a Poisson Random Field. |
Calculates the tract length histogram on multiple chromosomes of lengths chrom_lengths. |
|
|
|
|
|
|
|
|
|
|
This function computes the tract length distribution as a Phase-Type density or histogram on a finite chromosome of length L, using the Hybrid-Pedigree model. |
|
|
|
Convert a tree to its array representation. |
- tracts.hybrid_pedigree.HP_loglik(mig_matrix_f, mig_matrix_m, rr_f, rr_m, TP, Dioecious_model, X_chr, X_chr_male, N_cores, bins, Ls, data, num_samples, cutoff=0)
Calculates the maximum-likelihood in a Poisson Random Field. Used to fit model parameters.
- tracts.hybrid_pedigree.HP_tract_length_histogram_multi_windowed(mig_f, mig_m, TP, D_model, rr_f, rr_m, X_chr, X_chr_male, N_cores, population_number, bins, chrom_lengths)
Calculates the tract length histogram on multiple chromosomes of lengths chrom_lengths.
- Return type:
Union[Buffer,_SupportsArray[dtype[Any]],_NestedSequence[_SupportsArray[dtype[Any]]],bool,int,float,complex,str,bytes,_NestedSequence[bool|int|float|complex|str|bytes]]
- tracts.hybrid_pedigree.all_possible_trees_as_arrays(T, N, mig_at_last=True)
- tracts.hybrid_pedigree.density_hybrid_pedigree(which_migration, migration_list, T_PED, which_pop, D_model, which_L, bins, mmat_f, mmat_m, rrr_f, rrr_m, is_X_chr, is_X_chr_male, density_function)
- tracts.hybrid_pedigree.generate_trees(current_gen, max_gen, N, migrants_at_last_gen=True)
- tracts.hybrid_pedigree.get_pedigree(T)
- tracts.hybrid_pedigree.hybrid_pedigree_distribution(mig_matrix_f, mig_matrix_m, L, bingrid, whichpop, TP=2, Dioecious_model='DC', rr_f=1, rr_m=1, X_chr=False, X_chr_male=False, N_cores=1, density=True, freq=False, print_progress=True)
This function computes the tract length distribution as a Phase-Type density or histogram on a finite chromosome of length L, using the Hybrid-Pedigree model. The Phase-Type parameters are computed from a pair of migration matrices, the sex-specific recombination rates and the number of pedigree generations.
- Parameters:
mig_matrix_f (npt.ArrayLike) – An array containing the female migration proportions from a discrete number of populations over the last generations. Each row is a time, each column is a population. Row zero corresponds to the current generation. The (i,j) element of this matrix specifies the proportion of female individuals from the admixed population that are replaced by female individuals from population j at generation i. The migration rate at the last generation (migration_matrix_f[-1,:]) is the “founding generation” and should sum up to 1.
mig_matrix_m (npt.ArrayLike) – Counterpart of mig_matrix_f for male migration rates.
L (float) – The length of the finite chromosome.
bingrid (npt.ArrayLike) – A point grid on (0, infinity) where the CDF or density have to be evaluated.
whichpop (int) – The population of interest whose tract length distribution has to be computed. An integer from 0 to the number of populations - 1.
TP (int, default 2) – The number of generations of the pedigree. Shouldn’t be higher than 3 for the sake of computational efficiency.
Dioecious_model (default 'DC') – The Dioecious model to be considered. Takes the value ‘DF’ for Dioecious Fine and ‘DC’ for Dioecious Coarse.
rr_f (float, default 1) – The female-specific recombination rate (positive real number).
rr_m (float, default 1) – The male-specific recombination rate (positive real number). For X chromosome admixture, this value is ignored and set to 0.
X_chr (bool, default False) – Whether admixture is considered on the X chromosome. If False, the model considers autosomal admixture.
X_chr_male (bool, default False) – If X_chr is True, whether the individual at generation 0 is a male. In that case, only maternally inherited alleles are taken into account. If not X_chr, set to False.
N_cores (int, default 1) – The number of threads to be used for parallel computation.
density (bool, default False) – If True, computes the PhT density. Else, returns the histogram values on the grid.
freq (bool, default False,) – If density is True, whether to return density on the frequency scale. If density is False, this parameter is ignored.
print_progress (bool, default True) – Whether to display progress messages.
- Returns:
npt.ArrayLike – If density is True, the corrected bins grid as described in Notes. Else, the user-specified bins.
npt.ArrayLike – If density is True, the PhT density evaluated on the corrected bins grid. Returned on the frequency scale if freq = True. If density is False, the histogram values on the intervals defined by bins.
Notes
If density is True, the code truncates bins to the interval [0,L] and adds the point L if it is not included in bins. This is done because the density is defined on the finite chromosome [0,L] as a mixture of a continuous density on [0,L) and a Dirac measure at L. Consequently, the function returns as a first argument the transformed grid, that can be used as x-axis to plot the density. If density is False, the code produces a histogram supported on the user-specified grid. If the grid has n points, the histogram will be defined on n-1 intervals. Therefore, the returned array will have length len(bins)-1.
- tracts.hybrid_pedigree.prob_of_pop_setting(ms, all_possible_migrations_list, migrations_at_T_list, f_migrations, m_migrations, parent_sex, number_ind, number_anc, Number_pops, pedigree)
- tracts.hybrid_pedigree.tree_to_array(tree, max_nodes)
Convert a tree to its array representation.