OpenMS
OpenSwathWorkflow.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: Hannes Roest $
32 // $Authors: Hannes Roest $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 // Interfaces
42 
43 #include <OpenMS/FORMAT/MzMLFile.h> // debug file store only
44 
45 // Kernel and implementations
51 
52 // Helpers
54 // #include <OpenMS/ANALYSIS/OPENSWATH/DATAACCESS/DataAccessHelper.h>
58 
59 // Algorithms
66 
67 #include <cassert>
68 #include <limits>
69 
70 // #define OPENSWATH_WORKFLOW_DEBUG
71 
72 // The workflow class
73 namespace OpenMS
74 {
75 
83  {
91  bool ppm;
98  };
99 
100  class OPENMS_DLLAPI OpenSwathWorkflowBase :
101  public ProgressLogger
102  {
103 
104 protected:
105 
112  use_ms1_traces_(false),
113  use_ms1_ion_mobility_(false),
114  prm_(false),
115  pasef_(false),
116  threads_outer_loop_(-1)
117  {
118  }
119 
132  OpenSwathWorkflowBase(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, bool pasef, int threads_outer_loop) :
133  use_ms1_traces_(use_ms1_traces),
134  use_ms1_ion_mobility_(use_ms1_ion_mobility),
135  prm_(prm),
136  pasef_(pasef),
137  threads_outer_loop_(threads_outer_loop)
138  {
139  }
140 
155  const std::vector< OpenSwath::SwathMap > & swath_maps,
156  std::vector< MSChromatogram >& ms1_chromatograms,
157  const ChromExtractParams & cp,
158  const OpenSwath::LightTargetedExperiment& transition_exp,
159  const TransformationDescription& trafo_inverse,
160  bool ms1only = false,
161  int ms1_isotopes = 0);
162 
180  void prepareExtractionCoordinates_(std::vector< OpenSwath::ChromatogramPtr > & chrom_list,
181  std::vector< ChromatogramExtractorAlgorithm::ExtractionCoordinates > & coordinates,
182  const OpenSwath::LightTargetedExperiment & transition_exp_used,
183  const TransformationDescription& trafo_inverse,
184  const ChromExtractParams & cp,
185  const bool ms1 = false,
186  const int ms1_isotopes = -1) const;
187 
188 
196  OpenSwath::SpectrumAccessPtr ms1_map_ = nullptr;
197 
200 
203 
212  bool prm_;
213 
222  bool pasef_;
223 
234 
235 };
236 
253  class OPENMS_DLLAPI OpenSwathCalibrationWorkflow :
254  public OpenSwathWorkflowBase
255  {
256  public:
257 
260  {
261  }
262 
263  explicit OpenSwathCalibrationWorkflow(bool use_ms1_traces) :
264  OpenSwathWorkflowBase(use_ms1_traces, false, false, false, -1)
265  {
266  }
267 
294  std::vector< OpenSwath::SwathMap > & swath_maps,
295  TransformationDescription& im_trafo,
296  double min_rsq,
297  double min_coverage,
298  const Param & feature_finder_param,
299  const ChromExtractParams & cp_irt,
300  const Param& irt_detection_param,
301  const Param& calibration_param,
302  const String& irt_mzml_out,
303  Size debug_level,
304  bool sonar = false,
305  bool pasef = false,
306  bool load_into_memory = false);
307 
308  public:
309 
341  const std::vector< OpenMS::MSChromatogram >& chromatograms,
342  TransformationDescription& im_trafo,
343  std::vector< OpenSwath::SwathMap > & swath_maps,
344  double min_rsq,
345  double min_coverage,
346  const Param& default_ffparam,
347  const Param& irt_detection_param,
348  const Param& calibration_param,
349  const bool pasef);
350 
363  void simpleExtractChromatograms_(const std::vector< OpenSwath::SwathMap > & swath_maps,
364  const OpenSwath::LightTargetedExperiment & irt_transitions,
365  std::vector< OpenMS::MSChromatogram > & chromatograms,
366  const TransformationDescription& trafo,
367  const ChromExtractParams & cp,
368  bool sonar,
369  bool pasef,
370  bool load_into_memory);
371 
378  static void addChromatograms(MSChromatogram& base_chrom, const MSChromatogram& newchrom);
379 
380  };
381 
410  class OPENMS_DLLAPI OpenSwathWorkflow :
411  public OpenSwathWorkflowBase
412  {
415 
416  public:
417 
432  OpenSwathWorkflow(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, bool pasef, int threads_outer_loop) :
433  OpenSwathWorkflowBase(use_ms1_traces, use_ms1_ion_mobility, prm, pasef, threads_outer_loop)
434  {
435  }
436 
462  void performExtraction(const std::vector< OpenSwath::SwathMap > & swath_maps,
463  const TransformationDescription& trafo,
464  const ChromExtractParams & chromatogram_extraction_params,
465  const ChromExtractParams & ms1_chromatogram_extraction_params,
466  const Param & feature_finder_param,
467  const OpenSwath::LightTargetedExperiment& assay_library,
468  FeatureMap& result_featureFile,
469  bool store_features_in_featureFile,
470  OpenSwathTSVWriter & result_tsv,
471  OpenSwathOSWWriter & result_osw,
472  Interfaces::IMSDataConsumer * result_chromatograms,
473  int batchSize,
474  int ms1_isotopes,
475  bool load_into_memory);
476 
477  protected:
478 
479 
494  void writeOutFeaturesAndChroms_(std::vector< OpenMS::MSChromatogram > & chromatograms,
495  std::vector< MSChromatogram >& ms1_chromatograms,
496  const FeatureMap & featureFile,
497  FeatureMap& out_featureFile,
498  bool store_features,
499  Interfaces::IMSDataConsumer * chromConsumer);
500 
538  const std::vector< OpenMS::MSChromatogram > & ms2_chromatograms,
539  const std::vector< OpenMS::MSChromatogram > & ms1_chromatograms,
540  const std::vector< OpenSwath::SwathMap >& swath_maps,
541  const OpenSwath::LightTargetedExperiment& transition_exp,
542  const Param& feature_finder_param,
543  const TransformationDescription& trafo,
544  const double rt_extraction_window,
545  FeatureMap& output,
546  OpenSwathTSVWriter & tsv_writer,
547  OpenSwathOSWWriter & osw_writer,
548  int nr_ms1_isotopes = 0,
549  bool ms1only = false) const;
550 
567  OpenSwath::LightTargetedExperiment& transition_exp_used, int batch_size, size_t batch_idx);
568 
579  void copyBatchTransitions_(const std::vector<OpenSwath::LightCompound>& used_compounds,
580  const std::vector<OpenSwath::LightTransition>& all_transitions,
581  std::vector<OpenSwath::LightTransition>& output);
582  };
583 
609  class OPENMS_DLLAPI OpenSwathWorkflowSonar :
610  public OpenSwathWorkflow
611  {
612 
613  public:
614 
615  explicit OpenSwathWorkflowSonar(bool use_ms1_traces) :
616  OpenSwathWorkflow(use_ms1_traces, false, false, false, -1)
617  {
618  }
619 
641  void performExtractionSonar(const std::vector< OpenSwath::SwathMap > & swath_maps,
642  const TransformationDescription& trafo,
643  const ChromExtractParams & cp,
644  const ChromExtractParams & cp_ms1,
645  const Param & feature_finder_param,
646  const OpenSwath::LightTargetedExperiment& transition_exp,
647  FeatureMap& out_featureFile,
648  bool store_features,
649  OpenSwathTSVWriter & tsv_writer,
650  OpenSwathOSWWriter & osw_writer,
651  Interfaces::IMSDataConsumer * chromConsumer,
652  int batchSize,
653  bool load_into_memory);
654 
658  void computeSonarWindows_(const std::vector< OpenSwath::SwathMap > & swath_maps,
659  double & sonar_winsize,
660  double & sonar_start,
661  double & sonar_end,
662  int & sonar_total_win);
663 
667  void performSonarExtraction_(const std::vector< OpenSwath::SwathMap > & used_maps,
668  const std::vector< ChromatogramExtractor::ExtractionCoordinates > & coordinates,
669  std::vector< OpenSwath::ChromatogramPtr > & chrom_list,
670  const ChromExtractParams & cp);
671 
679  };
680 
681 }
682 
683 
A container for features.
Definition: FeatureMap.h:106
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:70
The representation of a group of transitions in a targeted proteomics experiment.
Definition: MRMTransitionGroup.h:68
The representation of a chromatogram.
Definition: MSChromatogram.h:57
Execute all steps for retention time and m/z calibration of SWATH-MS data.
Definition: OpenSwathWorkflow.h:255
OpenSwathCalibrationWorkflow()
Definition: OpenSwathWorkflow.h:258
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:263
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:116
Class to write out an OpenSwath TSV output (mProphet input).
Definition: OpenSwathTSVWriter.h:130
Definition: OpenSwathWorkflow.h:102
bool prm_
Whether data is acquired in targeted DIA (e.g. PRM mode) with potentially overlapping windows.
Definition: OpenSwathWorkflow.h:212
bool use_ms1_traces_
Whether to use the MS1 traces.
Definition: OpenSwathWorkflow.h:199
int threads_outer_loop_
How many threads should be used for the outer loop.
Definition: OpenSwathWorkflow.h:233
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:111
bool use_ms1_ion_mobility_
Whether to use ion mobility extraction on MS1 traces.
Definition: OpenSwathWorkflow.h:202
OpenSwathWorkflowBase(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, bool pasef, int threads_outer_loop)
Constructor.
Definition: OpenSwathWorkflow.h:132
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:222
Execute all steps in an OpenEcho analysis (OpenSwath for SONAR data)
Definition: OpenSwathWorkflow.h:611
OpenSwathWorkflowSonar(bool use_ms1_traces)
Definition: OpenSwathWorkflow.h:615
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:412
MRMTransitionGroup< MSChromatogram, TransitionType > MRMTransitionGroupType
Definition: OpenSwathWorkflow.h:414
OpenSwathWorkflow(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, bool pasef, int threads_outer_loop)
Constructor.
Definition: OpenSwathWorkflow.h:432
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:413
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:70
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:53
A more convenient string class.
Definition: String.h:60
Generic description of a coordinate transformation.
Definition: TransformationDescription.h:63
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
double im_extraction_window
Extraction window in ion mobility.
Definition: OpenSwathWorkflow.h:89
bool ppm
Whether the extraction window is given in ppm or Da.
Definition: OpenSwathWorkflow.h:91
String extraction_function
The extraction function in mass space.
Definition: OpenSwathWorkflow.h:93
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:97
double min_upper_edge_dist
Whether to not extract anything closer than this (in Da) from the upper edge.
Definition: OpenSwathWorkflow.h:85
double mz_extraction_window
Extraction window in Da or ppm (e.g. 50ppm means extraction +/- 25ppm)
Definition: OpenSwathWorkflow.h:87
double rt_extraction_window
The retention time extraction window.
Definition: OpenSwathWorkflow.h:95
ChromatogramExtractor parameters.
Definition: OpenSwathWorkflow.h:83
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:172
boost::shared_ptr< ISpectrumAccess > SpectrumAccessPtr
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:87
Definition: TransitionExperiment.h:219
Definition: TransitionExperiment.h:46