Struct Spectrum

Source
pub struct Spectrum<S: State> { /* private fields */ }
Expand description

A site spectrum.

The spectrum may either be over frequencies (Sfs) or counts (Scs).

Implementations§

Source§

impl<S: State> Spectrum<S>

Source

pub fn dimensions(&self) -> usize

Returns the number of dimensions of the spectrum.

Source

pub fn elements(&self) -> usize

Returns the number of elements in the spectrum.

Source

pub fn fold(&self) -> Folded<S>

Returns a folded spectrum.

Source

pub fn inner(&self) -> &Array<f64>

Returns the underlying array.

Source

pub fn into_normalized(self) -> Sfs

Returns a normalized frequency spectrum, consuming self.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn project<T>(&self, project_to: T) -> Result<Self, ProjectionError>
where T: Into<Shape>,

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.

Source

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.

Source

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.

Source

pub fn shape(&self) -> &Shape

Returns the shape of the spectrum.

Source

pub fn sum(&self) -> f64

Returns the sum of elements in the spectrum.

Source

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>

Source

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.

Source

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.

Source

pub fn from_range<S>(range: Range<usize>, shape: S) -> Result<Self, ShapeError>
where S: Into<Shape>,

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.

Source

pub fn from_vec<T>(vec: T) -> Self
where T: Into<Vec<f64>>,

Creates a new one-dimensional spectrum from a vector.

Source

pub fn from_zeros<S>(shape: S) -> Self
where S: Into<Shape>,

Creates a new spectrum filled with zeros to a shape.

Source

pub fn inner_mut(&mut self) -> &mut Array<f64>

Returns a mutable reference to the underlying array.

Source

pub fn new<D, S>(data: D, shape: S) -> Result<Self, ShapeError>
where D: Into<Vec<f64>>, S: Into<Shape>,

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.

Source

pub fn segregating_sites(&self) -> f64

Returns the number of sites segregating in any population in the spectrum.

Source§

impl Spectrum<Frequencies>

Source

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.

Source

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.

Source

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.

Source

pub fn fst(&self) -> Result<f64, StatisticError>

Returns Hudson’s estimator of Fst.

See Bhatia (2013) for details. (This uses a “ratio of estimates” as recommended there.)

§Errors

If the spectrum is not a 2-dimensional spectrum.

Trait Implementations§

Source§

impl<S: State> Clone for Spectrum<S>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: State> Debug for Spectrum<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I, S: State> Index<I> for Spectrum<S>
where I: AsRef<[usize]>,

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<I, S: State> IndexMut<I> for Spectrum<S>
where I: AsRef<[usize]>,

Source§

fn index_mut(&mut self, index: I) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<S: PartialEq + State> PartialEq for Spectrum<S>

Source§

fn eq(&self, other: &Spectrum<S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S: State> StructuralPartialEq for Spectrum<S>

Auto Trait Implementations§

§

impl<S> Freeze for Spectrum<S>

§

impl<S> RefUnwindSafe for Spectrum<S>
where S: RefUnwindSafe,

§

impl<S> Send for Spectrum<S>
where S: Send,

§

impl<S> Sync for Spectrum<S>
where S: Sync,

§

impl<S> Unpin for Spectrum<S>
where S: Unpin,

§

impl<S> UnwindSafe for Spectrum<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.