use std::path::Path;
use anyhow::Result;
use dihardts_omicstools::proteomics::post_translational_modifications::PostTranslationalModification as PTM;
pub struct Reader {}
impl Reader {
pub fn read(path: &Path) -> Result<Vec<PTM>> {
let reader = csv::ReaderBuilder::new()
.has_headers(true)
.delimiter(b',')
.from_path(path)?;
reader
.into_deserialize::<PTM>()
.map(|ptm_result| match ptm_result {
Ok(ptm) => Ok(ptm),
Err(e) => Err(anyhow::Error::new(e)),
})
.collect()
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_read() {
let mod_csv = Path::new("test_files/mods.csv");
let ptms = Reader::read(mod_csv).unwrap();
assert_eq!(ptms.len(), 2);
}
}