| OpenMS 2.5.0

MSSpectrum.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: Timo Sachsenberg$
32 // $Authors: Marc Sturm $
33 // --------------------------------------------------------------------------
34
35 #pragma once
36
37 #include <OpenMS/KERNEL/Peak1D.h>
38 #include <OpenMS/KERNEL/StandardDeclarations.h>
39 #include <OpenMS/METADATA/SpectrumSettings.h>
40 #include <OpenMS/KERNEL/RangeManager.h>
41 #include <OpenMS/KERNEL/ComparatorUtils.h>
42 #include <OpenMS/METADATA/DataArrays.h>
43 #include <OpenMS/METADATA/MetaInfoDescription.h>
44
45 namespace OpenMS
46 {
47 class Peak1D;
48
67 class OPENMS_DLLAPI MSSpectrum :
68 private std::vector<Peak1D>,
69 public RangeManager<1>,
70 public SpectrumSettings
71 {
72 public:
73
75 struct OPENMS_DLLAPI RTLess : public std::binary_function<MSSpectrum, MSSpectrum, bool>
76 {
77 bool operator()(const MSSpectrum& a, const MSSpectrum& b) const;
78 };
79
81
82 typedef OpenMS::Peak1D PeakType;
85 typedef typename PeakType::CoordinateType CoordinateType;
87 typedef std::vector<PeakType> ContainerType;
89 typedef OpenMS::DataArrays::FloatDataArray FloatDataArray ;
90 typedef std::vector<FloatDataArray> FloatDataArrays;
92 typedef OpenMS::DataArrays::StringDataArray StringDataArray ;
93 typedef std::vector<StringDataArray> StringDataArrays;
95 typedef OpenMS::DataArrays::IntegerDataArray IntegerDataArray ;
96 typedef std::vector<IntegerDataArray> IntegerDataArrays;
98
100
101 typedef typename ContainerType::iterator Iterator;
104 typedef typename ContainerType::const_iterator ConstIterator;
106 typedef typename ContainerType::reverse_iterator ReverseIterator;
108 typedef typename ContainerType::const_reverse_iterator ConstReverseIterator;
110
112
113 using ContainerType::operator[];
114 using ContainerType::begin;
115 using ContainerType::rbegin;
116 using ContainerType::end;
117 using ContainerType::rend;
118 using ContainerType::resize;
119 using ContainerType::size;
120 using ContainerType::push_back;
121 using ContainerType::emplace_back;
122 using ContainerType::pop_back;
123 using ContainerType::empty;
124 using ContainerType::front;
125 using ContainerType::back;
126 using ContainerType::reserve;
127 using ContainerType::insert;
128 using ContainerType::erase;
129 using ContainerType::swap;
130
131 using typename ContainerType::iterator;
132 using typename ContainerType::const_iterator;
133 using typename ContainerType::size_type;
134 using typename ContainerType::value_type;
135 using typename ContainerType::reference;
136 using typename ContainerType::const_reference;
137 using typename ContainerType::pointer;
138 using typename ContainerType::difference_type;
139
140 typedef Precursor::DriftTimeUnit DriftTimeUnit;
142
143
145 MSSpectrum();
146
148 MSSpectrum(const MSSpectrum& source);
149
151 MSSpectrum(MSSpectrum&&) = default;
152
154 ~MSSpectrum() override
155 {}
156
158 MSSpectrum& operator=(const MSSpectrum& source);
159
161 MSSpectrum& operator=(MSSpectrum&&) & = default;
162
164 MSSpectrum& operator=(const SpectrumSettings & source);
165
167 bool operator==(const MSSpectrum& rhs) const;
168
170 bool operator!=(const MSSpectrum& rhs) const
171 {
172 return !(operator==(rhs));
173 }
174
175 // Docu in base class (RangeManager)
176 void updateRanges() override;
177
181 double getRT() const;
182
184 void setRT(double rt);
185
194 double getDriftTime() const;
195
199 void setDriftTime(double dt);
200
204 DriftTimeUnit getDriftTimeUnit() const;
205
209 void setDriftTimeUnit(DriftTimeUnit dt);
210
216 UInt getMSLevel() const;
217
219 void setMSLevel(UInt ms_level);
220
222 const String& getName() const;
223
225 void setName(const String& name);
226
228
242 const FloatDataArrays& getFloatDataArrays() const;
244
246 FloatDataArrays& getFloatDataArrays()
247 {
248 return float_data_arrays_;
249 }
250
252 void setFloatDataArrays(const FloatDataArrays& fda);
253
255 const StringDataArrays& getStringDataArrays() const;
256
258 StringDataArrays& getStringDataArrays();
259
261 void setStringDataArrays(const StringDataArrays& sda);
262
264 const IntegerDataArrays& getIntegerDataArrays() const;
265
267 IntegerDataArrays& getIntegerDataArrays();
268
270 void setIntegerDataArrays(const IntegerDataArrays& ida);
272
274
275
280 void sortByIntensity(bool reverse = false);
281
287 void sortByPosition();
288
290 bool isSorted() const;
291
293
296
306 Size findNearest(CoordinateType mz) const;
307
319 Int findNearest(CoordinateType mz, CoordinateType tolerance) const;
320
334 Int findNearest(CoordinateType mz, CoordinateType tolerance_left, CoordinateType tolerance_right) const;
335
341 Iterator MZBegin(CoordinateType mz);
342
348 Iterator MZBegin(Iterator begin, CoordinateType mz, Iterator end);
349
355 Iterator MZEnd(CoordinateType mz);
356
362 Iterator MZEnd(Iterator begin, CoordinateType mz, Iterator end);
363
369 ConstIterator MZBegin(CoordinateType mz) const;
370
376 ConstIterator MZBegin(ConstIterator begin, CoordinateType mz, ConstIterator end) const;
377
383 ConstIterator MZEnd(CoordinateType mz) const;
384
390 ConstIterator MZEnd(ConstIterator begin, CoordinateType mz, ConstIterator end) const;
391
399 Iterator PosBegin(CoordinateType mz);
400
408 Iterator PosBegin(Iterator begin, CoordinateType mz, Iterator end);
409
417 ConstIterator PosBegin(CoordinateType mz) const;
418
426 ConstIterator PosBegin(ConstIterator begin, CoordinateType mz, ConstIterator end) const;
427
435 Iterator PosEnd(CoordinateType mz);
436
444 Iterator PosEnd(Iterator begin, CoordinateType mz, Iterator end);
445
453 ConstIterator PosEnd(CoordinateType mz) const;
454
462 ConstIterator PosEnd(ConstIterator begin, CoordinateType mz, ConstIterator end) const;
463
465
466
472 void clear(bool clear_meta_data);
473
474 /*
475 @brief Select a (subset of) spectrum and its data_arrays, only retaining the indices given in @p indices
476
477 @param indices Vector of indices to keep
478 @return Reference to this MSSpectrum
479
480 */
481 MSSpectrum& select(const std::vector<Size>& indices);
482
483
494 SpectrumSettings::SpectrumType getType(const bool query_data) const;
495 using SpectrumSettings::getType; // expose base class function
496
499 ConstIterator getBasePeak() const;
500
503 Iterator getBasePeak();
504
506 PeakType::IntensityType getTIC() const;
507
508 protected:
510 double retention_time_;
511
513 double drift_time_;
514
516 DriftTimeUnit drift_time_unit_;
517
519 UInt ms_level_;
520
522 String name_;
523
525 FloatDataArrays float_data_arrays_;
526
528 StringDataArrays string_data_arrays_;
529
531 IntegerDataArrays integer_data_arrays_;
532 };
533
534 inline std::ostream& operator<<(std::ostream& os, const MSSpectrum& spec)
535 {
536 os << "-- MSSPECTRUM BEGIN --" << std::endl;
537
538 // spectrum settings
539 os << static_cast<const SpectrumSettings&>(spec);
540
541 // peaklist
542 for (MSSpectrum::ConstIterator it = spec.begin(); it != spec.end(); ++it)
543 {
544 os << *it << std::endl;
545 }
546
547 os << "-- MSSPECTRUM END --" << std::endl;
548 return os;
549 }
550
551 } // namespace OpenMS
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::SpectrumSettings
Representation of 1D spectrum settings.
Definition: SpectrumSettings.h:63
OpenMS::RangeManager
Handles the management of a position and intensity range.
Definition: RangeManager.h:47
OpenMS::MSSpectrum::ContainerType
std::vector< PeakType > ContainerType
Spectrum base type.
Definition: MSSpectrum.h:87
OpenMS::MSSpectrum::IntegerDataArrays
std::vector< IntegerDataArray > IntegerDataArrays
Definition: MSSpectrum.h:96
OpenMS::MSSpectrum::drift_time_unit_
DriftTimeUnit drift_time_unit_
Drift time unit.
Definition: MSSpectrum.h:516
OpenMS::MSSpectrum::operator!=
bool operator!=(const MSSpectrum &rhs) const
Equality operator.
Definition: MSSpectrum.h:170
StandardDeclarations.h
OpenMS::MSSpectrum::StringDataArray
OpenMS::DataArrays::StringDataArray StringDataArray
String data array vector type.
Definition: MSSpectrum.h:92
OpenMS::MSSpectrum::float_data_arrays_
FloatDataArrays float_data_arrays_
Float data arrays.
Definition: MSSpectrum.h:525
OpenMS::MSSpectrum::Iterator
ContainerType::iterator Iterator
Mutable iterator.
Definition: MSSpectrum.h:102
OpenMS::MSSpectrum::drift_time_
double drift_time_
Drift time.
Definition: MSSpectrum.h:513
OpenMS::DataArrays::FloatDataArray
Float data array class.
Definition: DataArrays.h:45
DataArrays.h
OpenMS::MSSpectrum::RTLess
Comparator for the retention time.
Definition: MSSpectrum.h:75
Peak1D.h
OpenMS::MSSpectrum::getFloatDataArrays
FloatDataArrays & getFloatDataArrays()
Returns a mutable reference to the float meta data arrays.
Definition: MSSpectrum.h:246
Iterator
OpenMS::PeakType
Peak2D PeakType
Definition: MassTrace.h:47
OpenMS::DataArrays::StringDataArray
String data array class.
Definition: DataArrays.h:59
OpenMS::Peak1D
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:54
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
OpenMS::MSSpectrum::CoordinateType
PeakType::CoordinateType CoordinateType
Coordinate (m/z) type.
Definition: MSSpectrum.h:85
OpenMS::MSSpectrum::FloatDataArray
OpenMS::DataArrays::FloatDataArray FloatDataArray
Float data array vector type.
Definition: MSSpectrum.h:89
OpenMS::MSSpectrum::StringDataArrays
std::vector< StringDataArray > StringDataArrays
Definition: MSSpectrum.h:93
OpenMS::operator<<
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::DataArrays::IntegerDataArray
Integer data array class.
Definition: DataArrays.h:52
OpenMS::MSSpectrum::retention_time_
double retention_time_
Retention time.
Definition: MSSpectrum.h:510
SpectrumSettings.h
OpenMS::SpectrumSettings::getType
SpectrumType getType() const
returns the spectrum type (centroided (PEAKS) or profile data (RAW))
OpenMS::MSSpectrum::IntegerDataArray
OpenMS::DataArrays::IntegerDataArray IntegerDataArray
Integer data array vector type.
Definition: MSSpectrum.h:95
OpenMS::MSSpectrum::ConstIterator
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:104
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::MSSpectrum::ms_level_
UInt ms_level_
MS level.
Definition: MSSpectrum.h:519
OpenMS::MSSpectrum::integer_data_arrays_
IntegerDataArrays integer_data_arrays_
Integer data arrays.
Definition: MSSpectrum.h:531
RangeManager.h
double
float
ComparatorUtils.h
OpenMS::MSSpectrum::FloatDataArrays
std::vector< FloatDataArray > FloatDataArrays
Definition: MSSpectrum.h:90
MetaInfoDescription.h
int
OpenMS::SpectrumSettings::SpectrumType
SpectrumType
Spectrum peak type.
Definition: SpectrumSettings.h:70
OpenMS::MSSpectrum::name_
String name_
Name.
Definition: MSSpectrum.h:522
OpenMS::Precursor::DriftTimeUnit
DriftTimeUnit
Drift time unit.
Definition: Precursor.h:84
OpenMS::MSSpectrum::string_data_arrays_
StringDataArrays string_data_arrays_
String data arrays.
Definition: MSSpectrum.h:528
OpenMS::MSSpectrum::ReverseIterator
ContainerType::reverse_iterator ReverseIterator
Mutable reverse iterator.
Definition: MSSpectrum.h:106
OpenMS::MSSpectrum::~MSSpectrum
~MSSpectrum() override
Destructor.
Definition: MSSpectrum.h:154
OpenMS::MSSpectrum::ConstReverseIterator
ContainerType::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition: MSSpectrum.h:108
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::MSSpectrum::DriftTimeUnit
Precursor::DriftTimeUnit DriftTimeUnit
Definition: MSSpectrum.h:140
KDTree::operator==
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806