65 defaults_.setValue(
"spacing", 0.05,
"Spacing of the resampled output peaks.");
66 defaults_.setValue(
"ppm",
"false",
"Whether spacing is in ppm or Th");
79 template <
class SpecT>
83 if (container.empty())
return;
85 typename SpecT::iterator first = container.begin();
86 typename SpecT::iterator last = container.end();
88 double end_pos = (last - 1)->getMZ();
89 double start_pos = first->getMZ();
90 int number_resampled_points = (
int)(ceil((end_pos - start_pos) / spacing_ + 1));
92 std::vector<typename SpecT::PeakType> resampled_peak_container;
93 populate_raster_(resampled_peak_container, start_pos, end_pos, number_resampled_points);
95 raster(container.begin(), container.end(), resampled_peak_container.begin(), resampled_peak_container.end());
97 container.swap(resampled_peak_container);
115 template <
typename SpecT>
119 if (container.empty())
return;
121 if (end_pos < start_pos)
123 std::vector<typename SpecT::PeakType> empty;
124 container.swap(empty);
128 typename SpecT::iterator first = container.begin();
129 typename SpecT::iterator last = container.end();
132 while (first != container.end() && (first)->getMZ() < start_pos) {++first;}
133 while (last != first && (last - 1)->getMZ() > end_pos) {--last;}
135 int number_resampled_points = (
int)(ceil((end_pos - start_pos) / spacing_ + 1));
137 std::vector<typename SpecT::PeakType> resampled_peak_container;
138 populate_raster_(resampled_peak_container, start_pos, end_pos, number_resampled_points);
140 raster(first, last, resampled_peak_container.begin(), resampled_peak_container.end());
142 container.swap(resampled_peak_container);
166 template <
typename PeakTypeIterator,
typename ConstPeakTypeIterator>
167 void raster(ConstPeakTypeIterator raw_it, ConstPeakTypeIterator raw_end, PeakTypeIterator resample_it, PeakTypeIterator resample_end)
172 PeakTypeIterator resample_start = resample_it;
175 while (raw_it != raw_end && raw_it->getMZ() < resample_it->getMZ())
177 resample_it->setIntensity(resample_it->getIntensity() + raw_it->getIntensity());
181 while (raw_it != raw_end)
184 while (resample_it != resample_end && resample_it->getMZ() < raw_it->getMZ()) {resample_it++;}
185 if (resample_it != resample_start) {resample_it--;}
188 if ((resample_it + 1) == resample_end) {
break;}
190 double dist_left = fabs(raw_it->getMZ() - resample_it->getMZ());
191 double dist_right = fabs(raw_it->getMZ() - (resample_it + 1)->getMZ());
194 resample_it->setIntensity(resample_it->getIntensity() + raw_it->getIntensity() * dist_right / (dist_left + dist_right));
195 (resample_it + 1)->setIntensity((resample_it + 1)->getIntensity() + raw_it->getIntensity() * dist_left / (dist_left + dist_right));
201 while (raw_it != raw_end)
203 resample_it->setIntensity(resample_it->getIntensity() + raw_it->getIntensity());
233 template <
typename PeakTypeIterator,
typename ConstPeakTypeIterator>
234 #ifdef OPENMS_ASSERTIONS
235 void raster(ConstPeakTypeIterator mz_raw_it, ConstPeakTypeIterator mz_raw_end,
236 ConstPeakTypeIterator int_raw_it, ConstPeakTypeIterator int_raw_end,
237 PeakTypeIterator mz_resample_it, PeakTypeIterator mz_resample_end,
238 PeakTypeIterator int_resample_it, PeakTypeIterator int_resample_end)
240 void raster(ConstPeakTypeIterator mz_raw_it, ConstPeakTypeIterator mz_raw_end,
241 ConstPeakTypeIterator int_raw_it, ConstPeakTypeIterator ,
242 PeakTypeIterator mz_resample_it, PeakTypeIterator mz_resample_end,
243 PeakTypeIterator int_resample_it, PeakTypeIterator )
246 OPENMS_PRECONDITION(mz_resample_it != mz_resample_end,
"Output iterators cannot be identical")
247 OPENMS_PRECONDITION(std::distance(mz_resample_it, mz_resample_end) == std::distance(int_resample_it, int_resample_end),
248 "Resample m/z and intensity iterators need to cover the same distance")
249 OPENMS_PRECONDITION(std::distance(mz_raw_it, mz_raw_end) == std::distance(int_raw_it, int_raw_end),
250 "Raw m/z and intensity iterators need to cover the same distance")
253 PeakTypeIterator mz_resample_start = mz_resample_it;
256 while (mz_raw_it != mz_raw_end && (*mz_raw_it) < (*mz_resample_it) )
258 (*int_resample_it) = *int_resample_it + *int_raw_it;
263 while (mz_raw_it != mz_raw_end)
266 while (mz_resample_it != mz_resample_end && *mz_resample_it < *mz_raw_it)
268 ++mz_resample_it; ++int_resample_it;
270 if (mz_resample_it != mz_resample_start)
272 --mz_resample_it; --int_resample_it;
276 if ((mz_resample_it + 1) == mz_resample_end) {
break;}
278 double dist_left = fabs(*mz_raw_it - *mz_resample_it);
279 double dist_right = fabs(*mz_raw_it - *(mz_resample_it + 1));
282 *(int_resample_it) = *int_resample_it + (*int_raw_it) * dist_right / (dist_left + dist_right);
283 *(int_resample_it + 1) = *(int_resample_it + 1) + (*int_raw_it) * dist_left / (dist_left + dist_right);
290 while (mz_raw_it != mz_raw_end)
292 *int_resample_it = *int_resample_it + (*int_raw_it);
314 template <
typename PeakTypeIterator>
315 void raster_interpolate(PeakTypeIterator raw_it, PeakTypeIterator raw_end, PeakTypeIterator resample_it, PeakTypeIterator resampled_end)
320 PeakTypeIterator raw_start = raw_it;
323 while (resample_it != resampled_end && resample_it->getMZ() < raw_it->getMZ()) {resample_it++;}
325 while (resample_it != resampled_end)
328 while (raw_it != raw_end && raw_it->getMZ() < resample_it->getMZ()) {raw_it++;}
329 if (raw_it != raw_start) {raw_it--;}
332 if ((raw_it + 1) == raw_end) {
break;}
335 double m = ((raw_it + 1)->getIntensity() - raw_it->getIntensity()) / ((raw_it + 1)->getMZ() - raw_it->getMZ());
336 resample_it->setIntensity(raw_it->getIntensity() + (resample_it->getMZ() - raw_it->getMZ()) * m);
349 spacing_ = param_.getValue(
"spacing");
350 ppm_ = (bool)param_.getValue(
"ppm").toBool();
354 template <
typename PeakType>
356 double start_pos,
double end_pos,
int number_resampled_points)
361 resampled_peak_container.resize(number_resampled_points);
362 typename std::vector<PeakType>::iterator it = resampled_peak_container.begin();
363 for (
int i = 0; i < number_resampled_points; ++i)
365 it->setMZ(start_pos + i * spacing_);
372 double current_mz = start_pos;
373 while (current_mz < end_pos)
378 resampled_peak_container.push_back(p);
381 current_mz += current_mz * (spacing_ / 1e6);