imzml 0.1.3

A library for reading the mass spectrometry (imaging) formats mzML and imzML.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
use std::{
    collections::VecDeque,
    fmt::Display,
    fs::File,
    io::{BufRead, BufReader, Read, Seek, Write},
    path::{Path, PathBuf},
    sync::{Arc, Mutex},
};

use hashbrown::HashMap;
use quick_xml::{
    events::{BytesStart, Event},
    Decoder, Error, Reader,
};
use serde::{Deserialize, Serialize};

use crate::{
    error::{FatalParseError, ParseError},
    obo::{Ontology, MZML_ONTOLOGY},
    IndexedMzML, MzML, Representation, SpectrumAccess, SpectrumAccessIterator, BUFFER_SIZE,
};

use self::{
    attributes::{AttributeDefinition, AttributeType, AttributeValue},
    data_processing::{DataProcessing, DataProcessingRef},
    filedescription::{SourceFile, SourceFileRef},
    instrument::{InstrumentConfiguration, InstrumentConfigurationRef},
    referenceableparamgroup::{ReferenceableParamGroup, ReferenceableParamGroupRef},
    sample::Sample,
    scan_settings::ScanSettingsList,
    software::{Software, SoftwareRef},
    writer::Writer,
};

pub(crate) mod attributes;
pub(crate) mod binarydataarray;
pub(crate) mod cvlist;
/// Metadata in the form of cvParam entries (linked to ontology)
pub mod cvparam;
/// Information on data processing
pub mod data_processing;
/// Describes the file (e.g. style of data, source raw files used to create it, ...)
pub mod filedescription;
/// Provide instrument configuration information
pub mod instrument;
/// Handling mzML tag
pub mod mzml;
//mod parser;
/// Sets of cvParams which can be referenced to reduce overhead
pub mod referenceableparamgroup;
/// Captures information about the experiment (run) and data (e.g. list of spectra)
pub mod run;
pub(crate) mod sample;
pub(crate) mod scan;
/// Describes the settings used to acquire the data.
pub mod scan_settings;
pub(crate) mod software;
pub(crate) mod spectrum;

/// Writing .imzML files
pub mod writer;
//pub use writer::*;

/// Trait describing any tag present in an .mzML or .imzML file
pub trait MzMLTag {
    /// Returns the tag being described
    fn tag() -> Tag;

    /// Parse the start tag (capture any attributes, noting any missing or extra as errors).
    fn parse_start_tag<B: BufRead>(
        parser: &mut MzMLReader<B>,
        start_event: &BytesStart,
    ) -> Result<Option<Self>, FatalParseError>
    where
        Self: std::marker::Sized;

    /// Parse the child tags (if necessary). This is only called if there are expected to be child tags.
    fn parse_xml<B: BufRead>(
        &mut self,
        parser: &mut MzMLReader<B>,
        buffer: &mut Vec<u8>,
    ) -> Result<(), FatalParseError>;

    /// Write the tag in XML format.
    fn write_xml<W: Write>(&self, writer: &mut Writer<W>) -> Result<(), quick_xml::Error>;
}

/// DataReader enables reading the binary data stored in an mzML, as well as providing access to the metadata stored in the XML part.
pub struct DataReader<D: Read + Seek> {
    mzml: MzML,
    data_reader: Arc<Mutex<D>>,

    errors: VecDeque<ParseError>,
}

impl<D: Read + Seek> DataReader<D> {
    /// Create a new parser from the supplied reader, using the default mzML ontology
    pub fn new(mzml: MzML, data: D) -> Self {
        DataReader {
            mzml,
            data_reader: Arc::new(Mutex::new(data)),
            errors: VecDeque::new(),
        }
    }

