pub trait SpectrumGrouping<C = CentroidPeak, D = DeconvolutedPeak, S = MultiLayerSpectrum<C, D>>: Default{
// Required methods
fn precursor(&self) -> Option<&S>;
fn precursor_mut(&mut self) -> Option<&mut S>;
fn set_precursor(&mut self, prec: S);
fn products(&self) -> &[S];
fn products_mut(&mut self) -> &mut Vec<S>;
fn into_parts(self) -> (Option<S>, Vec<S>);
// Provided methods
fn total_spectra(&self) -> usize { ... }
fn earliest_spectrum(&self) -> Option<&S> { ... }
fn latest_spectrum(&self) -> Option<&S> { ... }
fn lowest_ms_level(&self) -> Option<u8> { ... }
fn highest_ms_level(&self) -> Option<u8> { ... }
}Expand description
An abstraction over SpectrumGroup’s interface.
Required Methods§
Sourcefn precursor_mut(&mut self) -> Option<&mut S>
fn precursor_mut(&mut self) -> Option<&mut S>
Get a mutable reference to the precursor spectrum, which may be absent
Sourcefn set_precursor(&mut self, prec: S)
fn set_precursor(&mut self, prec: S)
Explicitly set the precursor spectrum directly.
Sourcefn products_mut(&mut self) -> &mut Vec<S>
fn products_mut(&mut self) -> &mut Vec<S>
Get a mutable reference to the collection of product spectra
Sourcefn into_parts(self) -> (Option<S>, Vec<S>)
fn into_parts(self) -> (Option<S>, Vec<S>)
Decompose the group into its components, discarding any additional metrics
Provided Methods§
Sourcefn total_spectra(&self) -> usize
fn total_spectra(&self) -> usize
The total number of spectra in the group
Sourcefn earliest_spectrum(&self) -> Option<&S>
fn earliest_spectrum(&self) -> Option<&S>
The spectrum that occurred first chronologically
Examples found in repository?
examples/msn_target_mapping.rs (line 157)
153 fn initial_feed(&mut self) {
154 let group = self.source.next();
155 let start_time = group
156 .as_ref()
157 .and_then(|s| s.earliest_spectrum().map(|s| s.start_time()))
158 .unwrap();
159 let end_time = start_time + self.time_width;
160 eprintln!("Initial time window {start_time} to {end_time}");
161 if let Some(g) = group {
162 self.observe(&g);
163 self.buffer.push_back((g, start_time));
164 }
165 while let Some(group) = self.source.next() {
166 let t = group.earliest_spectrum().map(|s| s.start_time()).unwrap();
167 if t < end_time {
168 self.observe(&group);
169 self.buffer.push_back((group, t));
170 } else {
171 self.pushback_buffer = Some((group, t));
172 break;
173 }
174 }
175 eprintln!(
176 "{} targets extracted from buffer size {}",
177 self.targets.len(),
178 self.buffer.len()
179 );
180 }
181
182 fn get_current_window_end(&self) -> f64 {
183 if self.buffer.is_empty() {
184 return f64::NEG_INFINITY;
185 }
186 let start = self.buffer.front().map(|(_, t)| *t).unwrap();
187 let end = self.buffer.back().map(|(_, t)| *t).unwrap();
188 let mid = start + (end - start) / 2.0;
189 mid + self.time_width
190 }
191
192 fn feed_next(&mut self) {
193 let threshold = self.get_current_window_end();
194 let (use_pushback, pushback_populated) = if let Some((_, t)) = self.pushback_buffer.as_ref()
195 {
196 (*t < threshold, true)
197 } else {
198 (false, false)
199 };
200 if use_pushback {
201 let (group, t) = self.pushback_buffer.take().unwrap();
202 self.observe(&group);
203 self.buffer.push_back((group, t));
204 }
205 if !pushback_populated {
206 if let Some(group) = self.source.next() {
207 let t = group.earliest_spectrum().map(|s| s.start_time()).unwrap();
208 if t < threshold {
209 self.observe(&group);
210 self.buffer.push_back((group, t));
211 } else {
212 self.pushback_buffer = Some((group, t));
213 }
214 }
215 }
216 }More examples
examples/random_access_iter.rs (line 44)
6fn main() -> io::Result<()> {
7 let path = path::PathBuf::from(
8 env::args()
9 .nth(1)
10 .expect("Please pass an MS data file path"),
11 // "test/data/batching_test.mzML"
12 );
13
14 let mut reader = mzml::MzMLReader::open_path(path)?;
15
16 let n_spectra = reader.len();
17
18 // Find the spectrum at the midpoint of the run
19 let spec = reader.get_spectrum_by_index(n_spectra / 2).unwrap();
20 eprintln!(
21 "Midpoint spectrum {} (level {}) at time {}",
22 spec.id(),
23 spec.ms_level(),
24 spec.start_time()
25 );
26
27 // Jump the iterator to that point in time
28 reader.start_from_time(spec.start_time())?;
29 let s = reader.next().unwrap();
30 eprintln!(
31 "Resuming at {} (level {}) at time {}",
32 s.id(),
33 s.ms_level(),
34 s.start_time()
35 );
36
37 // Convert the iterator into a group iterator
38 let mut group_iter = reader.into_groups();
39 // Jump the group iterator to that point in time (If an MSn spectrum was found, the next MS1 may be shown instead)
40 group_iter.start_from_time(spec.start_time())?;
41 let g = group_iter.next().unwrap();
42 eprintln!(
43 "Resuming at group having {:?} at time {:?}",
44 g.earliest_spectrum().map(|s| s.id()),
45 g.earliest_spectrum().map(|s| s.start_time())
46 );
47
48 // Convert the group iterator into an averaging group iterator
49 let mut avg_iter = group_iter.averaging(1, 200.0, 2200.0, 0.005);
50 // Jump the group iterator to that point in time (If an MSn spectrum was found, the next MS1 may be shown instead)
51 avg_iter.start_from_time(spec.start_time())?;
52 let g = avg_iter.next().unwrap();
53 eprintln!(
54 "Resuming at group having {:?} at time {:?}",
55 g.earliest_spectrum().map(|s| s.id()),
56 g.earliest_spectrum().map(|s| s.start_time())
57 );
58
59 Ok(())
60}Sourcefn latest_spectrum(&self) -> Option<&S>
fn latest_spectrum(&self) -> Option<&S>
The spectrum that occurred last chronologically
Sourcefn lowest_ms_level(&self) -> Option<u8>
fn lowest_ms_level(&self) -> Option<u8>
The lowest MS level in the group. Returns None if the group is empty or the MS level is 0.
Sourcefn highest_ms_level(&self) -> Option<u8>
fn highest_ms_level(&self) -> Option<u8>
The highest MS level in the group. Returns None if the group is empty or the MS level is 0.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".