| OpenMS 2.5.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-2020.
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
38 #include <OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h>
39 #include <OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h>
40 #include <OpenMS/OPENSWATHALGO/DATAACCESS/TransitionExperiment.h>
41 #include <OpenMS/INTERFACES/IMSDataConsumer.h>
42
43 #include <OpenMS/FORMAT/MzMLFile.h> // debug file store only
44
45 // Kernel and implementations
46 #include <OpenMS/KERNEL/MSExperiment.h>
47 #include <OpenMS/ANALYSIS/OPENSWATH/DATAACCESS/SpectrumAccessOpenMS.h>
48 #include <OpenMS/ANALYSIS/OPENSWATH/DATAACCESS/SpectrumAccessTransforming.h>
49 #include <OpenMS/ANALYSIS/OPENSWATH/DATAACCESS/SpectrumAccessOpenMSInMemory.h>
50 #include <OpenMS/OPENSWATHALGO/DATAACCESS/SwathMap.h>
51
52 // Helpers
53 #include <OpenMS/ANALYSIS/OPENSWATH/OpenSwathHelper.h>
54 // #include <OpenMS/ANALYSIS/OPENSWATH/DATAACCESS/DataAccessHelper.h>
55 #include <OpenMS/ANALYSIS/OPENSWATH/DATAACCESS/SimpleOpenMSSpectraAccessFactory.h>
56 #include <OpenMS/ANALYSIS/OPENSWATH/OpenSwathTSVWriter.h>
57 #include <OpenMS/ANALYSIS/OPENSWATH/OpenSwathOSWWriter.h>
58
59 // Algorithms
60 #include <OpenMS/ANALYSIS/OPENSWATH/MRMRTNormalizer.h>
61 #include <OpenMS/ANALYSIS/OPENSWATH/ChromatogramExtractor.h>
62 #include <OpenMS/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.h>
63 #include <OpenMS/ANALYSIS/OPENSWATH/MRMTransitionGroupPicker.h>
64 #include <OpenMS/ANALYSIS/OPENSWATH/SwathMapMassCorrection.h>
65 #include <OpenMS/FILTERING/TRANSFORMERS/LinearResamplerAlign.h>
66
67 #include <cassert>
68 #include <limits>
69
70 // #define OPENSWATH_WORKFLOW_DEBUG
71
72 // The workflow class
73 namespace OpenMS
74 {
75
82 struct ChromExtractParams
83 {
85 double min_upper_edge_dist;
87 double mz_extraction_window;
89 double im_extraction_window;
91 bool ppm;
93 String extraction_function;
95 double rt_extraction_window;
97 double extra_rt_extract;
98 };
99
100 class OPENMS_DLLAPI OpenSwathWorkflowBase :
101 public ProgressLogger
102 {
103
104 protected:
105
111 OpenSwathWorkflowBase() :
112 use_ms1_traces_(false),
113 use_ms1_ion_mobility_(false),
114 prm_(false),
115 threads_outer_loop_(-1)
116 {
117 }
118
131 OpenSwathWorkflowBase(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, int threads_outer_loop) :
132 use_ms1_traces_(use_ms1_traces),
133 use_ms1_ion_mobility_(use_ms1_ion_mobility),
134 prm_(prm),
135 threads_outer_loop_(threads_outer_loop)
136 {
137 }
138
152 void MS1Extraction_(const OpenSwath::SpectrumAccessPtr ms1_map,
153 const std::vector< OpenSwath::SwathMap > & swath_maps,
154 std::vector< MSChromatogram >& ms1_chromatograms,
155 Interfaces::IMSDataConsumer * chromConsumer,
156 const ChromExtractParams & cp,
157 const OpenSwath::LightTargetedExperiment& transition_exp,
158 const TransformationDescription& trafo_inverse,
159 bool ms1only = false,
160 int ms1_isotopes = 0);
161
179 void prepareExtractionCoordinates_(std::vector< OpenSwath::ChromatogramPtr > & chrom_list,
180 std::vector< ChromatogramExtractorAlgorithm::ExtractionCoordinates > & coordinates,
181 const OpenSwath::LightTargetedExperiment & transition_exp_used,
182 const TransformationDescription trafo_inverse,
183 const ChromExtractParams & cp,
184 const bool ms1 = false,
185 const int ms1_isotopes = -1) const;
186
187
195 OpenSwath::SpectrumAccessPtr ms1_map_ = nullptr;
196
198 bool use_ms1_traces_;
199
201 bool use_ms1_ion_mobility_;
202
204 bool prm_;
205
215 int threads_outer_loop_;
216
217 };
218
235 class OPENMS_DLLAPI OpenSwathCalibrationWorkflow :
236 public OpenSwathWorkflowBase
237 {
238 public:
239
240 OpenSwathCalibrationWorkflow() :
241 OpenSwathWorkflowBase()
242 {
243 }
244
245 explicit OpenSwathCalibrationWorkflow(bool use_ms1_traces) :
246 OpenSwathWorkflowBase(use_ms1_traces, false, false, -1)
247 {
248 }
249
274 TransformationDescription performRTNormalization(const OpenSwath::LightTargetedExperiment & irt_transitions,
275 std::vector< OpenSwath::SwathMap > & swath_maps,
276 TransformationDescription& im_trafo,
277 double min_rsq,
278 double min_coverage,
279 const Param & feature_finder_param,
280 const ChromExtractParams & cp_irt,
281 const Param& irt_detection_param,
282 const Param& calibration_param,
283 const String& irt_mzml_out,
284 Size debug_level,
285 bool sonar = false,
286 bool load_into_memory = false);
287
288 public:
289
319 TransformationDescription doDataNormalization_(const OpenSwath::LightTargetedExperiment& transition_exp_,
320 const std::vector< OpenMS::MSChromatogram >& chromatograms,
321 TransformationDescription& im_trafo,
322 std::vector< OpenSwath::SwathMap > & swath_maps,
323 double min_rsq,
324 double min_coverage,
325 const Param& default_ffparam,
326 const Param& irt_detection_param,
327 const Param& calibration_param);
328
340 void simpleExtractChromatograms_(const std::vector< OpenSwath::SwathMap > & swath_maps,
341 const OpenSwath::LightTargetedExperiment & irt_transitions,
342 std::vector< OpenMS::MSChromatogram > & chromatograms,
343 const TransformationDescription& trafo,
344 const ChromExtractParams & cp,
345 bool sonar,
346 bool load_into_memory);
347
354 static void addChromatograms(MSChromatogram& base_chrom, const MSChromatogram& newchrom);
355
356 };
357
382 class OPENMS_DLLAPI OpenSwathWorkflow :
383 public OpenSwathWorkflowBase
384 {
385 typedef OpenSwath::LightTransition TransitionType;
386 typedef MRMTransitionGroup< MSChromatogram, TransitionType> MRMTransitionGroupType;
387
388 public:
389
404 OpenSwathWorkflow(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, int threads_outer_loop) :
405 OpenSwathWorkflowBase(use_ms1_traces, use_ms1_ion_mobility, prm, threads_outer_loop)
406 {
407 }
408
434 void performExtraction(const std::vector< OpenSwath::SwathMap > & swath_maps,
435 const TransformationDescription trafo,
436 const ChromExtractParams & chromatogram_extraction_params,
437 const ChromExtractParams & ms1_chromatogram_extraction_params,
438 const Param & feature_finder_param,
439 const OpenSwath::LightTargetedExperiment& assay_library,
440 FeatureMap& result_featureFile,
441 bool store_features_in_featureFile,
442 OpenSwathTSVWriter & result_tsv,
443 OpenSwathOSWWriter & result_osw,
444 Interfaces::IMSDataConsumer * result_chromatograms,
445 int batchSize,
446 int ms1_isotopes,
447 bool load_into_memory);
448
449 protected:
450
451
466 void writeOutFeaturesAndChroms_(std::vector< OpenMS::MSChromatogram > & chromatograms,
467 const FeatureMap & featureFile,
468 FeatureMap& out_featureFile,
469 bool store_features,
470 Interfaces::IMSDataConsumer * chromConsumer);
471
508 void scoreAllChromatograms_(
509 const std::vector< OpenMS::MSChromatogram > & ms2_chromatograms,
510 const std::vector< OpenMS::MSChromatogram > & ms1_chromatograms,
511 const std::vector< OpenSwath::SwathMap >& swath_maps,
512 const OpenSwath::LightTargetedExperiment& transition_exp,
513 const Param& feature_finder_param,
514 TransformationDescription trafo,
515 const double rt_extraction_window,
516 FeatureMap& output,
517 OpenSwathTSVWriter & tsv_writer,
518 OpenSwathOSWWriter & osw_writer,
519 int nr_ms1_isotopes = 0,
520 bool ms1only = false) const;
521
537 void selectCompoundsForBatch_(const OpenSwath::LightTargetedExperiment& transition_exp_used_all,
538 OpenSwath::LightTargetedExperiment& transition_exp_used, int batch_size, size_t batch_idx);
539
550 void copyBatchTransitions_(const std::vector<OpenSwath::LightCompound>& used_compounds,
551 const std::vector<OpenSwath::LightTransition>& all_transitions,
552 std::vector<OpenSwath::LightTransition>& output);
553
554 };
555
581 class OPENMS_DLLAPI OpenSwathWorkflowSonar :
582 public OpenSwathWorkflow
583 {
584
585 public:
586
587 explicit OpenSwathWorkflowSonar(bool use_ms1_traces) :
588 OpenSwathWorkflow(use_ms1_traces, false, false, -1)
589 {
590 }
591
613 void performExtractionSonar(const std::vector< OpenSwath::SwathMap > & swath_maps,
614 const TransformationDescription trafo,
615 const ChromExtractParams & cp,
616 const ChromExtractParams & cp_ms1,
617 const Param & feature_finder_param,
618 const OpenSwath::LightTargetedExperiment& transition_exp,
619 FeatureMap& out_featureFile,
620 bool store_features,
621 OpenSwathTSVWriter & tsv_writer,
622 OpenSwathOSWWriter & osw_writer,
623 Interfaces::IMSDataConsumer * chromConsumer,
624 int batchSize,
625 bool load_into_memory);
626
630 void computeSonarWindows_(const std::vector< OpenSwath::SwathMap > & swath_maps,
631 double & sonar_winsize,
632 double & sonar_start,
633 double & sonar_end,
634 int & sonar_total_win);
635
639 void performSonarExtraction_(const std::vector< OpenSwath::SwathMap > & used_maps,
640 const std::vector< ChromatogramExtractor::ExtractionCoordinates > & coordinates,
641 std::vector< OpenSwath::ChromatogramPtr > & chrom_list,
642 const ChromExtractParams & cp);
643
650 OpenSwath::ChromatogramPtr addChromatograms(OpenSwath::ChromatogramPtr base_chrom, OpenSwath::ChromatogramPtr newchrom);
651 };
652
653 }
654
655
OpenMS::String
A more convenient string class.
Definition: String.h:58
DataStructures.h
SpectrumAccessOpenMS.h
OpenMS::MSChromatogram
The representation of a chromatogram.
Definition: MSChromatogram.h:54
OpenMS::OpenSwathWorkflowBase::use_ms1_ion_mobility_
bool use_ms1_ion_mobility_
Whether to use ion mobility extraction on MS1 traces.
Definition: OpenSwathWorkflow.h:201
OpenMS::OpenSwathWorkflow::OpenSwathWorkflow
OpenSwathWorkflow(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, int threads_outer_loop)
Constructor.
Definition: OpenSwathWorkflow.h:404
SimpleOpenMSSpectraAccessFactory.h
OpenMS::ChromExtractParams
ChromatogramExtractor parameters.
Definition: OpenSwathWorkflow.h:82
OpenSwath::SpectrumAccessPtr
boost::shared_ptr< ISpectrumAccess > SpectrumAccessPtr
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:89
OpenMS::MRMTransitionGroup
The representation of a group of transitions in a targeted proteomics experiment. ...
Definition: MRMTransitionGroup.h:67
SwathMapMassCorrection.h
OpenMS::ChromExtractParams::extraction_function
String extraction_function
The extraction function in mass space.
Definition: OpenSwathWorkflow.h:93
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:95
OpenMS::OpenSwathWorkflowSonar::OpenSwathWorkflowSonar
OpenSwathWorkflowSonar(bool use_ms1_traces)
Definition: OpenSwathWorkflow.h:587
OpenMS::OpenSwathWorkflow
Execute all steps in an OpenSwath analysis.
Definition: OpenSwathWorkflow.h:382
OpenMS::TransformationDescription
Generic description of a coordinate transformation.
Definition: TransformationDescription.h:61
OpenMS::OpenSwathWorkflowBase::use_ms1_traces_
bool use_ms1_traces_
Whether to use the MS1 traces.
Definition: OpenSwathWorkflow.h:198
MRMFeatureFinderScoring.h
OpenMS::ChromExtractParams::extra_rt_extract
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
IMSDataConsumer.h
OpenMS::OpenSwathOSWWriter
Class to write out an OpenSwath OSW SQLite output (PyProphet input).
Definition: OpenSwathOSWWriter.h:115
MRMTransitionGroupPicker.h
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::ChromExtractParams::im_extraction_window
double im_extraction_window
Extraction window in ion mobility.
Definition: OpenSwathWorkflow.h:89
MSExperiment.h
OpenMS::ProgressLogger
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:54
OpenMS::OpenSwathWorkflowBase::OpenSwathWorkflowBase
OpenSwathWorkflowBase()
Default constructor.
Definition: OpenSwathWorkflow.h:111
OpenSwathTSVWriter.h
OpenMS::OpenSwathCalibrationWorkflow
Execute all steps for retention time and m/z calibration of SWATH-MS data.
Definition: OpenSwathWorkflow.h:235
OpenSwathHelper.h
OpenMS::OpenSwathTSVWriter
Class to write out an OpenSwath TSV output (mProphet input).
Definition: OpenSwathTSVWriter.h:129
OpenMS::Interfaces::IMSDataConsumer
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:69
OpenSwath::LightTargetedExperiment
Definition: TransitionExperiment.h:207
OpenMS::OpenSwathWorkflowBase::threads_outer_loop_
int threads_outer_loop_
How many threads should be used for the outer loop.
Definition: OpenSwathWorkflow.h:215
OpenSwathOSWWriter.h
LinearResamplerAlign.h
OpenMS::OpenSwathWorkflowSonar
Execute all steps in an OpenEcho analysis (OpenSwath for SONAR data)
Definition: OpenSwathWorkflow.h:581
OpenMS::OpenSwathWorkflowBase::prm_
bool prm_
Whether data is acquired in targeted DIA (e.g. PRM mode) with potentially overlapping windows...
Definition: OpenSwathWorkflow.h:204
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:73
OpenMS::OpenSwathCalibrationWorkflow::OpenSwathCalibrationWorkflow
OpenSwathCalibrationWorkflow(bool use_ms1_traces)
Definition: OpenSwathWorkflow.h:245
OpenMS::OpenSwathWorkflowBase
Definition: OpenSwathWorkflow.h:100
MRMRTNormalizer.h
SwathMap.h
SpectrumAccessTransforming.h
OpenSwath::LightTransition
Definition: TransitionExperiment.h:46
OpenMS::ChromExtractParams::min_upper_edge_dist
double min_upper_edge_dist
Whether to not extract anything closer than this (in Da) from the upper edge.
Definition: OpenSwathWorkflow.h:85
OpenMS::ChromExtractParams::rt_extraction_window
double rt_extraction_window
The retention time extraction window.
Definition: OpenSwathWorkflow.h:95
OpenMS::OpenSwathWorkflow::MRMTransitionGroupType
MRMTransitionGroup< MSChromatogram, TransitionType > MRMTransitionGroupType
Definition: OpenSwathWorkflow.h:386
TransitionExperiment.h
ISpectrumAccess.h
OpenSwath::ChromatogramPtr
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:172
OpenMS::OpenSwathCalibrationWorkflow::OpenSwathCalibrationWorkflow
OpenSwathCalibrationWorkflow()
Definition: OpenSwathWorkflow.h:240
SpectrumAccessOpenMSInMemory.h
OpenMS::OpenSwathWorkflowBase::OpenSwathWorkflowBase
OpenSwathWorkflowBase(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, int threads_outer_loop)
Constructor.
Definition: OpenSwathWorkflow.h:131
ChromatogramExtractor.h
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::ChromExtractParams::mz_extraction_window
double mz_extraction_window
Extraction window in Da or ppm (e.g. 50ppm means extraction +/- 25ppm)
Definition: OpenSwathWorkflow.h:87
OpenMS::OpenSwathWorkflow::TransitionType
OpenSwath::LightTransition TransitionType
Definition: OpenSwathWorkflow.h:385
MzMLFile.h
OpenMS::ChromExtractParams::ppm
bool ppm
Whether the extraction window is given in ppm or Da.
Definition: OpenSwathWorkflow.h:91