OpenMS  2.4.0
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-2018.
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  threads_outer_loop_(-1)
115  {
116  }
117 
130  OpenSwathWorkflowBase(bool use_ms1_traces, bool use_ms1_ion_mobility, int threads_outer_loop) :
131  use_ms1_traces_(use_ms1_traces),
132  use_ms1_ion_mobility_(use_ms1_ion_mobility),
133  threads_outer_loop_(threads_outer_loop)
134  {
135  }
136 
150  void MS1Extraction_(const std::vector< OpenSwath::SwathMap > & swath_maps,
151  std::vector< MSChromatogram >& ms1_chromatograms,
152  Interfaces::IMSDataConsumer * chromConsumer,
153  const ChromExtractParams & cp,
154  const OpenSwath::LightTargetedExperiment& transition_exp,
155  const TransformationDescription& trafo_inverse,
156  bool load_into_memory,
157  bool ms1only = false,
158  int ms1_isotopes = 0);
159 
177  void prepareExtractionCoordinates_(std::vector< OpenSwath::ChromatogramPtr > & chrom_list,
178  std::vector< ChromatogramExtractorAlgorithm::ExtractionCoordinates > & coordinates,
179  const OpenSwath::LightTargetedExperiment & transition_exp_used,
180  const TransformationDescription trafo_inverse,
181  const ChromExtractParams & cp,
182  const bool ms1 = false,
183  const int ms1_isotopes = -1) const;
184 
185 
194 
197 
200 
211 
212 };
213 
230  class OPENMS_DLLAPI OpenSwathCalibrationWorkflow :
231  public OpenSwathWorkflowBase
232  {
233  public:
234 
237  {
238  }
239 
240  explicit OpenSwathCalibrationWorkflow(bool use_ms1_traces) :
241  OpenSwathWorkflowBase(use_ms1_traces, false, -1)
242  {
243  }
244 
269  TransformationDescription performRTNormalization(const OpenSwath::LightTargetedExperiment & irt_transitions,
270  std::vector< OpenSwath::SwathMap > & swath_maps,
271  double min_rsq,
272  double min_coverage,
273  const Param & feature_finder_param,
274  const ChromExtractParams & cp_irt,
275  const Param & irt_detection_param,
276  const String & mz_correction_function,
277  const String& irt_mzml_out,
278  Size debug_level,
279  bool sonar = false,
280  bool load_into_memory = false);
281 
282  public:
283 
316  TransformationDescription doDataNormalization_(const OpenSwath::LightTargetedExperiment& transition_exp_,
317  const std::vector< OpenMS::MSChromatogram >& chromatograms,
318  double min_rsq,
319  double min_coverage,
320  const Param& default_ffparam,
321  const Param& irt_detection_param,
322  std::vector< OpenSwath::SwathMap > & swath_maps,
323  const String & mz_correction_function,
324  double mz_extraction_window,
325  bool ppm);
326 
338  void simpleExtractChromatograms_(const std::vector< OpenSwath::SwathMap > & swath_maps,
339  const OpenSwath::LightTargetedExperiment & irt_transitions,
340  std::vector< OpenMS::MSChromatogram > & chromatograms,
341  const TransformationDescription& trafo,
342  const ChromExtractParams & cp,
343  bool sonar,
344  bool load_into_memory);
345 
352  static void addChromatograms(MSChromatogram& base_chrom, const MSChromatogram& newchrom);
353 
354  };
355 
380  class OPENMS_DLLAPI OpenSwathWorkflow :
381  public OpenSwathWorkflowBase
382  {
385 
386  public:
387 
400  OpenSwathWorkflow(bool use_ms1_traces, bool use_ms1_ion_mobility, int threads_outer_loop) :
401  OpenSwathWorkflowBase(use_ms1_traces, use_ms1_ion_mobility, threads_outer_loop)
402  {
403  }
404 
430  void performExtraction(const std::vector< OpenSwath::SwathMap > & swath_maps,
431  const TransformationDescription trafo,
432  const ChromExtractParams & chromatogram_extraction_params,
433  const ChromExtractParams & ms1_chromatogram_extraction_params,
434  const Param & feature_finder_param,
435  const OpenSwath::LightTargetedExperiment& assay_library,
436  FeatureMap& result_featureFile,
437  bool store_features_in_featureFile,
438  OpenSwathTSVWriter & result_tsv,
439  OpenSwathOSWWriter & result_osw,
440  Interfaces::IMSDataConsumer * result_chromatograms,
441  int batchSize,
442  int ms1_isotopes,
443  bool load_into_memory);
444 
445  protected:
446 
447 
462  void writeOutFeaturesAndChroms_(std::vector< OpenMS::MSChromatogram > & chromatograms,
463  const FeatureMap & featureFile,
464  FeatureMap& out_featureFile,
465  bool store_features,
466  Interfaces::IMSDataConsumer * chromConsumer);
467 
504  void scoreAllChromatograms_(
505  const std::vector< OpenMS::MSChromatogram > & ms2_chromatograms,
506  const std::vector< OpenMS::MSChromatogram > & ms1_chromatograms,
507  const std::vector< OpenSwath::SwathMap >& swath_maps,
508  const OpenSwath::LightTargetedExperiment& transition_exp,
509  const Param& feature_finder_param,
511  const double rt_extraction_window,
512  FeatureMap& output,
513  OpenSwathTSVWriter & tsv_writer,
514  OpenSwathOSWWriter & osw_writer,
515  int nr_ms1_isotopes = 0,
516  bool ms1only = false) const;
517 
533  void selectCompoundsForBatch_(const OpenSwath::LightTargetedExperiment& transition_exp_used_all,
534  OpenSwath::LightTargetedExperiment& transition_exp_used, int batch_size, size_t batch_idx);
535 
546  void copyBatchTransitions_(const std::vector<OpenSwath::LightCompound>& used_compounds,
547  const std::vector<OpenSwath::LightTransition>& all_transitions,
548  std::vector<OpenSwath::LightTransition>& output);
549 
550  };
551 
577  class OPENMS_DLLAPI OpenSwathWorkflowSonar :
578  public OpenSwathWorkflow
579  {
580 
581  public:
582 
583  explicit OpenSwathWorkflowSonar(bool use_ms1_traces) :
584  OpenSwathWorkflow(use_ms1_traces, false, -1)
585  {
586  }
587 
609  void performExtractionSonar(const std::vector< OpenSwath::SwathMap > & swath_maps,
610  const TransformationDescription trafo,
611  const ChromExtractParams & cp,
612  const ChromExtractParams & cp_ms1,
613  const Param & feature_finder_param,
614  const OpenSwath::LightTargetedExperiment& transition_exp,
615  FeatureMap& out_featureFile,
616  bool store_features,
617  OpenSwathTSVWriter & tsv_writer,
618  OpenSwathOSWWriter & osw_writer,
619  Interfaces::IMSDataConsumer * chromConsumer,
620  int batchSize,
621  bool load_into_memory);
622 
626  void computeSonarWindows_(const std::vector< OpenSwath::SwathMap > & swath_maps,
627  double & sonar_winsize,
628  double & sonar_start,
629  double & sonar_end,
630  int & sonar_total_win);
631 
635  void performSonarExtraction_(const std::vector< OpenSwath::SwathMap > & used_maps,
636  const std::vector< ChromatogramExtractor::ExtractionCoordinates > & coordinates,
637  std::vector< OpenSwath::ChromatogramPtr > & chrom_list,
638  const ChromExtractParams & cp);
639 
647  };
648 
649 }
650 
651 
int threads_outer_loop_
How many threads should be used for the outer loop.
Definition: OpenSwathWorkflow.h:210
A more convenient string class.
Definition: String.h:58
double mz_extraction_window
Extraction window in Da or ppm (e.g. 50ppm means extraction +/- 25ppm)
Definition: OpenSwathWorkflow.h:87
ChromatogramExtractor parameters.
Definition: OpenSwathWorkflow.h:82
OpenSwathWorkflowSonar(bool use_ms1_traces)
Definition: OpenSwathWorkflow.h:583
OpenSwathWorkflowBase()
Default constructor.
Definition: OpenSwathWorkflow.h:111
boost::shared_ptr< ISpectrumAccess > SpectrumAccessPtr
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:89
The representation of a chromatogram.
Definition: MSChromatogram.h:54
OpenSwathWorkflow(bool use_ms1_traces, bool use_ms1_ion_mobility, int threads_outer_loop)
Constructor.
Definition: OpenSwathWorkflow.h:400
OpenSwathCalibrationWorkflow()
Definition: OpenSwathWorkflow.h:235
A container for features.
Definition: FeatureMap.h:93
bool ppm
Whether the extraction window is given in ppm or Da.
Definition: OpenSwathWorkflow.h:91
Definition: OpenSwathWorkflow.h:100
Class to write out an OpenSwath TSV output (mProphet input)
Definition: OpenSwathTSVWriter.h:56
MRMTransitionGroup< MSChromatogram, TransitionType > MRMTransitionGroupType
Definition: OpenSwathWorkflow.h:384
Execute all steps in an OpenSwath analysis.
Definition: OpenSwathWorkflow.h:380
Execute all steps in an OpenEcho analysis (OpenSwath for SONAR data)
Definition: OpenSwathWorkflow.h:577
OpenSwath::LightTransition TransitionType
Definition: OpenSwathWorkflow.h:383
double im_extraction_window
Extraction window in ion mobility.
Definition: OpenSwathWorkflow.h:89
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
Class to write out an OpenSwath OSW SQLite output (PyProphet input)
Definition: OpenSwathOSWWriter.h:58
The representation of a group of transitions in a targeted proteomics experiment. ...
Definition: MRMTransitionGroup.h:67
bool use_ms1_traces_
Whether to use the MS1 traces.
Definition: OpenSwathWorkflow.h:196
double rt_extraction_window
The retention time extraction window.
Definition: OpenSwathWorkflow.h:95
double min_upper_edge_dist
Whether to not extract anything closer than this (in Da) from the upper edge.
Definition: OpenSwathWorkflow.h:85
bool use_ms1_ion_mobility_
Whether to use ion mobility extraction on MS1 traces.
Definition: OpenSwathWorkflow.h:199
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:170
String extraction_function
The extraction function in mass space.
Definition: OpenSwathWorkflow.h:93
Management and storage of parameters / INI files.
Definition: Param.h:74
Definition: TransitionExperiment.h:46
OpenSwath::SpectrumAccessPtr ms1_map_
Spectrum Access to the MS1 map (note that this is *not* threadsafe!)
Definition: OpenSwathWorkflow.h:193
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:67
OpenSwathCalibrationWorkflow(bool use_ms1_traces)
Definition: OpenSwathWorkflow.h:240
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:54
OpenSwathWorkflowBase(bool use_ms1_traces, bool use_ms1_ion_mobility, int threads_outer_loop)
Constructor.
Definition: OpenSwathWorkflow.h:130
Execute all steps for retention time and m/z calibration of SWATH-MS data.
Definition: OpenSwathWorkflow.h:230
Generic description of a coordinate transformation.
Definition: TransformationDescription.h:61
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
Definition: TransitionExperiment.h:206