pub struct MzSpectrum {
pub mz: Vec<f64>,
pub intensity: Vec<f64>,
}
Expand description
Represents a mass spectrum with associated m/z values and intensities.
Fields§
§mz: Vec<f64>
§intensity: Vec<f64>
Implementations§
Source§impl MzSpectrum
impl MzSpectrum
Sourcepub fn new(mz: Vec<f64>, intensity: Vec<f64>) -> Self
pub fn new(mz: Vec<f64>, intensity: Vec<f64>) -> Self
Constructs a new MzSpectrum
.
§Arguments
mz
- A vector of m/z values.intensity
- A vector of intensity values corresponding to the m/z values.
§Panics
Panics if the lengths of mz
and intensity
are not the same. (actually, it doesn’t at the moment, planning on adding this later)
§Example
let spectrum = MzSpectrum::new(vec![100.0, 200.0], vec![10.0, 20.0]);
assert_eq!(spectrum.mz, vec![100.0, 200.0]);
assert_eq!(spectrum.intensity, vec![10.0, 20.0]);
pub fn filter_ranged( &self, mz_min: f64, mz_max: f64, intensity_min: f64, intensity_max: f64, ) -> Self
Sourcepub fn to_windows(
&self,
window_length: f64,
overlapping: bool,
min_peaks: usize,
min_intensity: f64,
) -> BTreeMap<i32, MzSpectrum>
pub fn to_windows( &self, window_length: f64, overlapping: bool, min_peaks: usize, min_intensity: f64, ) -> BTreeMap<i32, MzSpectrum>
Splits the spectrum into a collection of windows based on m/z values.
This function divides the spectrum into smaller spectra (windows) based on a specified window length. Each window contains peaks from the original spectrum that fall within the m/z range of that window.
§Arguments
-
window_length
: The size (in terms of m/z values) of each window. -
overlapping
: Iftrue
, each window will overlap with its neighboring windows by half of thewindow_length
. This means that a peak may belong to multiple windows. Iffalse
, windows do not overlap. -
min_peaks
: The minimum number of peaks a window must have to be retained in the result. -
min_intensity
: The minimum intensity value a window must have (in its highest intensity peak) to be retained in the result.
§Returns
A BTreeMap
where the keys represent the window indices and the values are the spectra (MzSpectrum
) within those windows.
Windows that do not meet the criteria of having at least min_peaks
peaks or a highest intensity peak
greater than or equal to min_intensity
are discarded.
§Example
let spectrum = MzSpectrum::new(vec![100.0, 101.0, 102.5, 103.0], vec![10.0, 20.0, 30.0, 40.0]);
let windowed_spectrum = spectrum.to_windows(1.0, false, 1, 10.0);
assert!(windowed_spectrum.contains_key(&100));
assert!(windowed_spectrum.contains_key(&102));
pub fn to_centroid( &self, baseline_noise_level: i32, sigma: f64, normalize: bool, ) -> MzSpectrum
pub fn from_collection(collection: Vec<MzSpectrum>) -> MzSpectrum
pub fn add_mz_noise_uniform(&self, ppm: f64, right_drag: bool) -> Self
pub fn add_mz_noise_normal(&self, ppm: f64) -> Self
Trait Implementations§
Source§impl Add for MzSpectrum
impl Add for MzSpectrum
Source§fn add(self, other: Self) -> MzSpectrum
fn add(self, other: Self) -> MzSpectrum
Combines two MzSpectrum
instances by summing up the intensities of matching m/z values.
§Description
Each m/z value is quantized to retain at least 6 decimals. If two spectra have m/z values that quantize to the same integer value, their intensities are summed.
§Example
let spectrum1 = MzSpectrum { mz: vec![100.523, 101.923], intensity: vec![10.0, 20.0] };
let spectrum2 = MzSpectrum { mz: vec![101.235, 105.112], intensity: vec![15.0, 30.0] };
let combined = spectrum1 + spectrum2;
assert_eq!(combined.mz, vec![100.523, 101.235, 101.923, 105.112]);
assert_eq!(combined.intensity, vec![10.0, 15.0, 20.0, 30.0]);
Source§type Output = MzSpectrum
type Output = MzSpectrum
+
operator.Source§impl<'__de> BorrowDecode<'__de> for MzSpectrum
impl<'__de> BorrowDecode<'__de> for MzSpectrum
Source§fn borrow_decode<__D: BorrowDecoder<'__de>>(
decoder: &mut __D,
) -> Result<Self, DecodeError>
fn borrow_decode<__D: BorrowDecoder<'__de>>( decoder: &mut __D, ) -> Result<Self, DecodeError>
Source§impl Clone for MzSpectrum
impl Clone for MzSpectrum
Source§fn clone(&self) -> MzSpectrum
fn clone(&self) -> MzSpectrum
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for MzSpectrum
impl Debug for MzSpectrum
Source§impl Decode for MzSpectrum
impl Decode for MzSpectrum
Source§impl<'de> Deserialize<'de> for MzSpectrum
impl<'de> Deserialize<'de> for MzSpectrum
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for MzSpectrum
impl Display for MzSpectrum
Formats the MzSpectrum
for display.
Source§impl Encode for MzSpectrum
impl Encode for MzSpectrum
Source§impl Mul<f64> for MzSpectrum
impl Mul<f64> for MzSpectrum
Source§impl Serialize for MzSpectrum
impl Serialize for MzSpectrum
Source§impl Sub for MzSpectrum
impl Sub for MzSpectrum
Source§impl ToResolution for MzSpectrum
impl ToResolution for MzSpectrum
Source§fn to_resolution(&self, resolution: i32) -> Self
fn to_resolution(&self, resolution: i32) -> Self
Bins the spectrum’s m/z values to a given resolution and sums the intensities.
§Arguments
resolution
- The desired resolution in terms of decimal places. For instance, a resolution of 2 would bin m/z values to two decimal places.
§Returns
A new MzSpectrum
where m/z values are binned according to the given resolution.
§Example
let spectrum = MzSpectrum::new(vec![100.123, 100.121, 100.131], vec![10.0, 20.0, 30.0]);
let binned_spectrum_1 = spectrum.to_resolution(1);
let binned_spectrum_2 = spectrum.to_resolution(2);
/// assert_eq!(binned_spectrum_2.mz, vec![100.1]);
assert_eq!(binned_spectrum_1.intensity, vec![60.0]);
assert_eq!(binned_spectrum_2.mz, vec![100.12, 100.13]);
assert_eq!(binned_spectrum_2.intensity, vec![30.0, 30.0]);
Source§impl Vectorized<MzSpectrumVectorized> for MzSpectrum
impl Vectorized<MzSpectrumVectorized> for MzSpectrum
Source§fn vectorized(&self, resolution: i32) -> MzSpectrumVectorized
fn vectorized(&self, resolution: i32) -> MzSpectrumVectorized
Convert the MzSpectrum
to a MzSpectrumVectorized
using the given resolution for binning.
After binning to the desired resolution, the binned m/z values are translated into integer indices.
Auto Trait Implementations§
impl Freeze for MzSpectrum
impl RefUnwindSafe for MzSpectrum
impl Send for MzSpectrum
impl Sync for MzSpectrum
impl Unpin for MzSpectrum
impl UnwindSafe for MzSpectrum
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.