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 #ifndef OPENMS_APPLICATIONS_TOPPBASE_H
36 #define OPENMS_APPLICATIONS_TOPPBASE_H
37 
42 
46 
49 
53 
56 
57 #include <fstream>
58 
59 class QStringList;
60 
61 namespace OpenMS
62 {
63 
64  class ConsensusMap;
65 
66  namespace Exception
67  {
69  class OPENMS_DLLAPI UnregisteredParameter :
71  {
72 public:
73  UnregisteredParameter(const char* file, int line, const char* function, const String& parameter) :
74  BaseException(file, line, function, "UnregisteredParameter", parameter)
75  {
77  }
78 
79  };
81  class OPENMS_DLLAPI WrongParameterType :
83  {
84 public:
85  WrongParameterType(const char* file, int line, const char* function, const String& parameter) :
86  BaseException(file, line, function, "WrongParameterType", parameter)
87  {
89  }
90 
91  };
93  class OPENMS_DLLAPI RequiredParameterNotGiven :
95  {
96 public:
97  RequiredParameterNotGiven(const char* file, int line, const char* function, const String& parameter) :
98  BaseException(file, line, function, "RequiredParameterNotGiven", parameter)
99  {
101  }
102 
103  };
104  }
105 
126  class OPENMS_DLLAPI TOPPBase
127  {
128 public:
129 
132  {
146  UNEXPECTED_RESULT
147  };
148 
163  TOPPBase(const String& name, const String& description, bool official = true, bool id_tag_support = false, bool require_args = true, const String& version = "");
164 
166  virtual ~TOPPBase();
167 
169  ExitCodes main(int argc, const char** argv);
170 
178  static void setMaxNumberOfThreads(int num_threads);
179 
180 private:
181 
184 
187 
190 
193 
196 
199 
202 
204  TOPPBase();
205 
207  TOPPBase(const TOPPBase&);
208 
211 
214 
217 
220 
223 
226 
228  mutable std::ofstream log_;
229 
238  void enableLogging_() const;
239 
241  std::vector<ParameterInformation> parameters_;
242 
252  virtual Param getSubsectionDefaults_(const String& section) const;
253 
261  Param getSubsectionDefaults_() const;
262 
264  std::map<String, String> subsections_;
265 
267  std::map<String, String> subsections_TOPP_;
268 
269 
282  Param parseCommandLine_(const int argc, const char** argv, const String& misc = "misc", const String& unknown = "unknown");
283 
293  String getParamAsString_(const String& key, const String& default_value = "") const;
294 
300  Int getParamAsInt_(const String& key, Int default_value = 0) const;
301 
307  double getParamAsDouble_(const String& key, double default_value = 0) const;
308 
314  StringList getParamAsStringList_(const String& key, const StringList& default_value) const;
315 
321  IntList getParamAsIntList_(const String& key, const IntList& default_value) const;
322 
328  DoubleList getParamAsDoubleList_(const String& key, const DoubleList& default_value) const;
329 
339  bool getParamAsBool_(const String& key) const;
340 
352  const DataValue& getParam_(const String& key) const;
353 
359  String getSubsection_(const String& name) const;
360 
362  Param getDefaultParameters_() const;
363 
365  Param getToolUserDefaults_(const String& tool_name) const;
367 
368 protected:
371 
374 
376  bool official_;
377 
385  const String& getIniLocation_() const
386  {
387  return ini_location_;
388  }
389 
391  const String& toolName_() const;
392 
413  virtual void registerOptionsAndFlags_() = 0;
414 
416  String getParamArgument_(const Param::ParamEntry& entry) const;
417 
419  std::vector<ParameterInformation> paramToParameterInformation_(const Param& param) const;
420 
430  ParameterInformation paramEntryToParameterInformation_(const Param::ParamEntry& entry, const String& argument = "", const String& full_name = "") const;
431 
432  void registerParamSubsectionsAsTOPPSubsections_(const Param& param);
433 
435  void registerFullParam_(const Param& param);
436 
447  void registerStringOption_(const String& name, const String& argument, const String& default_value, const String& description, bool required = true, bool advanced = false);
448 
455  void setValidStrings_(const String& name, const std::vector<String>& strings);
456 
466  void setValidStrings_(const String& name, const std::string vstrings[], int count);
467 
483  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());
484 
498  void registerOutputFile_(const String& name, const String& argument, const String& default_value, const String& description, bool required = true, bool advanced = false);
499 
510  void setValidFormats_(const String& name, const std::vector<String>& formats, const bool force_OpenMS_format = true);
511 
512 
523  void registerDoubleOption_(const String& name, const String& argument, double default_value, const String& description, bool required = true, bool advanced = false);
524 
530  void setMinInt_(const String& name, Int min);
536  void setMaxInt_(const String& name, Int max);
542  void setMinFloat_(const String& name, double min);
548  void setMaxFloat_(const String& name, double max);
549 
560  void registerIntOption_(const String& name, const String& argument,
561  Int default_value, const String& description,
562  bool required = true, bool advanced = false);
563 
575  void registerIntList_(const String& name, const String& argument, IntList default_value, const String& description, bool required = true, bool advanced = false);
576 
587  void registerDoubleList_(const String& name, const String& argument, DoubleList default_value, const String& description, bool required = true, bool advanced = false);
588 
599  void registerStringList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
600 
616  void registerInputFileList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false, const StringList& tags = StringList());
617 
631  void registerOutputFileList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
632 
634  void registerFlag_(const String& name, const String& description, bool advanced = false);
635 
643  void registerSubsection_(const String& name, const String& description);
644 
654  void registerTOPPSubsection_(const String& name, const String& description);
655 
656 
658  void addEmptyLine_();
659 
660 
669  String getStringOption_(const String& name) const;
670 
679  double getDoubleOption_(const String& name) const;
680 
689  Int getIntOption_(const String& name) const;
690 
699  StringList getStringList_(const String& name) const;
700 
709  IntList getIntList_(const String& name) const;
710 
719  DoubleList getDoubleList_(const String& name) const;
720 
722  bool getFlag_(const String& name) const;
723 
729  const ParameterInformation& findEntry_(const String& name) const;
730 
736  Param const& getParam_() const;
737 
751  void checkParam_(const Param& param, const String& filename, const String& location) const;
752 
753 
761  void checkIfIniParametersAreApplicable_(const Param& ini_params);
763 
765  void printUsage_();
766 
768  virtual ExitCodes main_(int argc, const char** argv) = 0;
769 
771 
772  void writeLog_(const String& text) const;
774 
776  void writeDebug_(const String& text, UInt min_level) const;
777 
779  void writeDebug_(const String& text, const Param& param, UInt min_level) const;
781 
783 
784  String makeTempDirectory_() const;
786 
792  void removeTempDirectory_(const String& dirname, Int keep_debug = 2) const;
794 
819  void inputFileReadable_(const String& filename, const String& param_name) const;
820 
831  void outputFileWritable_(const String& filename, const String& param_name) const;
833 
841  bool parseRange_(const String& text, double& low, double& high) const;
842 
850  bool parseRange_(const String& text, Int& low, Int& high) const;
851 
854 
856 
857 
859  void addDataProcessing_(ConsensusMap& map, const DataProcessing& dp) const;
860 
862  void addDataProcessing_(FeatureMap& map, const DataProcessing& dp) const;
863 
865  void addDataProcessing_(PeakMap& map, const DataProcessing& dp) const
866  {
867  boost::shared_ptr< DataProcessing > dp_(new DataProcessing(dp));
868  for (Size i = 0; i < map.size(); ++i)
869  {
870  map[i].getDataProcessing().push_back(dp_);
871  }
872  for (Size i = 0; i < map.getNrChromatograms(); ++i)
873  {
874  map.getChromatogram(i).getDataProcessing().push_back(dp_);
875  }
876  }
877 
879  DataProcessing getProcessingInfo_(DataProcessing::ProcessingAction action) const;
880 
882  DataProcessing getProcessingInfo_(const std::set<DataProcessing::ProcessingAction>& actions) const;
883 
885 
887  const DocumentIDTagger& getDocumentIDTagger_() const;
888 
890  bool writeCTD_();
891 
893  ExitCodes writeWSDL_(const String& filename);
894 
907 
910 
913 private:
914 
920  void addText_(const String& text);
921 
929  ParameterInformation& getParameterByName_(const String& name);
930 
931  };
932 
933 } // namespace OpenMS
934 
935 #endif //OPENMS_APPLICATIONS_TOPPBASE_H
String verboseVersion_
Version string including additional revision/date time information. Note: This differs from version_ ...
Definition: TOPPBase.h:373
Definition: TOPPBase.h:140
Description of the applied preprocessing steps.
Definition: DataProcessing.h:52
std::map< String, String > subsections_TOPP_
Storage location and description for allowed subsections from TOPP tool&#39;s command-line parameters...
Definition: TOPPBase.h:267
An unregistered parameter was accessed.
Definition: TOPPBase.h:69
Definition: TOPPBase.h:133
Definition: TOPPBase.h:136
A more convenient string class.
Definition: String.h:57
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:66
LogType
Possible log types.
Definition: ProgressLogger.h:71
UnregisteredParameter(const char *file, int line, const char *function, const String &parameter)
Definition: TOPPBase.h:73
RequiredParameterNotGiven(const char *file, int line, const char *function, const String &parameter)
Definition: TOPPBase.h:97
std::ofstream log_
Log file stream. Use the writeLog_() and writeDebug_() methods to access it.
Definition: TOPPBase.h:228
A container for features.
Definition: FeatureMap.h:94
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
bool official_
Flag indicating if this an official TOPP tool.
Definition: TOPPBase.h:376
Parameter entry used to store the actual information inside of a Param entry.
Definition: Param.h:80
Struct that captures all information of a command line parameter.
Definition: ParameterInformation.h:48
A container for consensus elements.
Definition: ConsensusMap.h:72
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:59
void addDataProcessing_(PeakMap &map, const DataProcessing &dp) const
Data processing setter for peak maps.
Definition: TOPPBase.h:865
Definition: TOPPBase.h:141
Definition: TOPPBase.h:137
std::map< String, String > subsections_
Storage location and description for allowed subsections.
Definition: TOPPBase.h:264
Definition: TOPPBase.h:143
Size size() const
Definition: MSExperiment.h:132
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
bool test_mode_
Test mode.
Definition: TOPPBase.h:906
Base class for TOPP applications.
Definition: TOPPBase.h:126
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:385
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
const char * tool_name
Definition: TOPPAS.cpp:91
Definition: TOPPBase.h:139
A parameter was accessed with the wrong type.
Definition: TOPPBase.h:81
Param param_cmdline_
Parameters from command line.
Definition: TOPPBase.h:216
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:222
Size getNrChromatograms() const
get the total number of chromatograms available
Definition: MSExperiment.h:893
ProcessingAction
Definition: DataProcessing.h:59
std::vector< DataProcessingPtr > & getDataProcessing()
returns a mutable reference to the description of the applied processing
bool id_tag_support_
Tool indicates it supports assignment of unique DocumentID from IDPool.
Definition: TOPPBase.h:189
Definition: TOPPBase.h:145
bool require_args_
Require at least one command line argument, exit immediately otherwise. GUI tools should disable this...
Definition: TOPPBase.h:192
Exception base class.
Definition: Exception.h:90
Param param_common_
Parameters from common section without tool name.
Definition: TOPPBase.h:225
String version_
Version string (if empty, the OpenMS/TOPP version is printed)
Definition: TOPPBase.h:370
DocumentIDTagger id_tagger_
Instance of DocumentIDTagger, which can be accessed using getDocumentIDTagger_()
Definition: TOPPBase.h:195
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:74
Management and storage of parameters / INI files.
Definition: Param.h:75
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:82
WrongParameterType(const char *file, int line, const char *function, const String &parameter)
Definition: TOPPBase.h:85
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:128
String const tool_name_
Tool name. This is assigned once and for all in the constructor.
Definition: TOPPBase.h:183
Param param_
All parameters relevant to this invocation of the program.
Definition: TOPPBase.h:210
Definition: TOPPBase.h:134
std::vector< ParameterInformation > parameters_
Storage location for parameter information.
Definition: TOPPBase.h:241
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:73
ExitCodes
Exit codes.
Definition: TOPPBase.h:131
String const ini_location_
Location in the ini file where to look for parameters.
Definition: TOPPBase.h:201
MSChromatogram & getChromatogram(Size id)
returns a single chromatogram
Definition: MSExperiment.h:875
String const tool_description_
Tool description. This is assigned once and for all in the constructor.
Definition: TOPPBase.h:186
Param param_inifile_
All parameters specified in the ini file.
Definition: TOPPBase.h:213
int Int
Signed integer type.
Definition: Types.h:103
Param param_instance_
Parameters from instance section.
Definition: TOPPBase.h:219
Int debug_level_
Debug level set by -debug.
Definition: TOPPBase.h:912
ProgressLogger::LogType log_type_
Type of progress logging.
Definition: TOPPBase.h:853
Int const instance_number_
Instance number.
Definition: TOPPBase.h:198
static String topp_ini_file_
.TOPP.ini file for storing system default parameters
Definition: TOPPBase.h:909
A required parameter was not given.
Definition: TOPPBase.h:93

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:04 using doxygen 1.8.13