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-2015.
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 
471  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());
472 
486  void registerOutputFile_(const String& name, const String& argument, const String& default_value, const String& description, bool required = true, bool advanced = false);
487 
498  void setValidFormats_(const String& name, const std::vector<String>& formats, const bool force_OpenMS_format = true);
499 
500 
511  void registerDoubleOption_(const String& name, const String& argument, double default_value, const String& description, bool required = true, bool advanced = false);
512 
518  void setMinInt_(const String& name, Int min);
524  void setMaxInt_(const String& name, Int max);
530  void setMinFloat_(const String& name, double min);
536  void setMaxFloat_(const String& name, double max);
537 
548  void registerIntOption_(const String& name, const String& argument,
549  Int default_value, const String& description,
550  bool required = true, bool advanced = false);
551 
563  void registerIntList_(const String& name, const String& argument, IntList default_value, const String& description, bool required = true, bool advanced = false);
564 
575  void registerDoubleList_(const String& name, const String& argument, DoubleList default_value, const String& description, bool required = true, bool advanced = false);
576 
587  void registerStringList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
588 
602  void registerInputFileList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
603 
617  void registerOutputFileList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
618 
620  void registerFlag_(const String& name, const String& description, bool advanced = false);
621 
629  void registerSubsection_(const String& name, const String& description);
630 
640  void registerTOPPSubsection_(const String& name, const String& description);
641 
642 
644  void addEmptyLine_();
645 
646 
655  String getStringOption_(const String& name) const;
656 
665  double getDoubleOption_(const String& name) const;
666 
675  Int getIntOption_(const String& name) const;
676 
685  StringList getStringList_(const String& name) const;
686 
695  IntList getIntList_(const String& name) const;
696 
705  DoubleList getDoubleList_(const String& name) const;
706 
708  bool getFlag_(const String& name) const;
709 
715  const ParameterInformation& findEntry_(const String& name) const;
716 
722  Param const& getParam_() const;
723 
737  void checkParam_(const Param& param, const String& filename, const String& location) const;
738 
739 
747  void checkIfIniParametersAreApplicable_(const Param& ini_params);
749 
751  void printUsage_();
752 
754  virtual ExitCodes main_(int argc, const char** argv) = 0;
755 
757 
758  void writeLog_(const String& text) const;
760 
762  void writeDebug_(const String& text, UInt min_level) const;
763 
765  void writeDebug_(const String& text, const Param& param, UInt min_level) const;
767 
768 
793  void inputFileReadable_(const String& filename, const String& param_name) const;
794 
805  void outputFileWritable_(const String& filename, const String& param_name) const;
807 
809  void parseRange_(const String& text, double& low, double& high) const;
810 
812  void parseRange_(const String& text, Int& low, Int& high) const;
813 
816 
818 
819 
821  void addDataProcessing_(ConsensusMap& map, const DataProcessing& dp) const;
822 
824  void addDataProcessing_(FeatureMap& map, const DataProcessing& dp) const;
825 
827  template <typename PeakType, typename CT>
829  {
830  for (Size i = 0; i < map.size(); ++i)
831  {
832  map[i].getDataProcessing().push_back(dp);
833  }
834  for (Size i = 0; i < map.getNrChromatograms(); ++i)
835  {
836  map.getChromatogram(i).getDataProcessing().push_back(dp);
837  }
838  }
839 
841  DataProcessing getProcessingInfo_(DataProcessing::ProcessingAction action) const;
842 
844  DataProcessing getProcessingInfo_(const std::set<DataProcessing::ProcessingAction>& actions) const;
845 
847 
849  const DocumentIDTagger& getDocumentIDTagger_() const;
850 
852  bool writeCTD_();
853 
855  ExitCodes writeWSDL_(const String& filename);
856 
869 
872 
875 private:
876 
882  void addText_(const String& text);
883 
891  ParameterInformation& getParameterByName_(const String& name);
892 
893  };
894 
895 } // namespace OpenMS
896 
897 #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:51
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
const std::vector< DataProcessing > & getDataProcessing() const
returns a const reference to the description of the applied processing
Definition: TOPPBase.h:132
Definition: TOPPBase.h:135
A more convenient string class.
Definition: String.h:57
Size size() const
Definition: MSExperiment.h:117
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:93
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:868
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:92
Definition: TOPPBase.h:138
ProcessingAction
Definition: DataProcessing.h:58
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:796
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:814
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:69
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:96
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:828
Int debug_level_
Debug level set by -debug.
Definition: TOPPBase.h:874
ProgressLogger::LogType log_type_
Type of progress logging.
Definition: TOPPBase.h:815
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:871
A required parameter was not given.
Definition: TOPPBase.h:92

OpenMS / TOPP release 2.0.0 Documentation generated on Fri May 29 2015 17:20:31 using doxygen 1.8.9.1