Skip to content

Commit aa9c2a4

Browse files
committed
feature: add precursor stack manipulation tools to SpectrumLike and similar.
1 parent 0bcf835 commit aa9c2a4

File tree

5 files changed

+81
-8
lines changed

5 files changed

+81
-8
lines changed

src/spectrum/bindata/encodings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ impl ArrayType {
994994
== (Self::NonStandardDataArray {
995995
name: "".to_string().into(),
996996
})
997-
.as_param_const()
997+
.as_param(None)
998998
.curie()
999999
.unwrap()
10001000
{

src/spectrum/chromatogram.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl TimeInterval<Time> for Chromatogram {
8585
/// Analog of [`SpectrumLike`](crate::spectrum::SpectrumLike) for chromatograms or
8686
/// other measures over time.
8787
pub trait ChromatogramLike: ParamDescribed {
88-
/// The method to access the spectrum description itself, which supplies
88+
/// The method to access the chromatogram description itself, which supplies
8989
/// the data for most other methods on this trait.
9090
fn description(&self) -> &ChromatogramDescription;
9191

@@ -98,7 +98,7 @@ pub trait ChromatogramLike: ParamDescribed {
9898
desc.precursor.first()
9999
}
100100

101-
/// Iterate over all precursors of the spectrum
101+
/// Iterate over all precursors of the chromatogram
102102
fn precursor_iter(&self) -> impl Iterator<Item = &Precursor> {
103103
let desc = self.description();
104104
desc.precursor.iter()
@@ -110,12 +110,32 @@ pub trait ChromatogramLike: ParamDescribed {
110110
desc.precursor.first_mut()
111111
}
112112

113-
/// Iterate over all precursors of the spectrum mutably
113+
/// Iterate over all precursors of the chromatogram mutably
114114
fn precursor_iter_mut(&mut self) -> impl Iterator<Item = &mut Precursor> {
115115
let desc = self.description_mut();
116116
desc.precursor.iter_mut()
117117
}
118118

119+
/// Add a precursor to the list of precursors for this chromatogram.
120+
///
121+
/// Precursors beyond the first one correspond to lower exponentiated spectra, e.g. for an MS3 chromatogram
122+
/// the first precursor is the MS2 product ion that was selected, and the second precursor corresponds
123+
/// to the original MS1 ion that was chosen for MS2.
124+
///
125+
/// Higher order precursors may be accessed with [`ChromatogramLike::precursor_iter`].
126+
fn add_precursor(&mut self, precursor: Precursor) {
127+
self.description_mut().precursor.push(precursor);
128+
}
129+
130+
/// Remove the precursor entry at `index` in the precursor list.
131+
///
132+
/// Care should be taken if you are attempting to re-order precursors.
133+
/// It may be simpler to use [`ChromatogramLike::precursor_iter_mut`] to
134+
/// re-arrange entries.
135+
fn remove_precursor(&mut self, index: usize) -> Precursor {
136+
self.description_mut().precursor.remove(index)
137+
}
138+
119139
#[inline]
120140
fn start_time(&self) -> Option<f64> {
121141
if let Ok(t) = self.time() {

src/spectrum/frame.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ impl From<IonMobilityFrameDescription> for SpectrumDescription {
155155
}
156156
}
157157

158-
/// A trait for providing a uniform delegated access to spectrum metadata
158+
/// A trait for providing a uniform delegated access to ion mobility frame metadata.
159+
///
160+
/// This is analogous to [`SpectrumLike`] but adapted for working with different underlying
161+
/// types.
159162
pub trait IonMobilityFrameLike<
160163
C: FeatureLike<MZ, IonMobility>,
161164
D: FeatureLike<Mass, IonMobility> + KnownCharge,
@@ -188,7 +191,7 @@ pub trait IonMobilityFrameLike<
188191
&mut self.description_mut().ion_mobility_unit
189192
}
190193

191-
/// Access the acquisition information for this spectrum.
194+
/// Access the acquisition information for this frame.
192195
#[inline]
193196
fn acquisition(&self) -> &Acquisition {
194197
&self.description().acquisition
@@ -205,7 +208,7 @@ pub trait IonMobilityFrameLike<
205208
}
206209
}
207210

208-
/// Iterate over all precursors of the spectrum
211+
/// Iterate over all precursors of the frame
209212
fn precursor_iter(&self) -> impl Iterator<Item = &Precursor> {
210213
let desc = self.description();
211214
desc.precursor.iter()
@@ -221,12 +224,33 @@ pub trait IonMobilityFrameLike<
221224
}
222225
}
223226

224-
/// Iterate over all precursors of the spectrum mutably
227+
/// Iterate over all precursors of the frame mutably
225228
fn precursor_iter_mut(&mut self) -> impl Iterator<Item = &mut Precursor> {
226229
let desc = self.description_mut();
227230
desc.precursor.iter_mut()
228231
}
229232

233+
/// Add a precursor to the list of precursors for this frame.
234+
///
235+
/// Precursors beyond the first one correspond to lower exponentiated spectra, e.g. for an MS3 frame
236+
/// the first precursor is the MS2 product ion that was selected, and the second precursor corresponds
237+
/// to the original MS1 ion that was chosen for MS2.
238+
///
239+
/// Higher order precursors may be accessed with [`IonMobilityFrameLike::precursor_iter`].
240+
fn add_precursor(&mut self, precursor: Precursor) {
241+
self.description_mut().precursor.push(precursor);
242+
}
243+
244+
245+
/// Remove the precursor entry at `index` in the precursor list.
246+
///
247+
/// Care should be taken if you are attempting to re-order precursors.
248+
/// It may be simpler to use [`IonMobilityFrameLike::precursor_iter_mut`] to
249+
/// re-arrange entries.
250+
fn remove_precursor(&mut self, index: usize) -> Precursor {
251+
self.description_mut().precursor.remove(index)
252+
}
253+
230254
/// A shortcut method to retrieve the scan start time of a spectrum
231255
#[inline]
232256
fn start_time(&self) -> f64 {

src/spectrum/scan_properties.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ pub trait IonMobilityMeasure: ParamDescribed {
175175
fn has_ion_mobility(&self) -> bool {
176176
self.ion_mobility().is_some()
177177
}
178+
179+
fn ion_mobility_type(&self) -> Option<&Param> {
180+
for u in ION_MOBILITY_SCAN_TERMS {
181+
if let Some(v) = self.get_param_by_curie(&u) {
182+
return Some(v);
183+
}
184+
}
185+
None
186+
}
178187
}
179188

180189
pub(crate) const PRESET_SCAN_CONFIGURATION: CURIE = curie!(MS:1000616);

src/spectrum/spectrum_types.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,26 @@ pub trait SpectrumLike<
8282
desc.precursor.iter_mut()
8383
}
8484

85+
/// Add a precursor to the list of precursors for this spectrum.
86+
///
87+
/// Precursors beyond the first one correspond to lower exponentiated spectra, e.g. for an MS3 spectrum
88+
/// the first precursor is the MS2 product ion that was selected, and the second precursor corresponds
89+
/// to the original MS1 ion that was chosen for MS2.
90+
///
91+
/// Higher order precursors may be accessed with [`SpectrumLike::precursor_iter`].
92+
fn add_precursor(&mut self, precursor: Precursor) {
93+
self.description_mut().precursor.push(precursor);
94+
}
95+
96+
/// Remove the precursor entry at `index` in the precursor list.
97+
///
98+
/// Care should be taken if you are attempting to re-order precursors.
99+
/// It may be simpler to use [`SpectrumLike::precursor_iter_mut`] to
100+
/// re-arrange entries.
101+
fn remove_precursor(&mut self, index: usize) -> Precursor {
102+
self.description_mut().precursor.remove(index)
103+
}
104+
85105
/// A shortcut method to retrieve the scan start time of a spectrum
86106
#[inline]
87107
fn start_time(&self) -> f64 {

0 commit comments

Comments
 (0)