Skip to main content

FragmentLengthDistribution

Struct FragmentLengthDistribution 

Source
pub struct FragmentLengthDistribution { /* private fields */ }
Expand description

Tracks the observed distribution of fragment lengths.

Implementations§

Source§

impl FragmentLengthDistribution

Source

pub fn new( alpha: f64, max_val: usize, prior_mu: f64, prior_sigma: f64, kernel_n: usize, kernel_p: f64, bin_size: usize, ) -> Self

Construct a distribution.

  • alpha – total pseudo-count mass (linear space).
  • max_val – maximum representable length.
  • prior_mu – Gaussian prior mean; if <= 0, a uniform prior is used.
  • prior_sigma – Gaussian prior standard deviation.
  • kernel_n – binomial kernel trials; must be even (after binning).
  • kernel_p – binomial kernel success probability.
  • bin_size – internal length binning (use 1 for no binning).
Source

pub fn default_for_paired() -> Self

salmon’s default fragment-length distribution: pseudo-count 1.0, max length 1000, no Gaussian prior (uniform), kernel n=4, p=0.5.

Source

pub fn max_val(&self) -> usize

Source

pub fn min_val(&self) -> usize

Source

pub fn add_val(&self, len: usize, mass: f64)

Add mass (log space) for an observed fragment of length len, spreading it over the smoothing kernel. Lock-free; safe to call from multiple threads. (Must not race with cache.)

Source

pub fn pmf(&self, len: usize) -> f64

Logged probability of observing a fragment of length len.

Source

pub fn refresh_online(&self)

Rebuild the online log-PMF snapshot from the current histogram (one pass over the length bins, with a single tot_mass read so the snapshot is internally consistent). Call at mini-batch boundaries during the online phase; no-op once the final cache has been taken. Cheap relative to mapping a batch, and decouples per-fragment reads from the concurrent add_val writes so identical lengths read identical values.

Source

pub fn online_snapshot(&self) -> Arc<Vec<f64>>

Cheap (one Arc clone) immutable handle to the current online log-PMF snapshot. Capture once per fragment and index by raw length: every transcript of a given length then reads an identical value even if another thread refreshes the shared snapshot meanwhile. Empty until the first refresh_online (the pre-burn-in window, where this term is not folded into the eq-class weight anyway).

Source

pub fn online_cmf_snapshot(&self) -> Arc<Vec<f64>>

Cheap (one Arc clone) immutable handle to the current online log-CMF snapshot, the cumulative companion to online_snapshot. Capture once per fragment for the ambiguous (orphan / single-end) fragment-length probability and the proper-pair length-conditioning. Empty until the first refresh_online.

Source

pub fn cmf(&self, len: usize) -> f64

Logged cumulative mass up to and including len.

Source

pub fn tot_mass(&self) -> f64

Total observed mass (log space).

Source

pub fn mean(&self) -> f64

Mean observed length.

Source

pub fn sd(&self) -> f64

Standard deviation of the observed length distribution, computed from the cached normalized PMF (call after cache).

Source

pub fn cache(&mut self)

Freeze the distribution and precompute normalized PMF/CMF for fast, allocation-free lookup. Call once after updates have stopped.

Source

pub fn from_log_pmf(log_pmf: &[f64]) -> Self

Reconstruct a cached distribution directly from a (log-space) PMF, e.g. one serialized into a RAD header during a previous run. log_pmf is indexed by raw length over [0, log_pmf.len()). The CMF, conditional means, mean and sd are all re-derived from it via cache, so a reconstructed distribution is interchangeable with the original for every read-side use. The masses need not be pre-normalized — cache normalizes them — but a normalized PMF round-trips exactly.

Source

pub fn log_pmf(&self) -> &[f64]

The cached, normalized log-PMF over [0, max_val]. Requires cache.

Source

pub fn conditional_means(&self) -> Vec<f64>

Cumulative conditional means E[L | L ≤ i] over [0, max_val], i.e. salmon’s correctionFactorsFromMass (DistributionUtils.cpp): cm[i] = (Σ_{l≤i} l·pmf[l]) / (Σ_{l≤i} pmf[l]).

These are the per-length correction factors computeSmoothedEffectiveLengths subtracts from the reference length to get the base effective length. The ratio is invariant to the PMF normalization, so the cached (normalized) PMF gives the same values as salmon’s 100·exp(logPMF) mass. Requires cache.

Trait Implementations§

Source§

impl Debug for FragmentLengthDistribution

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V