OpenMS
SiriusAdapterAlgorithm.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-2023.
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: Oliver Alka $
32 // $Authors: Oliver Alka, Lukas Zimmermann $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
38 
39 #include <OpenMS/SYSTEM/File.h>
40 
41 #include <unordered_map>
42 #include <QString>
43 #include <QStringList>
44 
45 using namespace std;
46 
47 namespace OpenMS
48 {
49  class FeatureMap;
50  class File;
51  class KDTreeFeatureMaps;
52 
53  class OPENMS_DLLAPI SiriusAdapterAlgorithm : public DefaultParamHandler
54  {
55  public:
58 
59  /*
60  * Accessors for Preprocessing Parameters
61  */
62 
63  bool isFeatureOnly() const { return preprocessing.getValue("feature_only").toBool(); }
64  UInt getFilterByNumMassTraces() const { return preprocessing.getValue("filter_by_num_masstraces"); }
65  double getPrecursorMzTolerance() const { return preprocessing.getValue("precursor_mz_tolerance"); }
66  double getPrecursorRtTolerance() const { return preprocessing.getValue("precursor_rt_tolerance"); }
67  bool precursorMzToleranceUnitIsPPM() const { return preprocessing.getValue("precursor_mz_tolerance_unit") == "ppm"; }
68  bool isNoMasstraceInfoIsotopePattern() const { return preprocessing.getValue("no_masstrace_info_isotope_pattern").toBool(); }
69  int getIsotopePatternIterations() const { return preprocessing.getValue("isotope_pattern_iterations"); }
70 
76  {
77  int number_of_candidates = sirius.getValue("candidates");
78  // default for SiriusAdapter is -1 to not pass a value to command and use SIRIUS 5 default (10)
79  // therefore 10 needs to be returned in this case
80  if (number_of_candidates == -1)
81  {
82  return 10;
83  }
84  else
85  {
86  return number_of_candidates;
87  }
88  }
89 
97  void updateExistingParameter(const Param &param);
98 
104  bool hasFullNameParameter(const String &name) const;
105 
108  {
109  public:
110 
113 
116 
117  const String& getTmpDir() const;
118  const String& getTmpOutDir() const;
119  const String& getTmpMsFile() const;
120 
121  private:
123 
127  };
128 
138 
146  static void sortSiriusWorkspacePathsByScanIndex(std::vector<String>& subdirs);
147 
148 
161  void preprocessingSirius(const String& featureinfo,
162  const MSExperiment& spectra,
164  FeatureMapping::FeatureToMs2Indices& feature_mapping) const;
165 
175  void logFeatureSpectraNumber(const String& featureinfo,
176  const FeatureMapping::FeatureToMs2Indices& feature_mapping,
177  const MSExperiment& spectra) const;
178 
185  void logInSiriusAccount(String& executable, const String& email, const String& password) const;
186 
197  const vector<String> callSiriusQProcess(const String& tmp_ms_file,
198  const String& tmp_out_dir,
199  String& executable,
200  const String& out_csifingerid,
201  const bool decoy_generation) const;
202 
203  private:
205  {
208 
209  public:
210  explicit ParameterModifier(const String &param_name, SiriusAdapterAlgorithm *enclose) :
211  openms_param_name(param_name), enclose(enclose) {}
212 
213  void withValidStrings(initializer_list<std::string> choices)
214  {
215  enclose->defaults_.setValidStrings(openms_param_name, choices);
216  }
217 
218  void withMinInt(int value)
219  {
220  enclose->defaults_.setMinInt(openms_param_name, value);
221  }
222  };
223 
225  {
226  // Maps the OpenMS Parameter Names to the one for Sirius
227  unordered_map<String, String> openms_to_sirius;
228 
229  String toFullParameter(const String &param_name) const
230  {
231  String result(param_name);
232  result.substitute('-', '_');
233  return sectionName() + ":" + result;
234  }
235 
236  protected:
238  const String &parameter_name,
239  const ParamValue &default_value,
240  const String &parameter_description);
241  void flag(
242  const String &parameter_name,
243  const String &parameter_description);
244 
245  explicit ParameterSection(SiriusAdapterAlgorithm* enclose): enclose(enclose) {}
246 
247  virtual void parameters() = 0;
248  virtual String sectionName() const = 0;
249 
251 
252  public:
253  virtual ~ParameterSection() = default;
254 
255  DataValue getValue(const String &param_name) const
256  {
257  return enclose->param_.getValue(toFullParameter(param_name));
258  }
259 
260  QStringList getCommandLine() const
261  {
262  QStringList result;
263  for (const auto &pair : openms_to_sirius)
264  {
265  DataValue value = enclose->param_.getValue(pair.first);
266  DataValue default_value = enclose->defaults_.getValue(pair.first);
267  if (!value.isEmpty() && value != default_value)
268  {
269  String string_value = value.toString(true);
270  if (string_value == "true")
271  {
272  result.push_back(String("--" + pair.second).toQString());
273  }
274  else if (string_value != "false")
275  {
276  result.push_back(String("--" + pair.second + "=" + string_value).toQString());
277  }
278  };
279  }
280  return result;
281  }
282  };
283 
285 
287  {
288  String sectionName() const override { return "preprocessing"; }
289  public:
290  explicit Preprocessing(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
291  void parameters() override;
292  };
293 
294  class Project final : public SiriusSubtool
295  {
296  String sectionName() const override { return "project"; }
297  public:
298  explicit Project(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
299  void parameters() override;
300  };
301 
302  class Sirius final : public SiriusSubtool
303  {
304  String sectionName() const override { return "sirius"; }
305  public:
306  explicit Sirius(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
307  void parameters() override;
308  };
309 
310  class Fingerid final : public SiriusSubtool
311  {
312  String sectionName() const override { return "fingerid"; }
313  public:
314  explicit Fingerid(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
315  void parameters() override;
316  };
317 
318  class Passatutto final : public SiriusSubtool
319  {
320  String sectionName() const override { return "passatutto"; }
321  public:
322  explicit Passatutto(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
323  void parameters() override;
324  };
325 
331 
332  };
333 } // namespace OpenMS
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:59
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:388
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
Param param_
Container for current parameters.
Definition: DefaultParamHandler.h:165
Param defaults_
Container for default parameters. This member should be filled in the constructor of derived classes!
Definition: DefaultParamHandler.h:172
Stores information required for preprocessing.
Definition: FeatureMapping.h:51
Stores preprocessed feature mapping information.
Definition: FeatureMapping.h:59
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:72
Class to hold strings, numeric values, vectors of strings and vectors of numeric values using the stl...
Definition: ParamValue.h:55
Management and storage of parameters / INI files.
Definition: Param.h:70
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:311
Fingerid(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:314
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:312
Definition: SiriusAdapterAlgorithm.h:205
SiriusAdapterAlgorithm * enclose
Definition: SiriusAdapterAlgorithm.h:207
ParameterModifier(const String &param_name, SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:210
void withValidStrings(initializer_list< std::string > choices)
Definition: SiriusAdapterAlgorithm.h:213
const String openms_param_name
Definition: SiriusAdapterAlgorithm.h:206
void withMinInt(int value)
Definition: SiriusAdapterAlgorithm.h:218
Definition: SiriusAdapterAlgorithm.h:225
unordered_map< String, String > openms_to_sirius
Definition: SiriusAdapterAlgorithm.h:227
ParameterModifier parameter(const String &parameter_name, const ParamValue &default_value, const String &parameter_description)
DataValue getValue(const String &param_name) const
Definition: SiriusAdapterAlgorithm.h:255
SiriusAdapterAlgorithm * enclose
Definition: SiriusAdapterAlgorithm.h:250
ParameterSection(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:245
void flag(const String &parameter_name, const String &parameter_description)
QStringList getCommandLine() const
Definition: SiriusAdapterAlgorithm.h:260
String toFullParameter(const String &param_name) const
Definition: SiriusAdapterAlgorithm.h:229
Definition: SiriusAdapterAlgorithm.h:319
Passatutto(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:322
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:320
Definition: SiriusAdapterAlgorithm.h:287
Preprocessing(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:290
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:288
Definition: SiriusAdapterAlgorithm.h:295
Project(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:298
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:296
Struct for temporary folder structure.
Definition: SiriusAdapterAlgorithm.h:108
SiriusTemporaryFileSystemObjects(int debug_level)
Construct temporary folder structure for SIRIUS (SiriusTemporaryFileSystemObjects)
String tmp_out_dir_
Definition: SiriusAdapterAlgorithm.h:126
~SiriusTemporaryFileSystemObjects()
Destructor of SiriusTemporaryFileSystemObjects based on debug level.
String tmp_dir_
Definition: SiriusAdapterAlgorithm.h:124
String tmp_ms_file_
Definition: SiriusAdapterAlgorithm.h:125
int debug_level_
Definition: SiriusAdapterAlgorithm.h:122
Definition: SiriusAdapterAlgorithm.h:303
Sirius(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:306
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:304
Definition: SiriusAdapterAlgorithm.h:54
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:326
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:75
Passatutto passatutto
Definition: SiriusAdapterAlgorithm.h:330
double getPrecursorMzTolerance() const
Definition: SiriusAdapterAlgorithm.h:65
bool isNoMasstraceInfoIsotopePattern() const
Definition: SiriusAdapterAlgorithm.h:68
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:63
double getPrecursorRtTolerance() const
Definition: SiriusAdapterAlgorithm.h:66
Sirius sirius
Definition: SiriusAdapterAlgorithm.h:328
Fingerid fingerid
Definition: SiriusAdapterAlgorithm.h:329
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:67
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:64
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:69
Project project
Definition: SiriusAdapterAlgorithm.h:327
A more convenient string class.
Definition: String.h:60
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:94
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48