sfs_core/
lib.rs

1#![deny(unsafe_code)]
2#![warn(missing_docs)]
3
4//! Tools for working with site frequency spectra.
5//!
6//! This serves as the core library implementation for the `sfs` CLI, but can also be used as a
7//! free-standing library for working with frequency spectra.
8//!
9//! # Overview
10//!
11//! The core struct is a [`Spectrum`], which is backed by an N-dimensional [`Array`].
12//! A spectrum may either be a *frequency* spectrum ([`Sfs`]), in which case we say that it is
13//! normalized, or it may be a *count* spectrum ([`Scs`]).
14//!
15//! # Example
16//!
17//! As a very brief introduction to the API, let's create a count spectrum, and then normalize it
18//! to obtain a per-base estimate of θ using Watterson's estimator.
19//!
20//! ```
21//! use sfs_core::Scs;
22//!
23//! // Create a 1-dimensional SCS from some data
24//! let scs = Scs::from_vec([25., 8., 4., 2., 1., 0.]);
25//!
26//! // Normalize the spectrum to frequencies
27//! let sfs = scs.into_normalized();
28//!
29//! // Calculate θ
30//! let theta = sfs.theta_watterson().expect("θ only defined in 1D");
31//!
32//! assert!((theta - 0.18).abs() < 1e-16);
33//! ```
34
35#[cfg(test)]
36#[macro_use]
37pub(crate) mod approx;
38
39pub mod input;
40pub use input::Input;
41
42pub mod spectrum;
43pub use spectrum::{Scs, Sfs, Spectrum};
44
45pub mod array;
46pub use array::Array;
47
48pub mod utils;