#frequency #spectrum #spectra #site #count #array #sfs

sfs-core

Core implementation of tools for working with site frequency spectra

1 unstable release

0.1.0 Aug 31, 2023

#5 in #spectra


Used in sfs-cli

MIT license

165KB
4.5K SLoC

Tools for working with site frequency spectra.

This serves as the core library implementation for the sfs CLI, but can also be used as a free-standing library for working with frequency spectra.

Overview

The core struct is a Spectrum, which is backed by an N-dimensional Array. A spectrum may either be a frequency spectrum ([Sfs]), in which case we say that it is normalized, or it may be a count spectrum ([Scs]).

Example

As a very brief introduction to the API, let's create a count spectrum, and then normalize it to obtain a per-base estimate of θ using Watterson's estimator.

use sfs_core::Scs;

// Create a 1-dimensional SCS from some data
let scs = Scs::from_vec([25., 8., 4., 2., 1., 0.]);

// Normalize the spectrum to frequencies
let sfs = scs.into_normalized();

// Calculate θ
let theta = sfs.theta_watterson().expect("θ only defined in 1D");

assert!((theta - 0.18).abs() < 1e-16);

Dependencies

~4.5MB
~83K SLoC