35 #ifndef OPENMS_FILTERING_TRANSFORMERS_LINEARRESAMPLERALIGN_H 36 #define OPENMS_FILTERING_TRANSFORMERS_LINEARRESAMPLERALIGN_H 66 defaults_.setValue(
"spacing", 0.05,
"Spacing of the resampled output peaks.");
67 defaults_.setValue(
"ppm",
"false",
"Whether spacing is in ppm or Th");
80 template <
class SpecT>
84 if (container.empty())
return;
86 typename SpecT::iterator first = container.begin();
87 typename SpecT::iterator last = container.end();
89 double end_pos = (last - 1)->getMZ();
90 double start_pos = first->getMZ();
91 int number_resampled_points = (int)(ceil((end_pos - start_pos) / spacing_ + 1));
93 std::vector<typename SpecT::PeakType> resampled_peak_container;
94 populate_raster_(resampled_peak_container, start_pos, end_pos, number_resampled_points);
96 raster(container.begin(), container.end(), resampled_peak_container.begin(), resampled_peak_container.end());
98 container.swap(resampled_peak_container);
116 template <
typename SpecT>
120 if (container.empty())
return;
122 if (end_pos < start_pos)
124 std::vector<typename SpecT::PeakType> empty;
125 container.swap(empty);
129 typename SpecT::iterator first = container.begin();
130 typename SpecT::iterator last = container.end();
133 while (first != container.end() && (first)->getMZ() < start_pos) {++first;}
134 while (last != first && (last - 1)->getMZ() > end_pos) {--last;}
136 int number_resampled_points = (int)(ceil((end_pos - start_pos) / spacing_ + 1));
138 std::vector<typename SpecT::PeakType> resampled_peak_container;
139 populate_raster_(resampled_peak_container, start_pos, end_pos, number_resampled_points);
141 raster(first, last, resampled_peak_container.begin(), resampled_peak_container.end());
143 container.swap(resampled_peak_container);
167 template <
typename PeakTypeIterator,
typename ConstPeakTypeIterator>
168 void raster(ConstPeakTypeIterator raw_it, ConstPeakTypeIterator raw_end, PeakTypeIterator resample_it, PeakTypeIterator resample_end)
173 PeakTypeIterator resample_start = resample_it;
176 while (raw_it != raw_end && raw_it->getMZ() < resample_it->getMZ())
178 resample_it->setIntensity(resample_it->getIntensity() + raw_it->getIntensity());
182 while (raw_it != raw_end)
185 while (resample_it != resample_end && resample_it->getMZ() < raw_it->getMZ()) {resample_it++;}
186 if (resample_it != resample_start) {resample_it--;}
189 if ((resample_it + 1) == resample_end) {
break;}
191 double dist_left = fabs(raw_it->getMZ() - resample_it->getMZ());
192 double dist_right = fabs(raw_it->getMZ() - (resample_it + 1)->getMZ());
195 resample_it->setIntensity(resample_it->getIntensity() + raw_it->getIntensity() * dist_right / (dist_left + dist_right));
196 (resample_it + 1)->setIntensity((resample_it + 1)->getIntensity() + raw_it->getIntensity() * dist_left / (dist_left + dist_right));
202 while (raw_it != raw_end)
204 resample_it->setIntensity(resample_it->getIntensity() + raw_it->getIntensity());
234 template <
typename PeakTypeIterator,
typename ConstPeakTypeIterator>
235 #ifdef OPENMS_ASSERTIONS 236 void raster(ConstPeakTypeIterator mz_raw_it, ConstPeakTypeIterator mz_raw_end,
237 ConstPeakTypeIterator int_raw_it, ConstPeakTypeIterator int_raw_end,
238 PeakTypeIterator mz_resample_it, PeakTypeIterator mz_resample_end,
239 PeakTypeIterator int_resample_it, PeakTypeIterator int_resample_end)
241 void raster(ConstPeakTypeIterator mz_raw_it, ConstPeakTypeIterator mz_raw_end,
242 ConstPeakTypeIterator int_raw_it, ConstPeakTypeIterator ,
243 PeakTypeIterator mz_resample_it, PeakTypeIterator mz_resample_end,
244 PeakTypeIterator int_resample_it, PeakTypeIterator )
247 OPENMS_PRECONDITION(mz_resample_it != mz_resample_end,
"Output iterators cannot be identical")
248 OPENMS_PRECONDITION(std::distance(mz_resample_it, mz_resample_end) == std::distance(int_resample_it, int_resample_end),
249 "Resample m/z and intensity iterators need to cover the same distance")
250 OPENMS_PRECONDITION(std::distance(mz_raw_it, mz_raw_end) == std::distance(int_raw_it, int_raw_end),
251 "Raw m/z and intensity iterators need to cover the same distance")
254 PeakTypeIterator mz_resample_start = mz_resample_it;
257 while (mz_raw_it != mz_raw_end && (*mz_raw_it) < (*mz_resample_it) )
259 (*int_resample_it) = *int_resample_it + *int_raw_it;
264 while (mz_raw_it != mz_raw_end)
267 while (mz_resample_it != mz_resample_end && *mz_resample_it < *mz_raw_it)
269 ++mz_resample_it; ++int_resample_it;
271 if (mz_resample_it != mz_resample_start)
273 --mz_resample_it; --int_resample_it;
277 if ((mz_resample_it + 1) == mz_resample_end) {
break;}
279 double dist_left = fabs(*mz_raw_it - *mz_resample_it);
280 double dist_right = fabs(*mz_raw_it - *(mz_resample_it + 1));
283 *(int_resample_it) = *int_resample_it + (*int_raw_it) * dist_right / (dist_left + dist_right);
284 *(int_resample_it + 1) = *(int_resample_it + 1) + (*int_raw_it) * dist_left / (dist_left + dist_right);
291 while (mz_raw_it != mz_raw_end)
293 *int_resample_it = *int_resample_it + (*int_raw_it);
315 template <
typename PeakTypeIterator>
316 void raster_interpolate(PeakTypeIterator raw_it, PeakTypeIterator raw_end, PeakTypeIterator resample_it, PeakTypeIterator resampled_end)
321 PeakTypeIterator raw_start = raw_it;
324 while (resample_it != resampled_end && resample_it->getMZ() < raw_it->getMZ()) {resample_it++;}
326 while (resample_it != resampled_end)
329 while (raw_it != raw_end && raw_it->getMZ() < resample_it->getMZ()) {raw_it++;}
330 if (raw_it != raw_start) {raw_it--;}
333 if ((raw_it + 1) == raw_end) {
break;}
336 double m = ((raw_it + 1)->getIntensity() - raw_it->getIntensity()) / ((raw_it + 1)->getMZ() - raw_it->getMZ());
337 resample_it->setIntensity(raw_it->getIntensity() + (resample_it->getMZ() - raw_it->getMZ()) * m);
350 spacing_ = param_.getValue(
"spacing");
351 ppm_ = (bool)param_.getValue(
"ppm").toBool();
355 template <
typename PeakType>
357 double start_pos,
double end_pos,
int number_resampled_points)
362 resampled_peak_container.resize(number_resampled_points);
363 typename std::vector<PeakType>::iterator it = resampled_peak_container.begin();
364 for (
int i = 0; i < number_resampled_points; ++i)
366 it->setMZ(start_pos + i * spacing_);
373 double current_mz = start_pos;
374 while (current_mz < end_pos)
379 resampled_peak_container.push_back(p);
382 current_mz += current_mz * (spacing_ / 1e6);
390 #endif // OPENMS_FILTERING_TRANSFORMERS_LINEARRESAMPLERALIGN_H void raster_interpolate(PeakTypeIterator raw_it, PeakTypeIterator raw_end, PeakTypeIterator resample_it, PeakTypeIterator resampled_end)
Applies the resampling algorithm using a linear interpolation.
Definition: LinearResamplerAlign.h:316
Linear Resampling of raw data.
Definition: LinearResampler.h:62
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:55
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1)
Definition: Peak2D.h:203
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:107
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
void setIntensity(IntensityType intensity)
Non-mutable access to the data point intensity (height)
Definition: Peak2D.h:173
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:356
void raster(ConstPeakTypeIterator mz_raw_it, ConstPeakTypeIterator mz_raw_end, ConstPeakTypeIterator int_raw_it, ConstPeakTypeIterator, PeakTypeIterator mz_resample_it, PeakTypeIterator mz_resample_end, PeakTypeIterator int_resample_it, PeakTypeIterator)
Applies the resampling algorithm.
Definition: LinearResamplerAlign.h:241
bool ppm_
Spacing of the resampled data.
Definition: LinearResamplerAlign.h:346
void raster(SpecT &container)
Applies the resampling algorithm to a container (MSSpectrum or MSChromatogram).
Definition: LinearResamplerAlign.h:81
Linear Resampling of raw data with alignment.
Definition: LinearResamplerAlign.h:58
virtual void updateMembers_()
This method is used to update extra member variables at the end of the setParameters() method...
Definition: LinearResamplerAlign.h:348
void raster_align(SpecT &container, double start_pos, double end_pos)
Applies the resampling algorithm to a container (MSSpectrum or MSChromatogram) with fixed coordinates...
Definition: LinearResamplerAlign.h:117
void raster(ConstPeakTypeIterator raw_it, ConstPeakTypeIterator raw_end, PeakTypeIterator resample_it, PeakTypeIterator resample_end)
Applies the resampling algorithm.
Definition: LinearResamplerAlign.h:168
LinearResamplerAlign()
Definition: LinearResamplerAlign.h:64