    /// Create a new parser from the supplied reader and ontology
    pub fn with_ontology<B: BufRead>(
        header: B,
        data: D,
        ontology: Ontology,
    ) -> Result<Self, FatalParseError> {
        let reader = MzMLReader::with_ontology(header, ontology)?;

        let mzml = reader.mzml.ok_or_else(|| {
            FatalParseError::UnexpectedError("No MzML generated when parsing".to_string())
        })?;

        Ok(DataReader {
            mzml,
            data_reader: Arc::new(Mutex::new(data)),
            errors: reader.errors,
        })
    }

    /// Returns reference to the `MzML` (metadata) information
    pub fn mzml(&self) -> &MzML {
        &self.mzml
    }

    /// Creates and returns an iterator over all spectra in the image.
    pub fn spectra(&self) -> SpectrumAccessIterator<D> {
        //impl Iterator<Item = DiskSpectrumAccess<D>> + '_ {
        SpectrumAccessIterator::new(
            self.data_reader.clone(),
            self.mzml().spectrum_list().unwrap(),
        )
    }

    /// Returns `SpectrumAccess` to the spectrum at the specified index (or None) if none present
    pub fn spectrum(&self, index: usize) -> Option<SpectrumAccess<D>> {
        if let Some(spectrum) = self.mzml().spectrum(index) {
            return Some(SpectrumAccess::new(
                self.data_reader.clone(),
                spectrum.clone(),
            ));
        }

        None
    }

    /// Return errors found during parsing
    pub fn errors(&self) -> &VecDeque<ParseError> {
        &self.errors
    }

    /// Returns mutable reference to error list
    pub fn errors_mut(&mut self) -> &mut VecDeque<ParseError> {
        &mut self.errors
    }
}

impl DataReader<BufReader<File>> {
    /// Create a DataReader from a path. This assumes that the ibd file has the exact same name and the extension '.ibd'
    pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, FatalParseError> {
        Self::from_path_with_ontology(path, MZML_ONTOLOGY.clone())
    }

    /// Create an ImzMLParser from a path, using the supplied ontology to map CV params.
    /// This assumes that the ibd file has the exact same name and the extension '.ibd'
    pub fn from_path_with_ontology<P: AsRef<Path>>(
        path: P,
        ontology: Ontology,
    ) -> Result<Self, FatalParseError> {
        let path = PathBuf::from(path.as_ref());
        let file = File::open(&path)?;
        let data_file = File::open(&path)?;

        Self::with_ontology(BufReader::new(file), BufReader::new(data_file), ontology)
    }
}

/// MzMLParser parses an mzML file (or the imzML part of an imzML file)
pub struct MzMLReader<B: BufRead> {
    reader: Reader<B>,

    decoder: Decoder,
    ontology: Ontology,
    errors: VecDeque<ParseError>,

    with_attribute_checks: bool,
    ignore_uncommon_tags: bool,

    breadcrumbs: VecDeque<(Tag, Option<String>)>,

    source_file_list: Vec<Arc<SourceFile>>,
    referenceable_param_group_list: Vec<Arc<ReferenceableParamGroup>>,
    sample_list: Vec<Arc<Sample>>,
    software_list: Vec<Arc<Software>>,
    scan_settings_list: ScanSettingsList,
    instrument_list: Vec<Arc<InstrumentConfiguration>>,
    data_processing_list: Vec<Arc<DataProcessing>>,

    representation: Option<Representation>,

    mzml: Option<MzML>,
}

impl<B: BufRead> MzMLReader<B> {
    /// Turn the `MzMLReader` into a `DataReader` to provide access to the data, using the reader specified
    pub fn with_data<R: Read + Seek>(self, data: R) -> Option<DataReader<R>> {
        Some(DataReader {
            mzml: self.mzml?,
            data_reader: Arc::new(Mutex::new(data)),
            errors: VecDeque::new(),
        })
    }
}

impl<B: BufRead> From<MzMLReader<B>> for MzML {
    fn from(mut parser: MzMLReader<B>) -> Self {
        parser.mzml.take().unwrap()
    }
}

