OpenMS
SiriusAdapterAlgorithm.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Oliver Alka $
6 // $Authors: Oliver Alka, Lukas Zimmermann $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
12 
13 #include <OpenMS/SYSTEM/File.h>
14 
15 #include <unordered_map>
16 #include <QString>
17 #include <QStringList>
18 
19 using namespace std;
20 
21 namespace OpenMS
22 {
23  class FeatureMap;
24  class File;
25  class KDTreeFeatureMaps;
26 
27  class OPENMS_DLLAPI SiriusAdapterAlgorithm : public DefaultParamHandler
28  {
29  public:
32 
33  /*
34  * Accessors for Preprocessing Parameters
35  */
36 
37  bool isFeatureOnly() const { return preprocessing.getValue("feature_only").toBool(); }
38  UInt getFilterByNumMassTraces() const { return preprocessing.getValue("filter_by_num_masstraces"); }
39  double getPrecursorMzTolerance() const { return preprocessing.getValue("precursor_mz_tolerance"); }
40  double getPrecursorRtTolerance() const { return preprocessing.getValue("precursor_rt_tolerance"); }
41  bool precursorMzToleranceUnitIsPPM() const { return preprocessing.getValue("precursor_mz_tolerance_unit") == "ppm"; }
42  bool isNoMasstraceInfoIsotopePattern() const { return preprocessing.getValue("no_masstrace_info_isotope_pattern").toBool(); }
43  int getIsotopePatternIterations() const { return preprocessing.getValue("isotope_pattern_iterations"); }
44 
50  {
51  int number_of_candidates = sirius.getValue("candidates");
52  // default for SiriusAdapter is -1 to not pass a value to command and use SIRIUS 5 default (10)
53  // therefore 10 needs to be returned in this case
54  if (number_of_candidates == -1)
55  {
56  return 10;
57  }
58  else
59  {
60  return number_of_candidates;
61  }
62  }
63 
71  void updateExistingParameter(const Param &param);
72 
78  bool hasFullNameParameter(const String &name) const;
79 
82  {
83  public:
84 
87 
90 
91  const String& getTmpDir() const;
92  const String& getTmpOutDir() const;
93  const String& getTmpMsFile() const;
94 
95  private:
97 
101  };
102 
112 
120  static void sortSiriusWorkspacePathsByScanIndex(std::vector<String>& subdirs);
121 
122 
135  void preprocessingSirius(const String& featureinfo,
136  const MSExperiment& spectra,
138  FeatureMapping::FeatureToMs2Indices& feature_mapping) const;
139 
149  void logFeatureSpectraNumber(const String& featureinfo,
150  const FeatureMapping::FeatureToMs2Indices& feature_mapping,
151  const MSExperiment& spectra) const;
152 
159  void logInSiriusAccount(String& executable, const String& email, const String& password) const;
160 
171  const vector<String> callSiriusQProcess(const String& tmp_ms_file,
172  const String& tmp_out_dir,
173  String& executable,
174  const String& out_csifingerid,
175  const bool decoy_generation) const;
176 
177  private:
179  {
182 
183  public:
184  explicit ParameterModifier(const String &param_name, SiriusAdapterAlgorithm *enclose) :
185  openms_param_name(param_name), enclose(enclose) {}
186 
187  void withValidStrings(initializer_list<std::string> choices)
188  {
189  enclose->defaults_.setValidStrings(openms_param_name, choices);
190  }
191 
192  void withMinInt(int value)
193  {
194  enclose->defaults_.setMinInt(openms_param_name, value);
195  }
196  };
197 
199  {
200  // Maps the OpenMS Parameter Names to the one for Sirius
201  unordered_map<String, String> openms_to_sirius;
202 
203  String toFullParameter(const String &param_name) const
204  {
205  String result(param_name);
206  result.substitute('-', '_');
207  return sectionName() + ":" + result;
208  }
209 
210  protected:
212  const String &parameter_name,
213  const ParamValue &default_value,
214  const String &parameter_description);
215  void flag(
216  const String &parameter_name,
217  const String &parameter_description);
218 
219  explicit ParameterSection(SiriusAdapterAlgorithm* enclose): enclose(enclose) {}
220 
221  virtual void parameters() = 0;
222  virtual String sectionName() const = 0;
223 
225 
226  public:
227  virtual ~ParameterSection() = default;
228 
229  DataValue getValue(const String &param_name) const
230  {
231  return enclose->param_.getValue(toFullParameter(param_name));
232  }
233 
234  QStringList getCommandLine() const
235  {
236  QStringList result;
237  for (const auto &pair : openms_to_sirius)
238  {
239  DataValue value = enclose->param_.getValue(pair.first);
240  DataValue default_value = enclose->defaults_.getValue(pair.first);
241  if (!value.isEmpty() && value != default_value)
242  {
243  String string_value = value.toString(true);
244  if (string_value == "true")
245  {
246  result.push_back(String("--" + pair.second).toQString());
247  }
248  else if (string_value != "false")
249  {
250  result.push_back(String("--" + pair.second + "=" + string_value).toQString());
251  }
252  };
253  }
254  return result;
255  }
256  };
257 
259 
261  {
262  String sectionName() const override { return "preprocessing"; }
263  public:
264  explicit Preprocessing(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
265  void parameters() override;
266  };
267 
268  class Project final : public SiriusSubtool
269  {
270  String sectionName() const override { return "project"; }
271  public:
272  explicit Project(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
273  void parameters() override;
274  };
275 
276  class Sirius final : public SiriusSubtool
277  {
278  String sectionName() const override { return "sirius"; }
279  public:
280  explicit Sirius(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
281  void parameters() override;
282  };
283 
284  class Fingerid final : public SiriusSubtool
285  {
286  String sectionName() const override { return "fingerid"; }
287  public:
288  explicit Fingerid(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
289  void parameters() override;
290  };
291 
292  class Passatutto final : public SiriusSubtool
293  {
294  String sectionName() const override { return "passatutto"; }
295  public:
296  explicit Passatutto(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
297  void parameters() override;
298  };
299 
305 
306  };
307 } // namespace OpenMS
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:33
String toString(bool full_precision=true) const
Conversion to String full_precision Controls number of fractional digits for all double types or list...
bool isEmpty() const
Test if the value is empty.
Definition: DataValue.h:362
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
Param param_
Container for current parameters.
Definition: DefaultParamHandler.h:139
Param defaults_
Container for default parameters. This member should be filled in the constructor of derived classes!
Definition: DefaultParamHandler.h:146
Stores information required for preprocessing.
Definition: FeatureMapping.h:25
Stores preprocessed feature mapping information.
Definition: FeatureMapping.h:33
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
Class to hold strings, numeric values, vectors of strings and vectors of numeric values using the stl...
Definition: ParamValue.h:29
Management and storage of parameters / INI files.
Definition: Param.h:44
void setValidStrings(const std::string &key, const std::vector< std::string > &strings)
Sets the valid strings for the parameter key.
const ParamValue & getValue(const std::string &key) const
Returns a value of a parameter.
void setMinInt(const std::string &key, int min)
Sets the minimum value for the integer or integer list parameter key.
Definition: SiriusAdapterAlgorithm.h:285
Fingerid(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:288
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:286
Definition: SiriusAdapterAlgorithm.h:179
SiriusAdapterAlgorithm * enclose
Definition: SiriusAdapterAlgorithm.h:181
ParameterModifier(const String &param_name, SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:184
void withValidStrings(initializer_list< std::string > choices)
Definition: SiriusAdapterAlgorithm.h:187
const String openms_param_name
Definition: SiriusAdapterAlgorithm.h:180
void withMinInt(int value)
Definition: SiriusAdapterAlgorithm.h:192
Definition: SiriusAdapterAlgorithm.h:199
unordered_map< String, String > openms_to_sirius
Definition: SiriusAdapterAlgorithm.h:201
ParameterModifier parameter(const String &parameter_name, const ParamValue &default_value, const String &parameter_description)
DataValue getValue(const String &param_name) const
Definition: SiriusAdapterAlgorithm.h:229
SiriusAdapterAlgorithm * enclose
Definition: SiriusAdapterAlgorithm.h:224
ParameterSection(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:219
void flag(const String &parameter_name, const String &parameter_description)
QStringList getCommandLine() const
Definition: SiriusAdapterAlgorithm.h:234
String toFullParameter(const String &param_name) const
Definition: SiriusAdapterAlgorithm.h:203
Definition: SiriusAdapterAlgorithm.h:293
Passatutto(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:296
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:294
Definition: SiriusAdapterAlgorithm.h:261
Preprocessing(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:264
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:262
Definition: SiriusAdapterAlgorithm.h:269
Project(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:272
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:270
Struct for temporary folder structure.
Definition: SiriusAdapterAlgorithm.h:82
SiriusTemporaryFileSystemObjects(int debug_level)
Construct temporary folder structure for SIRIUS (SiriusTemporaryFileSystemObjects)
String tmp_out_dir_
Definition: SiriusAdapterAlgorithm.h:100
~SiriusTemporaryFileSystemObjects()
Destructor of SiriusTemporaryFileSystemObjects based on debug level.
String tmp_dir_
Definition: SiriusAdapterAlgorithm.h:98
String tmp_ms_file_
Definition: SiriusAdapterAlgorithm.h:99
int debug_level_
Definition: SiriusAdapterAlgorithm.h:96
Definition: SiriusAdapterAlgorithm.h:277
Sirius(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:280
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:278
Definition: SiriusAdapterAlgorithm.h:28
const vector< String > callSiriusQProcess(const String &tmp_ms_file, const String &tmp_out_dir, String &executable, const String &out_csifingerid, const bool decoy_generation) const
Call SIRIUS with QProcess.
Preprocessing preprocessing
Definition: SiriusAdapterAlgorithm.h:300
static void sortSiriusWorkspacePathsByScanIndex(std::vector< String > &subdirs)
Sort function using the extracted scan_index from the sirius workspace file path.
int getNumberOfSiriusCandidates() const
Accessors for Sirius Parameters.
Definition: SiriusAdapterAlgorithm.h:49
Passatutto passatutto
Definition: SiriusAdapterAlgorithm.h:304
double getPrecursorMzTolerance() const
Definition: SiriusAdapterAlgorithm.h:39
bool isNoMasstraceInfoIsotopePattern() const
Definition: SiriusAdapterAlgorithm.h:42
static String determineSiriusExecutable(String &executable)
Checks if the provided String points to a valid SIRIUS executable, otherwise tries to select the exec...
bool isFeatureOnly() const
Definition: SiriusAdapterAlgorithm.h:37
double getPrecursorRtTolerance() const
Definition: SiriusAdapterAlgorithm.h:40
Sirius sirius
Definition: SiriusAdapterAlgorithm.h:302
Fingerid fingerid
Definition: SiriusAdapterAlgorithm.h:303
void updateExistingParameter(const Param &param)
Updates all parameters that already exist in this DefaultParamHandler with the values provided by the...
bool precursorMzToleranceUnitIsPPM() const
Definition: SiriusAdapterAlgorithm.h:41
void preprocessingSirius(const String &featureinfo, const MSExperiment &spectra, FeatureMapping::FeatureMappingInfo &fm_info, FeatureMapping::FeatureToMs2Indices &feature_mapping) const
Preprocessing needed for SIRIUS.
SiriusAdapterAlgorithm()
default constructor
void logFeatureSpectraNumber(const String &featureinfo, const FeatureMapping::FeatureToMs2Indices &feature_mapping, const MSExperiment &spectra) const
logs number of features and spectra used
bool hasFullNameParameter(const String &name) const
Checks whether this DefaultParamHandler has a ParamEntry with the provided name.
UInt getFilterByNumMassTraces() const
Definition: SiriusAdapterAlgorithm.h:38
void logInSiriusAccount(String &executable, const String &email, const String &password) const
Log in to Sirius with personal user account (required in Sirius >= 5).
int getIsotopePatternIterations() const
Definition: SiriusAdapterAlgorithm.h:43
Project project
Definition: SiriusAdapterAlgorithm.h:301
A more convenient string class.
Definition: String.h:34
QString toQString() const
Conversion to Qt QString.
String & substitute(char from, char to)
Replaces all occurrences of the character from by the character to.
unsigned int UInt
Unsigned integer type.
Definition: Types.h:68
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22