OpenMS  2.5.0
OnDiscMSExperiment.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2020.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Hannes Roest $
32 // $Authors: Hannes Roest $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
38 
44 
45 
46 #include <vector>
47 #include <algorithm>
48 #include <limits>
49 
50 #include <boost/shared_ptr.hpp>
51 
52 namespace OpenMS
53 {
68  class OPENMS_DLLAPI OnDiscMSExperiment
69  {
70 
72  typedef Peak1D PeakT;
73 
74 public:
75 
82 
92  bool openFile(const String& filename, bool skipMetaData = false)
93  {
94  filename_ = filename;
95  indexed_mzml_file_.openFile(filename);
96  if (filename != "" && !skipMetaData)
97  {
98  loadMetaData_(filename);
99  }
100  return indexed_mzml_file_.getParsingSuccess();
101  }
102 
105  filename_(source.filename_),
106  indexed_mzml_file_(source.indexed_mzml_file_),
107  meta_ms_experiment_(source.meta_ms_experiment_)
108  {
109  }
110 
118  bool operator==(const OnDiscMSExperiment& rhs) const
119  {
120  if (meta_ms_experiment_ == nullptr || rhs.meta_ms_experiment_ == nullptr)
121  {
122  return filename_ == rhs.filename_ &&
123  meta_ms_experiment_ == rhs.meta_ms_experiment_;
124  }
125 
126  // check if file and meta information is the same
127  return filename_ == rhs.filename_ &&
128  (*meta_ms_experiment_) == (*rhs.meta_ms_experiment_);
129  // do not check if indexed_mzml_file_ is equal -> they have the same filename...
130  }
131 
133  bool operator!=(const OnDiscMSExperiment& rhs) const
134  {
135  return !(operator==(rhs));
136  }
137 
144  bool isSortedByRT() const
145  {
146  if (!meta_ms_experiment_) return false;
147 
148  return meta_ms_experiment_->isSorted(false);
149  }
150 
152  inline Size size() const
153  {
154  return getNrSpectra();
155  }
156 
158  inline bool empty() const
159  {
160  return indexed_mzml_file_.getNrSpectra() == 0;
161  }
162 
164  inline Size getNrSpectra() const
165  {
166  return indexed_mzml_file_.getNrSpectra();
167  }
168 
170  inline Size getNrChromatograms() const
171  {
172  return indexed_mzml_file_.getNrChromatograms();
173  }
174 
176  boost::shared_ptr<const ExperimentalSettings> getExperimentalSettings() const
177  {
178  return boost::static_pointer_cast<const ExperimentalSettings>(meta_ms_experiment_);
179  }
180 
181  boost::shared_ptr<PeakMap> getMetaData() const
182  {
183  return meta_ms_experiment_;
184  }
185 
188  {
189  return getSpectrum(n);
190  }
191 
198  {
199  if (!meta_ms_experiment_) return indexed_mzml_file_.getMSSpectrumById(int(id));
200 
201  MSSpectrum spectrum(meta_ms_experiment_->operator[](id));
202  indexed_mzml_file_.getMSSpectrumById(int(id), spectrum);
203  return spectrum;
204  }
205 
210  {
211  return indexed_mzml_file_.getSpectrumById(id);
212  }
213 
220  {
221  if (!meta_ms_experiment_) return indexed_mzml_file_.getMSChromatogramById(int(id));
222 
223  MSChromatogram chromatogram(meta_ms_experiment_->getChromatogram(id));
224  indexed_mzml_file_.getMSChromatogramById(int(id), chromatogram);
225  return chromatogram;
226  }
227 
233  MSChromatogram getChromatogramByNativeId(const std::string& id);
234 
240  MSSpectrum getSpectrumByNativeId(const std::string& id);
241 
246  {
247  return indexed_mzml_file_.getChromatogramById(id);
248  }
249 
251  void setSkipXMLChecks(bool skip)
252  {
253  indexed_mzml_file_.setSkipXMLChecks(skip);
254  }
255 
256 private:
257 
259  OnDiscMSExperiment& operator=(const OnDiscMSExperiment& /* source */);
260 
261  void loadMetaData_(const String& filename);
262 
263  MSChromatogram getMetaChromatogramById_(const std::string& id);
264 
265  MSSpectrum getMetaSpectrumById_(const std::string& id);
266 
267 protected:
268 
274  boost::shared_ptr<PeakMap> meta_ms_experiment_;
276  std::unordered_map< std::string, Size > chromatograms_native_ids_;
278  std::unordered_map< std::string, Size > spectra_native_ids_;
279  };
280 
282 
283 } // namespace OpenMS
284 
285 
OpenMS::OnDiscMSExperiment::getSpectrumById
OpenMS::Interfaces::SpectrumPtr getSpectrumById(Size id)
returns a single spectrum
Definition: OnDiscMSExperiment.h:209
OpenMS::OnDiscMSExperiment::ChromatogramPeakT
ChromatogramPeak ChromatogramPeakT
Definition: OnDiscMSExperiment.h:71
OpenMS::Interfaces::SpectrumPtr
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:236
OpenMS::OnDiscMSExperiment::filename_
String filename_
The filename of the underlying data file.
Definition: OnDiscMSExperiment.h:270
DataStructures.h
OpenMS::OnDiscMSExperiment::getChromatogramById
OpenMS::Interfaces::ChromatogramPtr getChromatogramById(Size id)
returns a single chromatogram
Definition: OnDiscMSExperiment.h:245
OpenMS::OnDiscMSExperiment::OnDiscMSExperiment
OnDiscMSExperiment()
Constructor.
Definition: OnDiscMSExperiment.h:81
OpenMS::OnDiscMSExperiment::meta_ms_experiment_
boost::shared_ptr< PeakMap > meta_ms_experiment_
The meta-data.
Definition: OnDiscMSExperiment.h:274
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::OnDiscMSExperiment::empty
bool empty() const
returns whether spectra are empty
Definition: OnDiscMSExperiment.h:158
OpenMS::OnDiscMSExperiment::operator!=
bool operator!=(const OnDiscMSExperiment &rhs) const
Inequality operator.
Definition: OnDiscMSExperiment.h:133
OpenMS::OnDiscPeakMap
OpenMS::OnDiscMSExperiment OnDiscPeakMap
Definition: OnDiscMSExperiment.h:281
OpenMS::OnDiscMSExperiment::OnDiscMSExperiment
OnDiscMSExperiment(const OnDiscMSExperiment &source)
Copy constructor.
Definition: OnDiscMSExperiment.h:104
OpenMS::Interfaces::ChromatogramPtr
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:156
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::OnDiscMSExperiment::getNrSpectra
Size getNrSpectra() const
get the total number of spectra available
Definition: OnDiscMSExperiment.h:164
OpenMS::ChromatogramPeak
A 1-dimensional raw data point or peak for chromatograms.
Definition: ChromatogramPeak.h:54
OpenMS::OnDiscMSExperiment
Representation of a mass spectrometry experiment on disk.
Definition: OnDiscMSExperiment.h:68
OpenMS::OnDiscMSExperiment::setSkipXMLChecks
void setSkipXMLChecks(bool skip)
sets whether to skip some XML checks and be fast instead
Definition: OnDiscMSExperiment.h:251
OpenMS::Peak1D
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:54
OpenMS::OnDiscMSExperiment::getNrChromatograms
Size getNrChromatograms() const
get the total number of chromatograms available
Definition: OnDiscMSExperiment.h:170
OpenMS::OnDiscMSExperiment::operator[]
MSSpectrum operator[](Size n)
alias for getSpectrum
Definition: OnDiscMSExperiment.h:187
ExperimentalSettings.h
OpenMS::OnDiscMSExperiment::openFile
bool openFile(const String &filename, bool skipMetaData=false)
Open a specific file on disk.
Definition: OnDiscMSExperiment.h:92
OpenMS::OnDiscMSExperiment::PeakT
Peak1D PeakT
Definition: OnDiscMSExperiment.h:72
OpenMS::OnDiscMSExperiment::chromatograms_native_ids_
std::unordered_map< std::string, Size > chromatograms_native_ids_
Mapping of chromatogram native ids to offsets.
Definition: OnDiscMSExperiment.h:276
MSExperiment.h
OpenMS::OnDiscMSExperiment::isSortedByRT
bool isSortedByRT() const
Checks if all spectra are sorted with respect to ascending RT.
Definition: OnDiscMSExperiment.h:144
KDTree::operator==
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806
MSChromatogram.h
OpenMS::MSChromatogram
The representation of a chromatogram.
Definition: MSChromatogram.h:54
OpenMS::OnDiscMSExperiment::getChromatogram
MSChromatogram getChromatogram(Size id)
returns a single chromatogram
Definition: OnDiscMSExperiment.h:219
OpenMS::OnDiscMSExperiment::getExperimentalSettings
boost::shared_ptr< const ExperimentalSettings > getExperimentalSettings() const
returns the meta information of this experiment (const access)
Definition: OnDiscMSExperiment.h:176
OpenMS::OnDiscMSExperiment::size
Size size() const
alias for getNrSpectra
Definition: OnDiscMSExperiment.h:152
OpenMS::OnDiscMSExperiment::operator==
bool operator==(const OnDiscMSExperiment &rhs) const
Equality operator.
Definition: OnDiscMSExperiment.h:118
OpenMS::OnDiscMSExperiment::getMetaData
boost::shared_ptr< PeakMap > getMetaData() const
Definition: OnDiscMSExperiment.h:181
IndexedMzMLHandler.h
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
OpenMS::OnDiscMSExperiment::getSpectrum
MSSpectrum getSpectrum(Size id)
returns a single spectrum
Definition: OnDiscMSExperiment.h:197
OpenMS::OnDiscMSExperiment::spectra_native_ids_
std::unordered_map< std::string, Size > spectra_native_ids_
Mapping of spectra native ids to offsets.
Definition: OnDiscMSExperiment.h:278
OpenMS::OnDiscMSExperiment::indexed_mzml_file_
Internal::IndexedMzMLHandler indexed_mzml_file_
The index of the underlying data file.
Definition: OnDiscMSExperiment.h:272
MSSpectrum.h
OpenMS::Internal::IndexedMzMLHandler
A low-level class to read an indexedmzML file.
Definition: IndexedMzMLHandler.h:79