impl<B: BufRead + Seek> From<MzMLReader<B>> for DataReader<B> {
    fn from(reader: MzMLReader<B>) -> Self {
        DataReader {
            mzml: reader.mzml.unwrap(),
            data_reader: Arc::new(Mutex::new(reader.reader.into_inner())),
            errors: reader.errors,
        }
    }
}

impl MzMLReader<BufReader<File>> {
    /// Create an MzMLReader from a path. This assumes that the ibd file has the exact same name and the extension '.ibd'
    pub fn from_path<P: AsRef<Path>>(
        path: P,
    ) -> Result<MzMLReader<BufReader<File>>, FatalParseError> {
        Self::from_path_with_ontology(path, MZML_ONTOLOGY.clone())
    }

    /// Create an MzMLReader from a path, using the supplied ontology to map CV params.
    /// This assumes that the ibd file has the exact same name and the extension '.ibd'
    pub fn from_path_with_ontology<P: AsRef<Path>>(
        path: P,
        ontology: Ontology,
    ) -> Result<MzMLReader<BufReader<File>>, FatalParseError> {
        let path = PathBuf::from(path.as_ref());
        let file = File::open(&path)?;

        Self::with_ontology(BufReader::new(file), ontology)
    }
}

impl<B: BufRead> MzMLReader<B> {
    /// Create a new parser from the supplied reader, using the default mzML ontology
    pub fn new(reader: B) -> Result<Self, FatalParseError> {
        Self::with_ontology(reader, MZML_ONTOLOGY.clone())
    }

    /// Create a new parser from the supplied reader and ontology
    pub fn with_ontology(reader: B, ontology: Ontology) -> Result<Self, FatalParseError> {
        let mut reader = quick_xml::Reader::from_reader(reader);
        reader.trim_text(true);

        let mut parser = MzMLReader {
            decoder: reader.decoder(),
            reader,
            ontology,
            errors: VecDeque::new(),
            with_attribute_checks: false,
            ignore_uncommon_tags: false,
            source_file_list: Vec::new(),
            referenceable_param_group_list: Vec::new(),
            sample_list: Vec::new(),
            software_list: Vec::new(),
            scan_settings_list: ScanSettingsList::new(),
            instrument_list: Vec::new(),
            data_processing_list: Vec::new(),

            breadcrumbs: VecDeque::new(),
            representation: None,

            mzml: None,
        };

        let mut buffer = Vec::with_capacity(BUFFER_SIZE);

        loop {
            // Skip comments and declarations
            let next_event = parser.next(&mut buffer)?;

            match next_event {
                Event::Comment(_) => {}
                Event::Decl(_) => {}
                Event::DocType(_) => {}
                Event::Text(_) => {}
                Event::Start(start_event) => match start_event.name().as_ref() {
                    b"mzML" => {
                        // We can unwrap here as this should never return None
                        let mut mzml = MzML::parse_start_tag(&mut parser, &start_event)?.unwrap();

                        mzml.parse_xml(&mut parser, &mut buffer)?;

                        parser.mzml = Some(mzml);

                        break;
                    }
                    b"indexedmzML" => {
                        // We can unwrap here as this should never return None
                        let mut indexed_mzml =
                            IndexedMzML::parse_start_tag(&mut parser, &start_event)?.unwrap();

                        indexed_mzml.parse_xml(&mut parser, &mut buffer)?;

                        parser.mzml = Some(indexed_mzml.into());

                        break;
                    }
                    _ => {
                        return Err(FatalParseError::UnexpectedTag(format!("{:?}", start_event)));
                    }
                },
                _ => {
                    return Err(FatalParseError::UnexpectedEvent(format!(
                        "{:?}",
                        next_event
                    )));
                    // panic!("Unexpected event: {:?}", next_event);
                }
            }
        }

        Ok(parser)
    }

    /// Returns the ontology used to describe controlled vocabulary when parsing
    pub fn ontology(&self) -> &Ontology {
        &self.ontology
    }

    pub(crate) fn last_tag(&self) -> &Tag {
        &self.breadcrumbs.back().unwrap().0
    }

