51 template <
class DataArrayT>
54 typename DataArrayT::iterator it = a.begin();
55 for (; it != a.end(); ++it)
57 if (it->getName() == name)
return it;
62 template <
class DataArrayT>
65 typename DataArrayT::const_iterator it = a.begin();
66 for (; it != a.end(); ++it)
68 if (it->getName() == name)
return it;
74 template <
typename PeakContainerT>
77 const double pos_start,
79 const bool ignore_data_arrays =
false
82 typename PeakContainerT::iterator it_start = p.PosBegin(pos_start);
83 typename PeakContainerT::iterator it_end = p.PosEnd(pos_end);
84 if (!ignore_data_arrays)
86 Size hops_left = std::distance(p.begin(), it_start);
87 Size n_elems = std::distance(it_start, it_end);
89 typename PeakContainerT::StringDataArrays& SDAs = p.getStringDataArrays();
92 if (sda.size() == p.size())
94 sda.erase(sda.begin() + hops_left + n_elems, sda.end());
95 sda.erase(sda.begin(), sda.begin() + hops_left);
99 typename PeakContainerT::FloatDataArrays& FDAs = p.getFloatDataArrays();
102 if (fda.size() == p.size())
104 fda.erase(fda.begin() + hops_left + n_elems, fda.end());
105 fda.erase(fda.begin(), fda.begin() + hops_left);
109 typename PeakContainerT::IntegerDataArrays& IDAs = p.getIntegerDataArrays();
112 if (ida.size() == p.size())
114 ida.erase(ida.begin() + hops_left + n_elems, ida.end());
115 ida.erase(ida.begin(), ida.begin() + hops_left);
119 if (it_start == it_end)
125 p.erase(it_end, p.end());
126 p.erase(p.begin(), it_start);
130 template <
typename PeakContainerT>
133 if (p.empty())
return;
135 typename PeakContainerT::iterator it = std::min_element(p.begin(), p.end(),
138 return a.getIntensity() < b.getIntensity();
141 const double rebase = - it->getIntensity();
144 peak.setIntensity(peak.getIntensity() + rebase);
170 template <
typename PeakContainerT>
173 if (!p.getFloatDataArrays().empty() || !p.getStringDataArrays().empty() || !p.getIntegerDataArrays().empty())
175 OPENMS_LOG_WARN <<
"Warning: data arrays are being ignored in the method SpectrumHelper::makePeakPositionUnique().\n";
178 if (p.empty())
return;
182 double current_position = p.begin()->getPos();
183 PeakContainerT p_new;
184 double intensity_new(0);
185 std::vector<double> intensities_at_same_position;
188 if (peak.getPos() > current_position)
196 case IntensityAveragingMethod::MIN: intensity_new = *std::min_element(intensities_at_same_position.begin(), intensities_at_same_position.end());
break;
197 case IntensityAveragingMethod::MAX: intensity_new = *std::max_element(intensities_at_same_position.begin(), intensities_at_same_position.end());
break;
200 p_new.push_back(peak_new);
202 current_position = peak.getPos();
203 intensities_at_same_position.clear();
206 intensities_at_same_position.push_back(peak.getIntensity());
215 case IntensityAveragingMethod::MIN : intensity_new = *std::min_element(intensities_at_same_position.begin(), intensities_at_same_position.end());
break;
216 case IntensityAveragingMethod::MAX : intensity_new = *std::max_element(intensities_at_same_position.begin(), intensities_at_same_position.end());
break;
219 p_new.push_back(peak_new);
#define OPENMS_LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged.
Definition: LogStream.h:460
Float data array class.
Definition: DataArrays.h:48
Integer data array class.
Definition: DataArrays.h:55
String data array class.
Definition: DataArrays.h:62
A more convenient string class.
Definition: String.h:61
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
DataArrayT::iterator getDataArrayByName(DataArrayT &a, const String &name)
Helper functions for MSSpectrum and MSChromatogram.
Definition: SpectrumHelper.h:52
static double median(IteratorType begin, IteratorType end, bool sorted=false)
Calculates the median of a range of values.
Definition: StatisticFunctions.h:151
static double mean(IteratorType begin, IteratorType end)
Calculates the mean of a range of values.
Definition: StatisticFunctions.h:133
static double sum(IteratorType begin, IteratorType end)
Calculates the sum of a range of values.
Definition: StatisticFunctions.h:120
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Peak2D PeakType
Definition: MassTrace.h:47
IntensityAveragingMethod
Possible methods for merging peak intensities.
Definition: SpectrumHelper.h:154
void subtractMinimumIntensity(PeakContainerT &p)
Definition: SpectrumHelper.h:131
void removePeaks(PeakContainerT &p, const double pos_start, const double pos_end, const bool ignore_data_arrays=false)
remove all peaks EXCEPT in the given range
Definition: SpectrumHelper.h:75
void makePeakPositionUnique(PeakContainerT &p, const IntensityAveragingMethod m=IntensityAveragingMethod::MEDIAN)
Make peak positions unique.
Definition: SpectrumHelper.h:171