53 template <
class DataArrayT>
56 typename DataArrayT::iterator it = a.begin();
57 for (; it != a.end(); ++it)
59 if (it->getName() == name)
return it;
64 template <
class DataArrayT>
67 typename DataArrayT::const_iterator it = a.begin();
68 for (; it != a.end(); ++it)
70 if (it->getName() == name)
return it;
76 template <
typename PeakContainerT>
79 const double pos_start,
81 const bool ignore_data_arrays =
false
84 typename PeakContainerT::iterator it_start = p.PosBegin(pos_start);
85 typename PeakContainerT::iterator it_end = p.PosEnd(pos_end);
86 if (!ignore_data_arrays)
88 Size hops_left = std::distance(p.begin(), it_start);
89 Size n_elems = std::distance(it_start, it_end);
91 typename PeakContainerT::StringDataArrays& SDAs = p.getStringDataArrays();
94 if (sda.size() == p.size())
96 sda.erase(sda.begin() + hops_left + n_elems, sda.end());
97 sda.erase(sda.begin(), sda.begin() + hops_left);
101 typename PeakContainerT::FloatDataArrays& FDAs = p.getFloatDataArrays();
104 if (fda.size() == p.size())
106 fda.erase(fda.begin() + hops_left + n_elems, fda.end());
107 fda.erase(fda.begin(), fda.begin() + hops_left);
111 typename PeakContainerT::IntegerDataArrays& IDAs = p.getIntegerDataArrays();
114 if (ida.size() == p.size())
116 ida.erase(ida.begin() + hops_left + n_elems, ida.end());
117 ida.erase(ida.begin(), ida.begin() + hops_left);
121 if (it_start == it_end)
127 p.erase(it_end, p.end());
128 p.erase(p.begin(), it_start);
132 template <
typename PeakContainerT>
135 if (p.empty())
return;
137 typename PeakContainerT::iterator it = std::min_element(p.begin(), p.end(),
140 return a.getIntensity() < b.getIntensity();
143 const double rebase = - it->getIntensity();
146 peak.setIntensity(peak.getIntensity() + rebase);
172 template <
typename PeakContainerT>
175 if (!p.getFloatDataArrays().empty() || !p.getStringDataArrays().empty() || !p.getIntegerDataArrays().empty())
177 OPENMS_LOG_WARN <<
"Warning: data arrays are being ignored in the method SpectrumHelper::makePeakPositionUnique().\n";
180 if (p.empty())
return;
184 double current_position = p.begin()->getPos();
185 PeakContainerT p_new;
186 double intensity_new(0);
187 std::vector<double> intensities_at_same_position;
190 if (peak.getPos() > current_position)
198 case IntensityAveragingMethod::MIN: intensity_new = *std::min_element(intensities_at_same_position.begin(), intensities_at_same_position.end());
break;
199 case IntensityAveragingMethod::MAX: intensity_new = *std::max_element(intensities_at_same_position.begin(), intensities_at_same_position.end());
break;
202 p_new.push_back(peak_new);
204 current_position = peak.getPos();
205 intensities_at_same_position.clear();
208 intensities_at_same_position.push_back(peak.getIntensity());
217 case IntensityAveragingMethod::MIN : intensity_new = *std::min_element(intensities_at_same_position.begin(), intensities_at_same_position.end());
break;
218 case IntensityAveragingMethod::MAX : intensity_new = *std::max_element(intensities_at_same_position.begin(), intensities_at_same_position.end());
break;
221 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
The representation of a 1D spectrum.
Definition: MSSpectrum.h:70
A more convenient string class.
Definition: String.h:60
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:54
static double median(IteratorType begin, IteratorType end, bool sorted=false)
Calculates the median of a range of values.
Definition: StatisticFunctions.h:138
static double mean(IteratorType begin, IteratorType end)
Calculates the mean of a range of values.
Definition: StatisticFunctions.h:120
static double sum(IteratorType begin, IteratorType end)
Calculates the sum of a range of values.
Definition: StatisticFunctions.h:107
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Peak2D PeakType
Definition: MassTrace.h:47
IntensityAveragingMethod
Possible methods for merging peak intensities.
Definition: SpectrumHelper.h:156
void subtractMinimumIntensity(PeakContainerT &p)
Definition: SpectrumHelper.h:133
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:77
void makePeakPositionUnique(PeakContainerT &p, const IntensityAveragingMethod m=IntensityAveragingMethod::MEDIAN)
Make peak positions unique.
Definition: SpectrumHelper.h:173
void copySpectrumMeta(const MSSpectrum &input, MSSpectrum &output, bool clear_spectrum=true)
Copies only the meta data contained in the input spectrum to the output spectrum.