    /// Returns the
    pub fn mzml(&self) -> Option<&MzML> {
        self.mzml.as_ref()
    }

    /// Clone the MzML instance that has been parsed
    pub fn clone_mzml(&self) -> Option<MzML> {
        self.mzml.clone()
    }

    // pub fn coordinates(&self) -> Vec<Coordinate> {

    //     if let Some(mzml) = &self.mzml {
    //     let coordinates = Vec::with_capacity(mzml.num_spectra());
    //         for i in 0..mzml.num_spectra() {
    //             let spectrum = mzml.spectrum(i).unwrap();
    //             spectrum.x_position()
    //         }

    //         coordinates
    //     } else {
    //         Vec::new()
    //     }
    // }

    pub(crate) fn source_file_ref(&self, id: &[u8]) -> Option<SourceFileRef> {
        let id = self.decoder.decode(id).unwrap();

        for source_file in &self.source_file_list {
            if source_file.id() == id {
                return Some(SourceFileRef::Ref(source_file.clone()));
            }
        }

        None
    }

    pub(crate) fn referenceable_param_group_ref(
        &self,
        id: &[u8],
    ) -> Option<ReferenceableParamGroupRef> {
        let id = self.decoder.decode(id).unwrap();

        for referenceable_param_group in &self.referenceable_param_group_list {
            if referenceable_param_group.id() == id {
                return Some(ReferenceableParamGroupRef::Ref(
                    referenceable_param_group.clone(),
                ));
            }
        }

        None
    }

    pub(crate) fn software_ref(&self, id: &[u8]) -> Option<SoftwareRef> {
        let id = self.decoder.decode(id).unwrap();

        for software_ref in &self.software_list {
            if software_ref.id() == id {
                return Some(SoftwareRef::Ref(software_ref.clone()));
            }
        }

        None
    }

    pub(crate) fn instrument_configuration_ref(
        &self,
        id: &[u8],
    ) -> Option<InstrumentConfigurationRef> {
        let id = self.decoder.decode(id).unwrap();

        for instrument in &self.instrument_list {
            if instrument.id() == id {
                return Some(InstrumentConfigurationRef::Ref(instrument.clone()));
            }
        }

        None
    }

    pub(crate) fn data_processing_ref(&self, id: &[u8]) -> Option<DataProcessingRef> {
        let id = self.decoder.decode(id).unwrap();

        for data_processing in &self.data_processing_list {
            if data_processing.id() == id {
                return Some(DataProcessingRef::Ref(data_processing.clone()));
            }
        }

        None
    }

    /// Return errors found during parsing
    pub fn errors(&self) -> &VecDeque<ParseError> {
        &self.errors
    }

    /// Returns mutable reference to error list
    pub fn errors_mut(&mut self) -> &mut VecDeque<ParseError> {
        &mut self.errors
    }

    /*pub fn peek_next(&mut self, buffer: &mut Vec<u8>) -> Result<&Event, Error> {
        let event = self.reader.read_event(buffer)?;

        self.current_event = Some(event.into_owned());

        Ok(self.current_event.as_ref().unwrap())
    }*/

