Site frequency spectra

allel.sfs(dac, n=None)[source]

Compute the site frequency spectrum given derived allele counts at a set of biallelic variants.

Parameters:
dac : array_like, int, shape (n_variants,)

Array of derived allele counts.

n : int, optional

The total number of chromosomes called.

Returns:
sfs : ndarray, int, shape (n_chromosomes,)

Array where the kth element is the number of variant sites with k derived alleles.

allel.sfs_folded(ac, n=None)[source]

Compute the folded site frequency spectrum given reference and alternate allele counts at a set of biallelic variants.

Parameters:
ac : array_like, int, shape (n_variants, 2)

Allele counts array.

n : int, optional

The total number of chromosomes called.

Returns:
sfs_folded : ndarray, int, shape (n_chromosomes//2,)

Array where the kth element is the number of variant sites with a minor allele count of k.

allel.sfs_scaled(dac, n=None)[source]

Compute the site frequency spectrum scaled such that a constant value is expected across the spectrum for neutral variation and constant population size.

Parameters:
dac : array_like, int, shape (n_variants,)

Array of derived allele counts.

n : int, optional

The total number of chromosomes called.

Returns:
sfs_scaled : ndarray, int, shape (n_chromosomes,)

An array where the value of the kth element is the number of variants with k derived alleles, multiplied by k.

allel.sfs_folded_scaled(ac, n=None)[source]

Compute the folded site frequency spectrum scaled such that a constant value is expected across the spectrum for neutral variation and constant population size.

Parameters:
ac : array_like, int, shape (n_variants, 2)

Allele counts array.

n : int, optional

The total number of chromosomes called.

Returns:
sfs_folded_scaled : ndarray, int, shape (n_chromosomes//2,)

An array where the value of the kth element is the number of variants with minor allele count k, multiplied by the scaling factor (k * (n - k) / n).

allel.joint_sfs(dac1, dac2, n1=None, n2=None)[source]

Compute the joint site frequency spectrum between two populations.

Parameters:
dac1 : array_like, int, shape (n_variants,)

Derived allele counts for the first population.

dac2 : array_like, int, shape (n_variants,)

Derived allele counts for the second population.

n1, n2 : int, optional

The total number of chromosomes called in each population.

Returns:
joint_sfs : ndarray, int, shape (m_chromosomes, n_chromosomes)

Array where the (i, j)th element is the number of variant sites with i derived alleles in the first population and j derived alleles in the second population.

allel.joint_sfs_folded(ac1, ac2, n1=None, n2=None)[source]

Compute the joint folded site frequency spectrum between two populations.

Parameters:
ac1 : array_like, int, shape (n_variants, 2)

Allele counts for the first population.

ac2 : array_like, int, shape (n_variants, 2)

Allele counts for the second population.

n1, n2 : int, optional

The total number of chromosomes called in each population.

Returns:
joint_sfs_folded : ndarray, int, shape (n1//2 + 1, n2//2 + 1)

Array where the (i, j)th element is the number of variant sites with a minor allele count of i in the first population and j in the second population.

allel.joint_sfs_scaled(dac1, dac2, n1=None, n2=None)[source]

Compute the joint site frequency spectrum between two populations, scaled such that a constant value is expected across the spectrum for neutral variation, constant population size and unrelated populations.

Parameters:
dac1 : array_like, int, shape (n_variants,)

Derived allele counts for the first population.

dac2 : array_like, int, shape (n_variants,)

Derived allele counts for the second population.

n1, n2 : int, optional

The total number of chromosomes called in each population.

Returns:
joint_sfs_scaled : ndarray, int, shape (n1 + 1, n2 + 1)

Array where the (i, j)th element is the scaled frequency of variant sites with i derived alleles in the first population and j derived alleles in the second population.

allel.joint_sfs_folded_scaled(ac1, ac2, n1=None, n2=None)[source]

Compute the joint folded site frequency spectrum between two populations, scaled such that a constant value is expected across the spectrum for neutral variation, constant population size and unrelated populations.

Parameters:
ac1 : array_like, int, shape (n_variants, 2)

Allele counts for the first population.

ac2 : array_like, int, shape (n_variants, 2)

Allele counts for the second population.

n1, n2 : int, optional

The total number of chromosomes called in each population.

Returns:
joint_sfs_folded_scaled : ndarray, int, shape (n1//2 + 1, n2//2 + 1)

Array where the (i, j)th element is the scaled frequency of variant sites with a minor allele count of i in the first population and j in the second population.

allel.fold_sfs(s, n)[source]

Fold a site frequency spectrum.

Parameters:
s : array_like, int, shape (n_chromosomes,)

Site frequency spectrum

n : int

Total number of chromosomes called.

Returns:
sfs_folded : ndarray, int

Folded site frequency spectrum

allel.fold_joint_sfs(s, n1, n2)[source]

Fold a joint site frequency spectrum.

Parameters:
s : array_like, int, shape (m_chromosomes, n_chromosomes)

Joint site frequency spectrum.

n1, n2 : int, optional

The total number of chromosomes called in each population.

Returns:
joint_sfs_folded : ndarray, int

Folded joint site frequency spectrum.

allel.scale_sfs(s)[source]

Scale a site frequency spectrum.

Parameters:
s : array_like, int, shape (n_chromosomes,)

Site frequency spectrum.

Returns:
sfs_scaled : ndarray, int, shape (n_chromosomes,)

Scaled site frequency spectrum.

allel.scale_sfs_folded(s, n)[source]

Scale a folded site frequency spectrum.

Parameters:
s : array_like, int, shape (n_chromosomes//2,)

Folded site frequency spectrum.

n : int

Number of chromosomes called.

Returns:
sfs_folded_scaled : ndarray, int, shape (n_chromosomes//2,)

Scaled folded site frequency spectrum.

allel.scale_joint_sfs(s)[source]

Scale a joint site frequency spectrum.

Parameters:
s : array_like, int, shape (n1, n2)

Joint site frequency spectrum.

Returns:
joint_sfs_scaled : ndarray, int, shape (n1, n2)

Scaled joint site frequency spectrum.

allel.scale_joint_sfs_folded(s, n1, n2)[source]

Scale a folded joint site frequency spectrum.

Parameters:
s : array_like, int, shape (m_chromosomes//2, n_chromosomes//2)

Folded joint site frequency spectrum.

n1, n2 : int, optional

The total number of chromosomes called in each population.

Returns:
joint_sfs_folded_scaled : ndarray, int, shape (m_chromosomes//2, n_chromosomes//2)

Scaled folded joint site frequency spectrum.

allel.plot_sfs(s, yscale='log', bins=None, n=None, clip_endpoints=True, label=None, plot_kwargs=None, ax=None)[source]

Plot a site frequency spectrum.

Parameters:
s : array_like, int, shape (n_chromosomes,)

Site frequency spectrum.

yscale : string, optional

Y axis scale.

bins : int or array_like, int, optional

Allele count bins.

n : int, optional

Number of chromosomes sampled. If provided, X axis will be plotted as allele frequency, otherwise as allele count.

clip_endpoints : bool, optional

If True, do not plot first and last values from frequency spectrum.

label : string, optional

Label for data series in plot.

plot_kwargs : dict-like

Additional keyword arguments, passed through to ax.plot().

ax : axes, optional

Axes on which to draw. If not provided, a new figure will be created.

Returns:
ax : axes

The axes on which the plot was drawn.

allel.plot_sfs_folded(*args, **kwargs)[source]

Plot a folded site frequency spectrum.

Parameters:
s : array_like, int, shape (n_chromosomes/2,)

Site frequency spectrum.

yscale : string, optional

Y axis scale.

bins : int or array_like, int, optional

Allele count bins.

n : int, optional

Number of chromosomes sampled. If provided, X axis will be plotted as allele frequency, otherwise as allele count.

clip_endpoints : bool, optional

If True, do not plot first and last values from frequency spectrum.

label : string, optional

Label for data series in plot.

plot_kwargs : dict-like

Additional keyword arguments, passed through to ax.plot().

ax : axes, optional

Axes on which to draw. If not provided, a new figure will be created.

Returns:
ax : axes

The axes on which the plot was drawn.

allel.plot_sfs_scaled(*args, **kwargs)[source]

Plot a scaled site frequency spectrum.

Parameters:
s : array_like, int, shape (n_chromosomes,)

Site frequency spectrum.

yscale : string, optional

Y axis scale.

bins : int or array_like, int, optional

Allele count bins.

n : int, optional

Number of chromosomes sampled. If provided, X axis will be plotted as allele frequency, otherwise as allele count.

clip_endpoints : bool, optional

If True, do not plot first and last values from frequency spectrum.

label : string, optional

Label for data series in plot.

plot_kwargs : dict-like

Additional keyword arguments, passed through to ax.plot().

ax : axes, optional

Axes on which to draw. If not provided, a new figure will be created.

Returns:
ax : axes

The axes on which the plot was drawn.

allel.plot_sfs_folded_scaled(*args, **kwargs)[source]

Plot a folded scaled site frequency spectrum.

Parameters:
s : array_like, int, shape (n_chromosomes/2,)

Site frequency spectrum.

yscale : string, optional

Y axis scale.

bins : int or array_like, int, optional

Allele count bins.

n : int, optional

Number of chromosomes sampled. If provided, X axis will be plotted as allele frequency, otherwise as allele count.

clip_endpoints : bool, optional

If True, do not plot first and last values from frequency spectrum.

label : string, optional

Label for data series in plot.

plot_kwargs : dict-like

Additional keyword arguments, passed through to ax.plot().

ax : axes, optional

Axes on which to draw. If not provided, a new figure will be created.

Returns:
ax : axes

The axes on which the plot was drawn.

allel.plot_joint_sfs(s, ax=None, imshow_kwargs=None)[source]

Plot a joint site frequency spectrum.

Parameters:
s : array_like, int, shape (n_chromosomes_pop1, n_chromosomes_pop2)

Joint site frequency spectrum.

ax : axes, optional

Axes on which to draw. If not provided, a new figure will be created.

imshow_kwargs : dict-like

Additional keyword arguments, passed through to ax.imshow().

Returns:
ax : axes

The axes on which the plot was drawn.

allel.plot_joint_sfs_folded(*args, **kwargs)[source]

Plot a joint site frequency spectrum.

Parameters:
s : array_like, int, shape (n_chromosomes_pop1/2, n_chromosomes_pop2/2)

Joint site frequency spectrum.

ax : axes, optional

Axes on which to draw. If not provided, a new figure will be created.

imshow_kwargs : dict-like

Additional keyword arguments, passed through to ax.imshow().

Returns:
ax : axes

The axes on which the plot was drawn.

allel.plot_joint_sfs_scaled(*args, **kwargs)[source]

Plot a scaled joint site frequency spectrum.

Parameters:
s : array_like, int, shape (n_chromosomes_pop1, n_chromosomes_pop2)

Joint site frequency spectrum.

ax : axes, optional

Axes on which to draw. If not provided, a new figure will be created.

imshow_kwargs : dict-like

Additional keyword arguments, passed through to ax.imshow().

Returns:
ax : axes

The axes on which the plot was drawn.

allel.plot_joint_sfs_folded_scaled(*args, **kwargs)[source]

Plot a scaled folded joint site frequency spectrum.

Parameters:
s : array_like, int, shape (n_chromosomes_pop1/2, n_chromosomes_pop2/2)

Joint site frequency spectrum.

ax : axes, optional

Axes on which to draw. If not provided, a new figure will be created.

imshow_kwargs : dict-like

Additional keyword arguments, passed through to ax.imshow().

Returns:
ax : axes

The axes on which the plot was drawn.