~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to include/OpenMS/APPLICATIONS/MapAlignerBase.h

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2013-12-20 11:30:16 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131220113016-wre5g9bteeheq6he
Tags: 1.11.1-3
* remove version number from libbost development package names;
* ensure that AUTHORS is correctly shipped in all packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- mode: C++; tab-width: 2; -*-
2
 
// vi: set ts=2:
3
 
//
4
 
// --------------------------------------------------------------------------
5
 
//                   OpenMS Mass Spectrometry Framework
6
 
// --------------------------------------------------------------------------
7
 
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
8
 
//
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.
13
 
//
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.
18
 
//
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
 
1
// --------------------------------------------------------------------------
 
2
//                   OpenMS -- Open-Source Mass Spectrometry
 
3
// --------------------------------------------------------------------------
 
4
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
 
5
// ETH Zurich, and Freie Universitaet Berlin 2002-2013.
 
6
//
 
7
// This software is released under a three-clause BSD license:
 
8
//  * Redistributions of source code must retain the above copyright
 
9
//    notice, this list of conditions and the following disclaimer.
 
10
//  * Redistributions in binary form must reproduce the above copyright
 
11
//    notice, this list of conditions and the following disclaimer in the
 
12
//    documentation and/or other materials provided with the distribution.
 
13
//  * Neither the name of any author or any participating institution
 
14
//    may be used to endorse or promote products derived from this software
 
15
//    without specific prior written permission.
 
16
// For a full list of authors, refer to the file AUTHORS.
 
17
// --------------------------------------------------------------------------
 
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
19
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
20
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
21
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
 
22
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
23
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
24
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
25
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
26
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
27
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
28
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
29
//
23
30
// --------------------------------------------------------------------------
24
31
// $Maintainer: $
25
32
// $Authors: Marc Sturm, Clemens Groepl, Hendrik Weisser $
26
33
// --------------------------------------------------------------------------
 
34
 
 
35
#ifndef OPENMS_APPLICATIONS_MAPALIGNERBASE_H
 
36
#define OPENMS_APPLICATIONS_MAPALIGNERBASE_H
 
37
 
27
38
#include <OpenMS/FORMAT/MzMLFile.h>
28
39
#include <OpenMS/FORMAT/ConsensusXMLFile.h>
29
40
#include <OpenMS/FORMAT/FeatureXMLFile.h>
31
42
#include <OpenMS/FORMAT/FileHandler.h>
32
43
#include <OpenMS/FORMAT/FileTypes.h>
33
44
#include <OpenMS/FORMAT/TransformationXMLFile.h>
 
45
 
34
46
#include <OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentAlgorithm.h>
 
47
#include <OpenMS/ANALYSIS/MAPMATCHING/MapAlignmentTransformer.h>
35
48
 
36
49
#include <OpenMS/APPLICATIONS/TOPPBase.h>
37
50
 
43
56
//-------------------------------------------------------------
44
57
 
45
58
/**
46
 
        @page TOPP_MapAlignerBase MapAlignerBase
 
59
    @page TOPP_MapAlignerBase MapAlignerBase
47
60
 
48
 
        @brief Base class for different MapAligner TOPP tools.
 
61
    @brief Base class for different MapAligner TOPP tools.
49
62
*/
50
63
 
51
64
// We do not want this class to show up in the docu:
52
65
/// @cond TOPPCLASSES
53
66
 
54
 
class TOPPMapAlignerBase
55
 
  : public TOPPBase
 
67
class TOPPMapAlignerBase :
 
68
  public TOPPBase