    #[inline]
    pub(crate) fn next<'b>(&mut self, buffer: &'b mut Vec<u8>) -> Result<Event<'b>, Error> {
        self.reader.read_event_into(buffer)
    }

    pub(crate) fn process_attributes<'b>(
        &mut self,
        //parser: &mut Parser<'a, B>,
        tag: Tag,
        allowed: &'static HashMap<&'static [u8], AttributeDefinition>,
        e: &'b BytesStart<'b>,
    ) -> Result<HashMap<&'static str, AttributeValue<'b>>, FatalParseError> {
        let mut attributes = HashMap::with_capacity(allowed.capacity());

        for att in e.attributes().with_checks(self.with_attribute_checks) {
            match att {
                Ok(att) => {
                    let key = att.key.as_ref();

                    if let Some(definition) = allowed.get(key) {
                        match self.parse_string(tag, &att.value) {
                            Some(value) => {
                                let attribute_value = match definition.attribute_type {
                                    AttributeType::Integer => {
                                        let value = value.parse();
                                        match value {
                                            Ok(value) => AttributeValue::Integer(value),
                                            Err(error) => {
                                                self.errors
                                                    .push_back(ParseError::IntError((tag, error)));
                                                AttributeValue::String(att.value)
                                            }
                                        }
                                    }
                                    AttributeType::String => AttributeValue::String(att.value),
                                };

                                attributes.insert(definition.name.as_str(), attribute_value);
                            }
                            None => {
                                self.errors.push_back(ParseError::MissingAttributeValue((
                                    tag,
                                    definition.name.clone(),
                                    definition.attribute_type,
                                )));
                            }
                        }
                    } else {
                        self.errors.push_back(ParseError::UnexpectedAttribute((
                            tag,
                            std::str::from_utf8(att.key.as_ref())?.to_string(),
                        )));
                    }
                }
                Err(error) => {
                    self.errors
                        .push_back(ParseError::XMLError((tag, error.into())));
                }
            }
        }

        for (_name, definition) in allowed {
            if definition.required && !attributes.contains_key(definition.name.as_str()) {
                self.errors.push_back(ParseError::MissingAttribute((
                    tag,
                    definition.name.to_string(),
                )));
            }
        }

        Ok(attributes)
    }

    #[inline]
    fn parse_string<'b>(&mut self, tag: Tag, value: &'b [u8]) -> Option<&'b str> {
        match std::str::from_utf8(value) {
            Ok(value) => Some(value),
            Err(error) => {
                self.errors.push_back(ParseError::Utf8Error((tag, error)));

                None
            }
        }
    }
}

/// Enum describing the imzML tag.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum Tag {
    /// <indexedMzML>
    IndexedMzML,
    /// <indexList>
    IndexList,
    /// <mzML>
    MzML,
    /// <cvList>
    CVList,
    /// <cv>
    CV,
    /// <cvParam>
    CVParam,
    /// <userParam>
    UserParam,
    /// <fileDescription>
    FileDescription,
    /// <fileContent>
    FileContent,
    /// <sourceFileList>
    SourceFileList,
    /// <sourceFile>
    SourceFile,
    /// <sourceFileRefList>
    SourceFileRefList,
    /// <sourceFileRef>
    SourceFileRef,
    /// <contact>
    Contact,
    /// <referanceableParamGroupList>
    RefParamGroupList,
    /// <referenceableParamGroup>
    RefParamGroup,
    /// <referenceableParamGroupRef>
    RefParamGroupRef,
    /// <sampleList>
    SampleList,
    /// <sample>
    Sample,
    /// <softwareList>
    SoftwareList,
    /// <software>
    Software,
    /// <softwareRef>
    SoftwareRef,
    /// <scanSettingsList>
    ScanSettingsList,
    /// <scanSettings>
    ScanSettings,
    /// <instrumentConfigurationList>
    InstrumentConfigurationList,
    /// <instrumentConfiguration>
    InstrumentConfiguration,
    /// <componentList>
    ComponentList,
    /// General tag for either <source>, <analyser> or <detector>
    Component,
    /// <source>
    Source,
    /// <analyser>
    Analyser,
    /// <detector>
    Detector,
    /// <dataProcessingList>
    DataProcessingList,
    /// <dataProcessing>
    DataProcessing,
    /// <processingMethod>
    ProcessingMethod,
    /// <run>
    Run,
    /// <spectrumList>
    SpectrumList,
    /// <spectrum>
    Spectrum,
    /// <chromatogramList>
    ChromatogramList,
    /// <chromatogram>
    Chromatogram,
    /// <scanList>
    ScanList,
    /// <precursorList>
    PrecursorList,
    /// <precursor>
    Precursor,
    /// <product>
    Product,
    /// <isolationWindow>
    IsolationWindow,
    /// <selectedIonList>
    SelectedIonList,
    /// <selectedIon>
    SelectedIon,
    /// <activation>
    Activation,
    /// <scan>
    Scan,
    /// <scanWindowList>
    ScanWindowList,
    /// <scanWindow>
    ScanWindow,
    /// <binaryDataArrayList>
    BinaryDataArrayList,
    /// <binaryDataArray>
    BinaryDataArray,
    /// <binary>
    Binary,
}

