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: Erhan Kenar $
25
// $Authors: Erhan Kenar, Holger Franken $
26
// --------------------------------------------------------------------------
27
#include <OpenMS/FORMAT/MzMLFile.h>
28
#include <OpenMS/FORMAT/PeakFileOptions.h>
29
#include <OpenMS/FORMAT/FeatureXMLFile.h>
30
#include <OpenMS/KERNEL/MSExperiment.h>
31
#include <OpenMS/KERNEL/FeatureMap.h>
32
#include <OpenMS/KERNEL/MassTrace.h>
33
#include <OpenMS/FILTERING/DATAREDUCTION/MassTraceDetection.h>
34
#include <OpenMS/FILTERING/DATAREDUCTION/ElutionPeakDetection.h>
35
#include <OpenMS/APPLICATIONS/TOPPBase.h>
37
using namespace OpenMS;
40
//-------------------------------------------------------------
42
//-------------------------------------------------------------
45
@page TOPP_MassTraceExtractor MassTraceExtractor
47
@brief MassTraceExtractor extracts mass traces from a @ref MSExperiment map and stores them into a @ref FeatureXMLFile.
52
<td ALIGN = "center" BGCOLOR="#EBEBEB"> pot. predecessor tools </td>
53
<td VALIGN="middle" ROWSPAN=3> \f$ \longrightarrow \f$ MassTraceExtractor \f$ \longrightarrow \f$</td>
54
<td ALIGN = "center" BGCOLOR="#EBEBEB"> pot. successor tools </td>
57
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_PeakPickerHiRes </td>
58
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_FeatureFinderMetabo</td>
61
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_PeakPickerWavelet </td>
62
<td VALIGN="middle" ALIGN = "center" ROWSPAN=1> @ref TOPP_TextExporter </td>
68
This TOPP tool detects mass traces in centroided LC-MS maps and stores them as features in
69
a @ref FeatureMap. These features may be either used directly as input for an metabolite ID approach or further
70
be assembled to aggregate features according to a theoretical isotope pattern. For metabolomics experiments,
71
the @ref TOPP_FeatureFinderMetabo tool offers both mass trace extraction and isotope pattern assembly.
72
For proteomics data, please refer to the @ref TOPP_FeatureFinderCentroided tool.
74
<B>The command line parameters of this tool are:</B>
75
@verbinclude TOPP_MassTraceExtractor.cli
78
// We do not want this class to show up in the docu:
81
class TOPPMassTraceExtractor
85
TOPPMassTraceExtractor()
86
: TOPPBase("MassTraceExtractor", "Detects mass traces in centroided LC-MS data.")
92
void registerOptionsAndFlags_()
94
registerInputFile_("in","<file>", "", "input centroided mzML file");
95
setValidFormats_("in",StringList::create("mzML"));
96
registerOutputFile_("out", "<file>", "", "output featureXML file with mass traces");
97
setValidFormats_("out",StringList::create("featureXML"));
100
addText_("Parameters for the mass trace detection algorithm can be given in the 'algorithm' part of INI file.");
101
registerSubsection_("algorithm","Algorithm parameters section");
105
Param getSubsectionDefaults_(const String& /*section*/) const
110
p_com.setValue("chrom_fwhm" , 0.0 , "Allows filtering of mass traces with peak width (in seconds) less than this threshold. Disabled by default (set to 0.0).");
111
combined.insert("common:", p_com);
113
Param p_mtd = MassTraceDetection().getDefaults();
114
p_mtd.remove("chrom_fwhm");
115
combined.insert("mtd:", p_mtd);
117
Param p_epd = ElutionPeakDetection().getDefaults();
118
p_epd.remove("chrom_fwhm");
119
p_epd.setValue("enabled", "true", "Switches on/off the detection of elution peaks");
120
p_epd.setValidStrings("enabled", StringList::create("true,false"));
121
combined.insert("epd:", p_epd);
126
ExitCodes main_(int , const char**)
129
//-------------------------------------------------------------
130
// parameter handling
131
//-------------------------------------------------------------
133
String in = getStringOption_("in");
134
String out = getStringOption_("out");
136
//-------------------------------------------------------------
138
//-------------------------------------------------------------
139
MzMLFile mz_data_file;
140
mz_data_file.setLogType(log_type_);
141
MSExperiment<Peak1D> ms_peakmap;
142
std::vector<Int> ms_level(1, 1);
143
(mz_data_file.getOptions()).setMSLevels(ms_level);
144
mz_data_file.load(in, ms_peakmap);
146
if (ms_peakmap.size()==0)
148
LOG_WARN << "The given file does not contain any conventional peak data, but might"
149
" contain chromatograms. This tool currently cannot handle them, sorry.";
150
return INCOMPATIBLE_INPUT_DATA;
154
FeatureMap<> ms_feat_map;
155
vector<MassTrace> m_traces;
157
//-------------------------------------------------------------
158
// get params for MTD and EPD algorithms
159
//-------------------------------------------------------------
160
Param com_param = getParam_().copy("algorithm:common:",true);
161
writeDebug_("Common parameters passed to both subalgorithms (mtd and epd)", com_param,3);
163
Param mtd_param = getParam_().copy("algorithm:mtd:",true);
164
writeDebug_("Parameters passed to MassTraceDetection", mtd_param,3);
166
Param epd_param = getParam_().copy("algorithm:epd:",true);
167
writeDebug_("Parameters passed to ElutionPeakDetection", epd_param,3);
170
//-------------------------------------------------------------
171
// configure and run MTD
172
//-------------------------------------------------------------
174
MassTraceDetection mt_ext;
175
mtd_param.insert("", com_param);
176
mt_ext.setParameters(mtd_param);
177
mt_ext.run(ms_peakmap, m_traces);
179
vector<MassTrace> m_traces_final = m_traces;
181
bool use_epd = epd_param.getValue("enabled").toBool();
185
ElutionPeakDetection ep_det;
187
epd_param.remove("enabled"); // artificially added above
188
epd_param.insert("", com_param);
190
ep_det.setParameters(epd_param);
192
std::vector<MassTrace> splitted_mtraces;
194
ep_det.detectPeaks(m_traces, splitted_mtraces);
196
if (ep_det.getParameters().getValue("width_filtering").toBool())
198
m_traces_final.clear();
199
ep_det.filterByPeakWidth(splitted_mtraces, m_traces_final);
201
LOG_INFO << "Notice: " << splitted_mtraces.size() - m_traces_final.size() << " of total " << splitted_mtraces.size() << " were dropped because of too low peak width." << std::endl;
205
m_traces_final = splitted_mtraces;
209
//-----------------------------------------------------------
210
// convert mass traces to features
211
//-----------------------------------------------------------
213
for (Size i = 0; i < m_traces_final.size(); ++i)
215
if (m_traces_final[i].getSize() == 0) continue;
218
f.setMetaValue(3, m_traces_final[i].getLabel());
220
f.setMZ(m_traces_final[i].getCentroidMZ());
221
f.setIntensity(m_traces_final[i].computePeakArea());
222
f.setRT(m_traces_final[i].getCentroidRT());
223
f.setWidth(m_traces_final[i].estimateFWHM(use_epd));
224
f.setOverallQuality(1 - (1.0/m_traces_final[i].getSize()));
225
f.getConvexHulls().push_back(m_traces_final[i].getConvexhull());
227
ms_feat_map.push_back(f);
230
ms_feat_map.applyMemberFunction(&UniqueIdInterface::setUniqueId);
232
//-------------------------------------------------------------
234
//-------------------------------------------------------------
236
//annotate output with data processing info TODO
237
addDataProcessing_(ms_feat_map, getProcessingInfo_(DataProcessing::QUANTITATION));
238
ms_feat_map.setUniqueId();
240
FeatureXMLFile().store(out, ms_feat_map);
247
int main( int argc, const char** argv )
249
TOPPMassTraceExtractor tool;
250
return tool.main(argc, argv);