pub struct Pssm<const N: usize> { /* private fields */ }Expand description
A Position-Specific Scoring Matrix (PSSM) with a fixed alphabet size.
Scores are stored as log-odds ratios relative to background frequencies.
Implementations§
Source§impl<const N: usize> Pssm<N>
impl<const N: usize> Pssm<N>
Sourcepub fn from_counts(
counts: &[[f64; N]],
pseudocount: f64,
background: [f64; N],
) -> Result<Self>
pub fn from_counts( counts: &[[f64; N]], pseudocount: f64, background: [f64; N], ) -> Result<Self>
Build a PSSM from a count matrix.
Each row of counts represents one position; each column is a symbol.
A pseudocount is added to every cell before converting to frequencies.
Scores are computed as ln(freq / background).
§Errors
Returns an error if counts is empty or any background entry is zero.
Sourcepub fn score(
&self,
seq: &[u8],
mapping: &dyn Fn(u8) -> Option<usize>,
) -> Result<f64>
pub fn score( &self, seq: &[u8], mapping: &dyn Fn(u8) -> Option<usize>, ) -> Result<f64>
Score a sequence window against this PSSM.
seq must be exactly [self.len()] bytes. The mapping function
converts each byte to an alphabet index in 0..N.
§Errors
Returns an error if seq.len() != self.len() or if mapping returns
None for any byte.
Sourcepub fn scan(
&self,
seq: &[u8],
threshold: f64,
mapping: &dyn Fn(u8) -> Option<usize>,
) -> Vec<(usize, f64)>
pub fn scan( &self, seq: &[u8], threshold: f64, mapping: &dyn Fn(u8) -> Option<usize>, ) -> Vec<(usize, f64)>
Slide the PSSM across seq and return all hits at or above threshold.
Returns (position, score) pairs. Positions with unmapped characters
are silently skipped.
Sourcepub fn information_content(&self) -> Vec<f64>
pub fn information_content(&self) -> Vec<f64>
Information content (bits) at each position.
IC_j = sum_c freq_c * log2(freq_c / bg_c) where frequencies are
recovered from the stored log-odds scores.