Skip to content
Snippets Groups Projects
Commit 8b5f5a6f authored by Martin Larralde's avatar Martin Larralde
Browse files

Add getter to the raw data of a `FrequencyMatrix`

parent d560ad86
No related branches found
No related tags found
No related merge requests found
...@@ -180,9 +180,13 @@ impl<A: Alphabet> FrequencyMatrix<A> { ...@@ -180,9 +180,13 @@ impl<A: Alphabet> FrequencyMatrix<A> {
/// Create a new frequency matrix. /// Create a new frequency matrix.
/// ///
/// The matrix must contain frequency data, i.e. rows should all sum to 1. /// The matrix must contain frequency data, i.e. rows should all sum to 1
/// (with a tolerance of 0.01).
pub fn new(data: DenseMatrix<f32, A::K>) -> Result<Self, InvalidData> { pub fn new(data: DenseMatrix<f32, A::K>) -> Result<Self, InvalidData> {
if data.iter().all(|row| row.iter().sum::<f32>() == 1.0) { if data
.iter()
.all(|row| (row.iter().sum::<f32>() - 1.0).abs() < 0.01)
{
Ok(Self::new_unchecked(data)) Ok(Self::new_unchecked(data))
} else { } else {
Err(InvalidData) Err(InvalidData)
...@@ -235,6 +239,12 @@ impl<A: Alphabet> FrequencyMatrix<A> { ...@@ -235,6 +239,12 @@ impl<A: Alphabet> FrequencyMatrix<A> {
} }
ScoringMatrix::new(bg, scores) ScoringMatrix::new(bg, scores)
} }
/// The raw frequencies from the frequency matrix.
#[inline]
pub fn frequencies(&self) -> &DenseMatrix<f32, A::K> {
&self.data
}
} }
impl<A: ComplementableAlphabet> FrequencyMatrix<A> { impl<A: ComplementableAlphabet> FrequencyMatrix<A> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment