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-2016.
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 
42 
46 
49 
52 
55 
56 #include <fstream>
57 
58 class QStringList;
59 
60 namespace OpenMS
61 {
62 
63  class ConsensusMap;
64 
65  namespace Exception
66  {
68  class OPENMS_DLLAPI UnregisteredParameter :
70  {
71 public:
72  UnregisteredParameter(const char* file, int line, const char* function, const String& parameter) :
73  BaseException(file, line, function, "UnregisteredParameter", parameter)
74  {
76  }
77 
78  };
80  class OPENMS_DLLAPI WrongParameterType :
82  {
83 public:
84  WrongParameterType(const char* file, int line, const char* function, const String& parameter) :
85  BaseException(file, line, function, "WrongParameterType", parameter)
86  {
88  }
89 
90  };
92  class OPENMS_DLLAPI RequiredParameterNotGiven :
94  {
95 public:
96  RequiredParameterNotGiven(const char* file, int line, const char* function, const String& parameter) :
97  BaseException(file, line, function, "RequiredParameterNotGiven", parameter)
98  {
100  }
101 
102  };
103  }
104 
125  class OPENMS_DLLAPI TOPPBase
126  {
127 public:
128 
131  {
145  UNEXPECTED_RESULT
146  };
147 
162  TOPPBase(const String& name, const String& description, bool official = true, bool id_tag_support = false, bool require_args = true, const String& version = "");
163 
165  virtual ~TOPPBase();
166 
168  ExitCodes main(int argc, const char** argv);
169 
177  static void setMaxNumberOfThreads(int num_threads);
178 
179 private:
180 
183 
186 
189 
192 
195 
198 
201 
203  TOPPBase();
204 
206  TOPPBase(const TOPPBase&);
207 
210 
213 
216 
219 
222 
225 
227  mutable std::ofstream log_;
228 
237  void enableLogging_() const;
238 
240  std::vector<ParameterInformation> parameters_;
241 
251  virtual Param getSubsectionDefaults_(const String& section) const;
252 
260  Param getSubsectionDefaults_() const;
261 
263  std::map<String, String> subsections_;
264 
266  std::map<String, String> subsections_TOPP_;
267 
268 
281  Param parseCommandLine_(const int argc, const char** argv, const String& misc = "misc", const String& unknown = "unknown");
282 
292  String getParamAsString_(const String& key, const String& default_value = "") const;
293 
299  Int getParamAsInt_(const String& key, Int default_value = 0) const;
300 
306  double getParamAsDouble_(const String& key, double default_value = 0) const;
307 
313  StringList getParamAsStringList_(const String& key, const StringList& default_value) const;
314 
320  IntList getParamAsIntList_(const String& key, const IntList& default_value) const;
321 
327  DoubleList getParamAsDoubleList_(const String& key, const DoubleList& default_value) const;
328 
338  bool getParamAsBool_(const String& key) const;
339 
351  const DataValue& getParam_(const String& key) const;
352 
358  String getSubsection_(const String& name) const;
359 
361  Param getDefaultParameters_() const;
362 
364  Param getToolUserDefaults_(const String& tool_name) const;
366 
367 protected:
370 
373 
375  bool official_;
376 
384  const String& getIniLocation_() const
385  {
386  return ini_location_;
387  }
388 
390  const String& toolName_() const;
391 
412  virtual void registerOptionsAndFlags_() = 0;
413 
415  String getParamArgument_(const Param::ParamEntry& entry) const;
416 
418  std::vector<ParameterInformation> paramToParameterInformation_(const Param& param) const;
419 
429  ParameterInformation paramEntryToParameterInformation_(const Param::ParamEntry& entry, const String& argument = "", const String& full_name = "") const;
430 
431  void registerParamSubsectionsAsTOPPSubsections_(const Param& param);
432 
434  void registerFullParam_(const Param& param);
435 
446  void registerStringOption_(const String& name, const String& argument, const String& default_value, const String& description, bool required = true, bool advanced = false);
447 
454  void setValidStrings_(const String& name, const std::vector<String>& strings);
455 
465  void setValidStrings_(const String& name, const std::string vstrings[], int count);
466 
482  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());
483 
497  void registerOutputFile_(const String& name, const String& argument, const String& default_value, const String& description, bool required = true, bool advanced = false);
498 
509  void setValidFormats_(const String& name, const std::vector<String>& formats, const bool force_OpenMS_format = true);
510 
511 
522  void registerDoubleOption_(const String& name, const String& argument, double default_value, const String& description, bool required = true, bool advanced = false);
523 
529  void setMinInt_(const String& name, Int min);
535  void setMaxInt_(const String& name, Int max);
541  void setMinFloat_(const String& name, double min);
547  void setMaxFloat_(const String& name, double max);
548 
559  void registerIntOption_(const String& name, const String& argument,
560  Int default_value, const String& description,
561  bool required = true, bool advanced = false);
562 
574  void registerIntList_(const String& name, const String& argument, IntList default_value, const String& description, bool required = true, bool advanced = false);
575 
586  void registerDoubleList_(const String& name, const String& argument, DoubleList default_value, const String& description, bool required = true, bool advanced = false);
587 
598  void registerStringList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
599 
613  void registerInputFileList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
614 
628  void registerOutputFileList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
629 
631  void registerFlag_(const String& name, const String& description, bool advanced = false);
632 
640  void registerSubsection_(const String& name, const String& description);
641 
651  void registerTOPPSubsection_(const String& name, const String& description);
652 
653 
655  void addEmptyLine_();
656 
657 
666  String getStringOption_(const String& name) const;
667 
676  double getDoubleOption_(const String& name) const;
677 
686  Int getIntOption_(const String& name) const;
687 
696  StringList getStringList_(const String& name) const;
697 
706  IntList getIntList_(const String& name) const;
707 
716  DoubleList getDoubleList_(const String& name) const;
717 
719  bool getFlag_(const String& name) const;
720 
726  const ParameterInformation& findEntry_(const String& name) const;
727 
733  Param const& getParam_() const;
734 
748  void checkParam_(const Param& param, const String& filename, const String& location) const;
749 
750 
758  void checkIfIniParametersAreApplicable_(const Param& ini_params);
760 
762  void printUsage_();
763 
765  virtual ExitCodes main_(int argc, const char** argv) = 0;
766 
768 
769  void writeLog_(const String& text) const;
771 
773  void writeDebug_(const String& text, UInt min_level) const;
774 
776  void writeDebug_(const String& text, const Param& param, UInt min_level) const;
778 
779 
804  void inputFileReadable_(const String& filename, const String& param_name) const;
805 
816  void outputFileWritable_(const String& filename, const String& param_name) const;
818 
826  bool parseRange_(const String& text, double& low, double& high) const;
827 
835  bool parseRange_(const String& text, Int& low, Int& high) const;
836 
839 
841 
842 
844  void addDataProcessing_(ConsensusMap& map, const DataProcessing& dp) const;
845 
847  void addDataProcessing_(FeatureMap& map, const DataProcessing& dp) const;
848 
850  template <typename PeakType, typename CT>
852  {
853  boost::shared_ptr< DataProcessing > dp_(new DataProcessing(dp));
854  for (Size i = 0; i < map.size(); ++i)
855  {
856  map[i].getDataProcessing().push_back(dp_);
857  }
858  for (Size i = 0; i < map.getNrChromatograms(); ++i)
859  {
860  map.getChromatogram(i).getDataProcessing().push_back(dp_);
861  }
862  }
863 
865  DataProcessing getProcessingInfo_(DataProcessing::ProcessingAction action) const;
866 
868  DataProcessing getProcessingInfo_(const std::set<DataProcessing::ProcessingAction>& actions) const;
869 
871 
873  const DocumentIDTagger& getDocumentIDTagger_() const;
874 
876  bool writeCTD_();
877 
879  ExitCodes writeWSDL_(const String& filename);
880 
893 
896 
899 private:
900 
906  void addText_(const String& text);
907 
915  ParameterInformation& getParameterByName_(const String& name);
916 
917  };
918 
919 } // namespace OpenMS
920 
921 #endif //OPENMS_APPLICATIONS_TOPPBASE_H
String verboseVersion_
Version string including additional revision/date time information. Note: This differs from version_ ...
Definition: TOPPBase.h:372
Definition: TOPPBase.h:139
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's command-line parameters...
Definition: TOPPBase.h:266
An unregistered parameter was accessed.
Definition: TOPPBase.h:68
Definition: TOPPBase.h:132
Definition: TOPPBase.h:135
A more convenient string class.
Definition: String.h:57
Size size() const
Definition: MSExperiment.h:119
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:72
RequiredParameterNotGiven(const char *file, int line, const char *function, const String &parameter)
Definition: TOPPBase.h:96
std::ofstream log_
Log file stream. Use the writeLog_() and writeDebug_() methods to access it.
Definition: TOPPBase.h:227
A container for features.
Definition: FeatureMap.h:94
bool official_
Flag indicating if this an official TOPP tool.
Definition: TOPPBase.h:375
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
Definition: TOPPBase.h:140
Definition: TOPPBase.h:136
std::map< String, String > subsections_
Storage location and description for allowed subsections.
Definition: TOPPBase.h:263
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:384
Definition: TOPPBase.h:142
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
bool test_mode_
Test mode.
Definition: TOPPBase.h:892
Base class for TOPP applications.
Definition: TOPPBase.h:125
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:138
ProcessingAction
Definition: DataProcessing.h:59
A parameter was accessed with the wrong type.
Definition: TOPPBase.h:80
Param param_cmdline_
Parameters from command line.
Definition: TOPPBase.h:215
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:221
MSChromatogram< ChromatogramPeakType > & getChromatogram(Size id)
returns a single chromatogram
Definition: MSExperiment.h:864
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:188
Definition: TOPPBase.h:144
bool require_args_
Require at least one command line argument, exit immediately otherwise. GUI tools should disable this...
Definition: TOPPBase.h:191
Size getNrChromatograms() const
get the total number of chromatograms available
Definition: MSExperiment.h:882
Exception base class.
Definition: Exception.h:90
Param param_common_
Parameters from common section without tool name.
Definition: TOPPBase.h:224
String version_
Version string (if empty, the OpenMS/TOPP version is printed)
Definition: TOPPBase.h:369
DocumentIDTagger id_tagger_
Instance of DocumentIDTagger, which can be accessed using getDocumentIDTagger_()
Definition: TOPPBase.h:194
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:71
WrongParameterType(const char *file, int line, const char *function, const String &parameter)
Definition: TOPPBase.h:84
static void setMessage(const std::string &message)
String const tool_name_
Tool name. This is assigned once and for all in the constructor.
Definition: TOPPBase.h:182
Param param_
All parameters relevant to this invocation of the program.
Definition: TOPPBase.h:209
Definition: TOPPBase.h:133
std::vector< ParameterInformation > parameters_
Storage location for parameter information.
Definition: TOPPBase.h:240
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:73
ExitCodes
Exit codes.
Definition: TOPPBase.h:130
String const ini_location_
Location in the ini file where to look for parameters.
Definition: TOPPBase.h:200
String const tool_description_
Tool description. This is assigned once and for all in the constructor.
Definition: TOPPBase.h:185
Param param_inifile_
All parameters specified in the ini file.
Definition: TOPPBase.h:212
int Int
Signed integer type.
Definition: Types.h:103
Param param_instance_
Parameters from instance section.
Definition: TOPPBase.h:218
void addDataProcessing_(MSExperiment< PeakType, CT > &map, const DataProcessing &dp) const
Data processing setter for peak maps.
Definition: TOPPBase.h:851
Int debug_level_
Debug level set by -debug.
Definition: TOPPBase.h:898
ProgressLogger::LogType log_type_
Type of progress logging.
Definition: TOPPBase.h:838
Int const instance_number_
Instance number.
Definition: TOPPBase.h:197
static String topp_ini_file_
.TOPP.ini file for storing system default parameters
Definition: TOPPBase.h:895
A required parameter was not given.
Definition: TOPPBase.h:92

OpenMS / TOPP release 2.0.0 Documentation generated on Tue Jan 31 2017 06:39:55 using doxygen 1.8.8