Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
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-2017.
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 #ifndef OPENMS_KERNEL_MSSPECTRUM_H
36 #define OPENMS_KERNEL_MSSPECTRUM_H
37 
38 #include <OpenMS/KERNEL/Peak1D.h>
45 
46 namespace OpenMS
47 {
48  class Peak1D;
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;
87  typedef std::vector<PeakType> ContainerType;
90  typedef std::vector<FloatDataArray> FloatDataArrays;
93  typedef std::vector<StringDataArray> StringDataArrays;
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::pop_back;
122  using ContainerType::empty;
123  using ContainerType::front;
124  using ContainerType::back;
125  using ContainerType::reserve;
126  using ContainerType::insert;
127  using ContainerType::erase;
128  using ContainerType::swap;
129 
130  using typename ContainerType::iterator;
131  using typename ContainerType::const_iterator;
132  using typename ContainerType::size_type;
133  using typename ContainerType::value_type;
134  using typename ContainerType::reference;
135  using typename ContainerType::const_reference;
136  using typename ContainerType::pointer;
137  using typename ContainerType::difference_type;
139 
140 
142  MSSpectrum();
143 
145  MSSpectrum(const MSSpectrum& source);
146 
149  {}
150 
152  MSSpectrum& operator=(const MSSpectrum& source);
153 
155  MSSpectrum& operator=(const SpectrumSettings & source);
156 
158  bool operator==(const MSSpectrum& rhs) const;
159 
161  bool operator!=(const MSSpectrum& rhs) const
162  {
163  return !(operator==(rhs));
164  }
165 
166  // Docu in base class (RangeManager)
167  virtual void updateRanges();
168 
172  double getRT() const;
173 
175  void setRT(double rt);
176 
185  double getDriftTime() const;
186 
190  void setDriftTime(double dt);
191 
197  UInt getMSLevel() const;
198 
200  void setMSLevel(UInt ms_level);
201 
203  const String& getName() const;
204 
206  void setName(const String& name);
207 
209 
223  const FloatDataArrays& getFloatDataArrays() const;
225 
227  FloatDataArrays& getFloatDataArrays()
228  {
229  return float_data_arrays_;
230  }
231 
233  void setFloatDataArrays(const FloatDataArrays& fda);
234 
236  const StringDataArrays& getStringDataArrays() const;
237 
239  StringDataArrays& getStringDataArrays();
240 
242  void setStringDataArrays(const StringDataArrays& sda);
243 
245  const IntegerDataArrays& getIntegerDataArrays() const;
246 
248  IntegerDataArrays& getIntegerDataArrays();
249 
251  void setIntegerDataArrays(const IntegerDataArrays& ida);
252 
254  inline IntegerDataArray& getIntegerDataArrayByName(String name)
255  {
256  return *std::find_if(integer_data_arrays_.begin(), integer_data_arrays_.end(),
257  [&name](const IntegerDataArray& da) { return da.getName() == name; } );
258  }
259 
261  inline StringDataArray& getStringDataArrayByName(String name)
262  {
263  return *std::find_if(string_data_arrays_.begin(), string_data_arrays_.end(),
264  [&name](const StringDataArray& da) { return da.getName() == name; } );
265  }
266 
268  inline FloatDataArray& getFloatDataArrayByName(String name)
269  {
270  return *std::find_if(float_data_arrays_.begin(), float_data_arrays_.end(),
271  [&name](const FloatDataArray& da) { return da.getName() == name; } );
272  }
273 
275  inline const IntegerDataArray& getIntegerDataArrayByName(String name) const
276  {
277  return *std::find_if(integer_data_arrays_.begin(), integer_data_arrays_.end(),
278  [&name](const IntegerDataArray& da) { return da.getName() == name; } );
279  }
280 
282  inline const StringDataArray& getStringDataArrayByName(String name) const
283  {
284  return *std::find_if(string_data_arrays_.begin(), string_data_arrays_.end(),
285  [&name](const StringDataArray& da) { return da.getName() == name; } );
286  }
287 
289  inline const FloatDataArray& getFloatDataArrayByName(String name) const
290  {
291  return *std::find_if(float_data_arrays_.begin(), float_data_arrays_.end(),
292  [&name](const FloatDataArray& da) { return da.getName() == name; } );
293  }
294 
296 
298 
299 
304  void sortByIntensity(bool reverse = false);
305 
311  void sortByPosition();
312 
314  bool isSorted() const;
315 
317 
320 
330  Size findNearest(CoordinateType mz) const;
331 
343  Int findNearest(CoordinateType mz, CoordinateType tolerance) const;
344 
358  Int findNearest(CoordinateType mz, CoordinateType tolerance_left, CoordinateType tolerance_right) const;
359 
365  Iterator MZBegin(CoordinateType mz);
366 
372  Iterator MZBegin(Iterator begin, CoordinateType mz, Iterator end);
373 
379  Iterator MZEnd(CoordinateType mz);
380 
386  Iterator MZEnd(Iterator begin, CoordinateType mz, Iterator end);
387 
393  ConstIterator MZBegin(CoordinateType mz) const;
394 
400  ConstIterator MZBegin(ConstIterator begin, CoordinateType mz, ConstIterator end) const;
401 
407  ConstIterator MZEnd(CoordinateType mz) const;
408 
414  ConstIterator MZEnd(ConstIterator begin, CoordinateType mz, ConstIterator end) const;
415 
417 
418 
424  void clear(bool clear_meta_data);
425 
426  /*
427  @brief Select a (subset of) spectrum and its data_arrays, only retaining the indices given in @p indices
428 
429  @param indices Vector of indices to keep
430  @return Reference to this MSSpectrum
431 
432  */
433  MSSpectrum& select(const std::vector<Size>& indices);
434 
435 protected:
436 
439 
441  double drift_time_;
442 
445 
448 
450  FloatDataArrays float_data_arrays_;
451 
453  StringDataArrays string_data_arrays_;
454 
456  IntegerDataArrays integer_data_arrays_;
457  };
458 
459  inline std::ostream& operator<<(std::ostream& os, const MSSpectrum& spec)
460  {
461  os << "-- MSSPECTRUM BEGIN --" << std::endl;
462 
463  // spectrum settings
464  os << static_cast<const SpectrumSettings&>(spec);
465 
466  // peaklist
467  for (MSSpectrum::ConstIterator it = spec.begin(); it != spec.end(); ++it)
468  {
469  os << *it << std::endl;
470  }
471 
472  os << "-- MSSPECTRUM END --" << std::endl;
473  return os;
474  }
475 
476 } // namespace OpenMS
477 
478 #endif // OPENMS_KERNEL_MSSPECTRUM_H
PeakType::CoordinateType CoordinateType
Coordinate (m/z) type.
Definition: MSSpectrum.h:85
A more convenient string class.
Definition: String.h:57
IntegerDataArrays integer_data_arrays_
Integer data arrays.
Definition: MSSpectrum.h:456
FloatDataArray & getFloatDataArrayByName(String name)
Returns a mutable reference to the first float meta data array with the given name.
Definition: MSSpectrum.h:268
StringDataArrays string_data_arrays_
String data arrays.
Definition: MSSpectrum.h:453
Comparator for the retention time.
Definition: MSSpectrum.h:75
ContainerType::reverse_iterator ReverseIterator
Mutable reverse iterator.
Definition: MSSpectrum.h:106
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
Peak2D PeakType
Definition: MassTrace.h:48
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:104
OpenMS::DataArrays::FloatDataArray FloatDataArray
Float data array vector type.
Definition: MSSpectrum.h:89
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806
Representation of 1D spectrum settings.
Definition: SpectrumSettings.h:64
String name_
Name.
Definition: MSSpectrum.h:447
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
ContainerType::iterator Iterator
Mutable iterator.
Definition: MSSpectrum.h:102
const FloatDataArray & getFloatDataArrayByName(String name) const
Returns a const reference to the first float meta data array with the given name. ...
Definition: MSSpectrum.h:289
std::vector< FloatDataArray > FloatDataArrays
Definition: MSSpectrum.h:90
Float data array class.
Definition: DataArrays.h:46
Integer data array class.
Definition: DataArrays.h:52
FloatDataArrays float_data_arrays_
Float data arrays.
Definition: MSSpectrum.h:450
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
bool operator!=(const MSSpectrum &rhs) const
Equality operator.
Definition: MSSpectrum.h:161
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:55
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
std::vector< StringDataArray > StringDataArrays
Definition: MSSpectrum.h:93
FloatDataArrays & getFloatDataArrays()
Returns a mutable reference to the float meta data arrays.
Definition: MSSpectrum.h:227
std::vector< PeakType > ContainerType
Spectrum base type.
Definition: MSSpectrum.h:87
OpenMS::DataArrays::StringDataArray StringDataArray
String data array vector type.
Definition: MSSpectrum.h:92
std::vector< IntegerDataArray > IntegerDataArrays
Definition: MSSpectrum.h:96
StringDataArray & getStringDataArrayByName(String name)
Returns a mutable reference to the first string meta data array with the given name.
Definition: MSSpectrum.h:261
IntegerDataArray & getIntegerDataArrayByName(String name)
Returns a mutable reference to the first integer meta data array with the given name.
Definition: MSSpectrum.h:254
double retention_time_
Retention time.
Definition: MSSpectrum.h:438
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
UInt ms_level_
MS level.
Definition: MSSpectrum.h:444
OpenMS::DataArrays::IntegerDataArray IntegerDataArray
Integer data array vector type.
Definition: MSSpectrum.h:95
const IntegerDataArray & getIntegerDataArrayByName(String name) const
Returns a const reference to the first integer meta data array with the given name.
Definition: MSSpectrum.h:275
double drift_time_
Drift time.
Definition: MSSpectrum.h:441
const StringDataArray & getStringDataArrayByName(String name) const
Returns a const reference to the first string meta data array with the given name.
Definition: MSSpectrum.h:282
String data array class.
Definition: DataArrays.h:58
Handles the management of a position and intensity range.
Definition: RangeManager.h:48
int Int
Signed integer type.
Definition: Types.h:103
ContainerType::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition: MSSpectrum.h:108
~MSSpectrum()
Destructor.
Definition: MSSpectrum.h:148

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:02 using doxygen 1.8.13