Skip to content

Commit

Permalink
Update to mzdata 0.20.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfG committed Jul 1, 2024
1 parent 61fe19d commit 25717ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.20.0"
mzdata = "0.13.0"
mzdata = "0.20.0"
timsrust = "0.2.4"
32 changes: 13 additions & 19 deletions src/parse_mzdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<usize>().unwrap_or(0))
.map(|p| p.value.to_string())
.and_then(|v| {
v.strip_suffix('+')
.unwrap_or(v.as_str())
.parse::<usize>()
.ok()
})
})
}

Expand All @@ -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::<f64>() {
Ok(v) => Some(v),
Err(_) => None,
})?
.and_then(|p| p.value.to_f64().ok())
}

/// Try to get ion mobility from the selected ion parameters.
Expand All @@ -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::<f64>() {
Ok(v) => Some(v),
Err(_) => None,
})
})?
.and_then(|p| p.value.to_f64().ok())
})
}

/// Try to get ion mobility from the first scan parameters.
Expand All @@ -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::<f64>() {
Ok(v) => Some(v),
Err(_) => None,
})
})?
.and_then(|p| p.value.to_f64().ok())
})
}

0 comments on commit 25717ba

Please sign in to comment.