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

Avoid error on missing symbols in `CountMatrix.__init__`

parent 404a6b44
No related branches found
No related tags found
No related merge requests found
...@@ -124,22 +124,18 @@ impl CountMatrix { ...@@ -124,22 +124,18 @@ impl CountMatrix {
let mut data: Option<DenseMatrix<u32, <lightmotif::Dna as Alphabet>::K>> = None; let mut data: Option<DenseMatrix<u32, <lightmotif::Dna as Alphabet>::K>> = None;
for s in lightmotif::Dna::symbols() { for s in lightmotif::Dna::symbols() {
let key = String::from(s.as_char()); let key = String::from(s.as_char());
let column = values if let Some(res) = values.get_item(&key) {
.get_item(&key) let column = res.downcast::<PyList>()?;
.ok_or(PyKeyError::new_err(key))? if data.is_none() {
.downcast::<PyList>()?; data = Some(DenseMatrix::new(column.len()));
}
if data.is_none() { let matrix = data.as_mut().unwrap();
data = Some(DenseMatrix::new(column.len())); if matrix.rows() != column.len() {
} return Err(PyValueError::new_err("Invalid number of rows"));
}
let matrix = data.as_mut().unwrap(); for (i, x) in column.iter().enumerate() {
if matrix.rows() != column.len() { matrix[i][s.as_index()] = x.extract::<u32>()?;
return Err(PyValueError::new_err("Invalid number of rows")); }
}
for (i, x) in column.iter().enumerate() {
matrix[i][s.as_index()] = x.extract::<u32>()?;
} }
} }
......
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