OpenMS
SpectralDeconvolution.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: Kyowon Jeong, Jihyung Kim $
6 // $Authors: Kyowon Jeong, Jihyung Kim $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
18 #include <boost/dynamic_bitset.hpp>
19 #include <iostream>
20 
21 namespace OpenMS
22 {
33  class OPENMS_DLLAPI SpectralDeconvolution : public DefaultParamHandler
34  {
35  public:
38 
41 
44 
47 
50 
53 
56 
63  void performSpectrumDeconvolution(const MSSpectrum& spec, int scan_number, const PeakGroup& precursor_peak_group);
64 
67 
70 
73 
78  void setTargetMasses(const std::vector<double>& masses, bool exclude = false);
79 
83  void calculateAveragine(bool use_RNA_averagine);
84 
87  {
88  max_mass_dalton_tolerance_ = 100;
89  }
90 
92  static int getNominalMass(double mass);
93 
102  static float getCosine(const std::vector<float>& a, int a_start, int a_end, const IsotopeDistribution& b, int offset, int min_iso_len);
103 
104 
115  static float getIsotopeCosineAndIsoOffset(double mono_mass, const std::vector<float>& per_isotope_intensities, int& offset,
116  const PrecalculatedAveragine& avg, int iso_int_shift,
117  int window_width, const std::vector<double>& excluded_masses);
118 
124  void setTargetDecoyType(PeakGroup::TargetDecoyType target_decoy_type, const DeconvolvedSpectrum& target_dspec_for_decoy_calcualtion);
125 
127  const static int min_iso_size = 2;
128 
129  protected:
130  void updateMembers_() override;
131 
132  private:
134 
136  int allowed_iso_error_ = -1;
137 
139  int min_abs_charge_, max_abs_charge_;
143  double min_mass_, max_mass_;
151  double noise_iso_delta_ = .9444;
153  const static int min_support_peak_count_ = 2;
163  double min_qscore_ = .2;
164 
167 
169  PeakGroup::TargetDecoyType target_decoy_type_ = PeakGroup::TargetDecoyType::target;
170 
173 
175  boost::dynamic_bitset<> target_mass_bins_;
176  std::vector<double> target_mono_masses_;
177 
179  std::vector<double> excluded_masses_;
180 
182  boost::dynamic_bitset<> excluded_mass_bins_for_decoy_runs_;
184  std::vector<double> excluded_masses_for_decoy_runs_;
185 
187  std::vector<LogMzPeak> log_mz_peaks_;
191  boost::dynamic_bitset<> binned_log_masses_;
193  boost::dynamic_bitset<> binned_log_mz_peaks_;
194 
196  std::vector<double> universal_pattern_;
199 
201  std::vector<int> binned_universal_pattern_;
204 
208 
210  uint ms_level_;
211 
214 
216  int target_precursor_charge_ = 0;
217  double target_precursor_mz_ = 0;
218 
220  double max_mass_dalton_tolerance_ = .16;
221 
228  static double getBinValue_(Size bin, double min_value, double bin_mul_factor);
229 
236  static Size getBinNumber_(double value, double min_value, double bin_mul_factor);
237 
240 
245  void binLogMzPeaks_(Size bin_number, std::vector<float>& binned_log_mz_peak_intensities);
246 
248  double getMassFromMassBin_(Size mass_bin, double bin_mul_factor) const;
249 
251  double getMzFromMzBin_(Size mass_bin, double bin_mul_factor) const;
252 
255 
257  static void removeOverlappingPeakGroups_(DeconvolvedSpectrum& dspec, double tol, PeakGroup::TargetDecoyType target_decoy_type = PeakGroup::TargetDecoyType::target);
258 
263  Matrix<int> updateMassBins_(const std::vector<float>& mz_intensities);
264 
269  Matrix<int> filterMassBins_(const std::vector<float>& mass_intensities);
270 
275  void updateCandidateMassBins_(std::vector<float>& mass_intensities, const std::vector<float>& mz_intensities);
276 
280  void getCandidatePeakGroups_(const Matrix<int>& per_mass_abs_charge_ranges);
281 
283  void setFilters_();
284 
287 
290 
292  void removeExcludedMasses_(DeconvolvedSpectrum& dspec, std::vector<double> excluded_masses, double tol) const;
293 
295 
298 
301 
303  void registerPrecursorForMSn_(const PeakGroup& precursor_peak_group);
304 
305  bool isPeakGroupInExcludedMassForDecoyRuns_(const PeakGroup& peak_group, double tol, int offset = 0) const;
306  };
307 } // namespace OpenMS
A class representing a deconvolved spectrum. DeconvolvedSpectrum consists of PeakGroup instances repr...
Definition: DeconvolvedSpectrum.h:30
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
log transformed peak. After deconvolution, all necessary information from deconvolution such as charg...
Definition: FLASHHelperClasses.h:187
Averagine patterns pre-calculated for speed up. Other variables are also calculated for fast cosine c...
Definition: FLASHHelperClasses.h:39
Definition: IsotopeDistribution.h:39
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
TargetDecoyType
Definition: PeakGroup.h:34
FLASHDeconv algorithm: ultrafast mass deconvolution algorithm for top down mass spectrometry dataset ...
Definition: SpectralDeconvolution.h:34
const DeconvolvedSpectrum * target_dspec_for_decoy_calculation_
the peak group vector from normal run. This is used when dummy masses are generated.
Definition: SpectralDeconvolution.h:166
std::vector< double > excluded_masses_
mass bins that are excluded for FLASHIda global targeting mode
Definition: SpectralDeconvolution.h:179
DeconvolvedSpectrum & getDeconvolvedSpectrum()
return deconvolved spectrum
const PrecalculatedAveragine & getAveragine()
get calculated averagine. Call after calculateAveragine is called.
FLASHHelperClasses::PrecalculatedAveragine PrecalculatedAveragine
Definition: SpectralDeconvolution.h:36
FLASHHelperClasses::PrecalculatedAveragine avg_
precalculated averagine distributions for fast averagine generation
Definition: SpectralDeconvolution.h:172
double getMassFromMassBin_(Size mass_bin, double bin_mul_factor) const
get mass value for input mass bin: used for debugging
Matrix< int > updateMassBins_(const std::vector< float > &mz_intensities)
Update binned_log_masses_. It select candidate mass bins using the universal pattern,...
void removeExcludedMasses_(DeconvolvedSpectrum &dspec, std::vector< double > excluded_masses, double tol) const
filter out excluded masses
bool isPeakGroupInExcludedMassForDecoyRuns_(const PeakGroup &peak_group, double tol, int offset=0) const
void prepareNoiseDecoySpectrum_(const MSSpectrum &spec)
prepare noise decoy spectrum by filtering signal peaks
void updateLogMzPeaks_()
generate log mz peaks from the input spectrum
DeconvolvedSpectrum deconvolved_spectrum_
selected_peak_groups_ stores the deconvolved mass peak groups
Definition: SpectralDeconvolution.h:189
double current_max_mass_
max mass is controlled by precursor mass for MSn n>1; otherwise just max_mass
Definition: SpectralDeconvolution.h:147
static double getBinValue_(Size bin, double min_value, double bin_mul_factor)
static function that converts bin to value
bool is_positive_
is positive mode
Definition: SpectralDeconvolution.h:141
void updateCandidateMassBins_(std::vector< float > &mass_intensities, const std::vector< float > &mz_intensities)
Subfunction of updateMassBins_. It select candidate masses and update binned_log_masses_ using the un...
void removeChargeErrorPeakGroups_(DeconvolvedSpectrum &dspec, const PeakGroup::TargetDecoyType &target_decoy_type) const
filter out charge error masses
std::vector< double > excluded_masses_for_decoy_runs_
Definition: SpectralDeconvolution.h:184
Matrix< int > binned_harmonic_patterns
This stores the patterns for harmonic reduction in binned dimension.
Definition: SpectralDeconvolution.h:203
void registerPrecursorForMSn_(const PeakGroup &precursor_peak_group)
register precursor information for MSn spectra (n > 1)
static int getNominalMass(double mass)
convert double to nominal mass
DoubleList bin_mul_factors_
bin multiplication factor (log mz * bin_mul_factors_ = bin number) - for fast convolution,...
Definition: SpectralDeconvolution.h:157
SpectralDeconvolution & operator=(SpectralDeconvolution &&fd)=default
move assignment operator
~SpectralDeconvolution()=default
destructor
boost::dynamic_bitset target_mass_bins_
mass bins that are targeted for FLASHIda global targeting mode
Definition: SpectralDeconvolution.h:175
static float getIsotopeCosineAndIsoOffset(double mono_mass, const std::vector< float > &per_isotope_intensities, int &offset, const PrecalculatedAveragine &avg, int iso_int_shift, int window_width, const std::vector< double > &excluded_masses)
Examine intensity distribution over isotope indices. Also determines the most plausible isotope index...
Matrix< int > filterMassBins_(const std::vector< float > &mass_intensities)
Subfunction of updateMassBins_.
uint ms_level_
current ms Level
Definition: SpectralDeconvolution.h:210
double getMzFromMzBin_(Size mass_bin, double bin_mul_factor) const
get mz value for input mz bin: used for debugging
void setToleranceEstimation()
when estimating tolerance, max_mass_dalton_tolerance_ should be large
Definition: SpectralDeconvolution.h:86
SpectralDeconvolution & operator=(const SpectralDeconvolution &fd)=default
assignment operator
double mass_bin_min_value_
minimum mass and mz values representing the first bin of massBin and mzBin, respectively: to save mem...
Definition: SpectralDeconvolution.h:206
int current_max_charge_
current_max_charge_: controlled by precursor charge for MSn n>1; otherwise just max_abs_charge_
Definition: SpectralDeconvolution.h:145
double max_mass_
Definition: SpectralDeconvolution.h:143
void setAveragine(const PrecalculatedAveragine &avg)
set calculated averagine
boost::dynamic_bitset binned_log_masses_
binned_log_masses_ stores the selected bins for this spectrum + overlapped spectrum (previous a few s...
Definition: SpectralDeconvolution.h:191
std::vector< double > excluded_peak_masses_for_decoy_runs_
Definition: SpectralDeconvolution.h:183
std::vector< double > universal_pattern_
This stores the "universal pattern".
Definition: SpectralDeconvolution.h:196
std::vector< int > binned_universal_pattern_
This stores the "universal pattern" in binned dimension.
Definition: SpectralDeconvolution.h:201
DoubleList min_isotope_cosine_
Isotope cosine threshold for each MS level.
Definition: SpectralDeconvolution.h:159
FLASHHelperClasses::LogMzPeak LogMzPeak
Definition: SpectralDeconvolution.h:37
void calculateAveragine(bool use_RNA_averagine)
precalculate averagine (for predefined mass bins) to speed up averagine generation
void setTargetMasses(const std::vector< double > &masses, bool exclude=false)
set targeted or excluded masses for targeted deconvolution. Masses are targeted or excluded in all ms...
void performSpectrumDeconvolution(const MSSpectrum &spec, int scan_number, const PeakGroup &precursor_peak_group)
main deconvolution function that generates the deconvolved target and dummy spectrum based on the ori...
DoubleList min_snr_
snr threshold for each MS level
Definition: SpectralDeconvolution.h:161
boost::dynamic_bitset excluded_mass_bins_for_decoy_runs_
mass bins that are previously deconvolved and excluded for decoy mass generation
Definition: SpectralDeconvolution.h:182
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
void setTargetDecoyType(PeakGroup::TargetDecoyType target_decoy_type, const DeconvolvedSpectrum &target_dspec_for_decoy_calcualtion)
static void removeOverlappingPeakGroups_(DeconvolvedSpectrum &dspec, double tol, PeakGroup::TargetDecoyType target_decoy_type=PeakGroup::TargetDecoyType::target)
filter out overlapping masses
double iso_da_distance_
isotope dalton distance
Definition: SpectralDeconvolution.h:213
static float getCosine(const std::vector< float > &a, int a_start, int a_end, const IsotopeDistribution &b, int offset, int min_iso_len)
boost::dynamic_bitset binned_log_mz_peaks_
binned_log_mz_peaks_ stores the binned log mz peaks
Definition: SpectralDeconvolution.h:193
void prepareSignalDecoyExclusions_()
prepare signal decoy exclusions for decoy runs
SpectralDeconvolution(SpectralDeconvolution &&other)=default
move constructor
SpectralDeconvolution(const SpectralDeconvolution &)=default
copy constructor
std::vector< LogMzPeak > log_mz_peaks_
Stores log mz peaks.
Definition: SpectralDeconvolution.h:187
static Size getBinNumber_(double value, double min_value, double bin_mul_factor)
static function that converts value to bin
double current_min_mass_
max mass is max_mass for MS1 and 50 for MS2
Definition: SpectralDeconvolution.h:149
std::vector< double > target_mono_masses_
Definition: SpectralDeconvolution.h:176
void scoreAndFilterPeakGroups_()
function for peak group scoring and filtering
void binLogMzPeaks_(Size bin_number, std::vector< float > &binned_log_mz_peak_intensities)
generate mz bins and intensity per mz bin from log mz peaks
double mz_bin_min_value_
Definition: SpectralDeconvolution.h:207
DoubleList tolerance_
tolerance in ppm for each MS level
Definition: SpectralDeconvolution.h:155
void setFilters_()
Make the universal pattern.
void generatePeakGroupsFromSpectrum_()
Generate peak groups from the input spectrum.
SpectralDeconvolution()
default constructor
void getCandidatePeakGroups_(const Matrix< int > &per_mass_abs_charge_ranges)
For selected masses in binned_log_masses_, select the peaks from the original spectrum....
int max_abs_charge_
Definition: SpectralDeconvolution.h:139
Matrix< double > harmonic_pattern_matrix_
This stores the patterns for harmonic reduction.
Definition: SpectralDeconvolution.h:198
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:36
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19