From 25717ba4eb784cf7f89fcff90e3aac9802b4a8a6 Mon Sep 17 00:00:00 2001 From: RalfG Date: Mon, 1 Jul 2024 13:23:30 +0200 Subject: [PATCH] Update to mzdata 0.20.0 --- Cargo.toml | 2 +- src/parse_mzdata.rs | 32 +++++++++++++------------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ce21f91..64ddafa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,5 +10,5 @@ crate-type = ["cdylib"] [dependencies] pyo3 = "0.20.0" -mzdata = "0.13.0" +mzdata = "0.20.0" timsrust = "0.2.4" diff --git a/src/parse_mzdata.rs b/src/parse_mzdata.rs index a27115d..e11c805 100644 --- a/src/parse_mzdata.rs +++ b/src/parse_mzdata.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::fs::File; use mzdata::io::{MGFReader, MzMLReader}; +use mzdata::params::ParamValue; use crate::file_types::SpectrumFileType; use crate::ms2_spectrum::MS2Spectrum; @@ -127,8 +128,13 @@ fn get_charge_from_spectrum(spectrum: &mzdata::spectrum::MultiLayerSpectrum) -> .params .iter() .find(|p| p.name == "charge") - .map(|p| p.value.strip_suffix('+').unwrap_or(&p.value)) - .map(|v| v.parse::().unwrap_or(0)) + .map(|p| p.value.to_string()) + .and_then(|v| { + v.strip_suffix('+') + .unwrap_or(v.as_str()) + .parse::() + .ok() + }) }) } @@ -145,11 +151,7 @@ fn get_im_from_spectrum_description( || (p.name == "inverse reduced ion mobility") || (p.name == "reverse ion mobility") }) - .map(|p| p.value.clone()) - .map(|v| match v.parse::() { - Ok(v) => Some(v), - Err(_) => None, - })? + .and_then(|p| p.value.to_f64().ok()) } /// Try to get ion mobility from the selected ion parameters. @@ -167,12 +169,8 @@ fn get_im_from_selected_ion(spectrum: &mzdata::spectrum::MultiLayerSpectrum) -> || (p.name == "inverse reduced ion mobility") || (p.name == "reverse ion mobility") }) - .map(|p| p.value.clone()) - .map(|v| match v.parse::() { - Ok(v) => Some(v), - Err(_) => None, - }) - })? + .and_then(|p| p.value.to_f64().ok()) + }) } /// Try to get ion mobility from the first scan parameters. @@ -189,10 +187,6 @@ fn get_im_from_first_scan(spectrum: &mzdata::spectrum::MultiLayerSpectrum) -> Op || (p.name == "inverse reduced ion mobility") || (p.name == "reverse ion mobility") }) - .map(|p| p.value.clone()) - .map(|v| match v.parse::() { - Ok(v) => Some(v), - Err(_) => None, - }) - })? + .and_then(|p| p.value.to_f64().ok()) + }) }