OpenMS  2.7.0
MapAlignerBase.h
Go to the documentation of this file.
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-2021.
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.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Hendrik Weisser $
32 // $Authors: Marc Sturm, Clemens Groepl, Hendrik Weisser $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/FORMAT/MzMLFile.h>
44 
47 
52 
54 
55 //-------------------------------------------------------------
56 // Doxygen docu
57 //-------------------------------------------------------------
58 
65 // We do not want this class to show up in the docu:
67 
68 namespace OpenMS
69 {
70 
71 class TOPPMapAlignerBase :
72  public TOPPBase
73 {
74 
75 public:
76  TOPPMapAlignerBase(String name, String description, bool official = true) :
77  TOPPBase(name, description, official), ref_params_(REF_NONE)
78  {
79  }
80 
81  // "public" so it can be used in DefaultParamHandlerDocumenter to get docu
82  static Param getModelDefaults(const String& default_model)
83  {
84  Param params;
85  params.setValue("type", default_model, "Type of model");
86  // TODO: avoid referring to each TransformationModel subclass explicitly
87  std::vector<std::string> model_types = {"linear","b_spline","lowess","interpolated"};
88  if (!ListUtils::contains(model_types, default_model))
89  {
90  model_types.insert(model_types.begin(), default_model);
91  }
92  params.setValidStrings("type", model_types);
93 
94  Param model_params;
96  params.insert("linear:", model_params);
97  params.setSectionDescription("linear", "Parameters for 'linear' model");
98 
100  params.insert("b_spline:", model_params);
101  params.setSectionDescription("b_spline", "Parameters for 'b_spline' model");
102 
104  params.insert("lowess:", model_params);
105  params.setSectionDescription("lowess", "Parameters for 'lowess' model");
106 
108  params.insert("interpolated:", model_params);
109  params.setSectionDescription("interpolated",
110  "Parameters for 'interpolated' model");
111  return params;
112  }
113 
114 protected:
115 
116  // Kind of reference parameters that the tool offers:
117  // - REF_NONE: no reference
118  // - REF_RESTRICTED: reference file must have same type as input files
119  // - REF_FLEXIBLE: reference file can have any supported file type
120  enum ReferenceParameterKind { REF_NONE, REF_RESTRICTED, REF_FLEXIBLE }
121  ref_params_;
122 
123  void registerOptionsAndFlagsMapAligners_(const String& file_formats,
124  enum ReferenceParameterKind ref_params)
125  {
126  registerInputFileList_("in", "<files>", StringList(), "Input files to align (all must have the same file type)", true);
127  setValidFormats_("in", ListUtils::create<String>(file_formats));
128  registerOutputFileList_("out", "<files>", StringList(), "Output files (same file type as 'in'). This option or 'trafo_out' has to be provided; they can be used together.", false);
129  setValidFormats_("out", ListUtils::create<String>(file_formats));
130  registerOutputFileList_("trafo_out", "<files>", StringList(), "Transformation output files. This option or 'out' has to be provided; they can be used together.", false);
131  setValidFormats_("trafo_out", ListUtils::create<String>("trafoXML"));
132 
133  if (ref_params != REF_NONE)
134  {
135  registerTOPPSubsection_("reference", "Options to define a reference file (use either 'file' or 'index', not both)");
136  String description = "File to use as reference";
137  if (ref_params == REF_RESTRICTED)
138  {
139  description += " (same file format as input files required)";
140  }
141  registerInputFile_("reference:file", "<file>", "", description, false);
142  setValidFormats_("reference:file", ListUtils::create<String>(file_formats));
143  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);
144  setMinInt_("reference:index", 0);
145  }
146  ref_params_ = ref_params;
147  }
148 
149  ExitCodes checkParameters_()
150  {
151  //-------------------------------------------------------------
152  // parameter handling
153  //-------------------------------------------------------------
154  StringList ins = getStringList_("in");
155  StringList outs = getStringList_("out");
156  StringList trafos = getStringList_("trafo_out");
157 
158  //-------------------------------------------------------------
159  // check for valid input
160  //-------------------------------------------------------------
161  // check whether some kind of output file is given:
162  if (outs.empty() && trafos.empty())
163  {
164  writeLog_("Error: Data output or transformation output files have to be provided (parameters 'out'/'trafo_out')");
165  return ILLEGAL_PARAMETERS;
166  }
167  // check whether number of input files equals number of output files:
168  if (!outs.empty() && (ins.size() != outs.size()))
169  {
170  writeLog_("Error: The number of data input and output files has to be equal (parameters 'in'/'out')");
171  return ILLEGAL_PARAMETERS;
172  }
173  if (!trafos.empty() && (ins.size() != trafos.size()))
174  {
175  writeLog_("Error: The number of data input and transformation output files has to be equal (parameters 'in'/'trafo_out')");
176  return ILLEGAL_PARAMETERS;
177  }
178  // check whether all input files have the same type (this type is used to store the output type too):
179  FileTypes::Type in_type = FileHandler::getType(ins[0]);
180  for (Size i = 1; i < ins.size(); ++i)
181  {
182  if (FileHandler::getType(ins[i]) != in_type)
183  {
184  writeLog_("Error: All input files (parameter 'in') must have the same format!");
185  return ILLEGAL_PARAMETERS;
186  }
187  }
188 
189  if (ref_params_ != REF_NONE) // a valid ref. index OR file should be given
190  {
191  Size reference_index = getIntOption_("reference:index");
192  String reference_file = getStringOption_("reference:file");
193  if (reference_index > ins.size())
194  {
195  writeLog_("Error: Value of parameter 'reference:index' must not be higher than the number of input files");
196  return ILLEGAL_PARAMETERS;
197  }
198  if (reference_index && !reference_file.empty())
199  {
200  writeLog_("Error: Parameters 'reference:index' and 'reference:file' cannot be used together");
201  return ILLEGAL_PARAMETERS;
202  }
203 
204  if ((ref_params_ == REF_RESTRICTED) && !reference_file.empty() &&
205  (FileHandler::getType(reference_file) != in_type))
206  {
207  writeLog_("Error: Reference file must have the same format as other input files (parameters 'reference:file'/'in')");
208  return ILLEGAL_PARAMETERS;
209  }
210  }
211 
212  return EXECUTION_OK;
213  }
214 
215 };
216 
217 }
218 
220 
static FileTypes::Type getType(const String &filename)
Tries to determine the file type (by name or content)
static bool contains(const std::vector< T > &container, const E &elem)
Checks whether the element elem is contained in the given container.
Definition: ListUtils.h:162
static void getDefaultParameters(Param &params)
Gets the default parameters.
static void getDefaultParameters(Param &params)
Gets the default parameters.
static void getDefaultParameters(Param &params)
Gets the default parameters.
static void getDefaultParameters(Param &params)
Gets the default parameters.
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Type
Actual file types enum.
Definition: FileTypes.h:57