OpenMS
PeakGroup.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: Kyowon Jeong, Jihyung Kim $
6 // $Authors: Kyowon Jeong, Jihyung Kim $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
13 
14 namespace OpenMS
15 {
25  class OPENMS_DLLAPI PeakGroup
26  {
29 
30  public:
33  {
34  target = 0,
38  non_specific
39  };
40 
41 
43  PeakGroup() = default;
44 
51  explicit PeakGroup(int min_abs_charge, int max_abs_charge, bool is_positive);
52 
54  ~PeakGroup() = default;
55 
57  PeakGroup(const PeakGroup&) = default;
58 
60  PeakGroup(PeakGroup&& other) = default;
61 
63  bool operator<(const PeakGroup& a) const;
64 
65  bool operator>(const PeakGroup& a) const;
66 
67  bool operator==(const PeakGroup& a) const;
68 
70  PeakGroup& operator=(const PeakGroup& t) = default;
71 
76 
87  int updateQscore(std::vector<LogMzPeak>& noisy_peaks, const FLASHDeconvHelperStructs::PrecalculatedAveragine& avg, double min_cos, bool is_low_charge, bool is_profile = false, int allowed_iso_error = 1);
88 
98  std::vector<LogMzPeak> recruitAllPeaksInSpectrum(const MSSpectrum& spec, double tol, const FLASHDeconvHelperStructs::PrecalculatedAveragine& avg, double mono_mass);
99 
101  bool isSignalMZ(double mz, double tol) const;
102 
104  void setScanNumber(int scan_number);
105 
107  void setChargeIsotopeCosine(int abs_charge, float cos);
108 
110  void setAbsChargeRange(int min_abs_charge, int max_abs_charge);
111 
113  void setIsotopeCosine(float cos);
114 
116  void setRepAbsCharge(int max_snr_abs_charge);
117 
119  void setMonoisotopicMass(double mono_mass);
120 
122  void setQscore(double qscore);
123 
125  void setChargeScore(float charge_score);
126 
128  void setAvgPPMError(float error);
129 
131  void setSNR(float snr);
132 
134  void setChargeSNR(int abs_charge, float c_snr);
135 
137  void setTargeted();
138 
140  int getScanNumber() const;
141 
143  double getMonoMass() const;
144 
146  float getIntensity() const;
147 
149  float getChargeSNR(int abs_charge) const;
150 
152  float getChargeIsotopeCosine(int abs_charge) const;
153 
155  float getChargeIntensity(int abs_charge) const;
156 
158  std::tuple<double, double> getRepMzRange() const;
159 
161  std::tuple<double, double> getMzRange(int abs_charge) const;
162 
164  std::tuple<int, int> getAbsChargeRange() const;
165 
167  const std::vector<float>& getIsotopeIntensities() const;
168 
170  float getIsotopeCosine() const;
171 
173  int getRepAbsCharge() const;
174 
176  double getQscore() const;
177 
179  double getQscore2D() const;
180 
182  float getSNR() const;
183 
185  float getChargeScore() const;
186 
188  float getAvgPPMError() const;
189 
191  float getAvgDaError() const;
192 
194  bool isPositive() const;
195 
197  bool isTargeted() const;
198 
201 
204 
211  float getQvalue(PeakGroup::TargetDecoyType target_decoy_type = PeakGroup::TargetDecoyType::target) const;
212 
217  void setQvalue(double q, PeakGroup::TargetDecoyType target_decoy_type);
218 
220  void setIsotopeDaDistance(double d);
221 
223  double getIsotopeDaDistance() const;
224 
227 
229  void setIndex(uint i);
230 
232  void setQscore2D(double fqscore);
233 
235  void setFeatureIndex(uint findex);
236 
238  uint getIndex() const;
240  uint getFeatureIndex() const;
241 
243  {
244  return charge_range_for_DL_;
245  };
247  {
248  return iso_range_for_DL_;
249  };
251  {
252  return bin_width_DL_;
253  }
254 
261  void calculateDLMatrices(const MSSpectrum& spec, double tol, const PrecalculatedAveragine& avg);
262 
264  Matrix<float> getDLMatrix(int index) const;
265 
267  std::vector<FLASHDeconvHelperStructs::LogMzPeak>::const_iterator begin() const noexcept;
268  std::vector<FLASHDeconvHelperStructs::LogMzPeak>::const_iterator end() const noexcept;
269 
270  std::vector<FLASHDeconvHelperStructs::LogMzPeak>::iterator begin() noexcept;
271  std::vector<FLASHDeconvHelperStructs::LogMzPeak>::iterator end() noexcept;
272 
273  const FLASHDeconvHelperStructs::LogMzPeak& operator[](Size i) const;
274 
276  std::vector<FLASHDeconvHelperStructs::LogMzPeak>::const_iterator getNoisePeakBegin() const noexcept;
277  std::vector<FLASHDeconvHelperStructs::LogMzPeak>::const_iterator getNoisePeakEnd() const noexcept;
278 
279  std::vector<FLASHDeconvHelperStructs::LogMzPeak>::iterator getNoisePeakBegin() noexcept;
280  std::vector<FLASHDeconvHelperStructs::LogMzPeak>::iterator getNoisePeakEnd() noexcept;
281 
283  void push_back(const FLASHDeconvHelperStructs::LogMzPeak& pg);
285  Size size() const noexcept;
286 
287  void reserve(Size n);
288  bool empty() const;
289  void swap(std::vector<FLASHDeconvHelperStructs::LogMzPeak>& x);
290  void sort();
291 
292  private:
294  void updateChargeFitScoreAndChargeIntensities_(bool is_low_charge);
296  void updateAvgPPMError_();
298  void updateAvgDaError_();
300  float getAbsPPMError_(const LogMzPeak& p) const;
302  float getAbsDaError_(const LogMzPeak& p) const;
304  void updateSNR_();
306  void clear_();
308  void updatePerChargeInformation_(const std::vector<LogMzPeak>& noisy_peaks);
310  void updateChargeRange_(std::vector<LogMzPeak>& noisy_peaks);
312  void updatePerChargeCos_(const FLASHDeconvHelperStructs::PrecalculatedAveragine& avg);
313 
321  float getNoisePeakPower_(const std::vector<LogMzPeak>& noisy_peaks, const std::vector<LogMzPeak>& signal_peaks, const int z) const;
322  std::vector<Matrix<float>> dl_matrices_;
323 
325  std::vector<FLASHDeconvHelperStructs::LogMzPeak> logMzpeaks_;
327  std::vector<FLASHDeconvHelperStructs::LogMzPeak> negative_iso_peaks_;
329  std::vector<float> per_charge_sum_signal_squared_;
330  std::vector<float> per_charge_noise_pwr_;
331  std::vector<float> per_charge_cos_;
332  std::vector<float> per_charge_int_;
333  std::vector<float> per_charge_snr_;
335  std::vector<float> per_isotope_int_;
337  int min_abs_charge_ = 0, max_abs_charge_ = -1;
339  uint index_ = 0;
341  uint findex_ = 0;
343  int scan_number_ = 0;
345  bool is_positive_ = false;
347  bool is_targeted_ = false;
349  double monoisotopic_mass_ = -1.0;
350  float intensity_ = 0; // total intensity
352  PeakGroup::TargetDecoyType target_decoy_type_ = target;
354  int min_negative_isotope_index_ = -1;
355 
356  int charge_range_for_DL_ = 7;
357  float bin_width_DL_ = 0.25;
358  int iso_range_for_DL_ = 21;
359 
361  double iso_da_distance_ = Constants::ISOTOPE_MASSDIFF_55K_U;
363  int max_snr_abs_charge_ = -1;
364  float isotope_cosine_score_ = 0;
365  float charge_score_ = 0;
366  double qscore_ = .0f;
367  double qscore2D_ = -1.0f;
368  float avg_ppm_error_ = 0;
369  float avg_da_error_ = 0;
370  float snr_ = 0;
372  std::map<PeakGroup::TargetDecoyType, float> qvalue_;
373  };
374 } // namespace OpenMS
log transformed peak. After deconvolution, all necessary information from deconvolution such as charg...
Definition: FLASHDeconvHelperStructs.h:166
Averagine patterns pre-calculated for speed up. Other variables are also calculated for fast cosine c...
Definition: FLASHDeconvHelperStructs.h:33
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
Class describing a deconvolved mass. A mass contains multiple (LogMz) peaks of different charges and ...
Definition: PeakGroup.h:26
float getBinWidthDL()
Definition: PeakGroup.h:250
void setTargeted()
set if it is targeted
void setTargetDecoyType(PeakGroup::TargetDecoyType index)
for this PeakGroup, specify the target decoy type.
int getMinNegativeIsotopeIndex() const
get minimum neagative isotope index
void setIsotopeCosine(float cos)
set isotope cosine score
void setAvgPPMError(float error)
set average mass ppm error
std::tuple< double, double > getMzRange(int abs_charge) const
get mz range of the charge
FLASHDeconvHelperStructs::LogMzPeak LogMzPeak
Definition: PeakGroup.h:27
bool isTargeted() const
get if it is targeted
float getChargeSNR(int abs_charge) const
get per abs_charge SNR
uint getIndex() const
get index of this peak group
std::vector< LogMzPeak > recruitAllPeaksInSpectrum(const MSSpectrum &spec, double tol, const FLASHDeconvHelperStructs::PrecalculatedAveragine &avg, double mono_mass)
given a monoisotopic mass, recruit raw peaks from the raw input spectrum and add to this peakGroup....
float getIntensity() const
get intensity
float getAvgDaError() const
get average mass ppm error;
float getSNR() const
get total SNR
void setQvalue(double q, PeakGroup::TargetDecoyType target_decoy_type)
float getChargeIntensity(int abs_charge) const
get per abs_charge intenstiy
int getRepAbsCharge() const
get representative charge
bool operator<(const PeakGroup &a) const
comparison operators
void setSNR(float snr)
set SNR manually - for FLASHIda log file parsing
void setIsotopeDaDistance(double d)
set distance between consecutive isotopes
float getChargeIsotopeCosine(int abs_charge) const
get per abs_charge isotope cosine
void setChargeSNR(int abs_charge, float c_snr)
set charge SNR manually - for FLASHIda log file parsing
void setQscore2D(double fqscore)
set Q score 2D
bool operator>(const PeakGroup &a) const
float getChargeScore() const
get charge score
int getChargeRangeForDL()
Definition: PeakGroup.h:242
float getQvalue(PeakGroup::TargetDecoyType target_decoy_type=PeakGroup::TargetDecoyType::target) const
void setAbsChargeRange(int min_abs_charge, int max_abs_charge)
set min_abs_charge and max_abs_charge charge range
void setMonoisotopicMass(double mono_mass)
set monoisotopic mass
PeakGroup(int min_abs_charge, int max_abs_charge, bool is_positive)
Constructor specifying charge range.
int getScanNumber() const
get scan number
PeakGroup()=default
default constructor
~PeakGroup()=default
default destructor
std::tuple< int, int > getAbsChargeRange() const
get charge range - the actual charge values
uint getFeatureIndex() const
get feature index of this peak group
void setChargeIsotopeCosine(int abs_charge, float cos)
set per abs_charge isotope cosine
int updateQscore(std::vector< LogMzPeak > &noisy_peaks, const FLASHDeconvHelperStructs::PrecalculatedAveragine &avg, double min_cos, bool is_low_charge, bool is_profile=false, int allowed_iso_error=1)
Update setQscore. Cosine and SNRs are also updated.
double getQscore() const
get Q score
PeakGroup(const PeakGroup &)=default
copy constructor
std::vector< FLASHDeconvHelperStructs::LogMzPeak >::const_iterator begin() const noexcept
iterators for the signal LogMz peaks in this PeakGroup
float getIsotopeCosine() const
get isotopic cosine score
void setFeatureIndex(uint findex)
set feature index
PeakGroup & operator=(const PeakGroup &t)=default
assignment operator
void setRepAbsCharge(int max_snr_abs_charge)
set representative max_snr_abs_charge
void setScanNumber(int scan_number)
set scan number
PeakGroup(PeakGroup &&other)=default
move constructor
void setIndex(uint i)
set index of this peak group
void setQscore(double qscore)
set Q score - for FLASHIda log file parsing
double getIsotopeDaDistance() const
get distance between consecutive isotopes
void setChargeScore(float charge_score)
set charge score - for FLASHIda log file parsing
Matrix< float > getDLMatrix(int index) const
get the calcualted DL matrix
const std::vector< float > & getIsotopeIntensities() const
get per isotope intensities
bool operator==(const PeakGroup &a) const
PeakGroup::TargetDecoyType getTargetDecoyType() const
get the target decoy type of this
bool isSignalMZ(double mz, double tol) const
determine is an mz is a signal of this peakgroup. Input tol is ppm tolerance (e.g....
void updateMonoMassAndIsotopeIntensities()
add monoisotopic indices of peaks by offset and discard negative isotope peaks. Total intensity is al...
double getMonoMass() const
get monoisotopic mass
bool isPositive() const
get if it is positive mode
std::tuple< double, double > getRepMzRange() const
get mz range that results in max setQscore
TargetDecoyType
target decoy type of PeakGroup. This specifies if a PeakGroup is a target (0), charge decoy (1),...
Definition: PeakGroup.h:33
@ charge_decoy
Definition: PeakGroup.h:35
@ noise_decoy
Definition: PeakGroup.h:36
@ isotope_decoy
Definition: PeakGroup.h:37
FLASHDeconvHelperStructs::PrecalculatedAveragine PrecalculatedAveragine
Definition: PeakGroup.h:28
double getQscore2D() const
get feature Q score
void calculateDLMatrices(const MSSpectrum &spec, double tol, const PrecalculatedAveragine &avg)
calculate the matrices for DL training and scoring
int getIsotopeRangeForDL()
Definition: PeakGroup.h:246
float getAvgPPMError() const
get average mass ppm error;
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
const double ISOTOPE_MASSDIFF_55K_U
Definition: Constants.h:100
FLASHIda C++ to C# (or vice versa) bridge functions The functions here are called in C# to invoke fun...
Definition: FeatureDeconvolution.h:22
static FLASHDeconvHelperStructs::PrecalculatedAveragine avg
keeps the precalculated averagine to calculate average masses from monoisotopic masses
Definition: FLASHIdaBridgeFunctions.h:85
Wrapper struct for all the structs needed by the FLASHDeconv Three structures are defined: Precalcula...
Definition: FLASHDeconvHelperStructs.h:30