OpenMS  2.8.0
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-2021.
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 
44 using namespace std;
45 
46 namespace OpenMS
47 {
48  class FeatureMap;
49  class File;
50  class KDTreeFeatureMaps;
51 
52  class OPENMS_DLLAPI SiriusAdapterAlgorithm : public DefaultParamHandler
53  {
54  public:
57 
58  /*
59  * Accessors for Preprocessing Parameters
60  */
61 
62  bool isFeatureOnly() const { return preprocessing.getValue("feature_only").toBool(); }
63  UInt getFilterByNumMassTraces() const { return preprocessing.getValue("filter_by_num_masstraces"); }
64  double getPrecursorMzTolerance() const { return preprocessing.getValue("precursor_mz_tolerance"); }
65  double getPrecursorRtTolerance() const { return preprocessing.getValue("precursor_rt_tolerance"); }
66  bool precursorMzToleranceUnitIsPPM() const { return preprocessing.getValue("precursor_mz_tolerance_unit") == "ppm"; }
67  bool isNoMasstraceInfoIsotopePattern() const { return preprocessing.getValue("no_masstrace_info_isotope_pattern").toBool(); }
68  int getIsotopePatternIterations() const { return preprocessing.getValue("isotope_pattern_iterations"); }
69 
74  int getNumberOfSiriusCandidates() const { return sirius.getValue("candidates"); }
75 
83  void updateExistingParameter(const Param &param);
84 
90  bool hasFullNameParameter(const String &name) const;
91 
92 
93  int getNumberOfCSIFingerIDCandidates() const { return fingerid.getValue("candidates"); }
94 
95 
98  {
99  public:
100 
103 
106 
107  const String& getTmpDir() const;
108  const String& getTmpOutDir() const;
109  const String& getTmpMsFile() const;
110 
111  private:
113 
117  };
118 
128 
136  static void sortSiriusWorkspacePathsByScanIndex(std::vector<String>& subdirs);
137 
138 
151  void preprocessingSirius(const String& featureinfo,
152  const MSExperiment& spectra,
154  FeatureMapping::FeatureToMs2Indices& feature_mapping) const;
155 
165  void logFeatureSpectraNumber(const String& featureinfo,
166  const FeatureMapping::FeatureToMs2Indices& feature_mapping,
167  const MSExperiment& spectra) const;
168 
179  const vector<String> callSiriusQProcess(const String& tmp_ms_file,
180  const String& tmp_out_dir,
181  String& executable,
182  const String& out_csifingerid,
183  const bool decoy_generation) const;
184 
185  private:
187  {
190 
191  public:
192  explicit ParameterModifier(const String &param_name, SiriusAdapterAlgorithm *enclose) :
193  openms_param_name(param_name), enclose(enclose) {}
194 
195  void withValidStrings(initializer_list<std::string> choices)
196  {
197  enclose->defaults_.setValidStrings(openms_param_name, choices);
198  }
199 
200  void withMinInt(int value)
201  {
202  enclose->defaults_.setMinInt(openms_param_name, value);
203  }
204  };
205 
207  {
208  // Maps the OpenMS Parameter Names to the one for Sirius
209  unordered_map<String, String> openms_to_sirius;
210 
211  String toFullParameter(const String &param_name) const
212  {
213  String result(param_name);
214  result.substitute('-', '_');
215  return sectionName() + ":" + result;
216  }
217 
218  protected:
220  const String &parameter_name,
221  const ParamValue &default_value,
222  const String &parameter_description);
223  void flag(
224  const String &parameter_name,
225  const String &parameter_description);
226 
227  explicit ParameterSection(SiriusAdapterAlgorithm* enclose): enclose(enclose) {}
228 
229  virtual void parameters() = 0;
230  virtual String sectionName() const = 0;
231 
233 
234  public:
235  virtual ~ParameterSection() = default;
236 
237  DataValue getValue(const String &param_name) const
238  {
239  return enclose->param_.getValue(toFullParameter(param_name));
240  }
241 
242  QStringList getCommandLine() const
243  {
244  const DataValue omit_integer(-1);
245  const DataValue omit_string("");
246 
247  QStringList result;
248  for (const auto &pair : openms_to_sirius)
249  {
250  DataValue value = enclose->param_.getValue(pair.first);
251 
252  if (!value.isEmpty() && value != omit_integer && value != omit_string)
253  {
254  String string_value = value.toString(true);
255  if (string_value == "true")
256  {
257  result.push_back(String("--" + pair.second).toQString());
258  }
259  else if (string_value != "false")
260  {
261  result.push_back(String("--" + pair.second + "=" + string_value).toQString());
262  }
263  };
264  }
265  return result;
266  }
267  };
268 
270 
272  {
273  String sectionName() const override { return "preprocessing"; }
274  public:
275  explicit Preprocessing(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
276  void parameters() override;
277  };
278 
279  class Project final : public SiriusSubtool
280  {
281  String sectionName() const override { return "project"; }
282  public:
283  explicit Project(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
284  void parameters() override;
285  };
286 
287  class Sirius final : public SiriusSubtool
288  {
289  String sectionName() const override { return "sirius"; }
290  public:
291  explicit Sirius(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
292  void parameters() override;
293  };
294 
295  class Fingerid final : public SiriusSubtool
296  {
297  String sectionName() const override { return "fingerid"; }
298  public:
299  explicit Fingerid(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
300  void parameters() override;
301  };
302 
303  class Passatutto final : public SiriusSubtool
304  {
305  String sectionName() const override { return "passatutto"; }
306  public:
307  explicit Passatutto(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
308  void parameters() override;
309  };
310 
316 
317  };
318 } // 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:384
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:93
Param param_
Container for current parameters.
Definition: DefaultParamHandler.h:166
Param defaults_
Container for default parameters. This member should be filled in the constructor of derived classes!
Definition: DefaultParamHandler.h:173
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:73
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:296
Fingerid(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:299
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:297
Definition: SiriusAdapterAlgorithm.h:187
SiriusAdapterAlgorithm * enclose
Definition: SiriusAdapterAlgorithm.h:189
ParameterModifier(const String &param_name, SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:192
void withValidStrings(initializer_list< std::string > choices)
Definition: SiriusAdapterAlgorithm.h:195
const String openms_param_name
Definition: SiriusAdapterAlgorithm.h:188
void withMinInt(int value)
Definition: SiriusAdapterAlgorithm.h:200
Definition: SiriusAdapterAlgorithm.h:207
unordered_map< String, String > openms_to_sirius
Definition: SiriusAdapterAlgorithm.h:209
ParameterModifier parameter(const String &parameter_name, const ParamValue &default_value, const String &parameter_description)
DataValue getValue(const String &param_name) const
Definition: SiriusAdapterAlgorithm.h:237
SiriusAdapterAlgorithm * enclose
Definition: SiriusAdapterAlgorithm.h:232
ParameterSection(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:227
void flag(const String &parameter_name, const String &parameter_description)
QStringList getCommandLine() const
Definition: SiriusAdapterAlgorithm.h:242
String toFullParameter(const String &param_name) const
Definition: SiriusAdapterAlgorithm.h:211
Definition: SiriusAdapterAlgorithm.h:304
Passatutto(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:307
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:305
Definition: SiriusAdapterAlgorithm.h:272
Preprocessing(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:275
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:273
Definition: SiriusAdapterAlgorithm.h:280
Project(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:283
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:281
Struct for temporary folder structure.
Definition: SiriusAdapterAlgorithm.h:98
SiriusTemporaryFileSystemObjects(int debug_level)
Construct temporary folder structure for SIRIUS (SiriusTemporaryFileSystemObjects)
String tmp_out_dir_
Definition: SiriusAdapterAlgorithm.h:116
~SiriusTemporaryFileSystemObjects()
Destructor of SiriusTemporaryFileSystemObjects based on debug level.
String tmp_dir_
Definition: SiriusAdapterAlgorithm.h:114
String tmp_ms_file_
Definition: SiriusAdapterAlgorithm.h:115
int debug_level_
Definition: SiriusAdapterAlgorithm.h:112
Definition: SiriusAdapterAlgorithm.h:288
Sirius(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:291
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:289
Definition: SiriusAdapterAlgorithm.h:53
int getNumberOfCSIFingerIDCandidates() const
Definition: SiriusAdapterAlgorithm.h:93
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:311
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:74
Passatutto passatutto
Definition: SiriusAdapterAlgorithm.h:315
double getPrecursorMzTolerance() const
Definition: SiriusAdapterAlgorithm.h:64
bool isNoMasstraceInfoIsotopePattern() const
Definition: SiriusAdapterAlgorithm.h:67
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:62
double getPrecursorRtTolerance() const
Definition: SiriusAdapterAlgorithm.h:65
Sirius sirius
Definition: SiriusAdapterAlgorithm.h:313
Fingerid fingerid
Definition: SiriusAdapterAlgorithm.h:314
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:66
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:63
int getIsotopePatternIterations() const
Definition: SiriusAdapterAlgorithm.h:68
Project project
Definition: SiriusAdapterAlgorithm.h:312
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:47