Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_FILTERING_TRANSFORMERS_LINEARRESAMPLER_H
00036 #define OPENMS_FILTERING_TRANSFORMERS_LINEARRESAMPLER_H
00037
00038 #include <OpenMS/KERNEL/MSExperiment.h>
00039 #include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
00040 #include <OpenMS/CONCEPT/ProgressLogger.h>
00041
00042 #include <limits>
00043 #include <cmath>
00044
00045 namespace OpenMS
00046 {
00061 class OPENMS_DLLAPI LinearResampler :
00062 public DefaultParamHandler,
00063 public ProgressLogger
00064 {
00065
00066 public:
00067
00069 LinearResampler() :
00070 DefaultParamHandler("LinearResampler")
00071 {
00072 defaults_.setValue("spacing", 0.05, "Spacing of the resampled output peaks.");
00073 defaultsToParam_();
00074 }
00075
00077 ~LinearResampler()
00078 {
00079 }
00080
00084 template <typename PeakType>
00085 void raster(MSSpectrum<PeakType> & spectrum)
00086 {
00087
00088 if (spectrum.empty()) return;
00089
00090 typename MSSpectrum<PeakType>::iterator first = spectrum.begin();
00091 typename MSSpectrum<PeakType>::iterator last = spectrum.end();
00092
00093 double end_pos = (last - 1)->getMZ();
00094 double start_pos = first->getMZ();
00095 int number_raw_points = (int)spectrum.size();
00096 int number_resampled_points = (int)(ceil((end_pos - start_pos) / spacing_ + 1));
00097
00098 typename std::vector<PeakType> resampled_peak_container;
00099 resampled_peak_container.resize(number_resampled_points);
00100
00101
00102 typename std::vector<PeakType>::iterator it = resampled_peak_container.begin();
00103 for (int i = 0; i < number_resampled_points; ++i)
00104 {
00105 it->setMZ(start_pos + i * spacing_);
00106 ++it;
00107 }
00108
00109
00110
00111 double distance_left = 0.;
00112 double distance_right = 0.;
00113 int left_index = 0;
00114 int right_index = 0;
00115
00116 it = resampled_peak_container.begin();
00117 for (int i = 0; i < number_raw_points; ++i)
00118 {
00119 int help = (int)floor(((first + i)->getMZ() - start_pos) / spacing_);
00120 left_index = (help < 0) ? 0 : help;
00121 help = distance(first, last) - 1;
00122 right_index = (left_index >= help) ? help : left_index + 1;
00123
00124
00125 distance_left = fabs((first + i)->getMZ() - (it + left_index)->getMZ()) / spacing_;
00126
00127
00128 distance_right = fabs((first + i)->getMZ() - (it + right_index)->getMZ());
00129
00130
00131
00132
00133 DoubleReal intensity = (it + left_index)->getIntensity();
00134 intensity += (first + i)->getIntensity() * distance_right / spacing_;
00135 (it + left_index)->setIntensity(intensity);
00136 intensity = (it + right_index)->getIntensity();
00137 intensity += (first + i)->getIntensity() * distance_left;
00138 (it + right_index)->setIntensity(intensity);
00139 }
00140
00141 resampled_peak_container.swap(spectrum);
00142 }
00143
00147 template <typename PeakType>
00148 void rasterExperiment(MSExperiment<PeakType> & exp)
00149 {
00150 startProgress(0, exp.size(), "resampling of data");
00151 for (Size i = 0; i < exp.size(); ++i)
00152 {
00153 raster(exp[i]);
00154 setProgress(i);
00155 }
00156 endProgress();
00157 }
00158
00159 protected:
00160
00162 double spacing_;
00163
00164 virtual void updateMembers_()
00165 {
00166 spacing_ = param_.getValue("spacing");
00167 }
00168
00169 };
00170
00171
00172 }
00173
00174 #endif // OPENMS_FILTERING_TRANSFORMERS_LINEARRESAMPLER_H