OpenMS
Loading...
Searching...
No Matches
OnDiscMSExperiment.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- 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
13
20
21#include <vector>
22#include <limits>
23
24#include <memory>
25
26namespace OpenMS
27{
71 class OPENMS_DLLAPI OnDiscMSExperiment :
73 {
74
76 typedef Peak1D PeakT;
77
78public:
79
85 OnDiscMSExperiment() = default;
86
96 bool openFile(const std::string& filename, bool skipMetaData = false);
97
101 filename_(source.filename_),
102 indexed_mzml_file_(source.indexed_mzml_file_),
103 meta_ms_experiment_(source.meta_ms_experiment_),
104 options_(source.options_)
105 {
106 }
107
115 bool operator==(const OnDiscMSExperiment& rhs) const
116 {
117 if (meta_ms_experiment_ == nullptr || rhs.meta_ms_experiment_ == nullptr)
118 {
119 return filename_ == rhs.filename_ &&
120 meta_ms_experiment_ == rhs.meta_ms_experiment_;
121 }
122
123 // check if file and meta information is the same
124 return filename_ == rhs.filename_ &&
125 (*meta_ms_experiment_) == (*rhs.meta_ms_experiment_);
126 // do not check if indexed_mzml_file_ is equal -> they have the same filename...
127 }
128
130 bool operator!=(const OnDiscMSExperiment& rhs) const
131 {
132 return !(operator==(rhs));
133 }
134
141 bool isSortedByRT() const override
142 {
143 if (!meta_ms_experiment_) return false;
144
145 return meta_ms_experiment_->isSorted(false);
146 }
147
149 inline Size getNrSpectra() const override
150 {
151 return indexed_mzml_file_.getNrSpectra();
152 }
153
155 inline Size getNrChromatograms() const override
156 {
157 return indexed_mzml_file_.getNrChromatograms();
158 }
159
161 std::shared_ptr<const ExperimentalSettings> getExperimentalSettings() const override
162 {
163 return std::static_pointer_cast<const ExperimentalSettings>(meta_ms_experiment_);
164 }
165
166 std::shared_ptr<PeakMap> getMetaData() const
167 {
168 return meta_ms_experiment_;
169 }
170
173 {
174 return getSpectrum(n);
175 }
176
185
197
204 double getSpectrumRT(Size id) const override;
205
212 UInt getSpectrumMSLevel(Size id) const override;
213
215 std::unique_ptr<IMSExperimentRandomAccess> clone() const override;
216
221 {
222 return indexed_mzml_file_.getSpectrumById((int)id);
223 }
224
233
240
246 MSSpectrum getSpectrumByNativeId(const std::string& id);
247
252
254 void setSkipXMLChecks(bool skip);
255
258
261
263 void setOptions(const PeakFileOptions& options);
264
265private:
266
269
270 void loadMetaData_(const std::string& filename);
271
273
274 MSSpectrum getMetaSpectrumById_(const std::string& id);
275
276protected:
277
279 std::string filename_;
283 std::shared_ptr<PeakMap> meta_ms_experiment_;
285 std::unordered_map< std::string, Size > chromatograms_native_ids_;
287 std::unordered_map< std::string, Size > spectra_native_ids_;
290 };
291
293
294} // namespace OpenMS
295
296
A 1-dimensional raw data point or peak for chromatograms.
Definition ChromatogramPeak.h:29
Random access to the spectra and chromatograms of an MS run that stays on disk.
Definition IMSExperimentRandomAccess.h:37
A low-level class to read an indexedmzML file.
Definition IndexedMzMLHandler.h:54
The representation of a chromatogram.
Definition MSChromatogram.h:33
The representation of a 1D spectrum.
Definition MSSpectrum.h:44
Representation of a mass spectrometry experiment on disk.
Definition OnDiscMSExperiment.h:73
void setSkipXMLChecks(bool skip)
sets whether to skip some XML checks and be fast instead
MSSpectrum getMetaSpectrumById_(const std::string &id)
MSSpectrum getSpectrum(Size id) override
returns a single spectrum
Internal::IndexedMzMLHandler indexed_mzml_file_
The index of the underlying data file (mutable: reading moves the file stream)
Definition OnDiscMSExperiment.h:281
std::string filename_
The filename of the underlying data file.
Definition OnDiscMSExperiment.h:279
OpenMS::Interfaces::SpectrumPtr getSpectrumById(Size id)
returns a single spectrum (without applying PeakFileOptions filters)
Definition OnDiscMSExperiment.h:220
bool operator!=(const OnDiscMSExperiment &rhs) const
Inequality operator.
Definition OnDiscMSExperiment.h:130
double getSpectrumRT(Size id) const override
Retention time of spectrum id, from the meta data.
MSChromatogram getChromatogram(Size id) override
returns a single chromatogram
UInt getSpectrumMSLevel(Size id) const override
MS level of spectrum id, from the meta data.
OpenMS::Interfaces::ChromatogramPtr getChromatogramById(Size id)
returns a single chromatogram
void setOptions(const PeakFileOptions &options)
set options for loading/storing
const PeakFileOptions & getOptions() const
Non-mutable access to the options for loading/storing.
bool isSortedByRT() const override
Checks if all spectra are sorted with respect to ascending RT.
Definition OnDiscMSExperiment.h:141
MSSpectrum getSpectrumMetadata(Size id) override
returns a single spectrum without peaks and data arrays
PeakFileOptions options_
Options for loading / storing.
Definition OnDiscMSExperiment.h:289
MSSpectrum operator[](Size n)
alias for getSpectrum
Definition OnDiscMSExperiment.h:172
std::unique_ptr< IMSExperimentRandomAccess > clone() const override
A copy with its own file stream (see the copy constructor)
void loadMetaData_(const std::string &filename)
bool openFile(const std::string &filename, bool skipMetaData=false)
Open a specific file on disk.
std::shared_ptr< PeakMap > meta_ms_experiment_
The meta-data.
Definition OnDiscMSExperiment.h:283
bool operator==(const OnDiscMSExperiment &rhs) const
Equality operator.
Definition OnDiscMSExperiment.h:115
Peak1D PeakT
Definition OnDiscMSExperiment.h:76
PeakFileOptions & getOptions()
Mutable access to the options for loading/storing.
Size getNrSpectra() const override
get the total number of spectra available
Definition OnDiscMSExperiment.h:149
std::shared_ptr< PeakMap > getMetaData() const
Definition OnDiscMSExperiment.h:166
OnDiscMSExperiment()=default
Constructor.
Size getNrChromatograms() const override
get the total number of chromatograms available
Definition OnDiscMSExperiment.h:155
std::shared_ptr< const ExperimentalSettings > getExperimentalSettings() const override
returns the meta information of this experiment (const access)
Definition OnDiscMSExperiment.h:161
OnDiscMSExperiment & operator=(const OnDiscMSExperiment &)
Private Assignment operator -> we cannot copy file streams in IndexedMzMLHandler.
MSChromatogram getChromatogramByNativeId(const std::string &id)
returns a single chromatogram
ChromatogramPeak ChromatogramPeakT
Definition OnDiscMSExperiment.h:75
std::unordered_map< std::string, Size > spectra_native_ids_
Mapping of spectra native ids to offsets.
Definition OnDiscMSExperiment.h:287
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:285
MSChromatogram getMetaChromatogramById_(const std::string &id)
OnDiscMSExperiment(const OnDiscMSExperiment &source)
Copy constructor.
Definition OnDiscMSExperiment.h:99
A 1-dimensional raw data point or peak.
Definition Peak1D.h:30
Options for loading files containing peak data.
Definition PeakFileOptions.h:22
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
std::shared_ptr< Chromatogram > ChromatogramPtr
Definition openms/include/OpenMS/INTERFACES/DataStructures.h:130
std::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 openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
OpenMS::OnDiscMSExperiment OnDiscPeakMap
Definition IndexedMzMLFileLoader.h:17