56
69
{
57
70
 
58
71
public:
59
 
        TOPPMapAlignerBase(String name, String description, bool official=true)
60
 
                : TOPPBase(name, description, official)
61
 
        {
62
 
        }
63
 
 
64
 
        // "public" so it can be used in DefaultParamHandlerDocumenter to get docu
65
 
        static Param getModelDefaults(const String& default_model)
66
 
        {
67
 
                Param params;
68
 
                params.setValue("type", default_model, "Type of model");
69
 
                // TODO: avoid referring to each TransformationModel subclass explicitly
70
 
                StringList model_types = StringList::create("linear,b_spline,interpolated");
71
 
                if (!model_types.contains(default_model))
72
 
                {
73
 
                        model_types.insert(model_types.begin(), default_model);
74
 
                }
75
 
                params.setValidStrings("type", model_types);
76
 
 
77
 
                Param model_params;
78
 
                TransformationModelLinear::getDefaultParameters(model_params);
79
 
                params.insert("linear:", model_params);
80
 
                params.setSectionDescription("linear", "Parameters for 'linear' model");
81
 
                TransformationModelBSpline::getDefaultParameters(model_params);
82
 
                params.insert("b_spline:", model_params);
83
 
                params.setSectionDescription("b_spline", "Parameters for 'b_spline' model");
84
 
                TransformationModelInterpolated::getDefaultParameters(model_params);
85
 
                // "polynomial" interpolation is not suitable for RT data, so remove it:
86
 
                const Param::ParamEntry& entry = 
87
 
                        model_params.getEntry("interpolation_type");
88
 
                StringList interpolation_types = entry.valid_strings;
89
 
                StringList::Iterator pos = find(interpolation_types.begin(), 
90
 
                                                                                                                                                interpolation_types.end(), "polynomial"); 
91
 
                interpolation_types.erase(pos); 
92
 
                model_params.setValidStrings("interpolation_type", interpolation_types);
93
 
                params.insert("interpolated:", model_params);
94
 
                params.setSectionDescription("interpolated", 
95
 
                                                                                                                                 "Parameters for 'interpolated' model");
96
 
                return params;
97
 
        }
 
72
  TOPPMapAlignerBase(String name, String description, bool official = true) :
 
73
    TOPPBase(name, description, official)
 
74
  {
 
75
  }
 
76
 
 
77
  // "public" so it can be used in DefaultParamHandlerDocumenter to get docu
 
78
  static Param getModelDefaults(const String & default_model)
 
79
  {
 
80
    Param params;
 
81
    params.setValue("type", default_model, "Type of model");
 
82
    // TODO: avoid referring to each TransformationModel subclass explicitly
 
83
    StringList model_types = StringList::create("linear,b_spline,interpolated");
 
84
    if (!model_types.contains(default_model))
 
85
    {
 
86
      model_types.insert(model_types.begin(), default_model);
 
87
    }
 
88
    params.setValidStrings("type", model_types);
 
89
 
 
90
    Param model_params;
 
91
    TransformationModelLinear::getDefaultParameters(model_params);
 
92
    params.insert("linear:", model_params);
 
93
    params.setSectionDescription("linear", "Parameters for 'linear' model");
 
94
    TransformationModelBSpline::getDefaultParameters(model_params);
 
95
    params.insert("b_spline:", model_params);
 
96
    params.setSectionDescription("b_spline", "Parameters for 'b_spline' model");
 
97
    TransformationModelInterpolated::getDefaultParameters(model_params);
 
98
    // "polynomial" interpolation is not suitable for RT data, so remove it:
 
99
    const Param::ParamEntry & entry =
 
100
      model_params.getEntry("interpolation_type");
 
101
    StringList interpolation_types = entry.valid_strings;
 
102
    StringList::Iterator pos = find(interpolation_types.begin(),
 
103
                                    interpolation_types.end(), "polynomial");
 
104
    interpolation_types.erase(pos);
 
105
    model_params.setValidStrings("interpolation_type", interpolation_types);
 
106
    params.insert("interpolated:", model_params);
 
107
    params.setSectionDescription("interpolated",
 
108
                                 "Parameters for 'interpolated' model");
 
109
    return params;
 
110
  }
98
111
 
99
112
protected:
100
 
        void registerOptionsAndFlags_(const String& file_formats)
101
 
        {
102
 
                registerInputFileList_("in", "<files>", StringList(), "Input files separated by blanks (all must have the same file type)", true);
103
 
                setValidFormats_("in", StringList::create(file_formats));
104
 
                registerOutputFileList_("out", "<files>", StringList(), "Output files separated by blanks", false);
105
 
                setValidFormats_("out", StringList::create(file_formats));
106
 
                registerOutputFileList_("trafo_out", "<files>", StringList(), "Transformation output files separated by blanks", false);
107
 
                setValidFormats_("trafo_out", StringList::create("trafoXML"));
 
113
  void registerOptionsAndFlags_(const String & file_formats, const bool add_reference = false)
 
114
  {
 
115
    registerInputFileList_("in", "<files>", StringList(), "Input files separated by blanks (all must have the same file type)", true);
 
116
    setValidFormats_("in", StringList::create(file_formats));
 
117
    registerOutputFileList_("out", "<files>", StringList(), "Output files separated by blanks. Either 'out' or 'trafo_out' has to be provided. They can be used together.", false);
 
118
    setValidFormats_("out", StringList::create(file_formats));
 
119
    registerOutputFileList_("trafo_out", "<files>", StringList(), "Transformation output files separated by blanks. Either 'out' or 'trafo_out' has to be provided. They can be used together.", false);
 
120
    setValidFormats_("trafo_out", StringList::create("trafoXML"));
108
121
    addEmptyLine_();
109
 
                addText_("This tool takes a number of input files, aligns them and writes the results to the output files.");
110
 
                addText_("Either 'out' or 'trafo_out' has to be provided. They can be used together.");
111
 
        }
112
 
 
113
 
        void handleReference_(MapAlignmentAlgorithm* alignment)
114
 
        {
115
 
                // note: this function is in the base class to avoid code duplication, but
116
 
                // it only makes sense for some derived classes - don't call the function
117
 
                // in a class that doesn't support a reference!
118
 
 
119
 
                // check reference parameters:
120
 
                Size reference_index = getIntOption_("reference:index");
121
 
                String reference_file = getStringOption_("reference:file");
122
 
                if (reference_index > getStringList_("in").size())
123
 
                {
124
 
                        throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, "'reference:index' must not be higher than the number of input files");
125
 
                }
126
 
                if (reference_index && !reference_file.empty())
127
 
                {
128
 
                        throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, "'reference:index' and 'reference:file' cannot be used together");
129
 
                }
130
 
 
131
 
                // pass the reference parameters on to the algorithm:
132
 
                alignment->setReference(reference_index, reference_file);
133
 
        }
