mscore::data::spectrum

Struct MzSpectrum

Source
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

Source

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]);
Source

pub fn filter_ranged( &self, mz_min: f64, mz_max: f64, intensity_min: f64, intensity_max: f64, ) -> Self

Source

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: If true, each window will overlap with its neighboring windows by half of the window_length. This means that a peak may belong to multiple windows. If false, 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));
Source

pub fn to_centroid( &self, baseline_noise_level: i32, sigma: f64, normalize: bool, ) -> MzSpectrum

Source

pub fn from_collection(collection: Vec<MzSpectrum>) -> MzSpectrum

Source

pub fn add_mz_noise_uniform(&self, ppm: f64, right_drag: bool) -> Self

Source

pub fn add_mz_noise_normal(&self, ppm: f64) -> Self

Trait Implementations§

Source§

impl Add for MzSpectrum

Source§

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

The resulting type after applying the + operator.
Source§

impl<'__de> BorrowDecode<'__de> for MzSpectrum

Source§

fn borrow_decode<__D: BorrowDecoder<'__de>>( decoder: &mut __D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given BorrowDecode.
Source§

impl Clone for MzSpectrum

Source§

fn clone(&self) -> MzSpectrum

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MzSpectrum

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Decode for MzSpectrum

Source§

fn decode<__D: Decoder>(decoder: &mut __D) -> Result<Self, DecodeError>

Attempt to decode this type with the given Decode.
Source§

impl<'de> Deserialize<'de> for MzSpectrum

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for MzSpectrum

Formats the MzSpectrum for display.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Encode for MzSpectrum

Source§

fn encode<__E: Encoder>(&self, encoder: &mut __E) -> Result<(), EncodeError>

Encode a given type.
Source§

impl Mul<f64> for MzSpectrum

Source§

type Output = MzSpectrum

The resulting type after applying the * operator.
Source§

fn mul(self, scale: f64) -> Self::Output

Performs the * operation. Read more
Source§

impl Serialize for MzSpectrum

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub for MzSpectrum

Source§

type Output = MzSpectrum

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl ToResolution for MzSpectrum

Source§

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

Source§

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,