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-2016.
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 
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  StringList model_types = ListUtils::create<String>("linear,b_spline,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");
99  params.insert("b_spline:", model_params);
100  params.setSectionDescription("b_spline", "Parameters for 'b_spline' model");
102  params.insert("interpolated:", model_params);
103  params.setSectionDescription("interpolated",
104  "Parameters for 'interpolated' model");
105  return params;
106  }
107 
108 protected:
109 
110  // Kind of reference parameters that the tool offers:
111  // - REF_NONE: no reference
112  // - REF_RESTRICTED: reference file must have same type as input files
113  // - REF_FLEXIBLE: reference file can have any supported file type
114  enum ReferenceParameterKind { REF_NONE, REF_RESTRICTED, REF_FLEXIBLE }
115  ref_params_;
116 
117  void registerOptionsAndFlags_(const String& file_formats,
118  enum ReferenceParameterKind ref_params)
119  {
120  registerInputFileList_("in", "<files>", StringList(), "Input files to align (all must have the same file type)", true);
121  setValidFormats_("in", ListUtils::create<String>(file_formats));
122  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);
123  setValidFormats_("out", ListUtils::create<String>(file_formats));
124  registerOutputFileList_("trafo_out", "<files>", StringList(), "Transformation output files. Either this option or 'out' has to be provided; they can be used together.", false);
125  setValidFormats_("trafo_out", ListUtils::create<String>("trafoXML"));
126 
127  if (ref_params != REF_NONE)
128  {
129  registerTOPPSubsection_("reference", "Options to define a reference file (use either 'file' or 'index', not both)");
130  String description = "File to use as reference";
131  if (ref_params == REF_RESTRICTED)
132  {
133  description += " (same file format as input files required)";
134  }
135  registerInputFile_("reference:file", "<file>", "", description, false);
136  setValidFormats_("reference:file", ListUtils::create<String>(file_formats));
137  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);
138  setMinInt_("reference:index", 0);
139  }
140  ref_params_ = ref_params;
141  }
142 
143  ExitCodes checkParameters_()
144  {
145  //-------------------------------------------------------------
146  // parameter handling
147  //-------------------------------------------------------------
148  StringList ins = getStringList_("in");
149  StringList outs = getStringList_("out");
150  StringList trafos = getStringList_("trafo_out");
151 
152  //-------------------------------------------------------------
153  // check for valid input
154  //-------------------------------------------------------------
155  // check whether some kind of output file is given:
156  if (outs.empty() && trafos.empty())
157  {
158  writeLog_("Error: Either data output or transformation output files have to be provided (parameters 'out'/'trafo_out')");
159  return ILLEGAL_PARAMETERS;
160  }
161  // check whether number of input files equals number of output files:
162  if (!outs.empty() && (ins.size() != outs.size()))
163  {
164  writeLog_("Error: The number of data input and output files has to be equal (parameters 'in'/'out')");
165  return ILLEGAL_PARAMETERS;
166  }
167  if (!trafos.empty() && (ins.size() != trafos.size()))
168  {
169  writeLog_("Error: The number of data input and transformation output files has to be equal (parameters 'in'/'trafo_out')");
170  return ILLEGAL_PARAMETERS;
171  }
172  // check whether all input files have the same type (this type is used to store the output type too):
173  FileTypes::Type in_type = FileHandler::getType(ins[0]);
174  for (Size i = 1; i < ins.size(); ++i)
175  {
176  if (FileHandler::getType(ins[i]) != in_type)
177  {
178  writeLog_("Error: All input files (parameter 'in') must have the same format!");
179  return ILLEGAL_PARAMETERS;
180  }
181  }
182 
183  if (ref_params_ != REF_NONE) // a valid ref. index OR file should be given
184  {
185  Size reference_index = getIntOption_("reference:index");
186  String reference_file = getStringOption_("reference:file");
187  if (reference_index > ins.size())
188  {
189  writeLog_("Error: Value of parameter 'reference:index' must not be higher than the number of input files");
190  return ILLEGAL_PARAMETERS;
191  }
192  if (reference_index && !reference_file.empty())
193  {
194  writeLog_("Error: Parameters 'reference:index' and 'reference:file' cannot be used together");
195  return ILLEGAL_PARAMETERS;
196  }
197 
198  if ((ref_params_ == REF_RESTRICTED) && !reference_file.empty() &&
199  (FileHandler::getType(reference_file) != in_type))
200  {
201  writeLog_("Error: Reference file must have the same format as other input files (parameters 'reference:file'/'in')");
202  return ILLEGAL_PARAMETERS;
203  }
204  }
205 
206  return EXECUTION_OK;
207  }
208 
209 };
210 
211 }
212 
214 
215 #endif // OPENMS_APPLICATIONS_MAPALIGNERBASE_H
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
Type
Actual file types enum.
Definition: FileTypes.h:59
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.

OpenMS / TOPP release 2.0.0 Documentation generated on Tue Jan 31 2017 06:39:47 using doxygen 1.8.8