134
 
 
135
 
        ExitCodes commonMain_(MapAlignmentAlgorithm* alignment)
136
 
        {
137
 
                //-------------------------------------------------------------
138
 
                // parameter handling
139
 
                //-------------------------------------------------------------
140
 
                StringList ins = getStringList_("in");
141
 
                StringList outs = getStringList_("out");
142
 
                StringList trafos = getStringList_("trafo_out");
143
 
                Param model_params = getParam_().copy("model:", true);
144
 
                String model_type = model_params.getValue("type");
145
 
                model_params = model_params.copy(model_type + ":", true);
146
 
 
147
 
                ProgressLogger progresslogger;
148
 
                progresslogger.setLogType(log_type_);
149
 
 
150
 
                //-------------------------------------------------------------
151
 
                // check for valid input
152
 
                //-------------------------------------------------------------
153
 
                // check whether some kind of output file is given:
154
 
                if (outs.empty() && trafos.empty())
155
 
                {
156
 
                        writeLog_("Error: Either data output or transformation output files have to be provided!");
157
 
                        return ILLEGAL_PARAMETERS;
158
 
                }
159
 
                // check whether number of input files equals number of output files:
160
 
                if (!outs.empty() && (ins.size() != outs.size()))
161
 
                {
162
 
                        writeLog_("Error: The number of input and output files has to be equal!");
163
 
                        return ILLEGAL_PARAMETERS;
164
 
                }
165
 
                if (!trafos.empty() && (ins.size() != trafos.size()))
166
 
                {
167
 
                        writeLog_("Error: The number of input and transformation output files has to be equal!");
168
 
                        return ILLEGAL_PARAMETERS;
169
 
                }
170
 
                // check whether all input files have the same type (this type is used to store the output type too):
171
 
                FileTypes::Type in_type = FileHandler::getType(ins[0]);
172
 
                for (Size i = 1; i < ins.size(); ++i)
173
 
                {
174
 
                        if (FileHandler::getType(ins[i]) != in_type)
175
 
                        {
176
 
                                writeLog_("Error: All input files have to be in the same format!");
177
 
                                return ILLEGAL_PARAMETERS;
178
 
                        }
179
 
                }
 
122
    if (add_reference)
 
123
    {
 
124
      registerTOPPSubsection_("reference", "Options to define a reference file (use either 'file' or 'index', not both; if neither is given 'index' is used).");
 
125
      registerInputFile_("reference:file", "<file>", "", "File to use as reference (same file format as input files required)", false);
 
126
      setValidFormats_("reference:file", StringList::create(file_formats));
 
127
      registerIntOption_("reference:index", "<number>", 0, "Use one of the input files as reference ('1' for the first file, etc.).\nIf '0', no explicit reference is set - the algorithm will select a reference.", false);
 
128
      setMinInt_("reference:index", 0);
 
129
    }
 
130
  }
 
131
 
 
132
  /// deprecated? (not used in PoseClustering... and moved to initialize_() )
 
133
  void handleReference_(MapAlignmentAlgorithm * alignment)
 
