salmon_model/lib.rs
1//! `salmon-model`: statistical models used during quantification.
2//!
3//! Currently provides the fragment-length distribution ([`fld`]) and automatic
4//! library-type detection ([`libdetect`]). Bias models (sequence-specific, GC,
5//! positional) and the alignment error model are added in later phases.
6
7/// Fixed-point scale for deterministic bias-model mass accumulation. Bias
8/// observed models sum per-fragment posterior masses (each in `[0,1]`) into
9/// bins; an f64 `+=` is non-associative, so the accumulated model — and hence
10/// bias correction — varies with the worker-thread fragment partition (thread
11/// count). Accumulating `round_down(mass * BIAS_WEIGHT_SCALE)` as integers makes
12/// the sum associative (order/thread-count independent). `2^20` keeps the
13/// per-contribution resolution at ~1e-6 (ample for these coarse models) while a
14/// bin total (~num_fragments × 2^20) stays far below `u64::MAX`.
15pub const BIAS_WEIGHT_SCALE: f64 = (1u64 << 20) as f64;
16
17/// Quantize a bias mass (`[0,∞)`, typically a `[0,1]` posterior) to the
18/// fixed-point integer accumulator. Truncates (rounds toward zero) — cheaper
19/// than `round()` and the ≤1-ULP downward bias is negligible and cancels under
20/// the model's normalization.
21#[inline]
22pub fn bias_mass_to_fp(mass: f64) -> u64 {
23 (mass * BIAS_WEIGHT_SCALE) as u64
24}
25
26pub mod bias;
27pub mod dumps;
28pub mod fld;
29pub mod gcbias;
30pub mod libdetect;
31pub mod posbias;
32pub mod seqbias;
33pub mod spline;
34
35pub use bias::{
36 build_expected_pos, corrected_effective_length_full, positional_factor, BiasInputs,
37};
38pub use fld::FragLengthSource;
39pub use fld::{
40 ambig_frag_log_prob, smoothed_effective_length, DiscreteFld, FragmentLengthDistribution,
41};
42pub use gcbias::{
43 build_expected_gc, gc_corrected_effective_length, gc_desc, gc_prefix, gc_ratio, GcFragModel,
44 GcRank, GcStore, GcView, GC_SAMP_STRIDE,
45};
46pub use libdetect::{infer_format_from_counts, LibraryTypeDetector};
47pub use posbias::{
48 compute_length_quantiles, length_class_index, SimplePosBias, NUM_LENGTH_CLASSES, NUM_POS_BINS,
49};
50pub use seqbias::{build_expected, corrected_effective_length, LogBiasTable, SBModel};