OpenMS  3.0.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-2022.
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 
75  int getNumberOfSiriusCandidates() const { return sirius.getValue("candidates"); }
76 
84  void updateExistingParameter(const Param &param);
85 
91  bool hasFullNameParameter(const String &name) const;
92 
93 
94  int getNumberOfCSIFingerIDCandidates() const { return fingerid.getValue("candidates"); }
95 
96 
99  {
100  public:
101 
103  SiriusTemporaryFileSystemObjects(int debug_level);
104 
107 
108  const String& getTmpDir() const;
109  const String& getTmpOutDir() const;
110  const String& getTmpMsFile() const;
111 
112  private:
114 
118  };
119 
128  static String determineSiriusExecutable(String& executable);
129 
137  static void sortSiriusWorkspacePathsByScanIndex(std::vector<String>& subdirs);
138 
139 
152  void preprocessingSirius(const String& featureinfo,
153  const MSExperiment& spectra,
155  FeatureMapping::FeatureToMs2Indices& feature_mapping) const;
156 
166  void logFeatureSpectraNumber(const String& featureinfo,
167  const FeatureMapping::FeatureToMs2Indices& feature_mapping,
168  const MSExperiment& spectra) const;
169 
180  const vector<String> callSiriusQProcess(const String& tmp_ms_file,
181  const String& tmp_out_dir,
182  String& executable,
183  const String& out_csifingerid,
184  const bool decoy_generation) const;
185 
186  private:
188  {
191 
192  public:
193  explicit ParameterModifier(const String &param_name, SiriusAdapterAlgorithm *enclose) :
194  openms_param_name(param_name), enclose(enclose) {}
195 
196  void withValidStrings(initializer_list<std::string> choices)
197  {
198  enclose->defaults_.setValidStrings(openms_param_name, choices);
199  }
200 
201  void withMinInt(int value)
202  {
203  enclose->defaults_.setMinInt(openms_param_name, value);
204  }
205  };
206 
208  {
209  // Maps the OpenMS Parameter Names to the one for Sirius
210  unordered_map<String, String> openms_to_sirius;
211 
212  String toFullParameter(const String &param_name) const
213  {
214  String result(param_name);
215  result.substitute('-', '_');
216  return sectionName() + ":" + result;
217  }
218 
219  protected:
220  ParameterModifier parameter(
221  const String &parameter_name,
222  const ParamValue &default_value,
223  const String &parameter_description);
224  void flag(
225  const String &parameter_name,
226  const String &parameter_description);
227 
228  explicit ParameterSection(SiriusAdapterAlgorithm* enclose): enclose(enclose) {}
229 
230  virtual void parameters() = 0;
231  virtual String sectionName() const = 0;
232 
234 
235  public:
236  virtual ~ParameterSection() = default;
237 
238  DataValue getValue(const String &param_name) const
239  {
240  return enclose->param_.getValue(toFullParameter(param_name));
241  }
242 
243  QStringList getCommandLine() const
244  {
245  const DataValue omit_integer(-1);
246  const DataValue omit_string("");
247 
248  QStringList result;
249  for (const auto &pair : openms_to_sirius)
250  {
251  DataValue value = enclose->param_.getValue(pair.first);
252 
253  if (!value.isEmpty() && value != omit_integer && value != omit_string)
254  {
255  String string_value = value.toString(true);
256  if (string_value == "true")
257  {
258  result.push_back(String("--" + pair.second).toQString());
259  }
260  else if (string_value != "false")
261  {
262  result.push_back(String("--" + pair.second + "=" + string_value).toQString());
263  }
264  };
265  }
266  return result;
267  }
268  };
269 
271 
273  {
274  String sectionName() const override { return "preprocessing"; }
275  public:
276  explicit Preprocessing(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
277  void parameters() override;
278  };
279 
280  class Project final : public SiriusSubtool
281  {
282  String sectionName() const override { return "project"; }
283  public:
284  explicit Project(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
285  void parameters() override;
286  };
287 
288  class Sirius final : public SiriusSubtool
289  {
290  String sectionName() const override { return "sirius"; }
291  public:
292  explicit Sirius(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
293  void parameters() override;
294  };
295 
296  class Fingerid final : public SiriusSubtool
297  {
298  String sectionName() const override { return "fingerid"; }
299  public:
300  explicit Fingerid(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
301  void parameters() override;
302  };
303 
304  class Passatutto final : public SiriusSubtool
305  {
306  String sectionName() const override { return "passatutto"; }
307  public:
308  explicit Passatutto(SiriusAdapterAlgorithm *enclose) : ParameterSection(enclose) {}
309  void parameters() override;
310  };
311 
317 
318  };
319 } // namespace OpenMS
OpenMS::Exception::Postcondition
Postcondition failed exception.
Definition: Exception.h:171
MzTabFile.h
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:147
OpenMS::SiriusAdapterAlgorithm::ParameterSection
Definition: SiriusAdapterAlgorithm.h:207
OpenMS::MzTabFile
File adapter for MzTab files.
Definition: MzTabFile.h:55
OpenMS::SiriusAdapterAlgorithm::SiriusTemporaryFileSystemObjects::tmp_ms_file_
String tmp_ms_file_
Definition: SiriusAdapterAlgorithm.h:116
OpenMS::SiriusFragmentAnnotation::extractSiriusAnnotationsTgtOnly
static std::vector< MSSpectrum > extractSiriusAnnotationsTgtOnly(const std::vector< String > &sirius_workspace_subdirs, double score_threshold, bool use_exact_mass, bool resolve)
OpenMS::SiriusAdapterAlgorithm
Definition: SiriusAdapterAlgorithm.h:53
OpenMS::String::substitute
String & substitute(char from, char to)
Replaces all occurrences of the character from by the character to.
OpenMS::MzMLFile::store
void store(const String &filename, const PeakMap &map) const
Stores a map in an MzML file.
OpenMS::MzMLFile
File adapter for MzML files.
Definition: MzMLFile.h:57
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::SiriusAdapterAlgorithm::getNumberOfSiriusCandidates
int getNumberOfSiriusCandidates() const
Accessors for Sirius Parameters.
Definition: SiriusAdapterAlgorithm.h:75
OpenMS::DataValue::isEmpty
bool isEmpty() const
Test if the value is empty.
Definition: DataValue.h:388
MzMLFile.h
OpenMS::SiriusAdapterAlgorithm::passatutto
Passatutto passatutto
Definition: SiriusAdapterAlgorithm.h:316
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:70
OpenMS::DataValue::toString
String toString(bool full_precision=true) const
Conversion to String full_precision Controls number of fractional digits for all double types or list...
OpenMS::MzTab
Data model of MzTab files. Please see the official MzTab specification at https://code....
Definition: MzTab.h:477
CsiFingerIdMzTabWriter.h
OpenMS::SiriusAdapterAlgorithm::SiriusTemporaryFileSystemObjects::debug_level_
int debug_level_
Definition: SiriusAdapterAlgorithm.h:113
OpenMS::SiriusAdapterAlgorithm::ParameterSection::ParameterSection
ParameterSection(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:228
OpenMS::FeatureMapping::FeatureToMs2Indices
Stores preprocessed feature mapping information.
Definition: FeatureMapping.h:58
OpenMS::ParamValue
Class to hold strings, numeric values, vectors of strings and vectors of numeric values using the stl...
Definition: ParamValue.h:54
OpenMS::SiriusAdapterAlgorithm::Preprocessing::sectionName
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:274
OpenMS::SiriusAdapterAlgorithm::Passatutto
Definition: SiriusAdapterAlgorithm.h:304
OpenMS::SiriusAdapterAlgorithm::ParameterModifier::ParameterModifier
ParameterModifier(const String &param_name, SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:193
OpenMS::SiriusAdapterAlgorithm::Passatutto::Passatutto
Passatutto(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:308
OPENMS_LOG_WARN
#define OPENMS_LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged.
Definition: LogStream.h:460
OpenMS::SiriusAdapterAlgorithm::getNumberOfCSIFingerIDCandidates
int getNumberOfCSIFingerIDCandidates() const
Definition: SiriusAdapterAlgorithm.h:94
OpenMS::SiriusAdapterAlgorithm::preprocessing
Preprocessing preprocessing
Definition: SiriusAdapterAlgorithm.h:312
ListUtils.h
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
OpenMS::SiriusAdapterAlgorithm::SiriusTemporaryFileSystemObjects
Struct for temporary folder structure.
Definition: SiriusAdapterAlgorithm.h:98
OpenMS::SiriusAdapterAlgorithm::updateExistingParameter
void updateExistingParameter(const Param &param)
Updates all parameters that already exist in this DefaultParamHandler with the values provided by the...
Element.h
OpenMS::SiriusAdapterAlgorithm::ParameterModifier::withMinInt
void withMinInt(int value)
Definition: SiriusAdapterAlgorithm.h:201
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::SiriusAdapterAlgorithm::getPrecursorMzTolerance
double getPrecursorMzTolerance() const
Definition: SiriusAdapterAlgorithm.h:65
OpenMS::SiriusAdapterAlgorithm::ParameterSection::openms_to_sirius
unordered_map< String, String > openms_to_sirius
Definition: SiriusAdapterAlgorithm.h:210
OpenMS::SiriusAdapterAlgorithm::Project::Project
Project(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:284
OpenMS::SiriusAdapterAlgorithm::ParameterModifier
Definition: SiriusAdapterAlgorithm.h:187
OpenMS::SiriusAdapterAlgorithm::Passatutto::sectionName
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:306
OpenMS::DataValue
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:58
OpenMS::MzMLFile::load
void load(const String &filename, PeakMap &map)
Loads a map from a MzML file. Spectra and chromatograms are sorted by default (this can be disabled u...
OpenMS::SiriusAdapterAlgorithm::Sirius
Definition: SiriusAdapterAlgorithm.h:288
OpenMS::File::copyDirRecursively
static bool copyDirRecursively(const QString &from_dir, const QString &to_dir, File::CopyOptions option=CopyOptions::OVERWRITE)
SiriusMSConverter.h
OpenMS::Param::setMinInt
void setMinInt(const std::string &key, int min)
Sets the minimum value for the integer or integer list parameter key.
OpenMS::SiriusAdapterAlgorithm::Sirius::Sirius
Sirius(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:292
OpenMS::SiriusAdapterAlgorithm::Fingerid
Definition: SiriusAdapterAlgorithm.h:296
OpenMS::SiriusAdapterAlgorithm::ParameterSection::toFullParameter
String toFullParameter(const String &param_name) const
Definition: SiriusAdapterAlgorithm.h:212
OpenMS::SiriusMSFile::store
static void store(const MSExperiment &spectra, const OpenMS::String &msfile, const FeatureMapping::FeatureToMs2Indices &feature_mapping, const bool &feature_only, const int &isotope_pattern_iterations, const bool no_mt_info, std::vector< SiriusMSFile::CompoundInfo > &v_cmpinfo)
Internal structure used in SiriusAdapter that is used for the conversion of a MzMlFile to an internal...
OpenMS::SiriusAdapterAlgorithm::Preprocessing
Definition: SiriusAdapterAlgorithm.h:272
OpenMS::SiriusAdapterAlgorithm::logFeatureSpectraNumber
void logFeatureSpectraNumber(const String &featureinfo, const FeatureMapping::FeatureToMs2Indices &feature_mapping, const MSExperiment &spectra) const
logs number of features and spectra used
OpenMS::MzTabFile::store
void store(const String &filename, const MzTab &mz_tab) const
OpenMS::CsiFingerIdMzTabWriter::read
static void read(const std::vector< String > &sirius_output_paths, const String &original_input_mzml, const Size &top_n_hits, MzTab &result)
Conversion of CSI:FingerID output to mzTab.
OpenMS::SiriusAdapterAlgorithm::callSiriusQProcess
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.
OpenMS::SiriusAdapterAlgorithm::precursorMzToleranceUnitIsPPM
bool precursorMzToleranceUnitIsPPM() const
Definition: SiriusAdapterAlgorithm.h:67
SiriusMzTabWriter.h
OpenMS::DefaultParamHandler::getDefaults
const Param & getDefaults() const
Non-mutable access to the default parameters.
OpenMS::String::toQString
QString toQString() const
Conversion to Qt QString.
OpenMS::DefaultParamHandler::getParameters
const Param & getParameters() const
Non-mutable access to the parameters.
OpenMS::SiriusAdapterAlgorithm::ParameterSection::getCommandLine
QStringList getCommandLine() const
Definition: SiriusAdapterAlgorithm.h:243
OpenMS::SiriusAdapterAlgorithm::getFilterByNumMassTraces
UInt getFilterByNumMassTraces() const
Definition: SiriusAdapterAlgorithm.h:64
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
SiriusFragmentAnnotation.h
OpenMS::SiriusAdapterAlgorithm::project
Project project
Definition: SiriusAdapterAlgorithm.h:313
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:71
OpenMS::SiriusAdapterAlgorithm::Project
Definition: SiriusAdapterAlgorithm.h:280
FeatureMapping.h
OpenMS::SiriusAdapterAlgorithm::isNoMasstraceInfoIsotopePattern
bool isNoMasstraceInfoIsotopePattern() const
Definition: SiriusAdapterAlgorithm.h:68
OpenMS::SiriusAdapterAlgorithm::Sirius::sectionName
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:290
OpenMS::SiriusAdapterAlgorithm::sirius
Sirius sirius
Definition: SiriusAdapterAlgorithm.h:314
EmpiricalFormula.h
OpenMS::SiriusAdapterAlgorithm::getIsotopePatternIterations
int getIsotopePatternIterations() const
Definition: SiriusAdapterAlgorithm.h:69
OpenMS::SiriusAdapterAlgorithm::SiriusTemporaryFileSystemObjects::tmp_dir_
String tmp_dir_
Definition: SiriusAdapterAlgorithm.h:115
MetaboTargetedAssay.h
OpenMS::SiriusAdapterAlgorithm::Project::sectionName
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:282
OpenMS::DefaultParamHandler::defaults_
Param defaults_
Container for default parameters. This member should be filled in the constructor of derived classes!
Definition: DefaultParamHandler.h:173
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:69
OPENMS_LOG_INFO
#define OPENMS_LOG_INFO
Macro if a information, e.g. a status should be reported.
Definition: LogStream.h:465
OpenMS::SiriusAdapterAlgorithm::fingerid
Fingerid fingerid
Definition: SiriusAdapterAlgorithm.h:315
OpenMS::SiriusAdapterAlgorithm::isFeatureOnly
bool isFeatureOnly() const
Definition: SiriusAdapterAlgorithm.h:63
SiriusAdapterAlgorithm.h
OpenMS::SiriusMzTabWriter::read
static void read(const std::vector< String > &sirius_output_paths, const String &original_input_mzml, const Size &top_n_hits, MzTab &result)
Conversion of sirius output to mzTab.
OpenMS::MSExperiment::setSpectra
void setSpectra(const std::vector< MSSpectrum > &spectra)
sets the spectrum list
OpenMS::Param::getValue
const ParamValue & getValue(const std::string &key) const
Returns a value of a parameter.
OpenMS::SiriusAdapterAlgorithm::ParameterModifier::openms_param_name
const String openms_param_name
Definition: SiriusAdapterAlgorithm.h:189
OpenMS::Param::setValidStrings
void setValidStrings(const std::string &key, const std::vector< std::string > &strings)
Sets the valid strings for the parameter key.
File.h
OpenMS::SiriusAdapterAlgorithm::ParameterModifier::withValidStrings
void withValidStrings(initializer_list< std::string > choices)
Definition: SiriusAdapterAlgorithm.h:196
OpenMS::FeatureMapping::FeatureMappingInfo
Stores information required for preprocessing.
Definition: FeatureMapping.h:50
OpenMS::ProgressLogger::setLogType
void setLogType(LogType type) const
Sets the progress log that should be used. The default type is NONE!
OpenMS::SiriusAdapterAlgorithm::Preprocessing::Preprocessing
Preprocessing(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:276
TOPPBase.h
OpenMS::SiriusAdapterAlgorithm::ParameterModifier::enclose
SiriusAdapterAlgorithm * enclose
Definition: SiriusAdapterAlgorithm.h:190
OpenMS::SiriusAdapterAlgorithm::SiriusTemporaryFileSystemObjects::tmp_out_dir_
String tmp_out_dir_
Definition: SiriusAdapterAlgorithm.h:117
OpenMS::SiriusAdapterAlgorithm::sortSiriusWorkspacePathsByScanIndex
static void sortSiriusWorkspacePathsByScanIndex(std::vector< String > &subdirs)
Sort function using the extracted scan_index from the sirius workspace file path.
OpenMS::SiriusAdapterAlgorithm::preprocessingSirius
void preprocessingSirius(const String &featureinfo, const MSExperiment &spectra, FeatureMapping::FeatureMappingInfo &fm_info, FeatureMapping::FeatureToMs2Indices &feature_mapping) const
Preprocessing needed for SIRIUS.
OpenMS::SiriusAdapterAlgorithm::ParameterSection::getValue
DataValue getValue(const String &param_name) const
Definition: SiriusAdapterAlgorithm.h:238
OpenMS::SiriusAdapterAlgorithm::Fingerid::Fingerid
Fingerid(SiriusAdapterAlgorithm *enclose)
Definition: SiriusAdapterAlgorithm.h:300
OpenMS::DefaultParamHandler::param_
Param param_
Container for current parameters.
Definition: DefaultParamHandler.h:166
OpenMS::SiriusAdapterAlgorithm::getPrecursorRtTolerance
double getPrecursorRtTolerance() const
Definition: SiriusAdapterAlgorithm.h:66
OpenMS::SiriusAdapterAlgorithm::ParameterSection::enclose
SiriusAdapterAlgorithm * enclose
Definition: SiriusAdapterAlgorithm.h:233
OpenMS::SiriusAdapterAlgorithm::Fingerid::sectionName
String sectionName() const override
Definition: SiriusAdapterAlgorithm.h:298