OpenMS
Loading...
Searching...
No Matches
TOPPBase.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Marc Sturm, Clemens Groepl $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <OpenMS/APPLICATIONS/OpenMS_CLIConfig.h>
12
14
16
19
21
23
24#include <iosfwd>
25#include <map>
26#include <memory>
27#include <optional>
28#include <vector>
29
30namespace OpenMS
31{
32 class FeatureMap;
33 class ConsensusMap;
34 struct ParameterInformation;
35
56 class OPENMS_CLI_DLLAPI TOPPBase
57 {
58public:
60 inline static const char* TAG_OUTPUT_FILE = ParamTags::TAG_OUTPUT_FILE;
61 inline static const char* TAG_INPUT_FILE = ParamTags::TAG_INPUT_FILE;
62 inline static const char* TAG_OUTPUT_DIR = ParamTags::TAG_OUTPUT_DIR;
63 inline static const char* TAG_OUTPUT_PREFIX = ParamTags::TAG_OUTPUT_PREFIX;
64 inline static const char* TAG_ADVANCED = ParamTags::TAG_ADVANCED;
65 inline static const char* TAG_REQUIRED = ParamTags::TAG_REQUIRED;
66
86
87
88
90 TOPPBase() = delete;
91
93 TOPPBase(const TOPPBase&) = delete;
94
106 TOPPBase(const std::string& name, const std::string& description, const std::vector<Citation>& citations = {}, bool toolhandler_test = true);
107
109 virtual ~TOPPBase();
110
112 ExitCodes main(int argc, const char** argv);
113
121 static void setMaxNumberOfThreads(int num_threads);
122
130 std::string getToolPrefix() const;
131
133 std::string getDocumentationURL() const;
134
136 static const Citation cite_openms;
137
138 private:
140 std::string const tool_name_;
141
143 std::string const tool_description_;
144
146 std::string const ini_location_;
147
150
153
156
159
162
165
168 mutable std::unique_ptr<std::ofstream> log_;
169
178 void enableLogging_() const;
179
181 std::vector<ParameterInformation> parameters_;
182
192 virtual Param getSubsectionDefaults_(const std::string& section) const;
193
202
204 std::map<std::string, std::string> subsections_;
205
207 std::map<std::string, std::string> subsections_TOPP_;
208
209
222 Param parseCommandLine_(const int argc, const char** argv, const std::string& misc = "misc", const std::string& unknown = "unknown");
223
233 std::string getParamAsString_(const std::string& key, const std::string& default_value = "") const;
234
240 Int getParamAsInt_(const std::string& key, Int default_value = 0) const;
241
247 double getParamAsDouble_(const std::string& key, double default_value = 0) const;
248
254 StringList getParamAsStringList_(const std::string& key, const StringList& default_value) const;
255
261 IntList getParamAsIntList_(const std::string& key, const IntList& default_value) const;
262
268 DoubleList getParamAsDoubleList_(const std::string& key, const DoubleList& default_value) const;
269
279 bool getParamAsBool_(const std::string& key) const;
280
292 const ParamValue& getParam_(const std::string& key) const;
293
299 std::string getSubsection_(const std::string& name) const;
300
303
305 Param getToolUserDefaults_(const std::string& tool_name) const;
307
308protected:
310 std::string version_;
311
313 std::string verboseVersion_;
314
316 std::vector<Citation> citations_;
317
320
327 const std::string& getIniLocation_() const
328 {
329 return ini_location_;
330 }
331
333 const std::string& toolName_() const;
334
359 virtual void registerOptionsAndFlags_() = 0;
360
362 std::string getParamArgument_(const Param::ParamEntry& entry) const;
363
365 std::vector<ParameterInformation> paramToParameterInformation_(const Param& param) const;
366
376 ParameterInformation paramEntryToParameterInformation_(const Param::ParamEntry& entry, const std::string& argument = "", const std::string& full_name = "") const;
377
379
381 void registerFullParam_(const Param& param);
382
393 void registerStringOption_(const std::string& name, const std::string& argument, const std::string& default_value, const std::string& description, bool required = true, bool advanced = false);
394
401 void setValidStrings_(const std::string& name, const std::vector<std::string>& strings);
402
412 void setValidStrings_(const std::string& name, const std::string vstrings[], int count);
413
432 void registerInputFile_(const std::string& name, const std::string& argument, const std::string& default_value, const std::string& description, bool required = true, bool advanced = false, const StringList& tags = StringList());
433
447 void registerOutputFile_(const std::string& name, const std::string& argument, const std::string& default_value, const std::string& description, bool required = true, bool advanced = false);
448
469 void registerOutputPrefix_(const std::string& name, const std::string& argument, const std::string& default_value, const std::string& description, bool required = true, bool advanced = false);
470
483 void registerOutputDir_(const std::string& name, const std::string& argument, const std::string& default_value, const std::string& description, bool required = true, bool advanced = false);
484
485
498 void setValidFormats_(const std::string& name, const std::vector<std::string>& formats, const bool force_OpenMS_format = true);
499
500
511 void registerDoubleOption_(const std::string& name, const std::string& argument, double default_value, const std::string& description, bool required = true, bool advanced = false);
512
518 void setMinInt_(const std::string& name, Int min);
524 void setMaxInt_(const std::string& name, Int max);
530 void setMinFloat_(const std::string& name, double min);
536 void setMaxFloat_(const std::string& name, double max);
537
548 void registerIntOption_(const std::string& name, const std::string& argument,
549 Int default_value, const std::string& description,
550 bool required = true, bool advanced = false);
551
563 void registerIntList_(const std::string& name, const std::string& argument, const IntList& default_value, const std::string& description, bool required = true, bool advanced = false);
564
575 void registerDoubleList_(const std::string& name, const std::string& argument, const DoubleList& default_value, const std::string& description, bool required = true, bool advanced = false);
576
587 void registerStringList_(const std::string& name, const std::string& argument, const StringList& default_value, const std::string& description, bool required = true, bool advanced = false);
588
606 void registerInputFileList_(const std::string& name, const std::string& argument, const StringList& default_value, const std::string& description, bool required = true, bool advanced = false, const StringList& tags = StringList());
607
621 void registerOutputFileList_(const std::string& name, const std::string& argument, const StringList& default_value, const std::string& description, bool required = true, bool advanced = false);
622
630 void registerFlag_(const std::string& name, const std::string& description, bool advanced = false);
631
639 void registerSubsection_(const std::string& name, const std::string& description);
640
650 void registerTOPPSubsection_(const std::string& name, const std::string& description);
651
652
655
656
665 std::string getStringOption_(const std::string& name) const;
666
675 std::string getOutputDirOption(const std::string& name) const;
676
685 double getDoubleOption_(const std::string& name) const;
686
695 Int getIntOption_(const std::string& name) const;
696
705 StringList getStringList_(const std::string& name) const;
706
715 IntList getIntList_(const std::string& name) const;
716
725 DoubleList getDoubleList_(const std::string& name) const;
726
728 bool getFlag_(const std::string& name) const;
729
735 const ParameterInformation& findEntry_(const std::string& name) const;
736
742 Param const& getParam_() const;
743
757 void checkParam_(const Param& param, const std::string& filename, const std::string& location) const;
758
769 void fileParamValidityCheck_(const StringList& param_value, const std::string& param_name, const ParameterInformation& p) const;
770
786 void fileParamValidityCheck_(std::string& param_value, const std::string& param_name, const ParameterInformation& p) const;
787
797 virtual bool findExecutable_(std::string& executable) const;
798
808
811
813 virtual ExitCodes main_(int argc, const char** argv) = 0;
814
816
817
818 void writeLogInfo_(const std::string& text) const;
819
821 void writeLogWarn_(const std::string& text) const;
822
824 void writeLogError_(const std::string& text) const;
825
827 void writeDebug_(const std::string& text, UInt min_level) const;
828
830 void writeDebug_(const std::string& text, const Param& param, UInt min_level) const;
832
833 // NOTE: runExternalProcess_() moved to the TOPPExternalToolBase subclass
834 // (APPLICATIONS/TOPPExternalToolBase.h); tools that shell out should derive from it.
835
862 void inputFileReadable_(const std::string& filename, const std::string& param_name) const;
863
874 void outputFileWritable_(const std::string& filename, const std::string& param_name) const;
876
884 bool parseRange_(const std::string& text, double& low, double& high) const;
885
893 bool parseRange_(const std::string& text, Int& low, Int& high) const;
894
897
899
900
902 void addDataProcessing_(ConsensusMap& map, const DataProcessing& dp) const;
903
905 void addDataProcessing_(FeatureMap& map, const DataProcessing& dp) const;
906
908 void addDataProcessing_(PeakMap& map, const DataProcessing& dp) const;
909
912
914 DataProcessing getProcessingInfo_(const std::set<DataProcessing::ProcessingAction>& actions) const;
915
917
930
932 static std::string topp_ini_file_;
933
936private:
937
943 void addText_(const std::string& text);
944
952 ParameterInformation& getParameterByName_(const std::string& name);
953
961 std::optional<ExitCodes> handleWriteCommands_();
962
963 };
964
965} // namespace OpenMS
966
A container for consensus elements.
Definition ConsensusMap.h:67
Description of the applied preprocessing steps.
Definition DataProcessing.h:28
ProcessingAction
Definition DataProcessing.h:34
A container for features.
Definition FeatureMap.h:78
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
Class to hold strings, numeric values, vectors of strings and vectors of numeric values using the stl...
Definition ParamValue.h:31
Management and storage of parameters / INI files.
Definition Param.h:46
LogType
Possible log types.
Definition ProgressLogger.h:44
Base class for TOPP applications.
Definition TOPPBase.h:57
std::string getStringOption_(const std::string &name) const
Returns the value of a previously registered string option (use getOutputDirOption() for output direc...
void setValidFormats_(const std::string &name, const std::vector< std::string > &formats, const bool force_OpenMS_format=true)
Sets the formats for a input/output file option or for all members of an input/output file lists.
Param param_inifile_
All parameters specified in the ini file.
Definition TOPPBase.h:152
void registerInputFileList_(const std::string &name, const std::string &argument, const StringList &default_value, const std::string &description, bool required=true, bool advanced=false, const StringList &tags=StringList())
Registers a list of input files option.
void setValidStrings_(const std::string &name, const std::string vstrings[], int count)
Sets the valid strings for a string option or a whole string list.
Param const & getParam_() const
Return all parameters relevant to this TOPP tool.
bool getFlag_(const std::string &name) const
Returns the value of a previously registered flag.
void addEmptyLine_()
Adds an empty line between registered variables in the documentation.
std::vector< ParameterInformation > paramToParameterInformation_(const Param &param) const
Translates the given parameter object into a vector of ParameterInformation, that can be utilized for...
TOPPBase(const std::string &name, const std::string &description, const std::vector< Citation > &citations={}, bool toolhandler_test=true)
Constructor.
std::string getToolPrefix() const
Returns the prefix used to identify the tool.
const ParamValue & getParam_(const std::string &key) const
Return the value key of parameters as DataValue. ParamValue::EMPTY indicates that a parameter was not...
bool getParamAsBool_(const std::string &key) const
Return the value of flag parameter key as bool.
void enableLogging_() const
Ensures that at least some default logging destination is opened for writing in append mode.
Param parseCommandLine_(const int argc, const char **argv, const std::string &misc="misc", const std::string &unknown="unknown")
Parses command line arguments using parameter definitions from TOPPBase.
bool toolhandler_test_
Enable the ToolHandler tests.
Definition TOPPBase.h:319
Param param_
All parameters relevant to this invocation of the program.
Definition TOPPBase.h:149
void setValidStrings_(const std::string &name, const std::vector< std::string > &strings)
Sets the valid strings for a string option or a whole string list.
std::string const tool_description_
Tool description. This is assigned once and for all in the constructor.
Definition TOPPBase.h:143
double getDoubleOption_(const std::string &name) const
Returns the value of a previously registered double option.
std::vector< ParameterInformation > parameters_
Storage location for parameter information.
Definition TOPPBase.h:181
std::map< std::string, std::string > subsections_
Storage location and description for allowed subsections.
Definition TOPPBase.h:204
void registerOutputDir_(const std::string &name, const std::string &argument, const std::string &default_value, const std::string &description, bool required=true, bool advanced=false)
Registers an output directory used for tools with multiple output files which are not an output file ...
void registerSubsection_(const std::string &name, const std::string &description)
Registers an allowed subsection in the INI file (usually from OpenMS algorithms).
virtual ~TOPPBase()
Destructor.
void writeLogInfo_(const std::string &text) const
Writes a string to the log file and to OPENMS_LOG_INFO.
void printUsage_()
Prints the tool-specific command line options and appends the common options.
void registerStringOption_(const std::string &name, const std::string &argument, const std::string &default_value, const std::string &description, bool required=true, bool advanced=false)
Registers a string option.
void setMaxFloat_(const std::string &name, double max)
Sets the maximum value for the floating point parameter(can be a list of floating points,...
Int getIntOption_(const std::string &name) const
Returns the value of a previously registered integer option.
void registerTOPPSubsection_(const std::string &name, const std::string &description)
Registers an allowed subsection in the INI file originating from the TOPP tool itself.
void addDataProcessing_(FeatureMap &map, const DataProcessing &dp) const
Data processing setter for feature maps.
Param param_instance_
Parameters from the tool section of the INI file (e.g. "TOPPTool:1:"), see getIniLocation_()
Definition TOPPBase.h:158
std::vector< Citation > citations_
Papers, specific for this tool (will be shown in '–help')
Definition TOPPBase.h:316
DataProcessing getProcessingInfo_(const std::set< DataProcessing::ProcessingAction > &actions) const
Returns the data processing information.
ProgressLogger::LogType log_type_
Type of progress logging.
Definition TOPPBase.h:896
void addText_(const std::string &text)
void checkParam_(const Param &param, const std::string &filename, const std::string &location) const
Checks top-level entries of param according to the information during registration.
std::string version_
Version string (if empty, the OpenMS/TOPP version is printed)
Definition TOPPBase.h:310
std::string getOutputDirOption(const std::string &name) const
Returns the value of a previously registered output_dir option.
void registerStringList_(const std::string &name, const std::string &argument, const StringList &default_value, const std::string &description, bool required=true, bool advanced=false)
Registers a list of strings option.
ParameterInformation & getParameterByName_(const std::string &name)
Returns the parameter identified by the given name.
bool test_mode_
Test mode.
Definition TOPPBase.h:929
ExitCodes main(int argc, const char **argv)
Main routine of all TOPP applications.
void addDataProcessing_(PeakMap &map, const DataProcessing &dp) const
Data processing setter for peak maps.
static std::string topp_ini_file_
.TOPP.ini file for storing system default parameters
Definition TOPPBase.h:932
void registerIntOption_(const std::string &name, const std::string &argument, Int default_value, const std::string &description, bool required=true, bool advanced=false)
Registers an integer option.
TOPPBase()=delete
No default constructor.
StringList getStringList_(const std::string &name) const
Returns the value of a previously registered StringList.
std::string getParamAsString_(const std::string &key, const std::string &default_value="") const
Return the value of parameter key as a string or default_value if this value is not set.
void setMinInt_(const std::string &name, Int min)
Sets the minimum value for the integer parameter(can be a list of integers,too) name.
void inputFileReadable_(const std::string &filename, const std::string &param_name) const
Checks if an input file exists, is readable and is not empty.
virtual void registerOptionsAndFlags_()=0
Sets the valid command line options (with argument) and flags (without argument).
static const Citation cite_openms
The latest and greatest OpenMS citation.
Definition TOPPBase.h:136
const ParameterInformation & findEntry_(const std::string &name) const
Finds the entry in the parameters_ array that has the name name.
std::unique_ptr< std::ofstream > log_
Definition TOPPBase.h:168
DataProcessing getProcessingInfo_(DataProcessing::ProcessingAction action) const
Returns the data processing information.
Param param_common_tool_
Parameters from common section with tool name.
Definition TOPPBase.h:161
DoubleList getParamAsDoubleList_(const std::string &key, const DoubleList &default_value) const
Return the value of parameter key as a DoubleList or default_value if this value is not set.
void registerDoubleList_(const std::string &name, const std::string &argument, const DoubleList &default_value, const std::string &description, bool required=true, bool advanced=false)
Registers a list of doubles option.
void writeDebug_(const std::string &text, UInt min_level) const
Writes a string to the log file and to OPENMS_LOG_DEBUG if the debug level is at least min_level.
Int debug_level_
Debug level set by -debug.
Definition TOPPBase.h:935
void writeDebug_(const std::string &text, const Param &param, UInt min_level) const
Writes a std::string followed by a Param to the log file and to OPENMS_LOG_DEBUG if the debug level i...
TOPPBase(const TOPPBase &)=delete
No default copy constructor.
Param getDefaultParameters_() const
Returns the default parameters.
void registerOutputFile_(const std::string &name, const std::string &argument, const std::string &default_value, const std::string &description, bool required=true, bool advanced=false)
Registers an output file option.
void registerInputFile_(const std::string &name, const std::string &argument, const std::string &default_value, const std::string &description, bool required=true, bool advanced=false, const StringList &tags=StringList())
Registers an input file option.
Param param_cmdline_
Parameters from command line.
Definition TOPPBase.h:155
const std::string & getIniLocation_() const
Returns the location of the ini file where parameters are taken from, i.e. "TOPPTool:1:" for a tool n...
Definition TOPPBase.h:327
void registerOutputPrefix_(const std::string &name, const std::string &argument, const std::string &default_value, const std::string &description, bool required=true, bool advanced=false)
Registers an output file prefix used for tools with multiple file output.
double getParamAsDouble_(const std::string &key, double default_value=0) const
Return the value of parameter key as a double or default_value if this value is not set.
void registerFlag_(const std::string &name, const std::string &description, bool advanced=false)
Registers a flag.
DoubleList getDoubleList_(const std::string &name) const
Returns the value of a previously registered DoubleList.
std::string const ini_location_
Location in the ini file where to look for parameters.
Definition TOPPBase.h:146
std::string getSubsection_(const std::string &name) const
Get the part of a parameter name that makes up the subsection.
const std::string & toolName_() const
Returns the tool name.
void setMaxInt_(const std::string &name, Int max)
Sets the maximum value for the integer parameter(can be a list of integers,too) name.
static void setMaxNumberOfThreads(int num_threads)
Sets the maximal number of usable threads.
void writeLogWarn_(const std::string &text) const
Writes a string to the log file and to OPENMS_LOG_WARN.
void outputFileWritable_(const std::string &filename, const std::string &param_name) const
Checks if an output file is writable.
IntList getIntList_(const std::string &name) const
Returns the value of a previously registered IntList.
void fileParamValidityCheck_(std::string &param_value, const std::string &param_name, const ParameterInformation &p) const
checks if an input file exists (respecting the flags)
void registerParamSubsectionsAsTOPPSubsections_(const Param &param)
std::map< std::string, std::string > subsections_TOPP_
Storage location and description for allowed subsections from TOPP tool's command-line parameters.
Definition TOPPBase.h:207
ExitCodes
Exit codes.
Definition TOPPBase.h:69
@ INPUT_FILE_EMPTY
Definition TOPPBase.h:74
@ INPUT_FILE_CORRUPT
Definition TOPPBase.h:73
@ ILLEGAL_PARAMETERS
Definition TOPPBase.h:76
@ MISSING_PARAMETERS
Definition TOPPBase.h:77
@ EXTERNAL_PROGRAM_ERROR
Definition TOPPBase.h:79
@ INCOMPATIBLE_INPUT_DATA
Definition TOPPBase.h:81
@ UNKNOWN_ERROR
Definition TOPPBase.h:78
@ EXECUTION_OK
Definition TOPPBase.h:70
@ INTERNAL_ERROR
Definition TOPPBase.h:82
@ INPUT_FILE_NOT_FOUND
Definition TOPPBase.h:71
@ INPUT_FILE_NOT_READABLE
Definition TOPPBase.h:72
@ CANNOT_WRITE_OUTPUT_FILE
Definition TOPPBase.h:75
@ PARSE_ERROR
Definition TOPPBase.h:80
@ UNEXPECTED_RESULT
Definition TOPPBase.h:83
virtual ExitCodes main_(int argc, const char **argv)=0
The actual "main" method. main_() is invoked by main().
bool parseRange_(const std::string &text, Int &low, Int &high) const
Parses a range string ([a]:[b]) into two variables (integers)
void registerIntList_(const std::string &name, const std::string &argument, const IntList &default_value, const std::string &description, bool required=true, bool advanced=false)
Registers a list of integers option.
void writeLogError_(const std::string &text) const
Writes a string to the log file and to OPENMS_LOG_ERROR.
bool parseRange_(const std::string &text, double &low, double &high) const
Parses a range string ([a]:[b]) into two variables (doubles)
Int getParamAsInt_(const std::string &key, Int default_value=0) const
Return the value of parameter key as an integer or default_value if this value is not set.
void registerDoubleOption_(const std::string &name, const std::string &argument, double default_value, const std::string &description, bool required=true, bool advanced=false)
Registers a double option.
void checkIfIniParametersAreApplicable_(const Param &ini_params)
Checks if the parameters of the provided ini file are applicable to this tool.
void setMinFloat_(const std::string &name, double min)
Sets the minimum value for the floating point parameter(can be a list of floating points,...
Param getToolUserDefaults_(const std::string &tool_name) const
Returns the user defaults for the given tool, if any default parameters are stored in the users home.
virtual Param getSubsectionDefaults_(const std::string &section) const
This method should return the default parameters for subsections.
void fileParamValidityCheck_(const StringList &param_value, const std::string &param_name, const ParameterInformation &p) const
checks if files of an input file list exist
void addDataProcessing_(ConsensusMap &map, const DataProcessing &dp) const
Data processing setter for consensus maps.
Param getSubsectionDefaults_() const
Returns a single Param object containing all subsection parameters.
std::string getParamArgument_(const Param::ParamEntry &entry) const
Utility function that determines a suitable argument value for the given Param::ParamEntry.
void registerOutputFileList_(const std::string &name, const std::string &argument, const StringList &default_value, const std::string &description, bool required=true, bool advanced=false)
Registers a list of output files option.
std::string verboseVersion_
Version string including additional revision/date time information. Note: This differs from version_ ...
Definition TOPPBase.h:313
std::optional< ExitCodes > handleWriteCommands_()
Handles the '-write_ini/-write_ctd/-write_(nested_)cwl/-write_(nested_)json' command-line options.
IntList getParamAsIntList_(const std::string &key, const IntList &default_value) const
Return the value of parameter key as a IntList or default_value if this value is not set.
void registerFullParam_(const Param &param)
Register command line parameters for all entries in a Param object.
std::string const tool_name_
Tool name. This is assigned once and for all in the constructor.
Definition TOPPBase.h:140
std::string getDocumentationURL() const
Returns a link to the documentation of the tool (accessible on our servers and only after inclusion i...
Param param_common_
Parameters from common section without tool name.
Definition TOPPBase.h:164
StringList getParamAsStringList_(const std::string &key, const StringList &default_value) const
Return the value of parameter key as a StringList or default_value if this value is not set.
ParameterInformation paramEntryToParameterInformation_(const Param::ParamEntry &entry, const std::string &argument="", const std::string &full_name="") const
Transforms a ParamEntry object to command line parameter (ParameterInformation).
virtual bool findExecutable_(std::string &executable) const
Searches for the executable an input file parameter tagged 'is_executable' names.
int Int
Signed integer type.
Definition Types.h:72
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
std::vector< Int > IntList
Vector of signed integers.
Definition TypeAliases.h:24
std::vector< double > DoubleList
Vector of double precision real types.
Definition TypeAliases.h:31
std::vector< std::string > StringList
Vector of String.
Definition TypeAliases.h:39
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Stores Citations for individual TOPP tools.
Definition TOPPBase_defs.h:37
Parameter entry used to store the actual information inside of a Param entry.
Definition Param.h:51
Struct that captures all information of a command line parameter.
Definition ParameterInformation.h:24