35 #ifndef OPENMS_KERNEL_MSSPECTRUM_H
36 #define OPENMS_KERNEL_MSSPECTRUM_H
65 template <
typename PeakT = Peak1D>
67 private std::vector<PeakT>,
76 public std::vector<float>
82 public std::vector<Int>
88 public std::vector<String>
93 public std::binary_function<MSSpectrum, MSSpectrum, bool>
120 typedef typename ContainerType::iterator
Iterator;
132 using ContainerType::operator[];
133 using ContainerType::begin;
134 using ContainerType::rbegin;
135 using ContainerType::end;
136 using ContainerType::rend;
137 using ContainerType::resize;
138 using ContainerType::size;
139 using ContainerType::push_back;
140 using ContainerType::pop_back;
141 using ContainerType::empty;
142 using ContainerType::front;
143 using ContainerType::back;
144 using ContainerType::reserve;
145 using ContainerType::insert;
146 using ContainerType::erase;
147 using ContainerType::swap;
149 using typename ContainerType::iterator;
150 using typename ContainerType::const_iterator;
151 using typename ContainerType::size_type;
152 using typename ContainerType::value_type;
153 using typename ContainerType::reference;
154 using typename ContainerType::const_reference;
155 using typename ContainerType::pointer;
156 using typename ContainerType::difference_type;
193 if (&source ==
this)
return *
this;
195 ContainerType::operator=(source);
213 #pragma clang diagnostic push
214 #pragma clang diagnostic ignored "-Wfloat-equal"
215 return std::operator==(*
this, rhs) &&
224 #pragma clang diagnostic pop
358 std::vector<std::pair<typename PeakType::IntensityType, Size> > sorted_indices;
359 sorted_indices.reserve(ContainerType::size());
360 for (
Size i = 0; i < ContainerType::size(); ++i)
362 sorted_indices.push_back(std::make_pair(ContainerType::operator[](i).getIntensity(), i));
376 for (
Size i = 0; i < sorted_indices.size(); ++i)
378 tmp.push_back(*(ContainerType::begin() + (sorted_indices[i].second)));
380 ContainerType::swap(tmp);
384 std::vector<float> mda_tmp;
394 std::vector<String> mda_tmp;
404 std::vector<Int> mda_tmp;
428 std::vector<std::pair<typename PeakType::PositionType, Size> > sorted_indices;
429 sorted_indices.reserve(ContainerType::size());
430 for (
Size i = 0; i < ContainerType::size(); ++i)
432 sorted_indices.push_back(std::make_pair(ContainerType::operator[](i).getPosition(), i));
438 tmp.reserve(sorted_indices.size());
439 for (
Size i = 0; i < sorted_indices.size(); ++i)
441 tmp.push_back(*(ContainerType::begin() + (sorted_indices[i].second)));
443 ContainerType::swap(tmp);
447 std::vector<float> mda_tmp;
458 std::vector<String> mda_tmp;
469 std::vector<Int> mda_tmp;
483 if (this->size() < 2)
return true;
485 for (
Size i = 1; i < this->size(); ++i)
487 if (this->
operator[](i - 1).getMZ() > this->operator[](i).getMZ())
return false;
509 if (ContainerType::size() == 0)
throw Exception::Precondition(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"There must be at least one peak to determine the nearest peak!");
514 if (it == ContainerType::begin())
return 0;
516 if (it == ContainerType::end())
return ContainerType::size() - 1;
521 if (std::fabs(it->getMZ() - mz) < std::fabs(it2->getMZ() - mz))
523 return Size(it - ContainerType::begin());
527 return Size(it2 - ContainerType::begin());
637 ContainerType::clear();
674 template <
typename PeakT>
675 std::ostream& operator<<(std::ostream& os, const MSSpectrum<PeakT>& spec)
677 os <<
"-- MSSPECTRUM BEGIN --" << std::endl;
680 os << static_cast<const SpectrumSettings&>(spec);
685 os << *it << std::endl;
688 os <<
"-- MSSPECTRUM END --" << std::endl;
694 #endif // OPENMS_KERNEL_MSSPECTRUM_H
String data array class.
Definition: MSSpectrum.h:86
MSSpectrum & operator=(const MSSpectrum &source)
Assignment operator.
Definition: MSSpectrum.h:191
PeakType::CoordinateType CoordinateType
Coordinate (m/z) type.
Definition: MSSpectrum.h:107
ConstIterator MZEnd(ConstIterator begin, CoordinateType mz, ConstIterator end) const
Binary search for peak range end (returns the past-the-end iterator)
Definition: MSSpectrum.h:620
A more convenient string class.
Definition: String.h:57
IntegerDataArrays integer_data_arrays_
Integer data arrays.
Definition: MSSpectrum.h:670
UInt getMSLevel() const
Returns the MS level.
Definition: MSSpectrum.h:259
void sortByPosition()
Lexicographically sorts the peaks by their position.
Definition: MSSpectrum.h:419
Size findNearest(CoordinateType mz) const
Binary search for the peak nearest to a specific m/z.
Definition: MSSpectrum.h:506
Iterator MZEnd(Iterator begin, CoordinateType mz, Iterator end)
Binary search for peak range end (returns the past-the-end iterator)
Definition: MSSpectrum.h:572
StringDataArrays string_data_arrays_
String data arrays.
Definition: MSSpectrum.h:667
bool isSorted() const
Checks if all peaks are sorted with respect to ascending m/z.
Definition: MSSpectrum.h:481
Comparator for the retention time.
Definition: MSSpectrum.h:92
ContainerType::reverse_iterator ReverseIterator
Mutable reverse iterator.
Definition: MSSpectrum.h:125
Iterator MZBegin(Iterator begin, CoordinateType mz, Iterator end)
Binary search for peak range begin.
Definition: MSSpectrum.h:548
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:123
bool operator==(const MSSpectrum &rhs) const
Equality operator.
Definition: MSSpectrum.h:210
ReverseComparator< Cmp > reverseComparator(Cmp const &cmp)
Make-function to create a ReverseComparator from another comparator without the need to specify the t...
Definition: ComparatorUtils.h:261
Iterator MZEnd(CoordinateType mz)
Binary search for peak range end (returns the past-the-end iterator)
Definition: MSSpectrum.h:560
Integer data array class.
Definition: MSSpectrum.h:80
SpectrumSettings()
Constructor.
const String & getName() const
Returns the name.
Definition: MSSpectrum.h:271
Representation of 1D spectrum settings.
Definition: SpectrumSettings.h:64
void setName(const String &name)
Sets the name.
Definition: MSSpectrum.h:277
String name_
Name.
Definition: MSSpectrum.h:661
MSSpectrum(const MSSpectrum &source)
Copy constructor.
Definition: MSSpectrum.h:174
StringDataArrays & getStringDataArrays()
Returns a mutable reference to the string meta data arrays.
Definition: MSSpectrum.h:316
bool operator==(const RangeManager &rhs) const
Equality operator.
Definition: RangeManager.h:88
const IntegerDataArrays & getIntegerDataArrays() const
Returns a const reference to the integer meta data arrays.
Definition: MSSpectrum.h:322
A 1-dimensional raw data point or peak with meta information.
Definition: RichPeak1D.h:52
ContainerType::iterator Iterator
Mutable iterator.
Definition: MSSpectrum.h:121
Precondition failed exception.
Definition: Exception.h:167
IntegerDataArrays & getIntegerDataArrays()
Returns a mutable reference to the integer meta data arrays.
Definition: MSSpectrum.h:328
Comparator by position. As this class has dimension 1, this is basically an alias for MZLess...
Definition: Peak1D.h:241
Iterator MZBegin(CoordinateType mz)
Binary search for peak range begin.
Definition: MSSpectrum.h:536
bool operator!=(const MSSpectrum &rhs) const
Equality operator.
Definition: MSSpectrum.h:228
std::vector< FloatDataArray > FloatDataArrays
Float data array vector type.
Definition: MSSpectrum.h:111
virtual void updateRanges()
Updates minimum and maximum position/intensity.
Definition: MSSpectrum.h:234
FloatDataArrays float_data_arrays_
Float data arrays.
Definition: MSSpectrum.h:664
MSSpectrum()
Constructor.
Definition: MSSpectrum.h:161
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
SpectrumSettings & operator=(const SpectrumSettings &source)
RangeManager & operator=(const RangeManager &rhs)
Assignment operator.
Definition: RangeManager.h:77
void sortByIntensity(bool reverse=false)
Lexicographically sorts the peaks by their intensity.
Definition: MSSpectrum.h:342
void setPosition(PositionType const &position)
Mutable access to the position.
Definition: Peak1D.h:150
void clearRanges()
Resets the ranges.
Definition: RangeManager.h:140
double getRT() const
Definition: MSSpectrum.h:243
void setMSLevel(UInt ms_level)
Sets the MS level.
Definition: MSSpectrum.h:265
ConstIterator MZBegin(CoordinateType mz) const
Binary search for peak range begin.
Definition: MSSpectrum.h:584
std::vector< StringDataArray > StringDataArrays
String data array vector type.
Definition: MSSpectrum.h:113
ConstIterator MZBegin(ConstIterator begin, CoordinateType mz, ConstIterator end) const
Binary search for peak range begin.
Definition: MSSpectrum.h:596
FloatDataArrays & getFloatDataArrays()
Returns a mutable reference to the float meta data arrays.
Definition: MSSpectrum.h:304
std::vector< PeakType > ContainerType
Spectrum base type.
Definition: MSSpectrum.h:109
void clear(bool clear_meta_data)
Clears all data and meta data.
Definition: MSSpectrum.h:635
void setRT(double rt)
Sets the absolute retention time (is seconds)
Definition: MSSpectrum.h:249
PeakT PeakType
Peak type.
Definition: MSSpectrum.h:105
std::vector< IntegerDataArray > IntegerDataArrays
Integer data array vector type.
Definition: MSSpectrum.h:115
Float data array class.
Definition: MSSpectrum.h:74
const StringDataArrays & getStringDataArrays() const
Returns a const reference to the string meta data arrays.
Definition: MSSpectrum.h:310
bool operator()(const MSSpectrum &a, const MSSpectrum &b) const
Definition: MSSpectrum.h:95
double retention_time_
Retention time.
Definition: MSSpectrum.h:655
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:121
UInt ms_level_
MS level.
Definition: MSSpectrum.h:658
ConstIterator MZEnd(CoordinateType mz) const
Binary search for peak range end (returns the past-the-end iterator)
Definition: MSSpectrum.h:608
void updateRanges_(const PeakIteratorType &begin, const PeakIteratorType &end)
Updates the range using data points in the iterator range.
Definition: RangeManager.h:155
Handles the management of a position and intensity range.
Definition: RangeManager.h:48
Class for comparison of std::pair using first ONLY e.g. for use with std::sort.
Definition: ComparatorUtils.h:326
const FloatDataArrays & getFloatDataArrays() const
Returns a const reference to the float meta data arrays.
Definition: MSSpectrum.h:298
bool operator==(const SpectrumSettings &rhs) const
Equality operator.
ContainerType::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition: MSSpectrum.h:127
~MSSpectrum()
Destructor.
Definition: MSSpectrum.h:187