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 #ifndef OPENMS_FILTERING_SMOOTHING_SMOOTHFILTER_H
00029 #define OPENMS_FILTERING_SMOOTHING_SMOOTHFILTER_H
00030
00031 #include <OpenMS/KERNEL/MSExperiment.h>
00032 #include <OpenMS/CONCEPT/ProgressLogger.h>
00033
00034
00035 namespace OpenMS
00036 {
00040 class SmoothFilter : public ProgressLogger
00041 {
00042 public:
00043
00045 inline SmoothFilter()
00046 : coeffs_(0)
00047 {
00048 }
00049
00051 virtual ~SmoothFilter()
00052 {
00053 }
00054
00067 template <typename InputPeakIterator, typename OutputPeakContainer >
00068 void filter(InputPeakIterator first, InputPeakIterator last, OutputPeakContainer& smoothed_data_container)
00069 {
00070 smoothed_data_container.resize(distance(first,last));
00071
00072
00073 InputPeakIterator it_back;
00074 typename OutputPeakContainer::iterator out_it = smoothed_data_container.begin();
00075
00076 int m,i,j;
00077 DoubleReal help;
00078
00079 int frame_size = coeffs_.size();
00080
00081 for (i=0; i<frame_size;++i)
00082 {
00083 it_back=first;
00084 help=0;
00085 m=0;
00086
00087 for (j=i; j>=0; --j)
00088 {
00089 help+=it_back->getIntensity()*coeffs_[m];
00090 --it_back;
00091 ++m;
00092 }
00093
00094 out_it->setPosition(first->getPosition());
00095 out_it->setIntensity(help);
00096 ++out_it;
00097 ++first;
00098 }
00099
00100
00101 while (first!=last)
00102 {
00103 it_back=first;
00104 help=0;
00105
00106 for (j=0; j<frame_size; ++j)
00107 {
00108 help+=it_back->getIntensity()*coeffs_[j];
00109 --it_back;
00110 }
00111
00112 out_it->setPosition(first->getPosition());
00113 out_it->setIntensity(help);
00114 ++out_it;
00115 ++first;
00116 }
00117 }
00118
00119
00132 template <typename InputPeakContainer, typename OutputPeakContainer >
00133 void filter(const InputPeakContainer& input_peak_container, OutputPeakContainer& smoothed_data_container)
00134 {
00135
00136 static_cast<SpectrumSettings&>(smoothed_data_container) = input_peak_container;
00137
00138 filter(input_peak_container.begin(), input_peak_container.end(), smoothed_data_container);
00139 }
00140
00141
00153 template <typename InputSpectrumIterator, typename OutputPeakType >
00154 void filterExperiment(InputSpectrumIterator first, InputSpectrumIterator last, MSExperiment<OutputPeakType>& ms_exp_filtered)
00155 {
00156 UInt n = distance(first,last);
00157 ms_exp_filtered.reserve(n);
00158
00159 for (UInt i = 0; i < n; ++i)
00160 {
00161 MSSpectrum< OutputPeakType > spectrum;
00162 InputSpectrumIterator input_it(first+i);
00163
00164
00165 filter(*input_it,spectrum);
00166
00167
00168 if (spectrum.size() > 0)
00169 {
00170
00171 static_cast<SpectrumSettings&>(spectrum) = *input_it;
00172 spectrum.setType(SpectrumSettings::RAWDATA);
00173
00174
00175 spectrum.getPrecursorPeak() = input_it->getPrecursorPeak();
00176 spectrum.setRT(input_it->getRT());
00177 spectrum.setMSLevel(input_it->getMSLevel());
00178 spectrum.getName() = input_it->getName();
00179
00180 ms_exp_filtered.push_back(spectrum);
00181 }
00182 }
00183 }
00184
00185
00186
00196 template <typename InputPeakType, typename OutputPeakType >
00197 void filterExperiment(const MSExperiment< InputPeakType >& ms_exp_raw, MSExperiment<OutputPeakType>& ms_exp_filtered)
00198 {
00199
00200 static_cast<ExperimentalSettings&>(ms_exp_filtered) = ms_exp_raw;
00201
00202 filterExperiment(ms_exp_raw.begin(), ms_exp_raw.end(), ms_exp_filtered);
00203 }
00204
00205 protected:
00207 std::vector<DoubleReal> coeffs_;
00208 };
00209
00210 }
00211
00212
00213 #endif