35 #ifndef OPENMS_FILTERING_TRANSFORMERS_LINEARRESAMPLERALIGN_H
36 #define OPENMS_FILTERING_TRANSFORMERS_LINEARRESAMPLERALIGN_H
74 template <
template <
typename>
class SpecT,
typename PeakType>
75 void raster(SpecT<PeakType>& spectrum)
78 if (spectrum.empty())
return;
80 typename SpecT<PeakType>::iterator first = spectrum.begin();
81 typename SpecT<PeakType>::iterator last = spectrum.end();
83 double end_pos = (last - 1)->getMZ();
84 double start_pos = first->getMZ();
85 int number_resampled_points = (int)(ceil((end_pos - start_pos) /
spacing_ + 1));
87 typename std::vector<PeakType> resampled_peak_container;
88 populate_raster_(resampled_peak_container, start_pos, end_pos, number_resampled_points);
90 raster(spectrum.begin(), spectrum.end(), resampled_peak_container.begin(), resampled_peak_container.end());
92 spectrum.swap(resampled_peak_container);
102 template <
template <
typename>
class SpecT,
typename PeakType>
103 void raster_align(SpecT<PeakType>& spectrum,
double start_pos,
double end_pos)
106 if (spectrum.empty())
return;
108 if (end_pos < start_pos)
110 typename std::vector<PeakType> empty;
111 spectrum.swap(empty);
115 typename SpecT<PeakType>::iterator first = spectrum.begin();
116 typename SpecT<PeakType>::iterator last = spectrum.end();
119 while (first != spectrum.end() && (first)->getMZ() < start_pos) {++first; }
120 while (last != first && (last - 1)->getMZ() > end_pos) {--last; }
122 int number_resampled_points = (int)(ceil((end_pos - start_pos) /
spacing_ + 1));
124 typename std::vector<PeakType> resampled_peak_container;
125 populate_raster_(resampled_peak_container, start_pos, end_pos, number_resampled_points);
127 raster(first, last, resampled_peak_container.begin(), resampled_peak_container.end());
129 spectrum.swap(resampled_peak_container);
146 template <
typename PeakTypeIterator,
typename ConstPeakTypeIterator>
147 void raster(ConstPeakTypeIterator raw_it, ConstPeakTypeIterator raw_end, PeakTypeIterator resample_it, PeakTypeIterator resample_end)
152 PeakTypeIterator resample_start = resample_it;
155 while (raw_it != raw_end && raw_it->getMZ() < resample_it->getMZ())
157 resample_it->setIntensity(resample_it->getIntensity() + raw_it->getIntensity());
161 while (raw_it != raw_end)
164 while (resample_it != resample_end && resample_it->getMZ() < raw_it->getMZ()) {resample_it++; }
165 if (resample_it != resample_start) {resample_it--; }
168 if ((resample_it + 1) == resample_end) {
break; }
170 double dist_left = fabs(raw_it->getMZ() - resample_it->getMZ());
171 double dist_right = fabs(raw_it->getMZ() - (resample_it + 1)->getMZ());
174 resample_it->setIntensity(resample_it->getIntensity() + raw_it->getIntensity() * dist_right / (dist_left + dist_right));
175 (resample_it + 1)->setIntensity((resample_it + 1)->getIntensity() + raw_it->getIntensity() * dist_left / (dist_left + dist_right));
181 while (raw_it != raw_end)
183 resample_it->setIntensity(resample_it->getIntensity() + raw_it->getIntensity());
202 template <
typename PeakTypeIterator>
203 void raster_interpolate(PeakTypeIterator raw_it, PeakTypeIterator raw_end, PeakTypeIterator resample_it, PeakTypeIterator resampled_end)
208 PeakTypeIterator raw_start = raw_it;
211 while (resample_it != resampled_end && resample_it->getMZ() < raw_it->getMZ()) {resample_it++; }
213 while (resample_it != resampled_end)
216 while (raw_it != raw_end && raw_it->getMZ() < resample_it->getMZ()) {raw_it++; }
217 if (raw_it != raw_start) {raw_it--; }
220 if ((raw_it + 1) == raw_end) {
break; }
223 double m = ((raw_it + 1)->getIntensity() - raw_it->getIntensity()) / ((raw_it + 1)->getMZ() - raw_it->getMZ());
224 resample_it->setIntensity(raw_it->getIntensity() + (resample_it->getMZ() - raw_it->getMZ()) * m);
242 template <
typename PeakType>
244 double start_pos,
double end_pos,
int number_resampled_points)
249 resampled_peak_container.resize(number_resampled_points);
250 typename std::vector<PeakType>::iterator it = resampled_peak_container.begin();
251 for (
int i = 0; i < number_resampled_points; ++i)
253 it->setMZ(start_pos + i *
spacing_);
260 double current_mz = start_pos;
261 while (current_mz < end_pos)
266 resampled_peak_container.push_back(p);
269 current_mz += current_mz * (
spacing_ / 1e6);
void raster(SpecT< PeakType > &spectrum)
Applies the resampling algorithm to an MSSpectrum.
Definition: LinearResamplerAlign.h:75
Param defaults_
Container for default parameters. This member should be filled in the constructor of derived classes!...
Definition: DefaultParamHandler.h:157
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:203
void setValue(const String &key, const DataValue &value, const String &description="", const StringList &tags=StringList())
Sets a value.
Linear Resampling of raw data.
Definition: LinearResampler.h:61
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
Param param_
Container for current parameters.
Definition: DefaultParamHandler.h:150
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:107
void raster_align(SpecT< PeakType > &spectrum, double start_pos, double end_pos)
Applies the resampling algorithm to an MSSpectrum but it will be aligned between start_pos and end_po...
Definition: LinearResamplerAlign.h:103
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:243
const DataValue & getValue(const String &key) const
Returns a value of a parameter.
bool ppm_
Spacing of the resampled data.
Definition: LinearResamplerAlign.h:233
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:235
void raster(ConstPeakTypeIterator raw_it, ConstPeakTypeIterator raw_end, PeakTypeIterator resample_it, PeakTypeIterator resample_end)
Applies the resampling algorithm to an MSSpectrum.
Definition: LinearResamplerAlign.h:147
bool toBool() const
Conversion to bool.
LinearResamplerAlign()
Definition: LinearResamplerAlign.h:64
double spacing_
Spacing of the resampled data.
Definition: LinearResampler.h:162
void defaultsToParam_()
Updates the parameters after the defaults have been set in the constructor.