77 defaults_.setValue(
"spacing", 0.05,
"Spacing of the resampled output peaks.");
78 defaults_.setValue(
"ppm",
"false",
"Whether spacing is in ppm or Th");
91 template <
class PeakContainerT>
92 void raster(PeakContainerT& container)
111 template <
typename PeakContainerT>
112 void raster_align(PeakContainerT& container,
double start_pos,
double end_pos)
115 if (container.empty())
return;
117 if (end_pos < start_pos)
119 std::vector<typename PeakContainerT::PeakType> empty;
120 container.swap(empty);
124 auto first = container.begin();
125 auto last = container.end();
127 verifySpacing_(
first, last, [](
auto x){
return x->getPos();});
130 while (
first != container.end() && (
first)->getPos() < start_pos) {++
first;}
131 while (last !=
first && (last - 1)->getPos() > end_pos) {--last;}
133 int number_resampled_points = (int)(ceil((end_pos - start_pos) / spacing_ + 1));
135 std::vector<typename PeakContainerT::PeakType> resampled_peak_container;
136 populate_raster_(resampled_peak_container, start_pos, end_pos, number_resampled_points);
138 raster(
first, last, resampled_peak_container.begin(), resampled_peak_container.end());
140 container.swap(resampled_peak_container);
164 template <
typename PeakTypeIterator,
typename ConstPeakTypeIterator>
165 void raster(ConstPeakTypeIterator raw_it, ConstPeakTypeIterator raw_end, PeakTypeIterator resampled_begin, PeakTypeIterator resampled_end)
196 template <
typename PeakTypeIterator,
typename ConstPeakTypeIterator>
197 void raster(ConstPeakTypeIterator mz_raw_it, ConstPeakTypeIterator mz_raw_end,
198 ConstPeakTypeIterator int_raw_it, ConstPeakTypeIterator int_raw_end,
199 ConstPeakTypeIterator mz_resample_it, ConstPeakTypeIterator mz_resample_end,
200 PeakTypeIterator int_resample_it, PeakTypeIterator int_resample_end)
203 (void)int_resample_end;
204 OPENMS_PRECONDITION(mz_resample_it != mz_resample_end,
"Output iterators cannot be identical")
205 OPENMS_PRECONDITION(std::distance(mz_resample_it, mz_resample_end) == std::distance(int_resample_it, int_resample_end),
206 "Resample m/z and intensity iterators need to cover the same distance")
207 OPENMS_PRECONDITION(std::distance(mz_raw_it, mz_raw_end) == std::distance(int_raw_it, int_raw_end),
208 "Raw m/z and intensity iterators need to cover the same distance")
211 verifySpacing_(mz_raw_it, mz_raw_end, [](
auto x){
return *x;});
213 PeakTypeIterator mz_resample_start = mz_resample_it;
216 while (mz_raw_it != mz_raw_end && (*mz_raw_it) < (*mz_resample_it) )
218 (*int_resample_it) = *int_resample_it + *int_raw_it;
223 while (mz_raw_it != mz_raw_end)
226 while (mz_resample_it != mz_resample_end && *mz_resample_it < *mz_raw_it)
228 ++mz_resample_it; ++int_resample_it;
230 if (mz_resample_it != mz_resample_start)
232 --mz_resample_it; --int_resample_it;
236 if ((mz_resample_it + 1) == mz_resample_end) {
break;}
238 double dist_left = fabs(*mz_raw_it - *mz_resample_it);
239 double dist_right = fabs(*mz_raw_it - *(mz_resample_it + 1));
242 *(int_resample_it) = *int_resample_it + (*int_raw_it) * dist_right / (dist_left + dist_right);
243 *(int_resample_it + 1) = *(int_resample_it + 1) + (*int_raw_it) * dist_left / (dist_left + dist_right);
250 while (mz_raw_it != mz_raw_end)
252 *int_resample_it = *int_resample_it + (*int_raw_it);
274 template <
typename PeakTypeIterator>
275 void raster_interpolate(PeakTypeIterator raw_it, PeakTypeIterator raw_end, PeakTypeIterator resampled_start, PeakTypeIterator resampled_end)
280 verifySpacing_(raw_it, raw_end, [](PeakTypeIterator x){
return x->getPos();});
282 PeakTypeIterator raw_start = raw_it;
285 while (resampled_start != resampled_end && resampled_start->getPos() < raw_it->getPos()) {resampled_start++;}
287 while (resampled_start != resampled_end)
290 while (raw_it != raw_end && raw_it->getPos() < resampled_start->getPos()) {raw_it++;}
291 if (raw_it != raw_start) {raw_it--;}
294 if ((raw_it + 1) == raw_end) {
break;}
297 double m = ((raw_it + 1)->getIntensity() - raw_it->getIntensity()) / ((raw_it + 1)->getPos() - raw_it->getPos());
298 resampled_start->setIntensity(raw_it->getIntensity() + (resampled_start->getPos() - raw_it->getPos()) * m);
313 startProgress(0, exp.
size(),
"resampling of data");
314 for (
Size i = 0; i < exp.
size(); ++i)
333 spacing_ = param_.getValue(
"spacing");
334 ppm_ = (bool)param_.getValue(
"ppm").toBool();
338 template <
typename PeakType>
340 double start_pos,
double end_pos,
int number_resampled_points)
347 template <
typename PeakTypeIterator>
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
Shared linear resampling implementation without parameter or progress handling.
Definition LinearResampling.h:33
void verifySpacing(PeakTypeIterator it, PeakTypeIterator end, auto access)
Emit the existing spacing warning for absolute grids when enabled.
Definition LinearResampling.h:171
void populateRaster(std::vector< PeakType > &resampled_peak_container, double start_pos, double end_pos, int number_resampled_points)
Populate an absolute or ppm grid using the existing endpoint convention.
Definition LinearResampling.h:134
void raster(PeakContainerT &container)
Resample a peak container onto a grid spanning its first and last points.
Definition LinearResampling.h:49
Internal RAII guard for temporary resampling warning suppression.
Definition LinearResamplerAlign.h:31
ScopedResamplingWarningSuppression(bool suppress=true)
Definition LinearResamplerAlign.h:33
bool previous_
Definition LinearResamplerAlign.h:47
~ScopedResamplingWarningSuppression()
Definition LinearResamplerAlign.h:38
ScopedResamplingWarningSuppression & operator=(const ScopedResamplingWarningSuppression &)=delete
ScopedResamplingWarningSuppression(const ScopedResamplingWarningSuppression &)=delete
Linear Resampling of raw data with alignment.
Definition LinearResamplerAlign.h:72
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:165
double spacing_
Spacing of the resampled data.
Definition LinearResamplerAlign.h:326
LinearResamplerAlign()
Definition LinearResamplerAlign.h:75
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:112
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:275
void raster(PeakContainerT &container)
Applies the resampling algorithm to a container (MSSpectrum or MSChromatogram).
Definition LinearResamplerAlign.h:92
bool ppm_
Whether spacing_ is interpreted in ppm (true) or Th (false)
Definition LinearResamplerAlign.h:329
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
Definition LinearResamplerAlign.h:331
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:339
void rasterExperiment(PeakMap &exp)
Applies the resampling algorithm to all spectra of an MSExperiment.
Definition LinearResamplerAlign.h:311
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:197
void verifySpacing_(PeakTypeIterator it, PeakTypeIterator end, auto access)
helper function to warn the user when the resampling rate is too high
Definition LinearResamplerAlign.h:348
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
Size size() const noexcept
The number of spectra.
Base class for all classes that want to report their progress.
Definition ProgressLogger.h:27
OpenMS looks in the< code > OPENMS_THERMO_MANAGED_DIR</code > environment variable first
Definition common-cmake-parameters.doxygen:179
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition openms/include/OpenMS/CONCEPT/Macros.h:91
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::atomic< bool > suppress_resampling_spacing_warning
Shared process-wide flag controlling resampling-spacing warnings.