OpenMS
Loading...
Searching...
No Matches
OpenSwathWorkflow.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- 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
12
17
18// Kernel and implementations
24
25// Helpers
27// #include <OpenMS/ANALYSIS/OPENSWATH/DATAACCESS/DataAccessHelper.h>
30
31// Algorithms
38#include <cassert>
39#include <limits>
40#include <string>
41#include <unordered_map>
42#include <vector>
43
44// #define OPENSWATH_WORKFLOW_DEBUG
45
46// The workflow class
47namespace OpenMS
48{
49
73
74 class OPENMS_DLLAPI OpenSwathWorkflowBase :
75 public ProgressLogger
76 {
77
78protected:
79
86 use_ms1_traces_(false),
87 use_ms1_ion_mobility_(false),
88 prm_(false),
89 pasef_(false),
90 mrm_(false),
91 threads_outer_loop_(-1)
92 {
93 }
94
115 OpenSwathWorkflowBase(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, bool pasef, bool mrm, int threads_outer_loop) :
116 use_ms1_traces_(use_ms1_traces),
117 use_ms1_ion_mobility_(use_ms1_ion_mobility),
118 prm_(prm),
119 pasef_(pasef),
120 mrm_(mrm),
121 threads_outer_loop_(threads_outer_loop)
122 {
123 }
124
138 const std::vector<OpenSwath::SwathMap>& swath_maps,
139 std::vector<MSChromatogram>& ms1_chromatograms,
140 const ChromExtractParams& cp,
141 const OpenSwath::LightTargetedExperiment& transition_exp,
142 const TransformationDescription& trafo_inverse,
143 bool ms1_only = false,
144 int ms1_isotopes = 0);
145
164 void prepareExtractionCoordinates_(std::vector< OpenSwath::ChromatogramPtr > & chrom_list,
165 std::vector< ChromatogramExtractorAlgorithm::ExtractionCoordinates > & coordinates,
166 const OpenSwath::LightTargetedExperiment & transition_exp_used,
167 const TransformationDescription& trafo_inverse,
168 const ChromExtractParams & cp,
169 const bool ms1 = false,
170 const int ms1_isotopes = -1) const;
171
172
181
184
187
196 bool prm_;
197
206 bool pasef_;
207
213 bool mrm_;
214
228
229};
230
232 struct OPENMS_DLLAPI ChromatogramIndex
233 {
234 std::unordered_map<std::string, int> ms2;
235 std::unordered_map<std::string, int> ms1;
236
238 void build(const std::vector<MSChromatogram>& ms2_chromatograms, const std::vector<MSChromatogram>& ms1_chromatograms);
239 };
240
269 class OPENMS_DLLAPI OpenSwathWorkflow :
271 {
274
275 public:
276
293 OpenSwathWorkflow(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, bool pasef, bool mrm, int threads_outer_loop) :
294 OpenSwathWorkflowBase(use_ms1_traces, use_ms1_ion_mobility, prm, pasef, mrm, threads_outer_loop)
295 {
296 }
297
309 OpenSwath::SpectrumAccessPtr loadMS1Map(const std::vector<OpenSwath::SwathMap>& swath_maps, bool load_into_memory);
310
346 void performExtraction(const std::vector<OpenSwath::SwathMap>& swath_maps,
347 const TransformationDescription& rt_trafo,
348 const ChromExtractParams & chromatogram_extraction_params,
349 const ChromExtractParams & ms1_chromatogram_extraction_params,
350 const Param & feature_finder_param,
351 const OpenSwath::LightTargetedExperiment& assay_library,
352 FeatureMap& result_featureFile,
353 bool store_features_in_featureFile,
354 OpenSwathOSWWriter & result_osw,
355 Interfaces::IMSDataConsumer * result_chromatograms,
356 int batchSize,
357 int ms1_isotopes,
358 bool load_into_memory,
359 const Param & mrm_mapping_param = Param(),
360 class MobilogramParquetConsumer * mobilogram_consumer = nullptr,
361 int innerBatchSize = -1,
362 int maxConcurrentSwaths = -1);
363
364 protected:
365
366
382 void writeOutFeaturesAndChroms_(std::vector< OpenMS::MSChromatogram > & chromatograms,
383 std::vector< MSChromatogram >& ms1_chromatograms,
384 const FeatureMap & featureFile,
385 FeatureMap& out_featureFile,
386 bool store_features,
387 Interfaces::IMSDataConsumer * chromConsumer);
388
430 const std::vector<OpenMS::MSChromatogram>& ms2_chromatograms,
431 const std::vector<OpenMS::MSChromatogram>& ms1_chromatograms,
432 const std::vector<OpenSwath::SwathMap>& swath_maps,
433 const OpenSwath::LightTargetedExperiment& transition_exp,
434 const Param& feature_finder_param,
435 const TransformationDescription& trafo,
436 const double rt_extraction_window,
437 FeatureMap& output,
438 OpenSwathOSWWriter& osw_writer,
439 int nr_ms1_isotopes = 0,
440 bool ms1only = false,
441 class MobilogramParquetConsumer * mobilogram_consumer = nullptr,
442 OpenSwathOSWWriter::OSWData* deferred_osw_output = nullptr,
443 const ChromatogramIndex* chromatogram_index = nullptr) const;
444
461 OpenSwath::LightTargetedExperiment& transition_exp_used, int batch_size, size_t batch_idx);
462
473 void copyBatchTransitions_(const std::vector<OpenSwath::LightCompound>& used_compounds,
474 const std::vector<OpenSwath::LightTransition>& all_transitions,
475 std::vector<OpenSwath::LightTransition>& output);
476 };
477}
A container for features.
Definition FeatureMap.h:78
The interface of a consumer of spectra and chromatograms.
Definition IMSDataConsumer.h:46
The representation of a group of transitions in a targeted proteomics experiment.
Definition MRMTransitionGroup.h:41
Writes Mobilograms (ion-mobility traces) to a Parquet file using a PyProphet-compatible-like schema.
Definition MobilogramParquetConsumer.h:25
Class to write out an OpenSwath OSW SQLite output (PyProphet input).
Definition OpenSwathOSWWriter.h:97
Definition OpenSwathWorkflow.h:76
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 ms1_only=false, int ms1_isotopes=0)
Perform MS1 extraction and store result in ms1_chromatograms.
bool prm_
Whether data is acquired in targeted DIA (e.g. PRM mode) with potentially overlapping windows.
Definition OpenSwathWorkflow.h:196
bool use_ms1_traces_
Whether to use the MS1 traces.
Definition OpenSwathWorkflow.h:183
int threads_outer_loop_
How many threads should be used for the outer loop.
Definition OpenSwathWorkflow.h:227
OpenSwathWorkflowBase(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, bool pasef, bool mrm, int threads_outer_loop)
Constructor.
Definition OpenSwathWorkflow.h:115
OpenSwathWorkflowBase()
Default constructor.
Definition OpenSwathWorkflow.h:85
bool use_ms1_ion_mobility_
Whether to use ion mobility extraction on MS1 traces.
Definition OpenSwathWorkflow.h:186
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 mrm_
Whether data is chromatogram-only SRM/MRM data.
Definition OpenSwathWorkflow.h:213
bool pasef_
Whether data is diaPASEF data.
Definition OpenSwathWorkflow.h:206
Execute all steps in an OpenSwath analysis.
Definition OpenSwathWorkflow.h:271
MRMTransitionGroup< MSChromatogram, TransitionType > MRMTransitionGroupType
Definition OpenSwathWorkflow.h:273
void performExtraction(const std::vector< OpenSwath::SwathMap > &swath_maps, const TransformationDescription &rt_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, OpenSwathOSWWriter &result_osw, Interfaces::IMSDataConsumer *result_chromatograms, int batchSize, int ms1_isotopes, bool load_into_memory, const Param &mrm_mapping_param=Param(), class MobilogramParquetConsumer *mobilogram_consumer=nullptr, int innerBatchSize=-1, int maxConcurrentSwaths=-1)
Execute OpenSWATH analysis on a set of SwathMaps and transitions.
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:272
OpenSwath::SpectrumAccessPtr loadMS1Map(const std::vector< OpenSwath::SwathMap > &swath_maps, bool load_into_memory)
Load MS1 SpectrumAccessPtr from given swath maps.
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_()
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, OpenSwathOSWWriter &osw_writer, int nr_ms1_isotopes=0, bool ms1only=false, class MobilogramParquetConsumer *mobilogram_consumer=nullptr, OpenSwathOSWWriter::OSWData *deferred_osw_output=nullptr, const ChromatogramIndex *chromatogram_index=nullptr) const
Perform scoring on a set of chromatograms.
OpenSwathWorkflow(bool use_ms1_traces, bool use_ms1_ion_mobility, bool prm, bool pasef, bool mrm, int threads_outer_loop)
Constructor.
Definition OpenSwathWorkflow.h:293
Management and storage of parameters / INI files.
Definition Param.h:46
Base class for all classes that want to report their progress.
Definition ProgressLogger.h:27
Generic description of a coordinate transformation.
Definition TransformationDescription.h:38
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
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
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
std::string extraction_function
The extraction function in mass space.
Definition OpenSwathWorkflow.h:67
double rt_extraction_window
The retention time extraction window.
Definition OpenSwathWorkflow.h:69
ChromatogramExtractor parameters.
Definition OpenSwathWorkflow.h:57
std::shared_ptr< ISpectrumAccess > SpectrumAccessPtr
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:146
Positions of chromatograms by native ID (see OpenSwathWorkflow::scoreAllChromatograms_())
Definition OpenSwathWorkflow.h:233
std::unordered_map< std::string, int > ms1
index into the MS1 (precursor) chromatograms
Definition OpenSwathWorkflow.h:235
void build(const std::vector< MSChromatogram > &ms2_chromatograms, const std::vector< MSChromatogram > &ms1_chromatograms)
Index the chromatograms by their native ID.
std::unordered_map< std::string, int > ms2
index into the MS2 chromatograms
Definition OpenSwathWorkflow.h:234
Buffered OSW table rows ready for insertion through prepared statements.
Definition OpenSwathOSWWriter.h:186
Definition TransitionExperiment.h:369
Definition TransitionExperiment.h:106