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-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: Timo Sachsenberg $
32 // $Authors: Marc Sturm, Clemens Groepl $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
41 
45 
47 
51 
54 
55 #include <fstream>
56 
57 class QStringList;
58 
59 namespace OpenMS
60 {
61 
62  class ConsensusMap;
75  struct Citation
76  {
77  std::string authors;
78  std::string title;
79  std::string when_where;
80  std::string doi;
81 
83  std::string toString() const
84  {
85  return authors + ". " + title + ". " + when_where + ". doi:" + doi + ".";
86  }
87  };
88 
89  namespace Exception
90  {
92  class OPENMS_DLLAPI UnregisteredParameter :
94  {
95 public:
96  UnregisteredParameter(const char* file, int line, const char* function, const String& parameter) :
97  BaseException(file, line, function, "UnregisteredParameter", parameter)
98  {
100  }
101 
102  };
104  class OPENMS_DLLAPI WrongParameterType :
106  {
107 public:
108  WrongParameterType(const char* file, int line, const char* function, const String& parameter) :
109  BaseException(file, line, function, "WrongParameterType", parameter)
110  {
112  }
113 
114  };
116  class OPENMS_DLLAPI RequiredParameterNotGiven :
118  {
119 public:
120  RequiredParameterNotGiven(const char* file, int line, const char* function, const String& parameter) :
121  BaseException(file, line, function, "RequiredParameterNotGiven", parameter)
122  {
124  }
125 
126  };
127  }
128 
149  class OPENMS_DLLAPI TOPPBase
150  {
151 public:
152 
155  {
169  UNEXPECTED_RESULT
170  };
171 
182  TOPPBase(const String& name, const String& description, bool official = true, const std::vector<Citation>& citations = {});
183 
185  virtual ~TOPPBase();
186 
188  ExitCodes main(int argc, const char** argv);
189 
197  static void setMaxNumberOfThreads(int num_threads);
198 
199 private:
200 
203 
206 
209 
212 
214  TOPPBase();
215 
217  TOPPBase(const TOPPBase&);
218 
221 
224 
227 
230 
233 
236 
238  mutable std::ofstream log_;
239 
248  void enableLogging_() const;
249 
251  std::vector<ParameterInformation> parameters_;
252 
262  virtual Param getSubsectionDefaults_(const String& section) const;
263 
271  Param getSubsectionDefaults_() const;
272 
274  std::map<String, String> subsections_;
275 
277  std::map<String, String> subsections_TOPP_;
278 
279 
292  Param parseCommandLine_(const int argc, const char** argv, const String& misc = "misc", const String& unknown = "unknown");
293 
303  String getParamAsString_(const String& key, const String& default_value = "") const;
304 
310  Int getParamAsInt_(const String& key, Int default_value = 0) const;
311 
317  double getParamAsDouble_(const String& key, double default_value = 0) const;
318 
324  StringList getParamAsStringList_(const String& key, const StringList& default_value) const;
325 
331  IntList getParamAsIntList_(const String& key, const IntList& default_value) const;
332 
338  DoubleList getParamAsDoubleList_(const String& key, const DoubleList& default_value) const;
339 
349  bool getParamAsBool_(const String& key) const;
350 
362  const DataValue& getParam_(const String& key) const;
363 
369  String getSubsection_(const String& name) const;
370 
372  Param getDefaultParameters_() const;
373 
375  Param getToolUserDefaults_(const String& tool_name) const;
377 
378 protected:
381 
384 
386  bool official_;
387 
389  std::vector<Citation> citations_;
390 
398  const String& getIniLocation_() const
399  {
400  return ini_location_;
401  }
402 
404  const String& toolName_() const;
405 
426  virtual void registerOptionsAndFlags_() = 0;
427 
429  String getParamArgument_(const Param::ParamEntry& entry) const;
430 
432  std::vector<ParameterInformation> paramToParameterInformation_(const Param& param) const;
433 
443  ParameterInformation paramEntryToParameterInformation_(const Param::ParamEntry& entry, const String& argument = "", const String& full_name = "") const;
444 
445  void registerParamSubsectionsAsTOPPSubsections_(const Param& param);
446 
448  void registerFullParam_(const Param& param);
449 
460  void registerStringOption_(const String& name, const String& argument, const String& default_value, const String& description, bool required = true, bool advanced = false);
461 
468  void setValidStrings_(const String& name, const std::vector<String>& strings);
469 
479  void setValidStrings_(const String& name, const std::string vstrings[], int count);
480 
496  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());
497 
511  void registerOutputFile_(const String& name, const String& argument, const String& default_value, const String& description, bool required = true, bool advanced = false);
512 
523  void setValidFormats_(const String& name, const std::vector<String>& formats, const bool force_OpenMS_format = true);
524 
525 
536  void registerDoubleOption_(const String& name, const String& argument, double default_value, const String& description, bool required = true, bool advanced = false);
537 
543  void setMinInt_(const String& name, Int min);
549  void setMaxInt_(const String& name, Int max);
555  void setMinFloat_(const String& name, double min);
561  void setMaxFloat_(const String& name, double max);
562 
573  void registerIntOption_(const String& name, const String& argument,
574  Int default_value, const String& description,
575  bool required = true, bool advanced = false);
576 
588  void registerIntList_(const String& name, const String& argument, IntList default_value, const String& description, bool required = true, bool advanced = false);
589 
600  void registerDoubleList_(const String& name, const String& argument, DoubleList default_value, const String& description, bool required = true, bool advanced = false);
601 
612  void registerStringList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
613 
629  void registerInputFileList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false, const StringList& tags = StringList());
630 
644  void registerOutputFileList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
645 
647  void registerFlag_(const String& name, const String& description, bool advanced = false);
648 
656  void registerSubsection_(const String& name, const String& description);
657 
667  void registerTOPPSubsection_(const String& name, const String& description);
668 
669 
671  void addEmptyLine_();
672 
673 
682  String getStringOption_(const String& name) const;
683 
692  double getDoubleOption_(const String& name) const;
693 
702  Int getIntOption_(const String& name) const;
703 
712  StringList getStringList_(const String& name) const;
713 
722  IntList getIntList_(const String& name) const;
723 
732  DoubleList getDoubleList_(const String& name) const;
733 
735  bool getFlag_(const String& name) const;
736 
742  const ParameterInformation& findEntry_(const String& name) const;
743 
749  Param const& getParam_() const;
750 
764  void checkParam_(const Param& param, const String& filename, const String& location) const;
765 
766 
774  void checkIfIniParametersAreApplicable_(const Param& ini_params);
776 
778  void printUsage_();
779 
781  virtual ExitCodes main_(int argc, const char** argv) = 0;
782 
784 
785  void writeLog_(const String& text) const;
787 
789  void writeDebug_(const String& text, UInt min_level) const;
790 
792  void writeDebug_(const String& text, const Param& param, UInt min_level) const;
794 
796 
797  String makeTempDirectory_() const;
799 
805  void removeTempDirectory_(const String& dirname, Int keep_debug = 2) const;
807 
832  void inputFileReadable_(const String& filename, const String& param_name) const;
833 
844  void outputFileWritable_(const String& filename, const String& param_name) const;
846 
854  bool parseRange_(const String& text, double& low, double& high) const;
855 
863  bool parseRange_(const String& text, Int& low, Int& high) const;
864 
867 
869 
870 
872  void addDataProcessing_(ConsensusMap& map, const DataProcessing& dp) const;
873 
875  void addDataProcessing_(FeatureMap& map, const DataProcessing& dp) const;
876 
878  void addDataProcessing_(PeakMap& map, const DataProcessing& dp) const
879  {
880  boost::shared_ptr< DataProcessing > dp_(new DataProcessing(dp));
881  for (Size i = 0; i < map.size(); ++i)
882  {
883  map[i].getDataProcessing().push_back(dp_);
884  }
885  for (Size i = 0; i < map.getNrChromatograms(); ++i)
886  {
887  map.getChromatogram(i).getDataProcessing().push_back(dp_);
888  }
889  }
890 
892  DataProcessing getProcessingInfo_(DataProcessing::ProcessingAction action) const;
893 
895  DataProcessing getProcessingInfo_(const std::set<DataProcessing::ProcessingAction>& actions) const;
896 
898 
900  bool writeCTD_();
901 
903  ExitCodes writeWSDL_(const String& filename);
904 
917 
920 
922  static const Citation cite_openms_;
923 
926 private:
927 
933  void addText_(const String& text);
934 
942  ParameterInformation& getParameterByName_(const String& name);
943 
944  };
945 
946 } // namespace OpenMS
947 
String verboseVersion_
Version string including additional revision/date time information. Note: This differs from version_ ...
Definition: TOPPBase.h:383
Definition: TOPPBase.h:163
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:277
An unregistered parameter was accessed.
Definition: TOPPBase.h:92
Definition: TOPPBase.h:156
Definition: TOPPBase.h:159
A more convenient string class.
Definition: String.h:57
std::string doi
plain DOI (no urls), e.g. 10.1021/pr100177k
Definition: TOPPBase.h:80
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:96
RequiredParameterNotGiven(const char *file, int line, const char *function, const String &parameter)
Definition: TOPPBase.h:120
std::ofstream log_
Log file stream. Use the writeLog_() and writeDebug_() methods to access it.
Definition: TOPPBase.h:238
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:386
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:71
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:878
static const Citation cite_openms_
The OpenMS citation.
Definition: TOPPBase.h:922
Definition: TOPPBase.h:164
Definition: TOPPBase.h:160
std::map< String, String > subsections_
Storage location and description for allowed subsections.
Definition: TOPPBase.h:274
Definition: TOPPBase.h:166
Size size() const
Definition: MSExperiment.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
bool test_mode_
Test mode.
Definition: TOPPBase.h:916
std::string toString() const
mangle members to string
Definition: TOPPBase.h:83
Base class for TOPP applications.
Definition: TOPPBase.h:149
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:398
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:91
Definition: TOPPBase.h:162
A parameter was accessed with the wrong type.
Definition: TOPPBase.h:104
Param param_cmdline_
Parameters from command line.
Definition: TOPPBase.h:226
Stores Citations for individual TOPP tools.
Definition: TOPPBase.h:75
Param param_common_tool_
Parameters from common section with tool name.
Definition: TOPPBase.h:232
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:78
Definition: TOPPBase.h:168
std::vector< Citation > citations_
Papers, specific for this tool (will be shown in &#39;–help&#39;)
Definition: TOPPBase.h:389
Exception base class.
Definition: Exception.h:89
Param param_common_
Parameters from common section without tool name.
Definition: TOPPBase.h:235
String version_
Version string (if empty, the OpenMS/TOPP version is printed)
Definition: TOPPBase.h:380
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:108
std::string authors
list of authors in AMA style, i.e. <surname> <initials>, ...
Definition: TOPPBase.h:77
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:220
Definition: TOPPBase.h:157
std::vector< ParameterInformation > parameters_
Storage location for parameter information.
Definition: TOPPBase.h:251
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:73
ExitCodes
Exit codes.
Definition: TOPPBase.h:154
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:223
int Int
Signed integer type.
Definition: Types.h:102
Param param_instance_
Parameters from instance section.
Definition: TOPPBase.h:229
std::string when_where
suggested format: journal. year; volume, issue: pages
Definition: TOPPBase.h:79
Int debug_level_
Debug level set by -debug.
Definition: TOPPBase.h:925
ProgressLogger::LogType log_type_
Type of progress logging.
Definition: TOPPBase.h:866
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:919
A required parameter was not given.
Definition: TOPPBase.h:116

OpenMS / TOPP release 2.3.0 Documentation generated on Wed Apr 18 2018 19:29:09 using doxygen 1.8.14