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

Add convenience method to flatten a `StripedScores`

parent d01753ca
No related branches found
No related tags found
No related merge requests found
......@@ -54,7 +54,7 @@ impl Pipeline<DnaAlphabet, f32> {
result[row][col] = score;
}
StripedScores {
length: seq.length,
length: seq.length - pwm.data.rows() + 1,
data: result,
}
}
......@@ -149,7 +149,7 @@ impl Pipeline<DnaAlphabet, __m256> {
}
StripedScores {
length: seq.length,
length: seq.length - pwm.data.rows() + 1,
data: result,
}
}
......
......@@ -49,11 +49,13 @@ impl<A: Alphabet, const K: usize> CountMatrix<A, K> {
pub fn from_sequences<'seq, I, S>(name: S, sequences: I) -> Result<Self, ()>
where
I: IntoIterator<Item = &'seq EncodedSequence<A>>,
I: IntoIterator,
<I as IntoIterator>::Item: AsRef<EncodedSequence<A>>,
S: Into<String>,
{
let mut data = None;
for seq in sequences {
let seq = seq.as_ref();
let mut d = match data.as_mut() {
Some(d) => d,
None => {
......@@ -61,6 +63,9 @@ impl<A: Alphabet, const K: usize> CountMatrix<A, K> {
data.as_mut().unwrap()
}
};
if seq.len() != d.rows() {
return Err(());
}
for (i, x) in seq.data.iter().enumerate() {
d[i][x.as_index()] += 1;
}
......@@ -165,4 +170,16 @@ pub struct WeightMatrix<A: Alphabet, const K: usize> {
pub struct StripedScores<const C: usize = 32> {
pub length: usize,
pub data: DenseMatrix<f32, C>,
}
impl<const C: usize> StripedScores<C> {
pub fn to_vec(&self) -> Vec<f32> {
let mut vec = Vec::with_capacity(self.length);
for i in 0..self.length {
let col = i / self.data.rows();
let row = i % self.data.rows();
vec.push(self.data[row][col]);
}
vec
}
}
\ No newline at end of file
......@@ -45,6 +45,12 @@ impl<A: Alphabet> EncodedSequence<A> {
}
}
impl<A: Alphabet> AsRef<EncodedSequence<A>> for EncodedSequence<A> {
fn as_ref(&self) -> &Self {
&self
}
}
#[derive(Clone, Debug)]
pub struct StripedSequence<A: Alphabet, const C: usize = 32> {
pub alphabet: 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