impl Display for Tag {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Tag::IndexedMzML => write!(f, "indexedMzML"),
            Tag::IndexList => write!(f, "indexList"),
            Tag::MzML => write!(f, "mzML"),
            Tag::CVList => write!(f, "cvList"),
            Tag::CV => write!(f, "cv"),
            Tag::CVParam => write!(f, "cvParam"),
            Tag::UserParam => write!(f, "userParam"),
            Tag::FileDescription => write!(f, "fileDescription"),
            Tag::FileContent => write!(f, "fileContent"),
            Tag::SourceFileList => write!(f, "sourceFileList"),
            Tag::SourceFile => write!(f, "sourceFile"),
            Tag::SourceFileRefList => write!(f, "sourceFileRefList"),
            Tag::SourceFileRef => write!(f, "sourceFileRef"),
            Tag::Contact => write!(f, "contact"),
            Tag::RefParamGroupList => write!(f, "referenceableParamGroupList"),
            Tag::RefParamGroup => write!(f, "referenceableParamGroup"),
            Tag::RefParamGroupRef => write!(f, "referenceableParamGroupRef"),
            Tag::SampleList => write!(f, "sampleList"),
            Tag::Sample => write!(f, "sample"),
            Tag::SoftwareList => write!(f, "softwareList"),
            Tag::Software => write!(f, "software"),
            Tag::SoftwareRef => write!(f, "softwareRef"),
            Tag::ScanSettingsList => write!(f, "scanSettingsList"),
            Tag::ScanSettings => write!(f, "scanSettings"),
            Tag::InstrumentConfigurationList => write!(f, "instrumentConfigurationList"),
            Tag::InstrumentConfiguration => write!(f, "instrumentConfiguration"),
            Tag::ComponentList => write!(f, "componentList"),
            Tag::Component => write!(f, "source/analyzer/detector"),
            Tag::Source => write!(f, "source"),
            Tag::Analyser => write!(f, "analyzer"),
            Tag::Detector => write!(f, "detector"),
            Tag::DataProcessingList => write!(f, "dataProcessingList"),
            Tag::DataProcessing => write!(f, "dataProcessing"),
            Tag::ProcessingMethod => write!(f, "processingMethod"),
            Tag::Run => write!(f, "run"),
            Tag::SpectrumList => write!(f, "spectrumList"),
            Tag::Spectrum => write!(f, "spectrum"),
            Tag::ChromatogramList => write!(f, "chromatogramList"),
            Tag::Chromatogram => write!(f, "chromatogram"),
            Tag::ScanList => write!(f, "scanList"),
            Tag::PrecursorList => write!(f, "precursorList"),
            Tag::Precursor => write!(f, "precursor"),
            Tag::Product => write!(f, "product"),
            Tag::IsolationWindow => write!(f, "isolationWindow"),
            Tag::SelectedIonList => write!(f, "selectedIonList"),
            Tag::SelectedIon => write!(f, "selectedIon"),
            Tag::Activation => write!(f, "activation"),
            Tag::Scan => write!(f, "scan"),
            Tag::ScanWindowList => write!(f, "scanWindowList"),
            Tag::ScanWindow => write!(f, "scanWindow"),
            Tag::BinaryDataArrayList => write!(f, "binaryDataArrayList"),
            Tag::BinaryDataArray => write!(f, "binaryDataArray"),
            Tag::Binary => write!(f, "binary"),
        }
    }
}