pub struct FragmentLengthDistribution { /* private fields */ }Expand description
Tracks the observed distribution of fragment lengths.
Implementations§
Source§impl FragmentLengthDistribution
impl FragmentLengthDistribution
Sourcepub fn new(
alpha: f64,
max_val: usize,
prior_mu: f64,
prior_sigma: f64,
kernel_n: usize,
kernel_p: f64,
bin_size: usize,
) -> Self
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).
The prior is what the distribution believes before seeing any data; a paired-end run quickly overwhelms it with observations, while a single-end run (which observes no fragment lengths at all) keeps it.
Sourcepub fn default_for_paired() -> Self
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.
A uniform prior for paired-end data because the observations will supply the shape; the prior only has to avoid ruling anything out.
Sourcepub fn min_val(&self) -> usize
pub fn min_val(&self) -> usize
Smallest observed length; 1 when nothing has been observed (the sentinel initial value is the last bin).
Sourcepub fn add_val(&self, len: usize, mass: f64)
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.)
Sourcepub fn refresh_online(&self)
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.
Sourcepub fn online_snapshot(&self) -> Arc<Vec<f64>> ⓘ
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).
Sourcepub fn online_cmf_snapshot(&self) -> Arc<Vec<f64>> ⓘ
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.
Sourcepub fn cmf(&self, len: usize) -> f64
pub fn cmf(&self, len: usize) -> f64
Logged cumulative mass up to and including len.
The uncached path re-sums from zero each call, which is why the online phase uses the precomputed snapshot instead.
Sourcepub fn mean(&self) -> f64
pub fn mean(&self) -> f64
Mean observed length.
Σ l·mass / Σ mass, which in log space is one subtraction of the two
running accumulators.
Sourcepub fn sd(&self) -> f64
pub fn sd(&self) -> f64
Standard deviation of the observed length distribution, computed from the
cached normalized PMF (call after cache).
Two passes — mean, then squared deviations — rather than the one-pass
E[X²] − E[X]² form, which loses precision when the two terms are close.
Sourcepub fn cache(&mut self)
pub fn cache(&mut self)
Freeze the distribution and precompute normalized PMF/CMF for fast, allocation-free lookup. Call once after updates have stopped.
After this, every lookup is an array index; before it, each one does atomic loads and (for the CMF) a running sum.
Sourcepub fn from_log_pmf(log_pmf: &[f64]) -> Self
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.
This is what makes a RAD requant reproduce the original run: the exact distribution is restored rather than re-estimated.
Sourcepub fn log_pmf(&self) -> &[f64]
pub fn log_pmf(&self) -> &[f64]
The cached, normalized log-PMF over [0, max_val]. Requires cache.
Sourcepub fn conditional_means(&self) -> Vec<f64>
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]).
Read cm[i] as: given a transcript of length i, how long is a typical
fragment it can host? Subtracting that from the reference length is the
smoothed effective length — the transcript loses the tail where no fragment
of typical length could start.
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§
Auto Trait Implementations§
impl !Freeze for FragmentLengthDistribution
impl RefUnwindSafe for FragmentLengthDistribution
impl Send for FragmentLengthDistribution
impl Sync for FragmentLengthDistribution
impl Unpin for FragmentLengthDistribution
impl UnsafeUnpin for FragmentLengthDistribution
impl UnwindSafe for FragmentLengthDistribution
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.