OpenMS
OpenSwathWorkflow.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: Hannes Roest $
6 // $Authors: Hannes Roest $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 // Interfaces
16 
17 #include <OpenMS/FORMAT/MzMLFile.h> // debug file store only
18 
19 // Kernel and implementations
25 
26 // Helpers
28 // #include <OpenMS/ANALYSIS/OPENSWATH/DATAACCESS/DataAccessHelper.h>
32 
33 // Algorithms
40 
41 #include <cassert>
42 #include <limits>
43 
44 // #define OPENSWATH_WORKFLOW_DEBUG
45 
46 // The workflow class
47 namespace OpenMS
48 {
49 
57  {
65  bool ppm;
72  };
73 
74  class OPENMS_DLLAPI OpenSwathWorkflowBase :
75  public ProgressLogger
76  {
77 
78 protected:
79 
86  use_ms1_traces_(false),
87  use_ms1_ion_mobility_(false),
88  prm_(false),
89  pasef_(false),
90  threads_outer_loop_(-1)
91  {
92  }
93 
106  OpenSwathWorkflowBase(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, bool pasef, int threads_outer_loop) :
107  use_ms1_traces_(use_ms1_traces),
108  use_ms1_ion_mobility_(use_ms1_ion_mobility),
109  prm_(prm),
110  pasef_(pasef),
111  threads_outer_loop_(threads_outer_loop)
112  {
113  }
114 
129  const std::vector< OpenSwath::SwathMap > & swath_maps,
130  std::vector< MSChromatogram >& ms1_chromatograms,
131  const ChromExtractParams & cp,
132  const OpenSwath::LightTargetedExperiment& transition_exp,
133  const TransformationDescription& trafo_inverse,
134  bool ms1only = false,
135  int ms1_isotopes = 0);
136 
154  void prepareExtractionCoordinates_(std::vector< OpenSwath::ChromatogramPtr > & chrom_list,
155  std::vector< ChromatogramExtractorAlgorithm::ExtractionCoordinates > & coordinates,
156  const OpenSwath::LightTargetedExperiment & transition_exp_used,
157  const TransformationDescription& trafo_inverse,
158  const ChromExtractParams & cp,
159  const bool ms1 = false,
160  const int ms1_isotopes = -1) const;
161 
162 
170  OpenSwath::SpectrumAccessPtr ms1_map_ = nullptr;
171 
174 
177 
186  bool prm_;
187 
196  bool pasef_;
197 
208 
209 };
210 
227  class OPENMS_DLLAPI OpenSwathCalibrationWorkflow :
228  public OpenSwathWorkflowBase
229  {
230  public:
231 
234  {
235  }
236 
237  explicit OpenSwathCalibrationWorkflow(bool use_ms1_traces) :
238  OpenSwathWorkflowBase(use_ms1_traces, false, false, false, -1)
239  {
240  }
241 
268  std::vector< OpenSwath::SwathMap > & swath_maps,
269  TransformationDescription& im_trafo,
270  double min_rsq,
271  double min_coverage,
272  const Param & feature_finder_param,
273  const ChromExtractParams & cp_irt,
274  const Param& irt_detection_param,
275  const Param& calibration_param,
276  const String& irt_mzml_out,
277  Size debug_level,
278  bool sonar = false,
279  bool pasef = false,
280  bool load_into_memory = false);
281 
282  public:
283 
315  const std::vector< OpenMS::MSChromatogram >& chromatograms,
316  TransformationDescription& im_trafo,
317  std::vector< OpenSwath::SwathMap > & swath_maps,
318  double min_rsq,
319  double min_coverage,
320  const Param& default_ffparam,
321  const Param& irt_detection_param,
322  const Param& calibration_param,
323  const bool pasef);
324 
337  void simpleExtractChromatograms_(const std::vector< OpenSwath::SwathMap > & swath_maps,
338  const OpenSwath::LightTargetedExperiment & irt_transitions,
339  std::vector< OpenMS::MSChromatogram > & chromatograms,
340  const TransformationDescription& trafo,
341  const ChromExtractParams & cp,
342  bool sonar,
343  bool pasef,
344  bool load_into_memory);
345 
352  static void addChromatograms(MSChromatogram& base_chrom, const MSChromatogram& newchrom);
353 
354  };
355 
384  class OPENMS_DLLAPI OpenSwathWorkflow :
385  public OpenSwathWorkflowBase
386  {
389 
390  public:
391 
406  OpenSwathWorkflow(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, bool pasef, int threads_outer_loop) :
407  OpenSwathWorkflowBase(use_ms1_traces, use_ms1_ion_mobility, prm, pasef, threads_outer_loop)
408  {
409  }
410 
436  void performExtraction(const std::vector< OpenSwath::SwathMap > & swath_maps,
437  const TransformationDescription& trafo,
438  const ChromExtractParams & chromatogram_extraction_params,
439  const ChromExtractParams & ms1_chromatogram_extraction_params,
440  const Param & feature_finder_param,
441  const OpenSwath::LightTargetedExperiment& assay_library,
442  FeatureMap& result_featureFile,
443  bool store_features_in_featureFile,
444  OpenSwathTSVWriter & result_tsv,
445  OpenSwathOSWWriter & result_osw,
446  Interfaces::IMSDataConsumer * result_chromatograms,
447  int batchSize,
448  int ms1_isotopes,
449  bool load_into_memory);
450 
451  protected:
452 
453 
468  void writeOutFeaturesAndChroms_(std::vector< OpenMS::MSChromatogram > & chromatograms,
469  std::vector< MSChromatogram >& ms1_chromatograms,
470  const FeatureMap & featureFile,
471  FeatureMap& out_featureFile,
472  bool store_features,
473  Interfaces::IMSDataConsumer * chromConsumer);
474 
512  const std::vector< OpenMS::MSChromatogram > & ms2_chromatograms,
513  const std::vector< OpenMS::MSChromatogram > & ms1_chromatograms,
514  const std::vector< OpenSwath::SwathMap >& swath_maps,
515  const OpenSwath::LightTargetedExperiment& transition_exp,
516  const Param& feature_finder_param,
517  const TransformationDescription& trafo,
518  const double rt_extraction_window,
519  FeatureMap& output,
520  OpenSwathTSVWriter & tsv_writer,
521  OpenSwathOSWWriter & osw_writer,
522  int nr_ms1_isotopes = 0,
523  bool ms1only = false) const;
524 
541  OpenSwath::LightTargetedExperiment& transition_exp_used, int batch_size, size_t batch_idx);
542 
553  void copyBatchTransitions_(const std::vector<OpenSwath::LightCompound>& used_compounds,
554  const std::vector<OpenSwath::LightTransition>& all_transitions,
555  std::vector<OpenSwath::LightTransition>& output);
556  };
557 
583  class OPENMS_DLLAPI OpenSwathWorkflowSonar :
584  public OpenSwathWorkflow
585  {
586 
587  public:
588 
589  explicit OpenSwathWorkflowSonar(bool use_ms1_traces) :
590  OpenSwathWorkflow(use_ms1_traces, false, false, false, -1)
591  {
592  }
593 
615  void performExtractionSonar(const std::vector< OpenSwath::SwathMap > & swath_maps,
616  const TransformationDescription& trafo,
617  const ChromExtractParams & cp,
618  const ChromExtractParams & cp_ms1,
619  const Param & feature_finder_param,
620  const OpenSwath::LightTargetedExperiment& transition_exp,
621  FeatureMap& out_featureFile,
622  bool store_features,
623  OpenSwathTSVWriter & tsv_writer,
624  OpenSwathOSWWriter & osw_writer,
625  Interfaces::IMSDataConsumer * chromConsumer,
626  int batchSize,
627  bool load_into_memory);
628 
632  void computeSonarWindows_(const std::vector< OpenSwath::SwathMap > & swath_maps,
633  double & sonar_winsize,
634  double & sonar_start,
635  double & sonar_end,
636  int & sonar_total_win);
637 
641  void performSonarExtraction_(const std::vector< OpenSwath::SwathMap > & used_maps,
642  const std::vector< ChromatogramExtractor::ExtractionCoordinates > & coordinates,
643  std::vector< OpenSwath::ChromatogramPtr > & chrom_list,
644  const ChromExtractParams & cp);
645 
653  };
654 
655 }
656 
657 
A container for features.
Definition: FeatureMap.h:80
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:44
The representation of a group of transitions in a targeted proteomics experiment.
Definition: MRMTransitionGroup.h:42
The representation of a chromatogram.
Definition: MSChromatogram.h:31
Execute all steps for retention time and m/z calibration of SWATH-MS data.
Definition: OpenSwathWorkflow.h:229
OpenSwathCalibrationWorkflow()
Definition: OpenSwathWorkflow.h:232
TransformationDescription performRTNormalization(const OpenSwath::LightTargetedExperiment &irt_transitions, std::vector< OpenSwath::SwathMap > &swath_maps, TransformationDescription &im_trafo, double min_rsq, double min_coverage, const Param &feature_finder_param, const ChromExtractParams &cp_irt, const Param &irt_detection_param, const Param &calibration_param, const String &irt_mzml_out, Size debug_level, bool sonar=false, bool pasef=false, bool load_into_memory=false)
Perform RT and m/z correction of the input data using RT-normalization peptides.
static void addChromatograms(MSChromatogram &base_chrom, const MSChromatogram &newchrom)
Add two chromatograms.
OpenSwathCalibrationWorkflow(bool use_ms1_traces)
Definition: OpenSwathWorkflow.h:237
TransformationDescription doDataNormalization_(const OpenSwath::LightTargetedExperiment &transition_exp_, const std::vector< OpenMS::MSChromatogram > &chromatograms, TransformationDescription &im_trafo, std::vector< OpenSwath::SwathMap > &swath_maps, double min_rsq, double min_coverage, const Param &default_ffparam, const Param &irt_detection_param, const Param &calibration_param, const bool pasef)
Perform retention time and m/z calibration.
void simpleExtractChromatograms_(const std::vector< OpenSwath::SwathMap > &swath_maps, const OpenSwath::LightTargetedExperiment &irt_transitions, std::vector< OpenMS::MSChromatogram > &chromatograms, const TransformationDescription &trafo, const ChromExtractParams &cp, bool sonar, bool pasef, bool load_into_memory)
Simple method to extract chromatograms (for the RT-normalization peptides)
Class to write out an OpenSwath OSW SQLite output (PyProphet input).
Definition: OpenSwathOSWWriter.h:90
Class to write out an OpenSwath TSV output (mProphet input).
Definition: OpenSwathTSVWriter.h:104
Definition: OpenSwathWorkflow.h:76
bool prm_
Whether data is acquired in targeted DIA (e.g. PRM mode) with potentially overlapping windows.
Definition: OpenSwathWorkflow.h:186
bool use_ms1_traces_
Whether to use the MS1 traces.
Definition: OpenSwathWorkflow.h:173
int threads_outer_loop_
How many threads should be used for the outer loop.
Definition: OpenSwathWorkflow.h:207
void MS1Extraction_(const OpenSwath::SpectrumAccessPtr &ms1_map, const std::vector< OpenSwath::SwathMap > &swath_maps, std::vector< MSChromatogram > &ms1_chromatograms, const ChromExtractParams &cp, const OpenSwath::LightTargetedExperiment &transition_exp, const TransformationDescription &trafo_inverse, bool ms1only=false, int ms1_isotopes=0)
Perform MS1 extraction and store result in ms1_chromatograms.
OpenSwathWorkflowBase()
Default constructor.
Definition: OpenSwathWorkflow.h:85
bool use_ms1_ion_mobility_
Whether to use ion mobility extraction on MS1 traces.
Definition: OpenSwathWorkflow.h:176
OpenSwathWorkflowBase(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, bool pasef, int threads_outer_loop)
Constructor.
Definition: OpenSwathWorkflow.h:106
void prepareExtractionCoordinates_(std::vector< OpenSwath::ChromatogramPtr > &chrom_list, std::vector< ChromatogramExtractorAlgorithm::ExtractionCoordinates > &coordinates, const OpenSwath::LightTargetedExperiment &transition_exp_used, const TransformationDescription &trafo_inverse, const ChromExtractParams &cp, const bool ms1=false, const int ms1_isotopes=-1) const
Function to prepare extraction coordinates that also correctly handles RT transformations.
bool pasef_
Whether data is diaPASEF data.
Definition: OpenSwathWorkflow.h:196
Execute all steps in an OpenEcho analysis (OpenSwath for SONAR data)
Definition: OpenSwathWorkflow.h:585
OpenSwathWorkflowSonar(bool use_ms1_traces)
Definition: OpenSwathWorkflow.h:589
void computeSonarWindows_(const std::vector< OpenSwath::SwathMap > &swath_maps, double &sonar_winsize, double &sonar_start, double &sonar_end, int &sonar_total_win)
Compute start, end and total number of (virtual) SONAR windows.
OpenSwath::ChromatogramPtr addChromatograms(OpenSwath::ChromatogramPtr base_chrom, OpenSwath::ChromatogramPtr newchrom)
Add two chromatograms.
void performSonarExtraction_(const std::vector< OpenSwath::SwathMap > &used_maps, const std::vector< ChromatogramExtractor::ExtractionCoordinates > &coordinates, std::vector< OpenSwath::ChromatogramPtr > &chrom_list, const ChromExtractParams &cp)
Perform extraction from multiple SONAR windows.
void performExtractionSonar(const std::vector< OpenSwath::SwathMap > &swath_maps, const TransformationDescription &trafo, const ChromExtractParams &cp, const ChromExtractParams &cp_ms1, const Param &feature_finder_param, const OpenSwath::LightTargetedExperiment &transition_exp, FeatureMap &out_featureFile, bool store_features, OpenSwathTSVWriter &tsv_writer, OpenSwathOSWWriter &osw_writer, Interfaces::IMSDataConsumer *chromConsumer, int batchSize, bool load_into_memory)
Execute OpenSWATH analysis on a set of SONAR SwathMaps and transitions.
Execute all steps in an OpenSwath analysis.
Definition: OpenSwathWorkflow.h:386
MRMTransitionGroup< MSChromatogram, TransitionType > MRMTransitionGroupType
Definition: OpenSwathWorkflow.h:388
OpenSwathWorkflow(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, bool pasef, int threads_outer_loop)
Constructor.
Definition: OpenSwathWorkflow.h:406
void writeOutFeaturesAndChroms_(std::vector< OpenMS::MSChromatogram > &chromatograms, std::vector< MSChromatogram > &ms1_chromatograms, const FeatureMap &featureFile, FeatureMap &out_featureFile, bool store_features, Interfaces::IMSDataConsumer *chromConsumer)
Write output features and chromatograms.
void selectCompoundsForBatch_(const OpenSwath::LightTargetedExperiment &transition_exp_used_all, OpenSwath::LightTargetedExperiment &transition_exp_used, int batch_size, size_t batch_idx)
Select which compounds to analyze in the next batch (and copy to output)
OpenSwath::LightTransition TransitionType
Definition: OpenSwathWorkflow.h:387
void scoreAllChromatograms_(const std::vector< OpenMS::MSChromatogram > &ms2_chromatograms, const std::vector< OpenMS::MSChromatogram > &ms1_chromatograms, const std::vector< OpenSwath::SwathMap > &swath_maps, const OpenSwath::LightTargetedExperiment &transition_exp, const Param &feature_finder_param, const TransformationDescription &trafo, const double rt_extraction_window, FeatureMap &output, OpenSwathTSVWriter &tsv_writer, OpenSwathOSWWriter &osw_writer, int nr_ms1_isotopes=0, bool ms1only=false) const
Perform scoring on a set of chromatograms.
void performExtraction(const std::vector< OpenSwath::SwathMap > &swath_maps, const TransformationDescription &trafo, const ChromExtractParams &chromatogram_extraction_params, const ChromExtractParams &ms1_chromatogram_extraction_params, const Param &feature_finder_param, const OpenSwath::LightTargetedExperiment &assay_library, FeatureMap &result_featureFile, bool store_features_in_featureFile, OpenSwathTSVWriter &result_tsv, OpenSwathOSWWriter &result_osw, Interfaces::IMSDataConsumer *result_chromatograms, int batchSize, int ms1_isotopes, bool load_into_memory)
Execute OpenSWATH analysis on a set of SwathMaps and transitions.
void copyBatchTransitions_(const std::vector< OpenSwath::LightCompound > &used_compounds, const std::vector< OpenSwath::LightTransition > &all_transitions, std::vector< OpenSwath::LightTransition > &output)
Helper function for selectCompoundsForBatch_()
Management and storage of parameters / INI files.
Definition: Param.h:44
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:27
A more convenient string class.
Definition: String.h:34
Generic description of a coordinate transformation.
Definition: TransformationDescription.h:37
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
double im_extraction_window
Extraction window in ion mobility.
Definition: OpenSwathWorkflow.h:63
bool ppm
Whether the extraction window is given in ppm or Da.
Definition: OpenSwathWorkflow.h:65
String extraction_function
The extraction function in mass space.
Definition: OpenSwathWorkflow.h:67
double extra_rt_extract
Whether to extract some extra in the retention time (can be useful if one wants to look at the chroma...
Definition: OpenSwathWorkflow.h:71
double min_upper_edge_dist
Whether to not extract anything closer than this (in Da) from the upper edge.
Definition: OpenSwathWorkflow.h:59
double mz_extraction_window
Extraction window in Da or ppm (e.g. 50ppm means extraction +/- 25ppm)
Definition: OpenSwathWorkflow.h:61
double rt_extraction_window
The retention time extraction window.
Definition: OpenSwathWorkflow.h:69
ChromatogramExtractor parameters.
Definition: OpenSwathWorkflow.h:57
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:146
boost::shared_ptr< ISpectrumAccess > SpectrumAccessPtr
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:61
Definition: TransitionExperiment.h:185
Definition: TransitionExperiment.h:20