00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_APPLICATIONS_TOPPBASE_H
00036 #define OPENMS_APPLICATIONS_TOPPBASE_H
00037
00038 #include <OpenMS/APPLICATIONS/ToolHandler.h>
00039 #include <OpenMS/CONCEPT/Exception.h>
00040 #include <OpenMS/CONCEPT/GlobalExceptionHandler.h>
00041 #include <OpenMS/CONCEPT/LogStream.h>
00042 #include <OpenMS/CONCEPT/ProgressLogger.h>
00043 #include <OpenMS/CONCEPT/VersionInfo.h>
00044 #include <OpenMS/DATASTRUCTURES/Param.h>
00045 #include <OpenMS/DATASTRUCTURES/String.h>
00046 #include <OpenMS/DATASTRUCTURES/StringList.h>
00047 #include <OpenMS/DATASTRUCTURES/IntList.h>
00048 #include <OpenMS/DATASTRUCTURES/DoubleList.h>
00049 #include <OpenMS/METADATA/DataProcessing.h>
00050 #include <OpenMS/METADATA/DocumentIDTagger.h>
00051 #include <OpenMS/KERNEL/MSExperiment.h>
00052 #include <OpenMS/KERNEL/FeatureMap.h>
00053
00054
00055 #include <iostream>
00056 #include <fstream>
00057 #include <limits>
00058
00059 class QStringList;
00060
00061
00062 namespace OpenMS
00063 {
00064
00065 class ConsensusMap;
00066
00067 namespace Exception
00068 {
00070 class OPENMS_DLLAPI UnregisteredParameter :
00071 public Exception::BaseException
00072 {
00073 public:
00074 UnregisteredParameter(const char* file, int line, const char* function, const String& parameter) :
00075 BaseException(file, line, function, "UnregisteredParameter", parameter)
00076 {
00077 GlobalExceptionHandler::getInstance().setMessage(what_);
00078 }
00079
00080 };
00082 class OPENMS_DLLAPI WrongParameterType :
00083 public Exception::BaseException
00084 {
00085 public:
00086 WrongParameterType(const char* file, int line, const char* function, const String& parameter) :
00087 BaseException(file, line, function, "WrongParameterType", parameter)
00088 {
00089 GlobalExceptionHandler::getInstance().setMessage(what_);
00090 }
00091
00092 };
00094 class OPENMS_DLLAPI RequiredParameterNotGiven :
00095 public Exception::BaseException
00096 {
00097 public:
00098 RequiredParameterNotGiven(const char* file, int line, const char* function, const String& parameter) :
00099 BaseException(file, line, function, "RequiredParameterNotGiven", parameter)
00100 {
00101 GlobalExceptionHandler::getInstance().setMessage(what_);
00102 }
00103
00104 };
00105 }
00106
00107
00113 struct ParameterInformation
00114 {
00116 enum ParameterTypes
00117 {
00118 NONE = 0,
00119 STRING,
00120 INPUT_FILE,
00121 OUTPUT_FILE,
00122 DOUBLE,
00123 INT,
00124 STRINGLIST,
00125 INTLIST,
00126 DOUBLELIST,
00127 INPUT_FILE_LIST,
00128 OUTPUT_FILE_LIST,
00129 FLAG,
00130 TEXT,
00131 NEWLINE
00132 };
00133
00135 String name;
00137 ParameterTypes type;
00139 DataValue default_value;
00141 String description;
00143 String argument;
00145 bool required;
00147 bool advanced;
00149 StringList tags;
00150
00152
00153 std::vector<String> valid_strings;
00154 Int min_int;
00155 Int max_int;
00156 DoubleReal min_float;
00157 DoubleReal max_float;
00159
00161 ParameterInformation(const String& n, ParameterTypes t, const String& arg, const DataValue& def, const String& desc, bool req, bool adv, const StringList& tag_values = StringList()) :
00162 name(n),
00163 type(t),
00164 default_value(def),
00165 description(desc),
00166 argument(arg),
00167 required(req),
00168 advanced(adv),
00169 tags(tag_values),
00170 valid_strings(),
00171 min_int(-std::numeric_limits<Int>::max()),
00172 max_int(std::numeric_limits<Int>::max()),
00173 min_float(-std::numeric_limits<DoubleReal>::max()),
00174 max_float(std::numeric_limits<DoubleReal>::max())
00175 {
00176 }
00177
00178 ParameterInformation() :
00179 name(),
00180 type(NONE),
00181 default_value(),
00182 description(),
00183 argument(),
00184 required(true),
00185 advanced(false),
00186 tags(),
00187 valid_strings(),
00188 min_int(-std::numeric_limits<Int>::max()),
00189 max_int(std::numeric_limits<Int>::max()),
00190 min_float(-std::numeric_limits<DoubleReal>::max()),
00191 max_float(std::numeric_limits<DoubleReal>::max())
00192 {
00193 }
00194
00195 ParameterInformation& operator=(const ParameterInformation& rhs)
00196 {
00197 if (&rhs == this) return *this;
00198
00199 name = rhs.name;
00200 type = rhs.type;
00201 default_value = rhs.default_value;
00202 description = rhs.description;
00203 argument = rhs.argument;
00204 required = rhs.required;
00205 advanced = rhs.advanced;
00206 tags = rhs.tags;
00207 valid_strings = rhs.valid_strings;
00208 min_int = rhs.min_int;
00209 max_int = rhs.max_int;
00210 min_float = rhs.min_float;
00211 max_float = rhs.max_float;
00212
00213 return *this;
00214 }
00215
00216 };
00217
00218
00241 class OPENMS_DLLAPI TOPPBase
00242 {
00243 public:
00244
00246 enum ExitCodes
00247 {
00248 EXECUTION_OK,
00249 INPUT_FILE_NOT_FOUND,
00250 INPUT_FILE_NOT_READABLE,
00251 INPUT_FILE_CORRUPT,
00252 INPUT_FILE_EMPTY,
00253 CANNOT_WRITE_OUTPUT_FILE,
00254 ILLEGAL_PARAMETERS,
00255 MISSING_PARAMETERS,
00256 UNKNOWN_ERROR,
00257 EXTERNAL_PROGRAM_ERROR,
00258 PARSE_ERROR,
00259 INCOMPATIBLE_INPUT_DATA,
00260 INTERNAL_ERROR,
00261 UNEXPECTED_RESULT
00262 };
00263
00276 TOPPBase(const String& name, const String& description, bool official = true, bool id_tag_support = false, bool require_args = true , const String& version = "");
00277
00279 virtual ~TOPPBase();
00280
00282 ExitCodes main(int argc, const char** argv);
00283
00291 static void setMaxNumberOfThreads(int num_threads);
00292
00293 private:
00294
00296 String const tool_name_;
00297
00299 String const tool_description_;
00300
00302 bool id_tag_support_;
00303
00305 bool require_args_;
00306
00308 DocumentIDTagger id_tagger_;
00309
00311 Int const instance_number_;
00312
00314 String const ini_location_;
00315
00317 TOPPBase();
00318
00320 TOPPBase(const TOPPBase&);
00321
00323 Param param_;
00324
00326 Param param_inifile_;
00327
00329 Param param_cmdline_;
00330
00332 Param param_instance_;
00333
00335 Param param_common_tool_;
00336
00338 Param param_common_;
00339
00341 mutable std::ofstream log_;
00342
00350 void enableLogging_() const;
00351
00353 std::vector<ParameterInformation> parameters_;
00354
00364 virtual Param getSubsectionDefaults_(const String& section) const;
00365
00367 std::map<String, String> subsections_;
00368
00370 std::map<String, String> subsections_TOPP_;
00371
00381 String getParamAsString_(const String& key, const String& default_value = "") const;
00382
00388 Int getParamAsInt_(const String& key, Int default_value = 0) const;
00389
00395 DoubleReal getParamAsDouble_(const String& key, DoubleReal default_value = 0) const;
00396
00402 StringList getParamAsStringList_(const String& key, const StringList& default_value) const;
00403
00409 IntList getParamAsIntList_(const String& key, const IntList& default_value) const;
00410
00416 DoubleList getParamAsDoubleList_(const String& key, const DoubleList& default_value) const;
00417
00427 bool getParamAsBool_(const String& key) const;
00428
00440 const DataValue& getParam_(const String& key) const;
00441
00447 String getSubsection_(const String& name) const;
00448
00450 Param getDefaultParameters_() const;
00451
00453 Param getToolUserDefaults_(const String& tool_name) const;
00455
00456 protected:
00458 String version_;
00459
00461 String verboseVersion_;
00462
00464 bool official_;
00465
00473 const String& getIniLocation_() const
00474 {
00475 return ini_location_;
00476 }
00477
00479 const String& toolName_() const;
00480
00501 virtual void registerOptionsAndFlags_() = 0;
00502
00512 void registerParamEntry_(const Param::ParamEntry& entry, const String& argument = "", const String& full_name = "");
00513
00515 void registerFullParam_(const Param& param);
00516
00527 void registerStringOption_(const String& name, const String& argument, const String& default_value, const String& description, bool required = true, bool advanced = false);
00528
00535 void setValidStrings_(const String& name, const std::vector<String>& strings);
00536
00552 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());
00553
00567 void registerOutputFile_(const String& name, const String& argument, const String& default_value, const String& description, bool required = true, bool advanced = false);
00568
00579 void setValidFormats_(const String& name, const std::vector<String>& formats, const bool force_OpenMS_format = true);
00580
00581
00592 void registerDoubleOption_(const String& name, const String& argument, double default_value, const String& description, bool required = true, bool advanced = false);
00593
00599 void setMinInt_(const String& name, Int min);
00605 void setMaxInt_(const String& name, Int max);
00611 void setMinFloat_(const String& name, DoubleReal min);
00617 void setMaxFloat_(const String& name, DoubleReal max);
00618
00629 void registerIntOption_(const String& name, const String& argument,
00630 Int default_value, const String& description,
00631 bool required = true, bool advanced = false);
00632
00644 void registerIntList_(const String& name, const String& argument, IntList default_value, const String& description, bool required = true, bool advanced = false);
00645
00656 void registerDoubleList_(const String& name, const String& argument, DoubleList default_value, const String& description, bool required = true, bool advanced = false);
00657
00668 void registerStringList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
00669
00683 void registerInputFileList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
00684
00698 void registerOutputFileList_(const String& name, const String& argument, StringList default_value, const String& description, bool required = true, bool advanced = false);
00699
00701 void registerFlag_(const String& name, const String& description, bool advanced = false);
00702
00710 void registerSubsection_(const String& name, const String& description);
00711
00721 void registerTOPPSubsection_(const String& name, const String& description);
00722
00723
00725 void addEmptyLine_();
00726
00727
00736 String getStringOption_(const String& name) const;
00737
00746 DoubleReal getDoubleOption_(const String& name) const;
00747
00756 Int getIntOption_(const String& name) const;
00757
00766 StringList getStringList_(const String& name) const;
00767
00776 IntList getIntList_(const String& name) const;
00777
00786 DoubleList getDoubleList_(const String& name) const;
00787
00789 bool getFlag_(const String& name) const;
00790
00796 const ParameterInformation& findEntry_(const String& name) const;
00797
00803 Param const& getParam_() const;
00804
00818 void checkParam_(const Param& param, const String& filename, const String& location) const;
00819
00820
00828 void checkIfIniParametersAreApplicable_(const Param& ini_params);
00830
00832 String breakString_(const String& input, const Size line_len, const Size indentation, const Size max_lines) const;
00833
00835 void readConsoleSize_();
00836
00838 void printUsage_();
00839
00841 virtual ExitCodes main_(int argc, const char** argv) = 0;
00842
00844
00845
00846 void writeLog_(const String& text) const;
00847
00849 void writeDebug_(const String& text, UInt min_level) const;
00850
00852 void writeDebug_(const String& text, const Param& param, UInt min_level) const;
00854
00855
00880 void inputFileReadable_(const String& filename, const String& param_name) const;
00881
00892 void outputFileWritable_(const String& filename, const String& param_name) const;
00894
00896 void parseRange_(const String& text, double& low, double& high) const;
00897
00899 void parseRange_(const String& text, Int& low, Int& high) const;
00900
00902 ProgressLogger::LogType log_type_;
00903
00905
00906
00908 void addDataProcessing_(ConsensusMap& map, const DataProcessing& dp) const;
00909
00911 template <typename FeatureType>
00912 void addDataProcessing_(FeatureMap<FeatureType>& map, const DataProcessing& dp) const
00913 {
00914 map.getDataProcessing().push_back(dp);
00915 }
00916
00918 template <typename PeakType, typename CT>
00919 void addDataProcessing_(MSExperiment<PeakType, CT>& map, const DataProcessing& dp) const
00920 {
00921 for (Size i = 0; i < map.size(); ++i)
00922 {
00923 map[i].getDataProcessing().push_back(dp);
00924 }
00925 std::vector<MSChromatogram<CT> > chromatograms = map.getChromatograms();
00926 for (Size i = 0; i < chromatograms.size(); ++i)
00927 {
00928 chromatograms[i].getDataProcessing().push_back(dp);
00929 }
00930 map.setChromatograms(chromatograms);
00931 }
00932
00934 DataProcessing getProcessingInfo_(DataProcessing::ProcessingAction action) const;
00935
00937 DataProcessing getProcessingInfo_(const std::set<DataProcessing::ProcessingAction>& actions) const;
00938
00940
00942 const DocumentIDTagger& getDocumentIDTagger_() const;
00943
00945 bool writeCTD_();
00946
00948 ExitCodes writeWSDL_(const String& filename);
00949
00961 bool test_mode_;
00962
00964 static String topp_ini_file_;
00965
00967 int console_width_;
00968
00970 Int debug_level_;
00971
00972 private:
00973
00979 void addText_(const String& text);
00980
00981 };
00982
00983 }
00984
00985 #endif //OPENMS_APPLICATIONS_TOPPBASE_H