134
  {
 
135
    // note: this function is in the base class to avoid code duplication, but
 
136
    // it only makes sense for some derived classes - don't call the function
 
137
    // in a class that doesn't support a reference!
 
138
 
 
139
    // check reference parameters:
 
140
    Size reference_index = getIntOption_("reference:index");
 
141
    String reference_file = getStringOption_("reference:file");
 
142
    if (reference_index > getStringList_("in").size())
 
143
    {
 
144
      throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, "'reference:index' must not be higher than the number of input files");
 
145
    }
 
146
    if (reference_index && !reference_file.empty())
 
147
    {
 
148
      throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, "'reference:index' and 'reference:file' cannot be used together");
 
149
    }
 
150
 
 
151
    // pass the reference parameters on to the algorithm:
 
152
    alignment->setReference(reference_index, reference_file);
 
153
  }
 
154
 
 
155
  ExitCodes initialize_(MapAlignmentAlgorithm * alignment, bool check_ref = false)
 
156
  {
 
157
    //-------------------------------------------------------------
 
158
    // parameter handling
 
159
    //-------------------------------------------------------------
 
160
    StringList ins = getStringList_("in");
 
161
    StringList outs = getStringList_("out");
 
162
    StringList trafos = getStringList_("trafo_out");
 
163
 
 
164
    //-------------------------------------------------------------
 
165
    // check for valid input
 
166
    //-------------------------------------------------------------
 
167
    // check whether some kind of output file is given:
 
168
    if (outs.empty() && trafos.empty())
 
169
    {
 
170
      writeLog_("Error: Either data output or transformation output files have to be provided!");
 
171
      return ILLEGAL_PARAMETERS;
 
172
    }
 
173
    // check whether number of input files equals number of output files:
 
174
    if (!outs.empty() && (ins.size() != outs.size()))
 
175
    {
 
176
      writeLog_("Error: The number of input and output files has to be equal!");
 
177
      return ILLEGAL_PARAMETERS;
 
178
    }
 
179
    if (!trafos.empty() && (ins.size() != trafos.size()))
 
180
    {
 
181
      writeLog_("Error: The number of input and transformation output files has to be equal!");
 
182
      return ILLEGAL_PARAMETERS;
 
183
    }
 
184
    // check whether all input files have the same type (this type is used to store the output type too):
 
185
    FileTypes::Type in_type = FileHandler::getType(ins[0]);
 
186
    for (Size i = 1; i < ins.size(); ++i)
 
187
    {
 
188
      if (FileHandler::getType(ins[i]) != in_type)
 
189
      {
 
190
        writeLog_("Error: All input files have to be in the same format!");
 
191
        return ILLEGAL_PARAMETERS;
 
192
      }
 
193
    }
 
194
 
 
195
    if (check_ref) // a valid index OR file should be given
 
196
    {
 
197
      Size reference_index = getIntOption_("reference:index");
 
198
      String reference_file = getStringOption_("reference:file");
 
199
      if (reference_index > getStringList_("in").size())
 
200
      {
 
201
        throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, "'reference:index' must not be higher than the number of input files");
 
202
      }
 
203
      if (reference_index && !reference_file.empty())
 
204
      {
 
205
        throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, "'reference:index' and 'reference:file' cannot be used together");
 
206
      }
 
207
 
 
208
      // file should have same type as other input
 
209
      if (!reference_file.empty())
 
210
      {
 
211
        if (FileHandler::getType(reference_file) != in_type)
 
212
        {
 
213
          writeLog_("Error: Reference file has not the same format as other input files!");
 
214
          return ILLEGAL_PARAMETERS;
 
215
        }
 
216
      }
 
217
    }
180
218
 
181
219
    //-------------------------------------------------------------
182
220
    // set up alignment algorithm
183
221
    //-------------------------------------------------------------
184
 
                Param alignment_param = getParam_().copy("algorithm:", true);
185
 
 
186
 
                writeDebug_("Used alignment parameters", alignment_param, 3);
187
 
                alignment->setParameters(alignment_param);
188
 
                alignment->setLogType(log_type_);
189
 
 
190
 
                std::vector<TransformationDescription> transformations;
 
222
    Param alignment_param = getParam_().copy("algorithm:", true);
 
223
 
 
224
    writeDebug_("Used alignment parameters", alignment_param, 3);
 
225
    alignment->setParameters(alignment_param);
 
226
    alignment->setLogType(log_type_);
 
227
 
 
228
    return EXECUTION_OK;
 
229
  }
 
230
 
 
231
  /// deprecated? (not used in PoseClustering... and moved to initialize_() )
 
232
  ExitCodes commonMain_(MapAlignmentAlgorithm * alignment)
 
