@@ -58,23 +58,46 @@ pub trait SpectrumBuilding<'a, C: CentroidLike, D: DeconvolutedCentroidLike, S:
58
58
fn isolation_window_mut ( & mut self ) -> & mut IsolationWindow ;
59
59
/// Get the last scan window being constructed.
60
60
fn scan_window_mut ( & mut self ) -> & mut ScanWindow ;
61
+
62
+ /// Get the current [`SelectedIon`] being built.
61
63
fn selected_ion_mut ( & mut self ) -> & mut SelectedIon ;
64
+
65
+ /// Add a new [`SelectedIon`] to the stack for the current [`Precursor`].
66
+ /// This will be the current [`SelectedIon`].
62
67
fn new_selected_ion ( & mut self ) -> & mut SelectedIon ;
68
+
69
+ /// Add a new [`Precursor`] to the stack. This will be the current [`Precursor`].
63
70
fn new_precursor_mut ( & mut self ) -> & mut Precursor ;
71
+
72
+ /// Get the current [`Precursor`] being built.
64
73
fn precursor_mut ( & mut self ) -> & mut Precursor ;
74
+
75
+ /// Get the current [`DataArray`] being built. This may be an empty instance if
76
+ /// if there is no array being built currently.
65
77
fn current_array_mut ( & mut self ) -> & mut DataArray ;
78
+
66
79
/// Move all the data into the provided `spectrum` reference
67
80
fn into_spectrum ( self , spectrum : & mut S ) ;
68
81
82
+ /// Optionally set the global data processing identifier for the run to be used if
83
+ /// a data processing reference isn't specified locally.
84
+ ///
85
+ /// This is a no-op if not explicitly implemented.
86
+ fn set_run_data_processing ( & mut self , _identifier : Option < Box < str > > ) { }
87
+
88
+ /// Move all the data into the provided `chromatogram` reference
69
89
fn into_chromatogram ( self , chromatogram : & mut Chromatogram ) ;
70
90
91
+ /// Put a parameter-like instance into the current top-level instance
71
92
fn fill_spectrum < P : ParamLike + Into < Param > + ParamValue > ( & mut self , param : P ) ;
72
93
94
+ /// Set the compression method for the current [`DataArray`]
73
95
fn set_current_compressiion ( & mut self , compression : BinaryCompressionType ) {
74
96
trace ! ( "Setting current compression method for {:?} to {compression:?}" , self . current_array_mut( ) . name( ) ) ;
75
97
self . current_array_mut ( ) . compression = compression;
76
98
}
77
99
100
+ /// Put a parameter-like instance into the current [`DataArray`]
78
101
fn fill_binary_data_array < P : ParamLike + Into < Param > + ParamValue > ( & mut self , param : P ) {
79
102
if param. is_ms ( ) {
80
103
match param. accession ( ) . unwrap ( ) {
@@ -229,6 +252,7 @@ pub trait SpectrumBuilding<'a, C: CentroidLike, D: DeconvolutedCentroidLike, S:
229
252
}
230
253
}
231
254
255
+ /// Put a parameter-like instance into the current [`SelectedIon`]
232
256
fn fill_selected_ion ( & mut self , param : Param ) {
233
257
match param. name . as_ref ( ) {
234
258
"selected ion m/z" => {
@@ -248,6 +272,7 @@ pub trait SpectrumBuilding<'a, C: CentroidLike, D: DeconvolutedCentroidLike, S:
248
272
} ;
249
273
}
250
274
275
+ /// Put a parameter-like instance into the current [`IsolationWindow`]
251
276
fn fill_isolation_window ( & mut self , param : Param ) {
252
277
let window = self . isolation_window_mut ( ) ;
253
278
match param. name . as_ref ( ) {
@@ -324,6 +349,7 @@ pub trait SpectrumBuilding<'a, C: CentroidLike, D: DeconvolutedCentroidLike, S:
324
349
}
325
350
}
326
351
352
+ /// Put a parameter-like instance into the current [`ScanWindow`]
327
353
fn fill_scan_window ( & mut self , param : Param ) {
328
354
let window = self . scan_window_mut ( ) ;
329
355
match param. name . as_ref ( ) {
@@ -355,7 +381,10 @@ macro_rules! xml_error {
355
381
const BUFFER_SIZE : usize = 10000 ;
356
382
357
383
/// An accumulator for the attributes of a spectrum as it is read from an
358
- /// mzML document
384
+ /// mzML document.
385
+ ///
386
+ /// While this type is public, it is unnecessary for most users. Instead
387
+ /// just use [`MzMLReaderType::read_next`].
359
388
pub struct MzMLSpectrumBuilder <
360
389
' a ,
361
390
C : CentroidLike = CentroidPeak ,
@@ -376,6 +405,8 @@ pub struct MzMLSpectrumBuilder<
376
405
pub has_precursor : bool ,
377
406
pub detail_level : DetailLevel ,
378
407
pub instrument_id_map : Option < & ' a mut IncrementingIdMap > ,
408
+ pub run_level_data_processing : Option < Box < str > > ,
409
+ pub spectrum_data_processing_ref : Option < Box < str > > ,
379
410
entry_type : EntryType ,
380
411
centroid_type : PhantomData < C > ,
381
412
deconvoluted_type : PhantomData < D > ,
@@ -397,6 +428,8 @@ impl<C: CentroidLike, D: DeconvolutedCentroidLike> Default for MzMLSpectrumBuild
397
428
has_precursor : Default :: default ( ) ,
398
429
detail_level : Default :: default ( ) ,
399
430
instrument_id_map : Default :: default ( ) ,
431
+ run_level_data_processing : None ,
432
+ spectrum_data_processing_ref : None ,
400
433
entry_type : Default :: default ( ) ,
401
434
centroid_type : PhantomData ,
402
435
deconvoluted_type : PhantomData ,
@@ -410,6 +443,10 @@ impl<C: CentroidLike, D: DeconvolutedCentroidLike> CVParamParse for MzMLSpectrum
410
443
impl < ' inner , C : CentroidLike , D : DeconvolutedCentroidLike >
411
444
SpectrumBuilding < ' inner , C , D , MultiLayerSpectrum < C , D > > for MzMLSpectrumBuilder < ' inner , C , D >
412
445
{
446
+ fn set_run_data_processing ( & mut self , identifier : Option < Box < str > > ) {
447
+ self . run_level_data_processing = identifier;
448
+ }
449
+
413
450
fn isolation_window_mut ( & mut self ) -> & mut IsolationWindow {
414
451
& mut self . precursor_mut ( ) . isolation_window
415
452
}
@@ -542,6 +579,10 @@ impl<
542
579
Self :: with_detail_level ( DetailLevel :: Full )
543
580
}
544
581
582
+ pub fn set_run_data_processing ( & mut self , identifier : Option < Box < str > > ) {
583
+ self . run_level_data_processing = identifier;
584
+ }
585
+
545
586
pub fn with_detail_level ( detail_level : DetailLevel ) -> MzMLSpectrumBuilder < ' inner , C , D > {
546
587
Self {
547
588
detail_level,
@@ -707,6 +748,10 @@ impl<C: CentroidLike + BuildFromArrayMap, D: DeconvolutedCentroidLike + BuildFro
707
748
. expect ( "Failed to parse index" ) ;
708
749
trace ! ( "Stored spectrum index = {}" , self . index) ;
709
750
}
751
+ b"dataProcessingRef" => {
752
+ let ident: Box < str > = String :: from_utf8_lossy ( & attr. value ) . into ( ) ;
753
+ self . spectrum_data_processing_ref = Some ( ident) ;
754
+ }
710
755
_ => { }
711
756
} ,
712
757
Err ( msg) => {
@@ -799,6 +844,38 @@ impl<C: CentroidLike + BuildFromArrayMap, D: DeconvolutedCentroidLike + BuildFro
799
844
return Ok ( MzMLParserState :: BinaryDataArrayList ) ;
800
845
}
801
846
b"binaryDataArray" => {
847
+ let mut dp_set = false ;
848
+ for attr_parsed in event. attributes ( ) {
849
+ match attr_parsed {
850
+ Ok ( attr) => {
851
+ match attr. key . as_ref ( ) {
852
+ b"dataProcessingRef" => {
853
+ match attr. unescape_value ( ) {
854
+ Ok ( v) => {
855
+ self . current_array . set_data_processing_reference ( Some ( v. into ( ) ) ) ;
856
+ dp_set = true ;
857
+ break ;
858
+ } ,
859
+ Err ( msg) => return Err ( self . handle_xml_error ( msg. into ( ) , state) )
860
+ }
861
+ }
862
+ _ => { }
863
+ }
864
+ } ,
865
+ Err ( msg) => {
866
+ return Err ( self . handle_xml_error ( msg. into ( ) , state) ) ;
867
+ } ,
868
+ }
869
+ }
870
+ if !dp_set {
871
+ if let Some ( dp_ref) = self . spectrum_data_processing_ref . as_ref ( ) {
872
+ self . current_array . set_data_processing_reference ( Some ( dp_ref. clone ( ) ) ) ;
873
+ }
874
+ else if let Some ( dp_ref) = self . run_level_data_processing . as_ref ( ) {
875
+ self . current_array . set_data_processing_reference ( Some ( dp_ref. clone ( ) ) ) ;
876
+ }
877
+ }
878
+
802
879
return Ok ( MzMLParserState :: BinaryDataArray ) ;
803
880
}
804
881
b"binary" => {
@@ -1317,6 +1394,7 @@ impl<
1317
1394
let mut reader = Reader :: from_reader ( & mut self . handle ) ;
1318
1395
reader. trim_text ( true ) ;
1319
1396
accumulator = accumulator. borrow_instrument_configuration ( & mut self . instrument_id_map ) ;
1397
+ accumulator. set_run_data_processing ( self . run . default_data_processing_id . clone ( ) . map ( |v| v. into_boxed_str ( ) ) ) ;
1320
1398
let mut offset: usize = 0 ;
1321
1399
1322
1400
macro_rules! err_state {
0 commit comments