pub struct Spectrum<S: State> { /* private fields */ }
Expand description
Implementations§
Source§impl<S: State> Spectrum<S>
impl<S: State> Spectrum<S>
Sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
Returns the number of dimensions of the spectrum.
Sourcepub fn into_normalized(self) -> Sfs
pub fn into_normalized(self) -> Sfs
Returns a normalized frequency spectrum, consuming self
.
Sourcepub fn iter_frequencies(&self) -> FrequenciesIter<'_> ⓘ
pub fn iter_frequencies(&self) -> FrequenciesIter<'_> ⓘ
Returns an iterator over the allele frequencies of the elements in the spectrum in row-major order.
Note that this is not an iterator over frequencies in the sense of a frequency spectrum, but in the sense of allele frequencies corresponding to indices in a spectrum.
Sourcepub fn king(&self) -> Result<f64, StatisticError>
pub fn king(&self) -> Result<f64, StatisticError>
Returns the King statistic.
See Manichaikul (2010) and Waples (2019) for details.
§Errors
If the spectrum is not a 3x3 2-dimensional spectrum.
Sourcepub fn marginalize(&self, axes: &[Axis]) -> Result<Self, MarginalizationError>
pub fn marginalize(&self, axes: &[Axis]) -> Result<Self, MarginalizationError>
Returns a spectrum with the provided axes marginalized out.
§Errors
If the provided axes contain duplicates, or if any of them are out of bounds.
Sourcepub fn normalize(&mut self)
pub fn normalize(&mut self)
Normalizes the spectrum to frequencies in-place.
See also Spectrum::into_normalized
to normalize and convert to an Sfs
at the
type-level.
Sourcepub fn pi(&self) -> Result<f64, StatisticError>
pub fn pi(&self) -> Result<f64, StatisticError>
Returns the average number of pairwise differences, also known as π.
§Errors
If the spectrum is not a 1-dimensional spectrum.
Sourcepub fn pi_xy(&self) -> Result<f64, StatisticError>
pub fn pi_xy(&self) -> Result<f64, StatisticError>
Returns the average number of pairwise differences between two populations, also known as πₓᵧ or Dₓᵧ.
See Nei and Li (1987).
§Errors
If the spectrum is not a 1-dimensional spectrum.
Sourcepub fn project<T>(&self, project_to: T) -> Result<Self, ProjectionError>
pub fn project<T>(&self, project_to: T) -> Result<Self, ProjectionError>
Returns a spectrum projected down to a shape.
The projection is based on hypergeometric down-sampling. See Marth (2004) and Gutenkunst (2009) for details. Note that projecting a spectrum after creation may cause problems; prefer projecting site-wise during creation where possible.
§Errors
Errors if the projected shape is not valid for the provided spectrum.
Sourcepub fn r0(&self) -> Result<f64, StatisticError>
pub fn r0(&self) -> Result<f64, StatisticError>
Returns the R0 statistic.
See Waples (2019) for details.
§Errors
If the spectrum is not a 3x3 2-dimensional spectrum.
Sourcepub fn r1(&self) -> Result<f64, StatisticError>
pub fn r1(&self) -> Result<f64, StatisticError>
Returns the R0 statistic.
See Waples (2019) for details.
§Errors
If the spectrum is not a 3x3 2-dimensional spectrum.
Sourcepub fn theta_watterson(&self) -> Result<f64, StatisticError>
pub fn theta_watterson(&self) -> Result<f64, StatisticError>
Returns Watterson’s estimator of the mutation-scaled effective population size θ.
§Errors
If the spectrum is not a 1-dimensional spectrum.
Source§impl Spectrum<Counts>
impl Spectrum<Counts>
Sourcepub fn d_fu_li(&self) -> Result<f64, StatisticError>
pub fn d_fu_li(&self) -> Result<f64, StatisticError>
Returns Fu and Li’s D difference statistic.
See Fu and Li (1993).
§Errors
If the spectrum is not a 1-dimensional spectrum.
Sourcepub fn d_tajima(&self) -> Result<f64, StatisticError>
pub fn d_tajima(&self) -> Result<f64, StatisticError>
Returns Tajima’s D difference statistic.
See Tajima (1989).
§Errors
If the spectrum is not a 1-dimensional spectrum.
Sourcepub fn from_range<S>(range: Range<usize>, shape: S) -> Result<Self, ShapeError>
pub fn from_range<S>(range: Range<usize>, shape: S) -> Result<Self, ShapeError>
Creates a new spectrum from a range and a shape.
This is mainly intended for testing and illustration.
§Errors
If the number of items in the range does not match the provided shape.
Sourcepub fn from_zeros<S>(shape: S) -> Self
pub fn from_zeros<S>(shape: S) -> Self
Creates a new spectrum filled with zeros to a shape.
Sourcepub fn inner_mut(&mut self) -> &mut Array<f64>
pub fn inner_mut(&mut self) -> &mut Array<f64>
Returns a mutable reference to the underlying array.
Sourcepub fn new<D, S>(data: D, shape: S) -> Result<Self, ShapeError>
pub fn new<D, S>(data: D, shape: S) -> Result<Self, ShapeError>
Creates a new spectrum from data in row-major order and a shape.
§Errors
If the number of items in the data does not match the provided shape.
Sourcepub fn segregating_sites(&self) -> f64
pub fn segregating_sites(&self) -> f64
Returns the number of sites segregating in any population in the spectrum.
Source§impl Spectrum<Frequencies>
impl Spectrum<Frequencies>
Sourcepub fn f2(&self) -> Result<f64, StatisticError>
pub fn f2(&self) -> Result<f64, StatisticError>
Returns the f₂ statistic.
See Reich (2009) and Peter (2016) for details.
§Errors
If the spectrum is not a 2-dimensional spectrum.
Sourcepub fn f3(&self) -> Result<f64, StatisticError>
pub fn f3(&self) -> Result<f64, StatisticError>
Returns the f₃(A; B, C)-statistic, where A, B, C is in the order of the populations in the spectrum.
Note that f₃ may also be calculated as a linear combination of f₂, which is often going to be more efficient and flexible.
See Reich (2009) and Peter (2016) for details.
§Errors
If the spectrum is not a 3-dimensional spectrum.
Sourcepub fn f4(&self) -> Result<f64, StatisticError>
pub fn f4(&self) -> Result<f64, StatisticError>
Returns the f₄(A, B; C, D)-statistic, where A, B, C is in the order of the populations in the spectrum.
Note that f₄ may also be calculated as a linear combination of f₂, which is often going to be more efficient and flexible.
See Reich (2009) and Peter (2016) for details.
§Errors
If the spectrum is not a 4-dimensional spectrum.