27 template <
class DataArrayT>
30 typename DataArrayT::iterator it = a.begin();
31 for (; it != a.end(); ++it)
33 if (it->getName() == name)
return it;
38 template <
class DataArrayT>
41 typename DataArrayT::const_iterator it = a.begin();
42 for (; it != a.end(); ++it)
44 if (it->getName() == name)
return it;
50 template <
typename PeakContainerT>
53 const double pos_start,
55 const bool ignore_data_arrays =
false
58 typename PeakContainerT::iterator it_start = p.PosBegin(pos_start);
59 typename PeakContainerT::iterator it_end = p.PosEnd(pos_end);
60 if (!ignore_data_arrays)
62 Size hops_left = std::distance(p.begin(), it_start);
63 Size n_elems = std::distance(it_start, it_end);
65 typename PeakContainerT::StringDataArrays& SDAs = p.getStringDataArrays();
68 if (sda.size() == p.size())
70 sda.erase(sda.begin() + hops_left + n_elems, sda.end());
71 sda.erase(sda.begin(), sda.begin() + hops_left);
75 typename PeakContainerT::FloatDataArrays& FDAs = p.getFloatDataArrays();
78 if (fda.size() == p.size())
80 fda.erase(fda.begin() + hops_left + n_elems, fda.end());
81 fda.erase(fda.begin(), fda.begin() + hops_left);
85 typename PeakContainerT::IntegerDataArrays& IDAs = p.getIntegerDataArrays();
88 if (ida.size() == p.size())
90 ida.erase(ida.begin() + hops_left + n_elems, ida.end());
91 ida.erase(ida.begin(), ida.begin() + hops_left);
95 if (it_start == it_end)
101 p.erase(it_end, p.end());
102 p.erase(p.begin(), it_start);
106 template <
typename PeakContainerT>
109 if (p.empty())
return;
111 typename PeakContainerT::iterator it = std::min_element(p.begin(), p.end(),
114 return a.getIntensity() < b.getIntensity();
117 const double rebase = - it->getIntensity();
120 peak.setIntensity(peak.getIntensity() + rebase);
146 template <
typename PeakContainerT>
149 if (!p.getFloatDataArrays().empty() || !p.getStringDataArrays().empty() || !p.getIntegerDataArrays().empty())
151 OPENMS_LOG_WARN <<
"Warning: data arrays are being ignored in the method SpectrumHelper::makePeakPositionUnique().\n";
154 if (p.empty())
return;
158 double current_position = p.begin()->getPos();
159 PeakContainerT p_new;
160 double intensity_new(0);
161 std::vector<double> intensities_at_same_position;
164 if (peak.getPos() > current_position)
172 case IntensityAveragingMethod::MIN: intensity_new = *std::min_element(intensities_at_same_position.begin(), intensities_at_same_position.end());
break;
173 case IntensityAveragingMethod::MAX: intensity_new = *std::max_element(intensities_at_same_position.begin(), intensities_at_same_position.end());
break;
176 p_new.push_back(peak_new);
178 current_position = peak.getPos();
179 intensities_at_same_position.clear();
182 intensities_at_same_position.push_back(peak.getIntensity());
191 case IntensityAveragingMethod::MIN : intensity_new = *std::min_element(intensities_at_same_position.begin(), intensities_at_same_position.end());
break;
192 case IntensityAveragingMethod::MAX : intensity_new = *std::max_element(intensities_at_same_position.begin(), intensities_at_same_position.end());
break;
195 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:444
Float data array class.
Definition: DataArrays.h:22
Integer data array class.
Definition: DataArrays.h:30
String data array class.
Definition: DataArrays.h:38
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
A more convenient string class.
Definition: String.h:34
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
DataArrayT::iterator getDataArrayByName(DataArrayT &a, const String &name)
Helper functions for MSSpectrum and MSChromatogram.
Definition: SpectrumHelper.h:28
static double median(IteratorType begin, IteratorType end, bool sorted=false)
Calculates the median of a range of values.
Definition: StatisticFunctions.h:112
static double mean(IteratorType begin, IteratorType end)
Calculates the mean of a range of values.
Definition: StatisticFunctions.h:94
static double sum(IteratorType begin, IteratorType end)
Calculates the sum of a range of values.
Definition: StatisticFunctions.h:81
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Peak2D PeakType
Definition: MassTrace.h:21
IntensityAveragingMethod
Possible methods for merging peak intensities.
Definition: SpectrumHelper.h:130
void subtractMinimumIntensity(PeakContainerT &p)
Definition: SpectrumHelper.h:107
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:51
void makePeakPositionUnique(PeakContainerT &p, const IntensityAveragingMethod m=IntensityAveragingMethod::MEDIAN)
Make peak positions unique.
Definition: SpectrumHelper.h:147
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.