233
  {
 
234
    ExitCodes ret = initialize_(alignment);
 
235
    if (ret != EXECUTION_OK) return ret;
 
236
 
 
237
    ProgressLogger progresslogger;
 
238
    progresslogger.setLogType(log_type_);
 
239
 
 
240
 
 
241
    StringList ins = getStringList_("in");
 
242
    StringList outs = getStringList_("out");
 
243
    StringList trafos = getStringList_("trafo_out");
 
244
    Param model_params = getParam_().copy("model:", true);
 
245
    String model_type = model_params.getValue("type");
 
246
    model_params = model_params.copy(model_type + ":", true);
 
247
    FileTypes::Type in_type = FileHandler::getType(ins[0]);
 
248
    std::vector<TransformationDescription> transformations;
191
249
 
192
250
    //-------------------------------------------------------------
193
251
    // perform peak alignment
194
252
    //-------------------------------------------------------------
195
 
                if (in_type == FileTypes::MZML)
196
 
                {
197
 
                        // load input
198
 
                        std::vector< MSExperiment<> > peak_maps(ins.size());
199
 
                        MzMLFile f;
200
 
                        f.setLogType(log_type_);
201
 
                        for (Size i = 0; i < ins.size(); ++i)
202
 
                        {
203
 
                    f.load(ins[i], peak_maps[i]);
204
 
                        }
205
 
 
206
 
                        // try to align
207
 
                        try
208
 
                        {
209
 
                                alignment->alignPeakMaps(peak_maps, transformations);
210
 
                        }
211
 
                        catch (Exception::NotImplemented&)
212
 
                        {
213
 
                                writeLog_("Error: The algorithm '" + alignment->getName() + "' cannot be used for peak data!");
214
 
                                return INTERNAL_ERROR;
215
 
                        }
216
 
                        if (model_type != "none")
217
 
                        {
218
 
                                alignment->fitModel(model_type, model_params, transformations);
219
 
                        }
220
 
                        alignment->transformPeakMaps(peak_maps, transformations);
221
 
 
222
 
                        // write output
223
 
                        progresslogger.startProgress(0, outs.size(), "writing output files");
224
 
                        for (Size i = 0; i < outs.size(); ++i)
225
 
                        {
226
 
                                progresslogger.setProgress(i);
227
 
                                
228
 
                                //annotate output with data processing info
229
 
                                addDataProcessing_(peak_maps[i], getProcessingInfo_(DataProcessing::ALIGNMENT));
230
 
 
231
 
                    f.store(outs[i], peak_maps[i]);
232
 
                        }
233
 
                        progresslogger.endProgress();
234
 
                }
 
253
    if (in_type == FileTypes::MZML)
 
254
    {
 
255
      // load input
 
256
      std::vector<MSExperiment<> > peak_maps(ins.size());
 
257
      MzMLFile f;
 
258
      f.setLogType(log_type_);
 
259
      for (Size i = 0; i < ins.size(); ++i)
 
260
      {
 
261
        f.load(ins[i], peak_maps[i]);
 
262
      }
 
263
 
 
264
      // try to align
 
265
      try
 
266
      {
 
267
        alignment->alignPeakMaps(peak_maps, transformations);
 
268
      }
 
269
      catch (Exception::NotImplemented &)
 
270
      {
 
271
        writeLog_("Error: The algorithm '" + alignment->getName() + "' cannot be used for peak data!");
 
272
        return INTERNAL_ERROR;
 
273
      }
 
274
      if (model_type != "none")
 
275
      {
 
276
        alignment->fitModel(model_type, model_params, transformations);
 
277
      }
 
278
      MapAlignmentTransformer::transformPeakMaps(peak_maps, transformations);
 
279
 
 
280
      // write output
 
281
      progresslogger.startProgress(0, outs.size(), "writing output files");
 
282
      for (Size i = 0; i < outs.size(); ++i)
 
283
      {
 
284
        progresslogger.setProgress(i);
 
285
 
 
286
        //annotate output with data processing info
 
287
        addDataProcessing_(peak_maps[i], getProcessingInfo_(DataProcessing::ALIGNMENT));
 
288
 
 
289
        f.store(outs[i], peak_maps[i]);
 
290
      }
 
291
      progresslogger.endProgress();
 
292
    }
235
293
    //-------------------------------------------------------------
236
294
    // perform feature alignment
237
295
    //-------------------------------------------------------------
238
 
                else if (in_type == FileTypes::FEATUREXML)
239
 
                {
240
 
                        // load input
241
 
                        std::vector< FeatureMap<> > feat_maps(ins.size());
242
 
                        FeatureXMLFile f;
243
 
                        // f.setLogType(log_type_); // TODO
244
 
                        progresslogger.startProgress(0, ins.size(), "loading input files");
245
 
                        for (Size i = 0; i < ins.size(); ++i)
246
 
                        {
247
 
                                progresslogger.setProgress(i);
248
 
                    f.load(ins[i], feat_maps[i]);
249
 
                        }
250
 
                        progresslogger.endProgress();
251
 
 
252
 
                        // try to align
253
 
                        try
254
 
                        {
255
 
                                alignment->alignFeatureMaps(feat_maps, transformations);
256
 
                        }
257
 
                        catch (Exception::NotImplemented&)
258
 
                        {
259
 
                                writeLog_("Error: The algorithm '" + alignment->getName() + "' cannot be used for feature data!");
260
 
                                return INTERNAL_ERROR;
261
 
                        }
262
 
                        if (model_type != "none")
263
 
                        {
264
 
                                alignment->fitModel(model_type, model_params, transformations);
265
 
                        }
266
 
                        alignment->transformFeatureMaps(feat_maps, transformations);
267
 
 
268
 
                        // write output
269
 
                        progresslogger.startProgress(0, outs.size(), "writing output files");
270
 
                        for (Size i = 0; i < outs.size(); ++i)
271
 
                        {
272
 
                                progresslogger.setProgress(i);
273
 
                                
274
 
                                //annotate output with data processing info
275
 
                                addDataProcessing_(feat_maps[i], getProcessingInfo_(DataProcessing::ALIGNMENT));
276
 
 
277
 
                    f.store(outs[i], feat_maps[i]);
278
 
                        }
279
 
                        progresslogger.endProgress();
280
 
                }
 
296
    else if (in_type == FileTypes::FEATUREXML)
 
297
    {
 
298
      // load input
 
299
      std::vector<std::vector<Peak2D> > feat_maps(ins.size());
 
300
      FeatureXMLFile f;
 
301
      // f.setLogType(log_type_); // TODO
 
302
      progresslogger.startProgress(0, ins.size(), "loading input files");
 
303
      for (Size i = 0; i < ins.size(); ++i)
 
304
      {
 
305
        progresslogger.setProgress(i);
 
306
        FeatureMap<> feature_map;
 
307
        f.load(ins[i], feature_map);
 
308
        feat_maps[i].resize(feature_map.size());
 
309
 
 
310
        FeatureMap<>::const_iterator it = feature_map.begin();
 
311
        std::vector<Peak2D>::iterator c_it = feat_maps[i].begin();
 
312
        for (; it != feature_map.end(); ++it, ++c_it)
 
313
        {
 
314
          *c_it = reinterpret_cast<const Peak2D &>(*it);
 
315
        }
 
316
      }
 
317
      progresslogger.endProgress();
 
318
 
 
319
      // try to align
 
320
      try
 
321
      {
 
322
        alignment->alignCompactFeatureMaps(feat_maps, transformations);
 
323
      }
 
324
      catch (Exception::NotImplemented &)
 
325
      {
 
326
        writeLog_("Error: The algorithm '" + alignment->getName() + "' cannot be used for feature data!");
 
327
        return INTERNAL_ERROR;
 
328
      }
 
329
      if (model_type != "none")
 
330
      {
 
331
        alignment->fitModel(model_type, model_params, transformations);
 
332
      }
 
333
      // alignment->transformFeatureMaps(feat_maps, transformations);
 
334
 
 
335
      // write output
 
336
      progresslogger.startProgress(0, outs.size(), "writing output files");
 
337
      for (Size i = 0; i < outs.size(); ++i)
 
338
      {
 
339
        progresslogger.setProgress(i);
 
340
 
 
341
        FeatureMap<> feature_map;
 
342
        f.load(ins[i], feature_map);
 
343
 
 
344
        MapAlignmentTransformer::transformSingleFeatureMap(feature_map, transformations[i]);
 
345
 
 
346
        //annotate output with data processing info
 
347
        addDataProcessing_(feature_map, getProcessingInfo_(DataProcessing::ALIGNMENT));
 
348
 
 
349
        f.store(outs[i], feature_map);
 
350
      }
 
351
      progresslogger.endProgress();
 
352
    }
281
353
    //-------------------------------------------------------------
282
354
    // perform consensus alignment
283
355
    //-------------------------------------------------------------
284
 
                else if (in_type == FileTypes::CONSENSUSXML)
285
 
                {
286
 
                        // load input
287
 
                        std::vector<ConsensusMap> cons_maps(ins.size());
288
 
                        ConsensusXMLFile f;
289
 
                        // f.setLogType(log_type_); // TODO
290
 
                        progresslogger.startProgress(0, ins.size(), "loading input files");
291
 
                        for (Size i = 0; i < ins.size(); ++i)
292
 
                        {
293
 
                                progresslogger.setProgress(i);
294
 
                    f.load(ins[i], cons_maps[i]);
295
 
                        }
296
 
                        progresslogger.endProgress();
297
 
 
298
 
                        // try to align
299
 
                        try
300
 
                        {
301
 
                                alignment->alignConsensusMaps(cons_maps, transformations);
302
 
                        }
303
 
                        catch (Exception::NotImplemented&)
304
 
                        {
305
 
                                writeLog_("Error: The algorithm '" + alignment->getName() + "' cannot be used for consensus feature data!");
306
 
                                return INTERNAL_ERROR;
307
 
                        }
308
 
                        if (model_type != "none")
309
 
                        {
310
 
                                alignment->fitModel(model_type, model_params, transformations);
311
 
                        }
312
 
                        alignment->transformConsensusMaps(cons_maps, transformations);
313
 
 
314
 
                        // write output
315
 
                        progresslogger.startProgress(0, outs.size(), "writing output files");
316
 
                        for (Size i = 0; i < outs.size(); ++i)
317
 
                        {
318
 
                                progresslogger.setProgress(i);
319
 
                                
320
 
                                //annotate output with data processing info
321
 
                                addDataProcessing_(cons_maps[i], getProcessingInfo_(DataProcessing::ALIGNMENT));
322
 
 
323
 
                    f.store(outs[i], cons_maps[i]);
324
 
                        }
325
 
                        progresslogger.endProgress();
326
 
                }
 
356
    else if (in_type == FileTypes::CONSENSUSXML)
 
357
    {
 
358
      // load input
 
359
      std::vector<ConsensusMap> cons_maps(ins.size());
 
360
      ConsensusXMLFile f;
 
361
      // f.setLogType(log_type_); // TODO
 
362
      progresslogger.startProgress(0, ins.size(), "loading input files");
 
363
      for (Size i = 0; i < ins.size(); ++i)
 
364
      {
 
365
        progresslogger.setProgress(i);
 
366
        f.load(ins[i], cons_maps[i]);
 
367
      }
 
368
      progresslogger.endProgress();
 
369
 
 
370
      // try to align
 
371
      try
 
372
      {
 
373
        alignment->alignConsensusMaps(cons_maps, transformations);
 
374
      }
 
375
      catch (Exception::NotImplemented &)
 
376
      {
 
377
        writeLog_("Error: The algorithm '" + alignment->getName() + "' cannot be used for consensus feature data!");
 
378
        return INTERNAL_ERROR;
 
379
      }
 
380
      if (model_type != "none")
 
381
      {
 
382
        alignment->fitModel(model_type, model_params, transformations);
 
383
      }
 
384
      MapAlignmentTransformer::transformConsensusMaps(cons_maps, transformations);
 
385
 
 
386
      // write output
 
387
      progresslogger.startProgress(0, outs.size(), "writing output files");
 
388
      for (Size i = 0; i < outs.size(); ++i)
 
389
      {
 
390
        progresslogger.setProgress(i);
 
391
 
 
392
        //annotate output with data processing info
 
393
        addDataProcessing_(cons_maps[i], getProcessingInfo_(DataProcessing::ALIGNMENT));
 
394
 
 
395
        f.store(outs[i], cons_maps[i]);
 
396
      }
 
397
      progresslogger.endProgress();
 
398
    }
327
399
    //-------------------------------------------------------------
328
400
    // perform peptide alignment
329
401
    //-------------------------------------------------------------
330
 
                else if (in_type == FileTypes::IDXML)
331
 
                {
332
 
                        // load input
333
 
                        std::vector< std::vector<ProteinIdentification> > protein_ids_vec(ins.size());
334
 
                        std::vector< std::vector<PeptideIdentification> > peptide_ids_vec(ins.size());
335
 
 
336
 
                        IdXMLFile f;
337
 
                        // f.setLogType_(log_type_);
338
 
 
339
 
                        progresslogger.startProgress(0, ins.size(), "loading input files");
340
 
                        for (Size i = 0; i < ins.size(); ++i)
341
 
                        {
342
 
                                progresslogger.setProgress(i);
343
 
                    f.load(ins[i], protein_ids_vec[i], peptide_ids_vec[i]);
344
 
                        }
345
 
                        progresslogger.endProgress();
346
 
 
347
 
                        // try to align
348
 
                        try
349
 
                        {
350
 
                                alignment->alignPeptideIdentifications(peptide_ids_vec, transformations);
351
 
                        }
352
 
                        catch (Exception::NotImplemented&)
353
 
                        {
354
 
                                writeLog_("Error: The algorithm '" + alignment->getName() + "' cannot be used for peptide data!");
355
 
                                return INTERNAL_ERROR;
356
 
                        }
357
 
                        if (model_type != "none")
358
 
                        {
359
 
                                alignment->fitModel(model_type, model_params, transformations);
360
 
                        }
361
 
                        alignment->transformPeptideIdentifications(peptide_ids_vec, 
362
 
                                                                                                                                                                                                 transformations);
363
 
 
364
 
                        // write output
365
 
                        progresslogger.startProgress(0, outs.size(), "writing output files");
366
 
                        for (Size i = 0; i < outs.size(); ++i)
367
 
                        {
368
 
                                progresslogger.setProgress(i);
369
 
                    f.store(outs[i], protein_ids_vec[i], peptide_ids_vec[i]);
370
 
                        }
371
 
                        progresslogger.endProgress();
372
 
                }
373
 
                else
374
 
                {
375
 
                        // TODO can this really happen? I think it is tested above. Otherwise
376
 
                        // throw an appropriate exception?
377
 
                        return ILLEGAL_PARAMETERS;
378
 
                }
379
 
 
380
 
                if (!trafos.empty())
381
 
                {
382
 
                        for (Size i = 0; i < transformations.size(); ++i)
383
 
                        {
384
 
                                TransformationXMLFile().store(trafos[i], transformations[i]);
385
 
                        }
386
 
                }
387
 
 
388
 
                return EXECUTION_OK;
389
 
        }
 
