OpenMS
OnDiscMSExperiment.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Hannes Roest $
6 // $Authors: Hannes Roest $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
12 
18 
19 #include <vector>
20 #include <limits>
21 
22 #include <boost/shared_ptr.hpp>
23 
24 namespace OpenMS
25 {
40  class OPENMS_DLLAPI OnDiscMSExperiment
41  {
42 
44  typedef Peak1D PeakT;
45 
46 public:
47 
53  OnDiscMSExperiment() = default;
54 
64  bool openFile(const String& filename, bool skipMetaData = false);
65 
68  filename_(source.filename_),
69  indexed_mzml_file_(source.indexed_mzml_file_),
70  meta_ms_experiment_(source.meta_ms_experiment_)
71  {
72  }
73 
81  bool operator==(const OnDiscMSExperiment& rhs) const
82  {
83  if (meta_ms_experiment_ == nullptr || rhs.meta_ms_experiment_ == nullptr)
84  {
85  return filename_ == rhs.filename_ &&
86  meta_ms_experiment_ == rhs.meta_ms_experiment_;
87  }
88 
89  // check if file and meta information is the same
90  return filename_ == rhs.filename_ &&
91  (*meta_ms_experiment_) == (*rhs.meta_ms_experiment_);
92  // do not check if indexed_mzml_file_ is equal -> they have the same filename...
93  }
94 
96  bool operator!=(const OnDiscMSExperiment& rhs) const
97  {
98  return !(operator==(rhs));
99  }
100 
107  bool isSortedByRT() const
108  {
109  if (!meta_ms_experiment_) return false;
110 
111  return meta_ms_experiment_->isSorted(false);
112  }
113 
115  inline Size size() const
116  {
117  return getNrSpectra();
118  }
119 
121  inline bool empty() const
122  {
123  return getNrSpectra() == 0;
124  }
125 
127  inline Size getNrSpectra() const
128  {
129  return indexed_mzml_file_.getNrSpectra();
130  }
131 
133  inline Size getNrChromatograms() const
134  {
135  return indexed_mzml_file_.getNrChromatograms();
136  }
137 
139  boost::shared_ptr<const ExperimentalSettings> getExperimentalSettings() const
140  {
141  return boost::static_pointer_cast<const ExperimentalSettings>(meta_ms_experiment_);
142  }
143 
144  boost::shared_ptr<PeakMap> getMetaData() const
145  {
146  return meta_ms_experiment_;
147  }
148 
151  {
152  return getSpectrum(n);
153  }
154 
161  {
162  if (!meta_ms_experiment_) return indexed_mzml_file_.getMSSpectrumById(int(id));
163 
164  MSSpectrum spectrum(meta_ms_experiment_->operator[](id));
165  indexed_mzml_file_.getMSSpectrumById(int(id), spectrum);
166  return spectrum;
167  }
168 
173  {
174  return indexed_mzml_file_.getSpectrumById((int)id);
175  }
176 
183  {
184  if (!meta_ms_experiment_) return indexed_mzml_file_.getMSChromatogramById(int(id));
185 
186  MSChromatogram chromatogram(meta_ms_experiment_->getChromatogram(id));
187  indexed_mzml_file_.getMSChromatogramById(int(id), chromatogram);
188  return chromatogram;
189  }
190 
197 
203  MSSpectrum getSpectrumByNativeId(const std::string& id);
204 
209 
211  void setSkipXMLChecks(bool skip);
212 
213 private:
214 
217 
218  void loadMetaData_(const String& filename);
219 
220  MSChromatogram getMetaChromatogramById_(const std::string& id);
221 
222  MSSpectrum getMetaSpectrumById_(const std::string& id);
223 
224 protected:
225 
231  boost::shared_ptr<PeakMap> meta_ms_experiment_;
233  std::unordered_map< std::string, Size > chromatograms_native_ids_;
235  std::unordered_map< std::string, Size > spectra_native_ids_;
236  };
237 
239 
240 } // namespace OpenMS
241 
242 
A 1-dimensional raw data point or peak for chromatograms.
Definition: ChromatogramPeak.h:28
A low-level class to read an indexedmzML file.
Definition: IndexedMzMLHandler.h:54
The representation of a chromatogram.
Definition: MSChromatogram.h:31
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
Representation of a mass spectrometry experiment on disk.
Definition: OnDiscMSExperiment.h:41
MSSpectrum getSpectrum(Size id)
returns a single spectrum
Definition: OnDiscMSExperiment.h:160
boost::shared_ptr< PeakMap > getMetaData() const
Definition: OnDiscMSExperiment.h:144
void setSkipXMLChecks(bool skip)
sets whether to skip some XML checks and be fast instead
MSSpectrum getMetaSpectrumById_(const std::string &id)
Internal::IndexedMzMLHandler indexed_mzml_file_
The index of the underlying data file.
Definition: OnDiscMSExperiment.h:229
OpenMS::Interfaces::SpectrumPtr getSpectrumById(Size id)
returns a single spectrum
Definition: OnDiscMSExperiment.h:172
bool operator!=(const OnDiscMSExperiment &rhs) const
Inequality operator.
Definition: OnDiscMSExperiment.h:96
OpenMS::Interfaces::ChromatogramPtr getChromatogramById(Size id)
returns a single chromatogram
Size getNrSpectra() const
get the total number of spectra available
Definition: OnDiscMSExperiment.h:127
bool isSortedByRT() const
Checks if all spectra are sorted with respect to ascending RT.
Definition: OnDiscMSExperiment.h:107
String filename_
The filename of the underlying data file.
Definition: OnDiscMSExperiment.h:227
void loadMetaData_(const String &filename)
OnDiscMSExperiment & operator=(const OnDiscMSExperiment &)
Private Assignment operator -> we cannot copy file streams in IndexedMzMLHandler.
bool empty() const
returns whether spectra are empty
Definition: OnDiscMSExperiment.h:121
Size getNrChromatograms() const
get the total number of chromatograms available
Definition: OnDiscMSExperiment.h:133
MSSpectrum operator[](Size n)
alias for getSpectrum
Definition: OnDiscMSExperiment.h:150
MSChromatogram getChromatogram(Size id)
returns a single chromatogram
Definition: OnDiscMSExperiment.h:182
bool operator==(const OnDiscMSExperiment &rhs) const
Equality operator.
Definition: OnDiscMSExperiment.h:81
Peak1D PeakT
Definition: OnDiscMSExperiment.h:44
bool openFile(const String &filename, bool skipMetaData=false)
Open a specific file on disk.
boost::shared_ptr< PeakMap > meta_ms_experiment_
The meta-data.
Definition: OnDiscMSExperiment.h:231
OnDiscMSExperiment()=default
Constructor.
MSChromatogram getChromatogramByNativeId(const std::string &id)
returns a single chromatogram
boost::shared_ptr< const ExperimentalSettings > getExperimentalSettings() const
returns the meta information of this experiment (const access)
Definition: OnDiscMSExperiment.h:139
ChromatogramPeak ChromatogramPeakT
Definition: OnDiscMSExperiment.h:43
std::unordered_map< std::string, Size > spectra_native_ids_
Mapping of spectra native ids to offsets.
Definition: OnDiscMSExperiment.h:235
Size size() const
alias for getNrSpectra
Definition: OnDiscMSExperiment.h:115
MSSpectrum getSpectrumByNativeId(const std::string &id)
returns a single spectrum
std::unordered_map< std::string, Size > chromatograms_native_ids_
Mapping of chromatogram native ids to offsets.
Definition: OnDiscMSExperiment.h:233
MSChromatogram getMetaChromatogramById_(const std::string &id)
OnDiscMSExperiment(const OnDiscMSExperiment &source)
Copy constructor.
Definition: OnDiscMSExperiment.h:67
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:28
A more convenient string class.
Definition: String.h:34
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:130
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:210
bool operator==(const IDBoostGraph::ProteinGroup &lhs, const IDBoostGraph::ProteinGroup &rhs)
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
OpenMS::OnDiscMSExperiment OnDiscPeakMap
Definition: IndexedMzMLFileLoader.h:16