OpenMS
SpectralDeconvolution.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 
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 
43 
46 
49 
52 
55 
62  void performSpectrumDeconvolution(const MSSpectrum& spec, int scan_number, const PeakGroup& precursor_peak_group);
63 
66 
69 
72 
76  void setTargetMasses(const std::vector<double>& masses, bool exclude = false);
77 
81  void calculateAveragine(bool use_RNA_averagine);
82 
84  static int getNominalMass(double mass);
85 
94  static float getCosine(const std::vector<float>& a, int a_start, int a_end, const IsotopeDistribution& b, int offset, int min_iso_size, bool decoy = false);
95 
96 
109  static float getIsotopeCosineAndDetermineIsotopeIndex(double mono_mass, const std::vector<float>& per_isotope_intensities, int& offset, const PrecalculatedAveragine& avg, int iso_int_shift = 0,
110  int window_width = -1, int allowed_iso_error_for_second_best_cos = 0,
111  PeakGroup::TargetDecoyType target_decoy_type = PeakGroup::TargetDecoyType::target);
112 
118  void setTargetDecoyType(PeakGroup::TargetDecoyType target_decoy_type, const DeconvolvedSpectrum& target_dspec_for_decoy_calcualtion);
119 
121  static void removeOverlappingPeakGroups(DeconvolvedSpectrum& dspec, double tol, PeakGroup::TargetDecoyType target_decoy_type = PeakGroup::TargetDecoyType::target);
122 
123  protected:
124  void updateMembers_() override;
125 
126  private:
128 
130  const static int min_iso_size_ = 2;
131 
133  int allowed_iso_error_ = 1;
134 
136  int min_abs_charge_, max_abs_charge_;
140  double min_mass_, max_mass_;
148  const static int min_support_peak_count_ = 2;
161 
163  PeakGroup::TargetDecoyType target_decoy_type_ = PeakGroup::TargetDecoyType::target;
164 
167 
169  boost::dynamic_bitset<> target_mass_bins_;
170  std::vector<double> target_mono_masses_;
171 
173  std::vector<double> excluded_masses_;
174 
178 
180  std::vector<LogMzPeak> log_mz_peaks_;
184  boost::dynamic_bitset<> mass_bins_;
186  boost::dynamic_bitset<> mz_bins_;
187 
189  std::vector<double> filter_;
192 
195 
197  std::vector<int> bin_offsets_;
200 
204 
206  uint ms_level_;
207 
208  int target_precursor_charge_ = 0;
209  double target_precursor_mz_ = 0;
210 
217  static double getBinValue_(Size bin, double min_value, double bin_mul_factor);
218 
225  static Size getBinNumber_(double value, double min_value, double bin_mul_factor);
226 
229 
234  void updateMzBins_(Size bin_number, std::vector<float>& mz_bin_intensities);
235 
236 
238  double getMassFromMassBin_(Size mass_bin, double bin_mul_factor) const;
239 
241  double getMzFromMzBin_(Size mass_bin, double bin_mul_factor) const;
242 
245 
250  Matrix<int> updateMassBins_(const std::vector<float>& mz_intensities);
251 
256  Matrix<int> filterMassBins_(const std::vector<float>& mass_intensities);
257 
262  void updateCandidateMassBins_(std::vector<float>& mass_intensities, const std::vector<float>& mz_intensities);
263 
267  void getCandidatePeakGroups_(const Matrix<int>& per_mass_abs_charge_ranges);
268 
270  void setFilters_();
271 
274 
277 
280 
282 
283  };
284 } // namespace OpenMS
A class representing a deconvolved spectrum. DeconvolvedSpectrum consists of PeakGroups representing ...
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: FLASHDeconvHelperStructs.h:166
Averagine patterns pre-calculated for speed up. Other variables are also calculated for fast cosine c...
Definition: FLASHDeconvHelperStructs.h:33
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
target decoy type of PeakGroup. This specifies if a PeakGroup is a target (0), charge decoy (1),...
Definition: PeakGroup.h:33
FLASHDeconv algorithm: ultrafast mass deconvolution algorithm for top down mass spectrometry dataset ...
Definition: SpectralDeconvolution.h:34
std::vector< double > excluded_masses_
mass bins that are excluded for FLASHIda global targeting mode
Definition: SpectralDeconvolution.h:173
DeconvolvedSpectrum & getDeconvolvedSpectrum()
return deconvolved spectrum
const PrecalculatedAveragine & getAveragine()
get calculated averagine. Call after calculateAveragine is called.
double getMassFromMassBin_(Size mass_bin, double bin_mul_factor) const
get mass value for input mass bin
std::vector< double > filter_
This stores the "universal pattern".
Definition: SpectralDeconvolution.h:189
Matrix< int > updateMassBins_(const std::vector< float > &mz_intensities)
Update mass_bins_. It select candidate mass bins using the universal pattern, eliminate possible harm...
void removeExcludedMasses_(DeconvolvedSpectrum &dspec) const
filter out excluded masses
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:182
double current_max_mass_
max mass is controlled by precursor mass for MSn n>1; otherwise just max_mass
Definition: SpectralDeconvolution.h:144
static double getBinValue_(Size bin, double min_value, double bin_mul_factor)
static function that converts bin to value
FLASHDeconvHelperStructs::LogMzPeak LogMzPeak
Definition: SpectralDeconvolution.h:37
bool is_positive_
is positive mode
Definition: SpectralDeconvolution.h:138
void updateCandidateMassBins_(std::vector< float > &mass_intensities, const std::vector< float > &mz_intensities)
Subfunction of updateMassBins_. It select candidate masses and update mass_bins_ using the universal ...
void removeChargeErrorPeakGroups_(DeconvolvedSpectrum &dspec, const PeakGroup::TargetDecoyType &target_decoy_type) const
filter out charge error masses
std::vector< double > previously_deconved_mono_masses_for_decoy_
Definition: SpectralDeconvolution.h:177
DoubleList max_qvalue_
Q value threshold for each MS level.
Definition: SpectralDeconvolution.h:158
void updateMzBins_(Size bin_number, std::vector< float > &mz_bin_intensities)
generate mz bins and intensity per mz bin from log mz peaks
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:152
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:169
const DeconvolvedSpectrum * target_dspec_for_decoy_calcualtion_
the peak group vector from normal run. This is used when dummy masses are generated.
Definition: SpectralDeconvolution.h:160
FLASHDeconvHelperStructs::PrecalculatedAveragine avg_
precalculated averagine distributions for fast averagine generation
Definition: SpectralDeconvolution.h:166
Matrix< int > filterMassBins_(const std::vector< float > &mass_intensities)
Subfunction of updateMassBins_.
uint ms_level_
current ms Level
Definition: SpectralDeconvolution.h:206
double getMzFromMzBin_(Size mass_bin, double bin_mul_factor) const
get mz value for input mz bin
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:202
boost::dynamic_bitset previously_deconved_mass_bins_for_decoy_
mass bins that are previsouly deconvolved and excluded for dummy mass generation
Definition: SpectralDeconvolution.h:176
int current_max_charge_
current_max_charge_: controlled by precursor charge for MSn n>1; otherwise just max_abs_charge_
Definition: SpectralDeconvolution.h:142
double max_mass_
Definition: SpectralDeconvolution.h:140
void setAveragine(const PrecalculatedAveragine &avg)
set calculated averagine
DoubleList min_isotope_cosine_
Isotope cosine threshold for each MS level.
Definition: SpectralDeconvolution.h:154
Matrix< int > harmonic_bin_offset_matrix_
This stores the patterns for harmonic reduction in binned dimension.
Definition: SpectralDeconvolution.h:199
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:156
static float getCosine(const std::vector< float > &a, int a_start, int a_end, const IsotopeDistribution &b, int offset, int min_iso_size, bool decoy=false)
boost::dynamic_bitset mass_bins_
mass_bins_ stores the selected bins for this spectrum + overlapped spectrum (previous a few spectra).
Definition: SpectralDeconvolution.h:184
std::vector< int > bin_offsets_
This stores the "universal pattern" in binned dimension.
Definition: SpectralDeconvolution.h:197
static void removeOverlappingPeakGroups(DeconvolvedSpectrum &dspec, double tol, PeakGroup::TargetDecoyType target_decoy_type=PeakGroup::TargetDecoyType::target)
filter out overlapping masses
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)
Matrix< double > harmonic_filter_matrix_
This stores the patterns for harmonic reduction.
Definition: SpectralDeconvolution.h:191
double iso_da_distance_
isotope dalton distance
Definition: SpectralDeconvolution.h:194
static float getIsotopeCosineAndDetermineIsotopeIndex(double mono_mass, const std::vector< float > &per_isotope_intensities, int &offset, const PrecalculatedAveragine &avg, int iso_int_shift=0, int window_width=-1, int allowed_iso_error_for_second_best_cos=0, PeakGroup::TargetDecoyType target_decoy_type=PeakGroup::TargetDecoyType::target)
Examine intensity distribution over isotope indices. Also determines the most plausible isotope index...
SpectralDeconvolution(SpectralDeconvolution &&other)=default
copy constructor
boost::dynamic_bitset mz_bins_
mz_bins_ stores the binned log mz peaks
Definition: SpectralDeconvolution.h:186
std::vector< LogMzPeak > log_mz_peaks_
Stores log mz peaks.
Definition: SpectralDeconvolution.h:180
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:146
std::vector< double > target_mono_masses_
Definition: SpectralDeconvolution.h:170
void scoreAndFilterPeakGroups_()
function for peak group scoring and filtering
double mz_bin_min_value_
Definition: SpectralDeconvolution.h:203
FLASHDeconvHelperStructs::PrecalculatedAveragine PrecalculatedAveragine
Definition: SpectralDeconvolution.h:36
DoubleList tolerance_
tolerance in ppm for each MS level
Definition: SpectralDeconvolution.h:150
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 mass_bins_, select the peaks from the original spectrum. Also isotopic peaks a...
int max_abs_charge_
Definition: SpectralDeconvolution.h:136
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:36
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