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 SpecT>
57 if (container.empty())
return;
59 typename SpecT::iterator first = container.begin();
60 typename SpecT::iterator last = container.end();
62 double end_pos = (last - 1)->getMZ();
63 double start_pos = first->getMZ();
64 int number_resampled_points = (int)(ceil((end_pos - start_pos) / spacing_ + 1));
66 std::vector<typename SpecT::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 SpecT>
90 void raster_align(SpecT& container,
double start_pos,
double end_pos)
93 if (container.empty())
return;
95 if (end_pos < start_pos)
97 std::vector<typename SpecT::PeakType> empty;
98 container.swap(empty);
102 typename SpecT::iterator first = container.begin();
103 typename SpecT::iterator last = container.end();
106 while (first != container.end() && (first)->getMZ() < start_pos) {++first;}
107 while (last != first && (last - 1)->getMZ() > end_pos) {--last;}
109 int number_resampled_points = (int)(ceil((end_pos - start_pos) / spacing_ + 1));
111 std::vector<typename SpecT::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 resample_it, PeakTypeIterator resample_end)
146 PeakTypeIterator resample_start = resample_it;
149 while (raw_it != raw_end && raw_it->getMZ() < resample_it->getMZ())
151 resample_it->setIntensity(resample_it->getIntensity() + raw_it->getIntensity());
155 while (raw_it != raw_end)
158 while (resample_it != resample_end && resample_it->getMZ() < raw_it->getMZ()) {resample_it++;}
159 if (resample_it != resample_start) {resample_it--;}
162 if ((resample_it + 1) == resample_end) {
break;}
164 double dist_left = fabs(raw_it->getMZ() - resample_it->getMZ());
165 double dist_right = fabs(raw_it->getMZ() - (resample_it + 1)->getMZ());
168 resample_it->setIntensity(resample_it->getIntensity() + raw_it->getIntensity() * dist_right / (dist_left + dist_right));
169 (resample_it + 1)->setIntensity((resample_it + 1)->getIntensity() + raw_it->getIntensity() * dist_left / (dist_left + dist_right));
175 while (raw_it != raw_end)
177 resample_it->setIntensity(resample_it->getIntensity() + raw_it->getIntensity());
207 template <
typename PeakTypeIterator,
typename ConstPeakTypeIterator>
208 #ifdef OPENMS_ASSERTIONS
209 void raster(ConstPeakTypeIterator mz_raw_it, ConstPeakTypeIterator mz_raw_end,
210 ConstPeakTypeIterator int_raw_it, ConstPeakTypeIterator int_raw_end,
211 PeakTypeIterator mz_resample_it, PeakTypeIterator mz_resample_end,
212 PeakTypeIterator int_resample_it, PeakTypeIterator int_resample_end)
214 void raster(ConstPeakTypeIterator mz_raw_it, ConstPeakTypeIterator mz_raw_end,
215 ConstPeakTypeIterator int_raw_it, ConstPeakTypeIterator ,
216 PeakTypeIterator mz_resample_it, PeakTypeIterator mz_resample_end,
217 PeakTypeIterator int_resample_it, PeakTypeIterator )
220 OPENMS_PRECONDITION(mz_resample_it != mz_resample_end,
"Output iterators cannot be identical")
221 OPENMS_PRECONDITION(std::distance(mz_resample_it, mz_resample_end) == std::distance(int_resample_it, int_resample_end),
222 "Resample m/z and intensity iterators need to cover the same distance")
223 OPENMS_PRECONDITION(std::distance(mz_raw_it, mz_raw_end) == std::distance(int_raw_it, int_raw_end),
224 "Raw m/z and intensity iterators need to cover the same distance")
227 PeakTypeIterator mz_resample_start = mz_resample_it;
230 while (mz_raw_it != mz_raw_end && (*mz_raw_it) < (*mz_resample_it) )
232 (*int_resample_it) = *int_resample_it + *int_raw_it;
237 while (mz_raw_it != mz_raw_end)
240 while (mz_resample_it != mz_resample_end && *mz_resample_it < *mz_raw_it)
242 ++mz_resample_it; ++int_resample_it;
244 if (mz_resample_it != mz_resample_start)
246 --mz_resample_it; --int_resample_it;
250 if ((mz_resample_it + 1) == mz_resample_end) {
break;}
252 double dist_left = fabs(*mz_raw_it - *mz_resample_it);
253 double dist_right = fabs(*mz_raw_it - *(mz_resample_it + 1));
256 *(int_resample_it) = *int_resample_it + (*int_raw_it) * dist_right / (dist_left + dist_right);
257 *(int_resample_it + 1) = *(int_resample_it + 1) + (*int_raw_it) * dist_left / (dist_left + dist_right);
264 while (mz_raw_it != mz_raw_end)
266 *int_resample_it = *int_resample_it + (*int_raw_it);
288 template <
typename PeakTypeIterator>
289 void raster_interpolate(PeakTypeIterator raw_it, PeakTypeIterator raw_end, PeakTypeIterator resample_it, PeakTypeIterator resampled_end)
294 PeakTypeIterator raw_start = raw_it;
297 while (resample_it != resampled_end && resample_it->getMZ() < raw_it->getMZ()) {resample_it++;}
299 while (resample_it != resampled_end)
302 while (raw_it != raw_end && raw_it->getMZ() < resample_it->getMZ()) {raw_it++;}
303 if (raw_it != raw_start) {raw_it--;}
306 if ((raw_it + 1) == raw_end) {
break;}
309 double m = ((raw_it + 1)->getIntensity() - raw_it->getIntensity()) / ((raw_it + 1)->getMZ() - raw_it->getMZ());
310 resample_it->setIntensity(raw_it->getIntensity() + (resample_it->getMZ() - raw_it->getMZ()) * m);
323 spacing_ = param_.getValue(
"spacing");
324 ppm_ = (bool)param_.getValue(
"ppm").toBool();
328 template <
typename PeakType>
330 double start_pos,
double end_pos,
int number_resampled_points)
335 resampled_peak_container.resize(number_resampled_points);
336 typename std::vector<PeakType>::iterator it = resampled_peak_container.begin();
337 for (
int i = 0; i < number_resampled_points; ++i)
339 it->setMZ(start_pos + i * spacing_);
346 double current_mz = start_pos;
347 while (current_mz < end_pos)
352 resampled_peak_container.push_back(p);
355 current_mz += current_mz * (spacing_ / 1e6);
Linear Resampling of raw data with alignment.
Definition: LinearResamplerAlign.h:33
void raster(SpecT &container)
Applies the resampling algorithm to a container (MSSpectrum or MSChromatogram).
Definition: LinearResamplerAlign.h:54
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:90
LinearResamplerAlign()
Definition: LinearResamplerAlign.h:37
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:214
void raster(ConstPeakTypeIterator raw_it, ConstPeakTypeIterator raw_end, PeakTypeIterator resample_it, PeakTypeIterator resample_end)
Applies the resampling algorithm.
Definition: LinearResamplerAlign.h:141
bool ppm_
Spacing of the resampled data.
Definition: LinearResamplerAlign.h:319
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
Definition: LinearResamplerAlign.h:321
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:329
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:289
Linear Resampling of raw data.
Definition: LinearResampler.h:38
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:29
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1)
Definition: Peak2D.h:178
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: FeatureDeconvolution.h:22