402
    else if (in_type == FileTypes::IDXML)
 
403
    {
 
404
      // load input
 
405
      std::vector<std::vector<ProteinIdentification> > protein_ids_vec(ins.size());
 
406
      std::vector<std::vector<PeptideIdentification> > peptide_ids_vec(ins.size());
 
407
 
 
408
      IdXMLFile f;
 
409
      // f.setLogType_(log_type_);
 
410
 
 
411
      progresslogger.startProgress(0, ins.size(), "loading input files");
 
412
      for (Size i = 0; i < ins.size(); ++i)
 
413
      {
 
414
        progresslogger.setProgress(i);
 
415
        f.load(ins[i], protein_ids_vec[i], peptide_ids_vec[i]);
 
416
      }
 
417
      progresslogger.endProgress();
 
418
 
 
419
      // try to align
 
420
      try
 
421
      {
 
422
        alignment->alignPeptideIdentifications(peptide_ids_vec, transformations);
 
423
      }
 
424
      catch (Exception::NotImplemented &)
 
425
      {
 
426
        writeLog_("Error: The algorithm '" + alignment->getName() + "' cannot be used for peptide data!");
 
427
        return INTERNAL_ERROR;
 
428
      }
 
429
      if (model_type != "none")
 
430
      {
 
431
        alignment->fitModel(model_type, model_params, transformations);
 
432
      }
 
433
      MapAlignmentTransformer::transformPeptideIdentifications(peptide_ids_vec,
 
434
                                                               transformations);
 
435
 
 
436
      // write output
 
437
      progresslogger.startProgress(0, outs.size(), "writing output files");
 
438
      for (Size i = 0; i < outs.size(); ++i)
 
439
      {
 
440
        progresslogger.setProgress(i);
 
441
        f.store(outs[i], protein_ids_vec[i], peptide_ids_vec[i]);
 
442
      }
 
443
      progresslogger.endProgress();
 
444
    }
 
445
    else
 
446
    {
 
447
      // TODO can this really happen? I think it is tested above. Otherwise
 
448
      // throw an appropriate exception?
 
449
      return ILLEGAL_PARAMETERS;
 
450
    }
 
451
 
 
452
    if (!trafos.empty())
 
453
    {
 
454
      for (Size i = 0; i < transformations.size(); ++i)
 
455
      {
 
456
        TransformationXMLFile().store(trafos[i], transformations[i]);
 
457
      }
 
458
    }
 
459
 
 
460
    return EXECUTION_OK;
 
461
  }
 
462
 
390
463
};
391
464
 
392
465
/// @endcond
 
466
 
 
467
#endif // OPENMS_APPLICATIONS_MAPALIGNERBASE_H