OpenMS
TwoDOptimization.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: Timo Sachsenberg $
6 // $Authors: $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 //#define DEBUG_2D
12 #undef DEBUG_2D
13 
14 #ifdef DEBUG_2D
15 #include <iostream>
16 #include <fstream>
17 #endif
18 
19 #include <vector>
20 #include <utility>
21 #include <cmath>
22 #include <set>
23 
34 
35 
36 #ifndef OPENMS_SYSTEM_STOPWATCH_H
37 #endif
38 
41 
42 namespace OpenMS
43 {
44 
59  class OPENMS_DLLAPI TwoDOptimization :
60  public DefaultParamHandler
61  {
62 public:
63 
65 
68 
71 
73  ~TwoDOptimization() override{}
74 
77 
78 
80  inline double getMZTolerance() const {return tolerance_mz_; }
82  inline void setMZTolerance(double tolerance_mz)
83  {
84  tolerance_mz_ = tolerance_mz;
85  param_.setValue("2d:tolerance_mz", tolerance_mz);
86  }
87 
89  inline double getMaxPeakDistance() const {return max_peak_distance_; }
91  inline void setMaxPeakDistance(double max_peak_distance)
92  {
93  max_peak_distance_ = max_peak_distance;
94  param_.setValue("2d:max_peak_distance", max_peak_distance);
95  }
96 
98  inline UInt getMaxIterations() const {return max_iteration_; }
100  inline void setMaxIterations(UInt max_iteration)
101  {
102  max_iteration_ = max_iteration;
103  param_.setValue("iterations", max_iteration);
104  }
105 
107  inline const OptimizationFunctions::PenaltyFactorsIntensity& getPenalties() const {return penalties_; }
110  {
111  penalties_ = penalties;
112  param_.setValue("penalties:position", penalties.pos);
113  param_.setValue("penalties:height", penalties.height);
114  param_.setValue("penalties:left_width", penalties.lWidth);
115  param_.setValue("penalties:right_width", penalties.rWidth);
116  }
117 
136  PeakMap& ms_exp, bool real2D = true);
137 
138 
139 protected:
141  struct Data
142  {
143  std::vector<std::pair<SignedSize, SignedSize> > signal2D;
144  std::multimap<double, IsotopeCluster>::iterator iso_map_iter;
146  std::map<Int, std::vector<PeakIndex> > matching_peaks;
150  std::vector<double> positions;
151  std::vector<double> signal;
152  };
153 
154  class OPENMS_DLLAPI TwoDOptFunctor
155  {
156  public:
157  int inputs() const { return m_inputs; }
158  int values() const { return m_values; }
159 
160  TwoDOptFunctor(unsigned dimensions, unsigned num_data_points, const TwoDOptimization::Data* data)
161  : m_inputs(dimensions), m_values(num_data_points), m_data(data) {}
162 
164  // compute Jacobian matrix for the different parameters
165  int df(const Eigen::VectorXd &x, Eigen::MatrixXd &J);
166 
167  private:
168  const int m_inputs, m_values;
170  };
171 
172 
174  std::multimap<double, IsotopeCluster> iso_map_;
175 
177  std::multimap<double, IsotopeCluster>::const_iterator curr_region_;
178 
181 
184 
186  // std::map<Int, std::vector<PeakMap::SpectrumType::Iterator > > matching_peaks_;
187  std::map<Int, std::vector<PeakIndex> > matching_peaks_;
188 
189 
192 
194  bool real_2D_;
195 
196 
199 
200 
205  std::vector<double>::iterator searchInScan_(std::vector<double>::iterator scan_begin,
206  std::vector<double>::iterator scan_end,
207  double current_mz);
208 
211  InputSpectrumIterator& last,
212  PeakMap& ms_exp);
213 
216  InputSpectrumIterator& last,
217  PeakMap& ms_exp);
218 
219 
222  InputSpectrumIterator& first,
223  InputSpectrumIterator& last,
224  Size iso_map_idx,
225  double noise_level,
227 
229  void findMatchingPeaks_(std::multimap<double, IsotopeCluster>::iterator& it,
230  PeakMap& ms_exp);
231 
233 
235  void updateMembers_() override;
236  };
237 
238 }
239 
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
Base::const_iterator const_iterator
Definition: MSExperiment.h:91
std::vector< SpectrumType >::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSExperiment.h:79
Definition: TwoDOptimization.h:155
int values() const
Definition: TwoDOptimization.h:158
int df(const Eigen::VectorXd &x, Eigen::MatrixXd &J)
const int m_inputs
Definition: TwoDOptimization.h:168
int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec)
const TwoDOptimization::Data * m_data
Definition: TwoDOptimization.h:169
TwoDOptFunctor(unsigned dimensions, unsigned num_data_points, const TwoDOptimization::Data *data)
Definition: TwoDOptimization.h:160
int inputs() const
Definition: TwoDOptimization.h:157
This class provides the two-dimensional optimization of the picked peak parameters.
Definition: TwoDOptimization.h:61
double getMZTolerance() const
Non-mutable access to the matching epsilon.
Definition: TwoDOptimization.h:80
std::multimap< double, IsotopeCluster >::iterator iso_map_iter
Definition: TwoDOptimization.h:144
std::vector< std::pair< SignedSize, SignedSize > > signal2D
Definition: TwoDOptimization.h:143
void getRegionEndpoints_(PeakMap &exp, InputSpectrumIterator &first, InputSpectrumIterator &last, Size iso_map_idx, double noise_level, TwoDOptimization::Data &d)
Get the indices of the first and last raw data point of this region.
OptimizationFunctions::PenaltyFactorsIntensity penalties_
Penalty factors for some parameters in the optimization.
Definition: TwoDOptimization.h:198
void setPenalties(OptimizationFunctions::PenaltyFactorsIntensity &penalties)
Mutable access to the minimal number of adjacent scans.
Definition: TwoDOptimization.h:109
PeakMap::ConstIterator raw_data_first
Definition: TwoDOptimization.h:148
std::map< Int, std::vector< PeakIndex > > matching_peaks
Definition: TwoDOptimization.h:146
PeakMap picked_peaks
Definition: TwoDOptimization.h:147
OptimizationFunctions::PenaltyFactorsIntensity penalties
Definition: TwoDOptimization.h:149
void findMatchingPeaks_(std::multimap< double, IsotopeCluster >::iterator &it, PeakMap &ms_exp)
Identify matching peak in a peak cluster.
std::map< Int, std::vector< PeakIndex > > matching_peaks_
Indices of peaks in the adjacent scans matching peaks in the scan with no. ref_scan.
Definition: TwoDOptimization.h:187
void optimizeRegions_(InputSpectrumIterator &first, InputSpectrumIterator &last, PeakMap &ms_exp)
TwoDOptimization()
Constructor.
void optimizeRegionsScanwise_(InputSpectrumIterator &first, InputSpectrumIterator &last, PeakMap &ms_exp)
bool real_2D_
Optimization considering all scans of a cluster or optimization of each scan separately.
Definition: TwoDOptimization.h:194
std::vector< double > positions
Definition: TwoDOptimization.h:150
MSExperiment::const_iterator InputSpectrumIterator
Definition: TwoDOptimization.h:64
double max_peak_distance_
upper bound for distance between two peaks belonging to the same region
Definition: TwoDOptimization.h:180
double tolerance_mz_
threshold for the difference in the peak position of two matching peaks
Definition: TwoDOptimization.h:183
UInt max_iteration_
Convergence Parameter: Maximal number of iterations.
Definition: TwoDOptimization.h:191
double getMaxPeakDistance() const
Non-mutable access to the maximal peak distance in a cluster.
Definition: TwoDOptimization.h:89
UInt getMaxIterations() const
Non-mutable access to the maximal number of iterations.
Definition: TwoDOptimization.h:98
Size total_nr_peaks
Definition: TwoDOptimization.h:145
std::vector< double >::iterator searchInScan_(std::vector< double >::iterator scan_begin, std::vector< double >::iterator scan_end, double current_mz)
std::multimap< double, IsotopeCluster > iso_map_
stores the retention time of each isotopic cluster
Definition: TwoDOptimization.h:174
void setMaxPeakDistance(double max_peak_distance)
Mutable access to the maximal peak distance in a cluster.
Definition: TwoDOptimization.h:91
TwoDOptimization(const TwoDOptimization &opt)
Copy constructor.
TwoDOptimization & operator=(const TwoDOptimization &opt)
Assignment operator.
void updateMembers_() override
update members method from DefaultParamHandler to update the members
std::multimap< double, IsotopeCluster >::const_iterator curr_region_
Pointer to the current region.
Definition: TwoDOptimization.h:177
void optimize(InputSpectrumIterator first, InputSpectrumIterator last, PeakMap &ms_exp, bool real2D=true)
Find two dimensional peak clusters and optimize their peak parameters.
void setMZTolerance(double tolerance_mz)
Mutable access to the matching epsilon.
Definition: TwoDOptimization.h:82
const OptimizationFunctions::PenaltyFactorsIntensity & getPenalties() const
Non-mutable access to the minimal number of adjacent scans.
Definition: TwoDOptimization.h:107
void setMaxIterations(UInt max_iteration)
Mutable access to the maximal number of iterations.
Definition: TwoDOptimization.h:100
~TwoDOptimization() override
Destructor.
Definition: TwoDOptimization.h:73
std::vector< double > signal
Definition: TwoDOptimization.h:151
Helper struct (contains the size of an area and a raw data container)
Definition: TwoDOptimization.h:142
unsigned int UInt
Unsigned integer type.
Definition: Types.h:68
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
Definition: IsobaricIsotopeCorrector.h:17
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
Class for the penalty factors used during the optimization.
Definition: OptimizePeakDeconvolution.h:33
double height
Definition: OptimizePeakDeconvolution.h:50
double rWidth
Penalty factor for the peak shape's right width parameter.
Definition: OptimizePick.h:64
double pos
Penalty factor for the peak shape's position.
Definition: OptimizePick.h:60
double lWidth
Penalty factor for the peak shape's left width parameter.
Definition: OptimizePick.h:62