Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
TOPPBase.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-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.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Stephan Aiche $
32 // $Authors: Marc Sturm, Clemens Groepl $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_APPLICATIONS_TOPPBASE_H
36 #define OPENMS_APPLICATIONS_TOPPBASE_H
37 
43 
49 
52 
55 
58 
59 #include <iostream>
60 #include <fstream>
61 #include <limits>
62 
63 class QStringList;
64 
65 namespace OpenMS
66 {
67 
68  class ConsensusMap;
69 
70  namespace Exception
71  {
73  class OPENMS_DLLAPI UnregisteredParameter :
75  {
76 public:
77  UnregisteredParameter(const char* file, int line, const char* function, const String& parameter) :
78  BaseException(file, line, function, "UnregisteredParameter", parameter)
79  {
81  }
82 
83  };
85  class OPENMS_DLLAPI WrongParameterType :
87  {
88 public:
89  WrongParameterType(const char* file, int line, const char* function, const String& parameter) :
90  BaseException(file, line, function, "WrongParameterType", parameter)
91  {
93  }
94 
95  };
97  class OPENMS_DLLAPI RequiredParameterNotGiven :
99  {
100 public:
101  RequiredParameterNotGiven(const char* file, int line, const char* function, const String& parameter) :
102  BaseException(file, line, function, "RequiredParameterNotGiven", parameter)
103  {
105  }
106 
107  };
108  }
109 
130  class OPENMS_DLLAPI TOPPBase
131  {
132 public:
133 
136  {
150  UNEXPECTED_RESULT
151  };
152 
167  TOPPBase(const String& name, const String& description, bool official = true, bool id_tag_support = false, bool require_args = true, const String& version = "");
168 
170  virtual ~TOPPBase();
171 
173  ExitCodes main(int argc, const char** argv);
174 
182  static void setMaxNumberOfThreads(int num_threads);
183 
184 private:
185 
188 
191 
194 
197 
200 
203 
206 
208  TOPPBase();
209 
211  TOPPBase(const TOPPBase&);
212 
215 
218 
221 
224 
227 
230 
232  mutable std::ofstream log_;
233 
242  void enableLogging_() const;
243 
245  std::vector<ParameterInformation> parameters_;
246 
256  virtual Param getSubsectionDefaults_(const String& section) const;
257 
265  Param getSubsectionDefaults_() const;
266 
268  std::map<String, String> subsections_;
269 
271  std::map<String, String> subsections_TOPP_;
272 
273 
286  Param parseCommandLine_(const int argc, const char** argv, const String& misc = "misc", const String& unknown = "unknown");
287 
297  String getParamAsString_(const String& key, const String& default_value = "") const;
298 
304  Int getParamAsInt_(const String& key, Int default_value = 0) const;
305 
311  DoubleReal getParamAsDouble_(const String& key, DoubleReal default_value = 0) const;
312 
318  StringList getParamAsStringList_(const String& key, const StringList& default_value) const;
319 
325  IntList getParamAsIntList_(const String& key, const IntList& default_value) const;
326 
332  DoubleList getParamAsDoubleList_(const String& key, const DoubleList& default_value) const;
333 
343  bool getParamAsBool_(const String& key) const;
344 
356  const DataValue& getParam_(const String& key) const;
357 
363  String getSubsection_(const String& name) const;
364 
366  Param getDefaultParameters_() const;
367 
369  Param getToolUserDefaults_(const String& tool_name) const;
371 
372 protected:
375 
378 
380  bool official_;
381 
389  const String& getIniLocation_() const
390  {
391  return ini_location_;
392  }
393 
395  const String& toolName_() const;
396 
417  virtual void registerOptionsAndFlags_() = 0;
418 
420  String getParamArgument_(const Param::ParamEntry& entry) const;
421 
423  std::vector<ParameterInformation> paramToParameterInformation_(const Param& param) const;
424 
434  ParameterInformation paramEntryToParameterInformation_(const Param::ParamEntry& entry, const String& argument = "", const String& full_name = "") const;
435 
436  void registerParamSubsectionsAsTOPPSubsections_(const Param& param);
437 
439  void registerFullParam_(const Param& param);
440 
451  void registerStringOption_(const String& name, const String& argument, const String& default_value, const String& description, bool required = true, bool advanced = false);
452 
459  void setValidStrings_(const String& name, const std::vector<String>& strings);
460 
476  void registerInputFile_(const String& name, const String& argument, const String& default_value, const String& description, bool required = true, bool advanced = false, const StringList& tags = StringList());
477 
491  void registerOutputFile_(const String& name, const String& argument, const String& default_value, const String& description, bool required = true, bool advanced = false);
492 
503  void setValidFormats_(const String& name, const std::vector<String>& formats, const bool force_OpenMS_format = true);
504 
505 
516  void registerDoubleOption_(const String& name, const String& argument, double default_value, const String& description, bool required = true, bool advanced = false);
517 
523  void setMinInt_(const String& name, Int min);
529  void setMaxInt_(const String& name, Int max);
535  void setMinFloat_(const String& name, DoubleReal min);
541  void setMaxFloat_(const String& name, DoubleReal max);
542 
553  void registerIntOption_(const String& name, const String& argument,
554  Int default_value, const String& description,
555  bool required = true, bool advanced = false);
556 
568  void registerIntList_(const String& name, const String& argument, IntList default_value, const String& description, bool required = true, bool advanced = false);
569 
580  void registerDoubleList_(const String& name, const String& argument, DoubleList default_value, const String& description, bool required = true, bool advanced = false);
581 
592  void registerStringList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
593 
607  void registerInputFileList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
608 
622  void registerOutputFileList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
623 
625  void registerFlag_(const String& name, const String& description, bool advanced = false);
626 
634  void registerSubsection_(const String& name, const String& description);
635 
645  void registerTOPPSubsection_(const String& name, const String& description);
646 
647 
649  void addEmptyLine_();
650 
651 
660  String getStringOption_(const String& name) const;
661 
670  DoubleReal getDoubleOption_(const String& name) const;
671 
680  Int getIntOption_(const String& name) const;
681 
690  StringList getStringList_(const String& name) const;
691 
700  IntList getIntList_(const String& name) const;
701 
710  DoubleList getDoubleList_(const String& name) const;
711 
713  bool getFlag_(const String& name) const;
714 
720  const ParameterInformation& findEntry_(const String& name) const;
721 
727  Param const& getParam_() const;
728 
742  void checkParam_(const Param& param, const String& filename, const String& location) const;
743 
744 
752  void checkIfIniParametersAreApplicable_(const Param& ini_params);
754 
756  void printUsage_();
757 
759  virtual ExitCodes main_(int argc, const char** argv) = 0;
760 
762 
763  void writeLog_(const String& text) const;
765 
767  void writeDebug_(const String& text, UInt min_level) const;
768 
770  void writeDebug_(const String& text, const Param& param, UInt min_level) const;
772 
773 
798  void inputFileReadable_(const String& filename, const String& param_name) const;
799 
810  void outputFileWritable_(const String& filename, const String& param_name) const;
812 
814  void parseRange_(const String& text, double& low, double& high) const;
815 
817  void parseRange_(const String& text, Int& low, Int& high) const;
818 
821 
823 
824 
826  void addDataProcessing_(ConsensusMap& map, const DataProcessing& dp) const;
827 
829  template <typename FeatureType>
831  {
832  map.getDataProcessing().push_back(dp);
833  }
834 
836  template <typename PeakType, typename CT>
838  {
839  for (Size i = 0; i < map.size(); ++i)
840  {
841  map[i].getDataProcessing().push_back(dp);
842  }
843  std::vector<MSChromatogram<CT> > chromatograms = map.getChromatograms();
844  for (Size i = 0; i < chromatograms.size(); ++i)
845  {
846  chromatograms[i].getDataProcessing().push_back(dp);
847  }
848  map.setChromatograms(chromatograms);
849  }
850 
852  DataProcessing getProcessingInfo_(DataProcessing::ProcessingAction action) const;
853 
855  DataProcessing getProcessingInfo_(const std::set<DataProcessing::ProcessingAction>& actions) const;
856 
858 
860  const DocumentIDTagger& getDocumentIDTagger_() const;
861 
863  bool writeCTD_();
864 
866  ExitCodes writeWSDL_(const String& filename);
867 
880 
883 
886 private:
887 
893  void addText_(const String& text);
894 
902  ParameterInformation& getParameterByName_(const String& name);
903 
904  };
905 
906 } // namespace OpenMS
907 
908 #endif //OPENMS_APPLICATIONS_TOPPBASE_H
String verboseVersion_
Version string including additional revision/date time information. Note: This differs from version_ ...
Definition: TOPPBase.h:377
Definition: TOPPBase.h:144
Descripton of the applied preprocessing steps.
Definition: DataProcessing.h:51
std::map< String, String > subsections_TOPP_
Storage location and description for allowed subsections from TOPP tool&#39;s command-line parameters...
Definition: TOPPBase.h:271
An unregistered parameter was accessed.
Definition: TOPPBase.h:73
Definition: TOPPBase.h:137
Definition: TOPPBase.h:140
A more convenient string class.
Definition: String.h:56
const char * tool_name
Definition: TOPPAS.C:91
Size size() const
Definition: MSExperiment.h:117
LogType
Possible log types.
Definition: ProgressLogger.h:66
UnregisteredParameter(const char *file, int line, const char *function, const String &parameter)
Definition: TOPPBase.h:77
RequiredParameterNotGiven(const char *file, int line, const char *function, const String &parameter)
Definition: TOPPBase.h:101
std::ofstream log_
Log file stream. Use the writeLog_() and writeDebug_() methods to access it.
Definition: TOPPBase.h:232
A container for features.
Definition: FeatureMap.h:111
bool official_
Flag indicating if this an official TOPP tool.
Definition: TOPPBase.h:380
Parameter entry used to store the actual information inside of a Param entry.
Definition: Param.h:74
Struct that captures all information of a command line parameter.
Definition: ParameterInformation.h:48
A container for consensus elements.
Definition: ConsensusMap.h:60
Definition: TOPPBase.h:145
Definition: TOPPBase.h:141
std::map< String, String > subsections_
Storage location and description for allowed subsections.
Definition: TOPPBase.h:268
const String & getIniLocation_() const
Returns the location of the ini file where parameters are taken from. E.g. if the command line was TO...
Definition: TOPPBase.h:389
Definition: TOPPBase.h:147
bool test_mode_
Test mode.
Definition: TOPPBase.h:879
Base class for TOPP applications.
Definition: TOPPBase.h:130
static GlobalExceptionHandler & getInstance()
The accessor for the singleton. It also serves as a replacement for the constructor.
Definition: GlobalExceptionHandler.h:89
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:57
Definition: TOPPBase.h:143
const std::vector< DataProcessing > & getDataProcessing() const
returns a const reference to the description of the applied data processing
Definition: FeatureMap.h:446
A parameter was accessed with the wrong type.
Definition: TOPPBase.h:85
Param param_cmdline_
Parameters from command line.
Definition: TOPPBase.h:220
Tags OpenMS file containers with a DocumentID.
Definition: DocumentIDTagger.h:55
Param param_common_tool_
Parameters from common section with tool name.
Definition: TOPPBase.h:226
ProcessingAction
Definition: DataProcessing.h:58
int main(int argc, const char **argv)
Definition: RNPxl.C:1354
bool id_tag_support_
Tool indicates it supports assignment of unique DocumentID from IDPool.
Definition: TOPPBase.h:193
Definition: TOPPBase.h:149
bool require_args_
Require at least one command line argument, exit immediately otherwise. GUI tools should disable this...
Definition: TOPPBase.h:196
Exception base class.
Definition: Exception.h:90
Param param_common_
Parameters from common section without tool name.
Definition: TOPPBase.h:229
String version_
Version string (if empty, the OpenMS/TOPP version is printed)
Definition: TOPPBase.h:374
DocumentIDTagger id_tagger_
Instance of DocumentIDTagger, which can be accessed using getDocumentIDTagger_()
Definition: TOPPBase.h:199
Management and storage of parameters / INI files.
Definition: Param.h:69
Representation of a mass spectrometry experiment.
Definition: MSExperiment.h:68
WrongParameterType(const char *file, int line, const char *function, const String &parameter)
Definition: TOPPBase.h:89
void setChromatograms(const std::vector< MSChromatogram< ChromatogramPeakType > > &chromatograms)
sets the chromatogram list
Definition: MSExperiment.h:756
String list.
Definition: StringList.h:56
static void setMessage(const std::string &message)
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
String const tool_name_
Tool name. This is assigned once and for all in the constructor.
Definition: TOPPBase.h:187
Param param_
All parameters relevant to this invocation of the program.
Definition: TOPPBase.h:214
void addDataProcessing_(FeatureMap< FeatureType > &map, const DataProcessing &dp) const
Data processing setter for feature maps.
Definition: TOPPBase.h:830
Definition: TOPPBase.h:138
std::vector< ParameterInformation > parameters_
Storage location for parameter information.
Definition: TOPPBase.h:245
ExitCodes
Exit codes.
Definition: TOPPBase.h:135
String const ini_location_
Location in the ini file where to look for parameters.
Definition: TOPPBase.h:205
String const tool_description_
Tool description. This is assigned once and for all in the constructor.
Definition: TOPPBase.h:190
Param param_inifile_
All parameters specified in the ini file.
Definition: TOPPBase.h:217
int Int
Signed integer type.
Definition: Types.h:100
Param param_instance_
Parameters from instance section.
Definition: TOPPBase.h:223
void addDataProcessing_(MSExperiment< PeakType, CT > &map, const DataProcessing &dp) const
Data processing setter for peak maps.
Definition: TOPPBase.h:837
Int debug_level_
Debug level set by -debug.
Definition: TOPPBase.h:885
DoubleReal list.
Definition: DoubleList.h:56
ProgressLogger::LogType log_type_
Type of progress logging.
Definition: TOPPBase.h:820
const std::vector< MSChromatogram< ChromatogramPeakType > > & getChromatograms() const
returns the chromatogram list
Definition: MSExperiment.h:768
Int const instance_number_
Instance number.
Definition: TOPPBase.h:202
static String topp_ini_file_
.TOPP.ini file for storing system default parameters
Definition: TOPPBase.h:882
Int list.
Definition: IntList.h:56
A required parameter was not given.
Definition: TOPPBase.h:97

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:22 using doxygen 1.8.5