39 defaults_.setValue(
"spacing", 0.05,
"Spacing of the resampled output peaks.");
40 defaults_.setValue(
"ppm",
"false",
"Whether spacing is in ppm or Th");
53 template <
class PeakContainerT>
54 void raster(PeakContainerT& container)
57 if (container.empty())
return;
59 auto first = container.begin();
60 auto last = container.end();
62 double end_pos = (last - 1)->getPos();
63 double start_pos = first->getPos();
64 int number_resampled_points = (int)(ceil((end_pos - start_pos) / spacing_ + 1));
66 std::vector<typename PeakContainerT::PeakType> resampled_peak_container;
67 populate_raster_(resampled_peak_container, start_pos, end_pos, number_resampled_points);
69 raster(container.begin(), container.end(), resampled_peak_container.begin(), resampled_peak_container.end());
71 container.swap(resampled_peak_container);
89 template <
typename PeakContainerT>
90 void raster_align(PeakContainerT& container,
double start_pos,
double end_pos)
93 if (container.empty())
return;
95 if (end_pos < start_pos)
97 std::vector<typename PeakContainerT::PeakType> empty;
98 container.swap(empty);
102 auto first = container.begin();
103 auto last = container.end();
106 while (first != container.end() && (first)->getPos() < start_pos) {++first;}
107 while (last != first && (last - 1)->getPos() > end_pos) {--last;}
109 int number_resampled_points = (int)(ceil((end_pos - start_pos) / spacing_ + 1));
111 std::vector<typename PeakContainerT::PeakType> resampled_peak_container;
112 populate_raster_(resampled_peak_container, start_pos, end_pos, number_resampled_points);
114 raster(first, last, resampled_peak_container.begin(), resampled_peak_container.end());
116 container.swap(resampled_peak_container);
140 template <
typename PeakTypeIterator,
typename ConstPeakTypeIterator>
141 void raster(ConstPeakTypeIterator raw_it, ConstPeakTypeIterator raw_end, PeakTypeIterator resampled_begin, PeakTypeIterator resampled_end)
143 OPENMS_PRECONDITION(resampled_begin != resampled_end,
"Output iterators cannot be identical")
146 PeakTypeIterator resample_start = resampled_begin;
149 while (raw_it != raw_end && raw_it->getPos() < resampled_begin->getPos())
151 resampled_begin->setIntensity(resampled_begin->getIntensity() + raw_it->getIntensity());
155 while (raw_it != raw_end)
158 while (resampled_begin != resampled_end && resampled_begin->getPos() < raw_it->getPos()) {resampled_begin++;}
159 if (resampled_begin != resample_start) {resampled_begin--;}
162 if ((resampled_begin + 1) == resampled_end) {
break;}
164 double dist_left = fabs(raw_it->getPos() - resampled_begin->getPos());
165 double dist_right = fabs(raw_it->getPos() - (resampled_begin + 1)->getPos());
168 resampled_begin->setIntensity(resampled_begin->getIntensity() + raw_it->getIntensity() * dist_right / (dist_left + dist_right));
169 (resampled_begin + 1)->setIntensity((resampled_begin + 1)->getIntensity() + raw_it->getIntensity() * dist_left / (dist_left + dist_right));
175 while (raw_it != raw_end)
177 resampled_begin->setIntensity(resampled_begin->getIntensity() + raw_it->getIntensity());
208 template <
typename PeakTypeIterator,
typename ConstPeakTypeIterator>
209 void raster(ConstPeakTypeIterator mz_raw_it, ConstPeakTypeIterator mz_raw_end,
210 ConstPeakTypeIterator int_raw_it, ConstPeakTypeIterator int_raw_end,
211 ConstPeakTypeIterator mz_resample_it, ConstPeakTypeIterator mz_resample_end,
212 PeakTypeIterator int_resample_it, PeakTypeIterator int_resample_end)
215 (void)int_resample_end;
216 OPENMS_PRECONDITION(mz_resample_it != mz_resample_end,
"Output iterators cannot be identical")
217 OPENMS_PRECONDITION(std::distance(mz_resample_it, mz_resample_end) == std::distance(int_resample_it, int_resample_end),
218 "Resample m/z and intensity iterators need to cover the same distance")
219 OPENMS_PRECONDITION(std::distance(mz_raw_it, mz_raw_end) == std::distance(int_raw_it, int_raw_end),
220 "Raw m/z and intensity iterators need to cover the same distance")
223 PeakTypeIterator mz_resample_start = mz_resample_it;
226 while (mz_raw_it != mz_raw_end && (*mz_raw_it) < (*mz_resample_it) )
228 (*int_resample_it) = *int_resample_it + *int_raw_it;
233 while (mz_raw_it != mz_raw_end)
236 while (mz_resample_it != mz_resample_end && *mz_resample_it < *mz_raw_it)
238 ++mz_resample_it; ++int_resample_it;
240 if (mz_resample_it != mz_resample_start)
242 --mz_resample_it; --int_resample_it;
246 if ((mz_resample_it + 1) == mz_resample_end) {
break;}
248 double dist_left = fabs(*mz_raw_it - *mz_resample_it);
249 double dist_right = fabs(*mz_raw_it - *(mz_resample_it + 1));
252 *(int_resample_it) = *int_resample_it + (*int_raw_it) * dist_right / (dist_left + dist_right);
253 *(int_resample_it + 1) = *(int_resample_it + 1) + (*int_raw_it) * dist_left / (dist_left + dist_right);
260 while (mz_raw_it != mz_raw_end)
262 *int_resample_it = *int_resample_it + (*int_raw_it);
284 template <
typename PeakTypeIterator>
285 void raster_interpolate(PeakTypeIterator raw_it, PeakTypeIterator raw_end, PeakTypeIterator resampled_start, PeakTypeIterator resampled_end)
290 PeakTypeIterator raw_start = raw_it;
293 while (resampled_start != resampled_end && resampled_start->getPos() < raw_it->getPos()) {resampled_start++;}
295 while (resampled_start != resampled_end)
298 while (raw_it != raw_end && raw_it->getPos() < resampled_start->getPos()) {raw_it++;}
299 if (raw_it != raw_start) {raw_it--;}
302 if ((raw_it + 1) == raw_end) {
break;}
305 double m = ((raw_it + 1)->getIntensity() - raw_it->getIntensity()) / ((raw_it + 1)->getPos() - raw_it->getPos());
306 resampled_start->setIntensity(raw_it->getIntensity() + (resampled_start->getPos() - raw_it->getPos()) * m);
319 spacing_ = param_.getValue(
"spacing");
320 ppm_ = (bool)param_.getValue(
"ppm").toBool();
324 template <
typename PeakType>
326 double start_pos,
double end_pos,
int number_resampled_points)
331 resampled_peak_container.resize(number_resampled_points);
332 typename std::vector<PeakType>::iterator it = resampled_peak_container.begin();
333 for (
int i = 0; i < number_resampled_points; ++i)
335 it->setPos(start_pos + i * spacing_);
342 double current_mz = start_pos;
343 while (current_mz < end_pos)
347 p.setPos(current_mz);
348 resampled_peak_container.push_back(p);
351 current_mz += current_mz * (spacing_ / 1e6);
Linear Resampling of raw data with alignment.
Definition: LinearResamplerAlign.h:33
void raster(ConstPeakTypeIterator raw_it, ConstPeakTypeIterator raw_end, PeakTypeIterator resampled_begin, PeakTypeIterator resampled_end)
Resample points (e.g. Peak1D) from an input range onto a prepopulated output range with given m/z,...
Definition: LinearResamplerAlign.h:141
LinearResamplerAlign()
Definition: LinearResamplerAlign.h:37
void raster_align(PeakContainerT &container, double start_pos, double end_pos)
Applies the resampling algorithm to a container (MSSpectrum or MSChromatogram) with fixed coordinates...
Definition: LinearResamplerAlign.h:90
void raster_interpolate(PeakTypeIterator raw_it, PeakTypeIterator raw_end, PeakTypeIterator resampled_start, PeakTypeIterator resampled_end)
Applies the resampling algorithm using a linear interpolation.
Definition: LinearResamplerAlign.h:285
void raster(PeakContainerT &container)
Applies the resampling algorithm to a container (MSSpectrum or MSChromatogram).
Definition: LinearResamplerAlign.h:54
bool ppm_
Spacing of the resampled data.
Definition: LinearResamplerAlign.h:315
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
Definition: LinearResamplerAlign.h:317
void populate_raster_(std::vector< PeakType > &resampled_peak_container, double start_pos, double end_pos, int number_resampled_points)
Generate raster for resampled peak container.
Definition: LinearResamplerAlign.h:325
void raster(ConstPeakTypeIterator mz_raw_it, ConstPeakTypeIterator mz_raw_end, ConstPeakTypeIterator int_raw_it, ConstPeakTypeIterator int_raw_end, ConstPeakTypeIterator mz_resample_it, ConstPeakTypeIterator mz_resample_end, PeakTypeIterator int_resample_it, PeakTypeIterator int_resample_end)
Resample points (with m/z and intensity in separate containers, but of same length) from an input ran...
Definition: LinearResamplerAlign.h:209
Linear Resampling of raw data.
Definition: LinearResampler.h:38
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:29
void setIntensity(IntensityType intensity)
Sets data point intensity (height)
Definition: Peak2D.h:148
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:94
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19