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

Add `pwm` module with count matrix implementation

parent c194e614
No related branches found
No related tags found
No related merge requests found
......@@ -2,4 +2,5 @@
mod abc;
mod dense;
mod pwm;
mod seq;
use super::abc::Alphabet;
use super::abc::Symbol;
use super::dense::DenseMatrix;
use super::seq::EncodedSequence;
#[derive(Clone, Debug)]
pub struct CountMatrix<A: Alphabet, const K: usize> {
pub alphabet: A,
pub data: DenseMatrix<u32, K>,
}
impl<A: Alphabet, const K: usize> CountMatrix<A, K> {
pub fn from_sequences<'seq, I>(sequences: I) -> Result<Self, ()>
where
I: IntoIterator<Item = &'seq EncodedSequence<A>>,
{
let mut data = None;
for seq in sequences {
let mut d = match data.as_mut() {
Some(d) => d,
None => {
data = Some(DenseMatrix::new(seq.len()));
data.as_mut().unwrap()
}
};
for (i, x) in seq.data.iter().enumerate() {
d[i][x.as_index()] += 1;
}
}
Ok(Self {
alphabet: A::default(),
data: data.unwrap_or_else(|| DenseMatrix::new(0)),
})
}
}
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