OpenMS  2.4.0
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-2018.
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: Timo Sachsenberg $
32 // $Authors: Marc Sturm, Clemens Groepl $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
41 
45 
47 
51 
54 
55 #include <fstream>
56 
57 #include <QStringList>
58 
59 
60 namespace OpenMS
61 {
62 
63  class ConsensusMap;
76  struct Citation
77  {
78  std::string authors;
79  std::string title;
80  std::string when_where;
81  std::string doi;
82 
84  std::string toString() const
85  {
86  return authors + ". " + title + ". " + when_where + ". doi:" + doi + ".";
87  }
88  };
89 
90  namespace Exception
91  {
93  class OPENMS_DLLAPI UnregisteredParameter :
95  {
96 public:
97  UnregisteredParameter(const char* file, int line, const char* function, const String& parameter) :
98  BaseException(file, line, function, "UnregisteredParameter", parameter)
99  {
101  }
102 
103  };
105  class OPENMS_DLLAPI WrongParameterType :
107  {
108 public:
109  WrongParameterType(const char* file, int line, const char* function, const String& parameter) :
110  BaseException(file, line, function, "WrongParameterType", parameter)
111  {
113  }
114 
115  };
117  class OPENMS_DLLAPI RequiredParameterNotGiven :
119  {
120 public:
121  RequiredParameterNotGiven(const char* file, int line, const char* function, const String& parameter) :
122  BaseException(file, line, function, "RequiredParameterNotGiven", parameter)
123  {
125  }
126 
127  };
128  }
129 
150  class OPENMS_DLLAPI TOPPBase
151  {
152 public:
153 
156  {
170  UNEXPECTED_RESULT
171  };
172 
183  TOPPBase(const String& name, const String& description, bool official = true, const std::vector<Citation>& citations = {});
184 
186  virtual ~TOPPBase();
187 
189  ExitCodes main(int argc, const char** argv);
190 
198  static void setMaxNumberOfThreads(int num_threads);
199 
200 private:
203 
206 
209 
212 
215 
218 
220  TOPPBase();
221 
223  TOPPBase(const TOPPBase&);
224 
227 
230 
233 
236 
239 
242 
244  mutable std::ofstream log_;
245 
254  void enableLogging_() const;
255 
257  std::vector<ParameterInformation> parameters_;
258 
268  virtual Param getSubsectionDefaults_(const String& section) const;
269 
277  Param getSubsectionDefaults_() const;
278 
280  std::map<String, String> subsections_;
281 
283  std::map<String, String> subsections_TOPP_;
284 
285 
298  Param parseCommandLine_(const int argc, const char** argv, const String& misc = "misc", const String& unknown = "unknown");
299 
309  String getParamAsString_(const String& key, const String& default_value = "") const;
310 
316  Int getParamAsInt_(const String& key, Int default_value = 0) const;
317 
323  double getParamAsDouble_(const String& key, double default_value = 0) const;
324 
330  StringList getParamAsStringList_(const String& key, const StringList& default_value) const;
331 
337  IntList getParamAsIntList_(const String& key, const IntList& default_value) const;
338 
344  DoubleList getParamAsDoubleList_(const String& key, const DoubleList& default_value) const;
345 
355  bool getParamAsBool_(const String& key) const;
356 
368  const DataValue& getParam_(const String& key) const;
369 
375  String getSubsection_(const String& name) const;
376 
378  Param getDefaultParameters_() const;
379 
381  Param getToolUserDefaults_(const String& tool_name) const;
383 
384 protected:
387 
390 
392  bool official_;
393 
395  std::vector<Citation> citations_;
396 
404  const String& getIniLocation_() const
405  {
406  return ini_location_;
407  }
408 
410  const String& toolName_() const;
411 
432  virtual void registerOptionsAndFlags_() = 0;
433 
435  String getParamArgument_(const Param::ParamEntry& entry) const;
436 
438  std::vector<ParameterInformation> paramToParameterInformation_(const Param& param) const;
439 
449  ParameterInformation paramEntryToParameterInformation_(const Param::ParamEntry& entry, const String& argument = "", const String& full_name = "") const;
450 
451  void registerParamSubsectionsAsTOPPSubsections_(const Param& param);
452 
454  void registerFullParam_(const Param& param);
455 
466  void registerStringOption_(const String& name, const String& argument, const String& default_value, const String& description, bool required = true, bool advanced = false);
467 
474  void setValidStrings_(const String& name, const std::vector<String>& strings);
475 
485  void setValidStrings_(const String& name, const std::string vstrings[], int count);
486 
502  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());
503 
517  void registerOutputFile_(const String& name, const String& argument, const String& default_value, const String& description, bool required = true, bool advanced = false);
518 
529  void setValidFormats_(const String& name, const std::vector<String>& formats, const bool force_OpenMS_format = true);
530 
531 
542  void registerDoubleOption_(const String& name, const String& argument, double default_value, const String& description, bool required = true, bool advanced = false);
543 
549  void setMinInt_(const String& name, Int min);
555  void setMaxInt_(const String& name, Int max);
561  void setMinFloat_(const String& name, double min);
567  void setMaxFloat_(const String& name, double max);
568 
579  void registerIntOption_(const String& name, const String& argument,
580  Int default_value, const String& description,
581  bool required = true, bool advanced = false);
582 
594  void registerIntList_(const String& name, const String& argument, IntList default_value, const String& description, bool required = true, bool advanced = false);
595 
606  void registerDoubleList_(const String& name, const String& argument, DoubleList default_value, const String& description, bool required = true, bool advanced = false);
607 
618  void registerStringList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
619 
635  void registerInputFileList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false, const StringList& tags = StringList());
636 
650  void registerOutputFileList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
651 
653  void registerFlag_(const String& name, const String& description, bool advanced = false);
654 
662  void registerSubsection_(const String& name, const String& description);
663 
673  void registerTOPPSubsection_(const String& name, const String& description);
674 
675 
677  void addEmptyLine_();
678 
679 
688  String getStringOption_(const String& name) const;
689 
698  double getDoubleOption_(const String& name) const;
699 
708  Int getIntOption_(const String& name) const;
709 
718  StringList getStringList_(const String& name) const;
719 
728  IntList getIntList_(const String& name) const;
729 
738  DoubleList getDoubleList_(const String& name) const;
739 
741  bool getFlag_(const String& name) const;
742 
748  const ParameterInformation& findEntry_(const String& name) const;
749 
755  Param const& getParam_() const;
756 
770  void checkParam_(const Param& param, const String& filename, const String& location) const;
771 
772 
780  void checkIfIniParametersAreApplicable_(const Param& ini_params);
782 
784  void printUsage_();
785 
787  virtual ExitCodes main_(int argc, const char** argv) = 0;
788 
790 
791  void writeLog_(const String& text) const;
793 
795  void writeDebug_(const String& text, UInt min_level) const;
796 
798  void writeDebug_(const String& text, const Param& param, UInt min_level) const;
800 
802 
803  String makeTempDirectory_() const;
805 
807  String makeAutoRemoveTempDirectory_(Int keep_debug = 2);
808 
814  void removeTempDirectory_(const String& dirname, Int keep_debug = 2) const;
816 
818 
819  ExitCodes runExternalProcess_(const QString& executable, const QStringList& arguments, const QString& workdir = "") const;
822 
847  void inputFileReadable_(const String& filename, const String& param_name) const;
848 
859  void outputFileWritable_(const String& filename, const String& param_name) const;
861 
869  bool parseRange_(const String& text, double& low, double& high) const;
870 
878  bool parseRange_(const String& text, Int& low, Int& high) const;
879 
882 
884 
885 
887  void addDataProcessing_(ConsensusMap& map, const DataProcessing& dp) const;
888 
890  void addDataProcessing_(FeatureMap& map, const DataProcessing& dp) const;
891 
893  void addDataProcessing_(PeakMap& map, const DataProcessing& dp) const
894  {
895  boost::shared_ptr< DataProcessing > dp_(new DataProcessing(dp));
896  for (Size i = 0; i < map.size(); ++i)
897  {
898  map[i].getDataProcessing().push_back(dp_);
899  }
900  for (Size i = 0; i < map.getNrChromatograms(); ++i)
901  {
902  map.getChromatogram(i).getDataProcessing().push_back(dp_);
903  }
904  }
905 
907  DataProcessing getProcessingInfo_(DataProcessing::ProcessingAction action) const;
908 
910  DataProcessing getProcessingInfo_(const std::set<DataProcessing::ProcessingAction>& actions) const;
911 
913 
915  bool writeCTD_();
916 
918  ExitCodes writeWSDL_(const String& filename);
919 
932 
935 
937  static const Citation cite_openms_;
938 
941 private:
942 
948  void addText_(const String& text);
949 
957  ParameterInformation& getParameterByName_(const String& name);
958 
959  };
960 
961 } // namespace OpenMS
962 
String verboseVersion_
Version string including additional revision/date time information. Note: This differs from version_ ...
Definition: TOPPBase.h:389
Definition: TOPPBase.h:164
Description 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:283
An unregistered parameter was accessed.
Definition: TOPPBase.h:93
Definition: TOPPBase.h:157
Definition: TOPPBase.h:160
A more convenient string class.
Definition: String.h:57
std::string doi
plain DOI (no urls), e.g. 10.1021/pr100177k
Definition: TOPPBase.h:81
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:65
LogType
Possible log types.
Definition: ProgressLogger.h:70
UnregisteredParameter(const char *file, int line, const char *function, const String &parameter)
Definition: TOPPBase.h:97
RequiredParameterNotGiven(const char *file, int line, const char *function, const String &parameter)
Definition: TOPPBase.h:121
std::ofstream log_
Log file stream. Use the writeLog_() and writeDebug_() methods to access it.
Definition: TOPPBase.h:244
Int working_dir_keep_debug_lvl_
Debug level at which to keep working dir.
Definition: TOPPBase.h:217
A container for features.
Definition: FeatureMap.h:93
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
bool official_
Flag indicating if this an official TOPP tool.
Definition: TOPPBase.h:392
Parameter entry used to store the actual information inside of a Param entry.
Definition: Param.h:79
Struct that captures all information of a command line parameter.
Definition: ParameterInformation.h:47
A container for consensus elements.
Definition: ConsensusMap.h:75
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:58
void addDataProcessing_(PeakMap &map, const DataProcessing &dp) const
Data processing setter for peak maps.
Definition: TOPPBase.h:893
static const Citation cite_openms_
The OpenMS citation.
Definition: TOPPBase.h:937
Definition: TOPPBase.h:165
Definition: TOPPBase.h:161
std::map< String, String > subsections_
Storage location and description for allowed subsections.
Definition: TOPPBase.h:280
Definition: TOPPBase.h:167
Size size() const
Definition: MSExperiment.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
bool test_mode_
Test mode.
Definition: TOPPBase.h:931
std::string toString() const
mangle members to string
Definition: TOPPBase.h:84
Base class for TOPP applications.
Definition: TOPPBase.h:150
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:404
static GlobalExceptionHandler & getInstance()
The accessor for the singleton. It also serves as a replacement for the constructor.
Definition: GlobalExceptionHandler.h:88
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:56
const char * tool_name
Definition: TOPPAS.cpp:94
Definition: TOPPBase.h:163
A parameter was accessed with the wrong type.
Definition: TOPPBase.h:105
Param param_cmdline_
Parameters from command line.
Definition: TOPPBase.h:232
Stores Citations for individual TOPP tools.
Definition: TOPPBase.h:76
Param param_common_tool_
Parameters from common section with tool name.
Definition: TOPPBase.h:238
Size getNrChromatograms() const
get the total number of chromatograms available
ProcessingAction
Definition: DataProcessing.h:58
std::vector< DataProcessingPtr > & getDataProcessing()
returns a mutable reference to the description of the applied processing
std::string title
title of article
Definition: TOPPBase.h:79
Definition: TOPPBase.h:169
std::vector< Citation > citations_
Papers, specific for this tool (will be shown in &#39;–help&#39;)
Definition: TOPPBase.h:395
Exception base class.
Definition: Exception.h:89
Param param_common_
Parameters from common section without tool name.
Definition: TOPPBase.h:241
String version_
Version string (if empty, the OpenMS/TOPP version is printed)
Definition: TOPPBase.h:386
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:73
Management and storage of parameters / INI files.
Definition: Param.h:74
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
WrongParameterType(const char *file, int line, const char *function, const String &parameter)
Definition: TOPPBase.h:109
std::string authors
list of authors in AMA style, i.e. <surname> <initials>, ...
Definition: TOPPBase.h:78
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:127
String const tool_name_
Tool name. This is assigned once and for all in the constructor.
Definition: TOPPBase.h:202
Param param_
All parameters relevant to this invocation of the program.
Definition: TOPPBase.h:226
Definition: TOPPBase.h:158
std::vector< ParameterInformation > parameters_
Storage location for parameter information.
Definition: TOPPBase.h:257
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:73
String working_dir_
An optional temporary working directory.
Definition: TOPPBase.h:214
ExitCodes
Exit codes.
Definition: TOPPBase.h:155
String const ini_location_
Location in the ini file where to look for parameters.
Definition: TOPPBase.h:211
MSChromatogram & getChromatogram(Size id)
returns a single chromatogram
String const tool_description_
Tool description. This is assigned once and for all in the constructor.
Definition: TOPPBase.h:205
Param param_inifile_
All parameters specified in the ini file.
Definition: TOPPBase.h:229
int Int
Signed integer type.
Definition: Types.h:102
Param param_instance_
Parameters from instance section.
Definition: TOPPBase.h:235
std::string when_where
suggested format: journal. year; volume, issue: pages
Definition: TOPPBase.h:80
Int debug_level_
Debug level set by -debug.
Definition: TOPPBase.h:940
ProgressLogger::LogType log_type_
Type of progress logging.
Definition: TOPPBase.h:881
Int const instance_number_
Instance number.
Definition: TOPPBase.h:208
static String topp_ini_file_
.TOPP.ini file for storing system default parameters
Definition: TOPPBase.h:934
A required parameter was not given.
Definition: TOPPBase.h:117