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

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:01 using doxygen 1.8.13