1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
// --------------------------------------------------------------------------
24
// $Maintainer: Alexandra Zerck $
25
// $Authors: Eva Lange $
26
// --------------------------------------------------------------------------
27
#include <OpenMS/config.h>
29
#include <OpenMS/FILTERING/SMOOTHING/SavitzkyGolayFilter.h>
30
#include <OpenMS/FORMAT/MzMLFile.h>
31
#include <OpenMS/KERNEL/MSExperiment.h>
32
#include <OpenMS/APPLICATIONS/TOPPBase.h>
33
#include <OpenMS/FORMAT/PeakTypeEstimator.h>
34
#include <OpenMS/DATASTRUCTURES/StringList.h>
36
using namespace OpenMS;
39
//-------------------------------------------------------------
41
//-------------------------------------------------------------
44
@page TOPP_NoiseFilterSGolay NoiseFilterSGolay
46
@brief Executes a Savitzky Golay filter to reduce the noise in an MS experiment.
51
<td ALIGN = "center" BGCOLOR="#EBEBEB"> pot. predecessor tools </td>
52
<td VALIGN="middle" ROWSPAN=4> \f$ \longrightarrow \f$ NoiseFilterSGolay \f$ \longrightarrow \f$</td>
53
<td ALIGN = "center" BGCOLOR="#EBEBEB"> pot. successor tools </td>
56
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_FileConverter </td>
57
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_PeakPickerWavelet</td>
60
<td VALIGN="middle" ALIGN = "center" ROWSPAN=2> @ref TOPP_Resampler </td>
61
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_PeakPickerHiRes</td>
64
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_BaselineFilter</td>
70
The idea of the Savitzky Golay filter is to find filter-coefficients
71
that preserve higher moments, which means to approximate the underlying
72
function within the moving window by a polynomial of higher order
73
(typically quadratic or quartic) (see A. Savitzky and M. J. E. Golay,
74
''Smoothing and Differentiation of Data by Simplified Least Squares Procedures'').
76
@note The Savitzky Golay filter works only on uniform data (to generate equally spaced data use the @ref TOPP_Resampler tool).
78
<B>The command line parameters of this tool are:</B>
79
@verbinclude TOPP_NoiseFilterSGolay.cli
81
<B>The algorithm parameters for the Savitzky Golay filter are:</B>
82
@htmlinclude OpenMS_SavitzkyGolayFilter.parameters
85
// We do not want this class to show up in the docu:
89
class TOPPNoiseFilterSGolay
93
TOPPNoiseFilterSGolay()
94
: TOPPBase("NoiseFilterSGolay","Removes noise from profile spectra by using a Savitzky Golay filter.")
98
void registerOptionsAndFlags_()
100
registerInputFile_("in","<file>","","input raw data file ");
101
setValidFormats_("in",StringList::create("mzML"));
102
registerOutputFile_("out","<file>","","output raw data file ");
103
setValidFormats_("out",StringList::create("mzML"));
105
addText_("Parameters for the algorithms can be given in the INI file only.");
107
addText_("Note: The Savitzky Golay filter works only on uniform data (to generate equally spaced data use the Resampler tool).");
108
registerSubsection_("algorithm","Algorithm parameters section");
111
Param getSubsectionDefaults_(const String& /*section*/) const
113
return SavitzkyGolayFilter().getDefaults();
116
ExitCodes main_(int , const char**)
118
//-------------------------------------------------------------
119
// parameter handling
120
//-------------------------------------------------------------
121
String in = getStringOption_("in");
122
String out = getStringOption_("out");
124
//-------------------------------------------------------------
126
//-------------------------------------------------------------
127
MzMLFile mz_data_file;
128
mz_data_file.setLogType(log_type_);
129
MSExperiment<Peak1D> exp;
130
mz_data_file.load(in,exp);
134
LOG_WARN << "The given file does not contain any conventional peak data, but might"
135
" contain chromatograms. This tool currently cannot handle them, sorry.";
136
return INCOMPATIBLE_INPUT_DATA;
138
//check for peak type (profile data required)
139
if (PeakTypeEstimator().estimateType(exp[0].begin(),exp[0].end())==SpectrumSettings::PEAKS)
141
writeLog_("Warning: OpenMS peak type estimation indicates that this is not profile data!");
144
//check if spectra are sorted
145
for (Size i=0; i< exp.size(); ++i)
147
if (!exp[i].isSorted())
149
writeLog_("Error: Not all spectra are sorted according to peak m/z positions. Use FileFilter to sort the input!");
150
return INCOMPATIBLE_INPUT_DATA;
154
//-------------------------------------------------------------
156
//-------------------------------------------------------------
157
Param filter_param = getParam_().copy("algorithm:",true);
158
writeDebug_("Parameters passed to filter", filter_param,3);
160
SavitzkyGolayFilter sgolay;
161
sgolay.setLogType(log_type_);
162
sgolay.setParameters( filter_param );
163
sgolay.filterExperiment(exp);
165
//-------------------------------------------------------------
167
//-------------------------------------------------------------
169
//annotate output with data processing info
170
addDataProcessing_(exp, getProcessingInfo_(DataProcessing::SMOOTHING));
172
mz_data_file.store(out,exp);
179
int main( int argc, const char** argv )
181
TOPPNoiseFilterSGolay tool;
182
return tool.main(argc,argv);