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