OpenMS  2.9.1
FLASHDeconvAlgorithm.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2022.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Kyowon Jeong, Jihyung Kim $
32 // $Authors: Kyowon Jeong, Jihyung Kim $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
44 
45 #include <boost/dynamic_bitset.hpp>
46 #include <iostream>
47 
48 namespace OpenMS
49 {
60  class OPENMS_DLLAPI FLASHDeconvAlgorithm :
61  public DefaultParamHandler
62  {
63  public:
66 
69 
72 
75 
78 
81 
83  ~FLASHDeconvAlgorithm() = default;
84 
93  const std::vector<DeconvolvedSpectrum>& survey_scans,
94  int scan_number,
95  const std::map<int, std::vector<std::vector<float>>>& precursor_map_for_FLASHIda);
96 
99 
102 
105 
109  void setTargetMasses(const std::vector<double>& masses, bool exclude = false);
110 
114  void calculateAveragine(bool use_RNA_averagine);
115 
117  static int getNominalMass(double mass);
118 
128  static float getCosine(const std::vector<float>& a,
129  int a_start,
130  int a_end,
131  const IsotopeDistribution& b,
132  int b_size,
133  int offset,
134  int min_iso_size);
135 
136 
147  static float getIsotopeCosineAndDetermineIsotopeIndex(double mono_mass,
148  const std::vector<float>& per_isotope_intensities,
149  int& offset,
150  const PrecalculatedAveragine& avg,
151  int window_width = -1, int allowed_iso_error_for_second_best_cos = 0, PeakGroup::DecoyFlag decoyFlag = PeakGroup::DecoyFlag::target);
152 
155 
156  protected:
157  void updateMembers_() override;
158 
159  private:
161 
163  const static int min_iso_size_ = 2;
164 
166  int allowed_iso_error_ = 1;
167 
169  double min_rt_, max_rt_;
171  double min_mz_, max_mz_;
173  int min_abs_charge_, max_abs_charge_;
177  double min_mass_, max_mass_;
187  const static int min_support_peak_count_ = 2;
194 
196 
198  PeakGroup::DecoyFlag decoy_flag_ = PeakGroup::DecoyFlag::target;
199 
202 
204  boost::dynamic_bitset<> target_mass_bins_;
205  std::vector<double> target_mono_masses_;
206 
208  std::vector<double> excluded_masses_;
209 
213  std::unordered_set<int> excluded_integer_mzs_;
214 
216  std::vector<LogMzPeak> log_mz_peaks_;
220  boost::dynamic_bitset<> mass_bins_;
222  boost::dynamic_bitset<> mz_bins_;
223 
225  std::vector<double> filter_;
228 
231 
233  std::vector<int> bin_offsets_;
236 
240 
242  uint ms_level_;
243 
244 
247 
254  static double getBinValue_(Size bin, double min_value, double bin_width);
255 
262  static Size getBinNumber_(double value, double min_value, double bin_width);
263 
266 
271  void updateMzBins_(Size bin_number, std::vector<float>& mz_bin_intensities);
272 
273 
275  double getMassFromMassBin_(Size mass_bin, double bin_width) const;
276 
278  double getMzFromMzBin_(Size mass_bin, double bin_width) const;
279 
282 
287  Matrix<int> updateMassBins_(const std::vector<float>& mz_intensities);
288 
293  Matrix<int> filterMassBins_(const std::vector<float>& mass_intensities);
294 
299  void updateCandidateMassBins_(std::vector<float>& mass_intensities, const std::vector<float>& mz_intensities);
300 
304  void getCandidatePeakGroups_(const Matrix<int>& per_mass_abs_charge_ranges);
305 
307  void setFilters_();
308 
311 
314 
317 
326  bool registerPrecursor_(const std::vector<DeconvolvedSpectrum>& survey_scans,
327  const std::map<int, std::vector<std::vector<float>>>& precursor_map_for_real_time_acquisition);
328 
329  };
330 }
A class representing a deconvolved spectrum. DeconvolvedSpectrum consists of PeakGroups representing ...
Definition: DeconvolvedSpectrum.h:57
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:93
FLASHDeconv algorithm: ultrafast mass deconvolution algorithm for top down mass spectrometry dataset ...
Definition: FLASHDeconvAlgorithm.h:62
std::vector< double > excluded_masses_
mass bins that are excluded for FLASHIda global targeting mode
Definition: FLASHDeconvAlgorithm.h:208
DeconvolvedSpectrum & getDeconvolvedSpectrum()
return deconvolved spectrum
FLASHDeconvAlgorithm()
default constructor
const PrecalculatedAveragine & getAveragine()
get calculated averagine. Call after calculateAveragine is called.
std::vector< double > filter_
This stores the "universal pattern".
Definition: FLASHDeconvAlgorithm.h:225
static float getIsotopeCosineAndDetermineIsotopeIndex(double mono_mass, const std::vector< float > &per_isotope_intensities, int &offset, const PrecalculatedAveragine &avg, int window_width=-1, int allowed_iso_error_for_second_best_cos=0, PeakGroup::DecoyFlag decoyFlag=PeakGroup::DecoyFlag::target)
Examine intensity distribution over isotope indices. Also determines the most plausible isotope index...
Matrix< int > updateMassBins_(const std::vector< float > &mz_intensities)
Update mass_bins_. It select candidate mass bins using the universal pattern, eliminate possible harm...
boost::dynamic_bitset previously_deconved_mass_bins_for_decoy
mass bins that are previsouly deconvolved and excluded for decoy mass generation
Definition: FLASHDeconvAlgorithm.h:211
void updateLogMzPeaks_()
generate log mz peaks from the input spectrum
DeconvolvedSpectrum deconvolved_spectrum_
deconvolved_spectrum_ stores the deconvolved mass peak groups
Definition: FLASHDeconvAlgorithm.h:218
void setDecoyFlag(PeakGroup::DecoyFlag flag, FLASHDeconvAlgorithm &targetFD)
set decoy_flag_
~FLASHDeconvAlgorithm()=default
destructor
double max_mz_
Definition: FLASHDeconvAlgorithm.h:171
double current_max_mass_
max mass is controlled by precursor mass for MSn n>1; otherwise just max_mass
Definition: FLASHDeconvAlgorithm.h:181
FLASHDeconvHelperStructs::LogMzPeak LogMzPeak
Definition: FLASHDeconvAlgorithm.h:65
bool is_positive_
is positive mode
Definition: FLASHDeconvAlgorithm.h:175
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 updateMzBins_(Size bin_number, std::vector< float > &mz_bin_intensities)
generate mz bins and intensity per mz bin from log mz peaks
std::unordered_set< int > excluded_integer_mzs_
Definition: FLASHDeconvAlgorithm.h:213
static int getNominalMass(double mass)
convert double to nominal mass
FLASHDeconvAlgorithm(FLASHDeconvAlgorithm &&other)=default
move constructor
boost::dynamic_bitset target_mass_bins_
mass bins that are targeted for FLASHIda global targeting mode
Definition: FLASHDeconvAlgorithm.h:204
FLASHDeconvHelperStructs::PrecalculatedAveragine avg_
precalculated averagine distributions for fast averagine generation
Definition: FLASHDeconvAlgorithm.h:201
Matrix< int > filterMassBins_(const std::vector< float > &mass_intensities)
Subfunction of updateMassBins_.
std::vector< double > previously_deconved_mono_masses_for_decoy
Definition: FLASHDeconvAlgorithm.h:212
uint ms_level_
current ms Level
Definition: FLASHDeconvAlgorithm.h:242
static double getBinValue_(Size bin, double min_value, double bin_width)
static function that converts bin to value
double mass_bin_min_value_
minimum mass and mz values representing the first bin of massBin and mzBin, respectively: to save mem...
Definition: FLASHDeconvAlgorithm.h:238
int current_max_charge_
current_max_charge_: controlled by precursor charge for MSn n>1; otherwise just max_abs_charge_
Definition: FLASHDeconvAlgorithm.h:179
double max_mass_
Definition: FLASHDeconvAlgorithm.h:177
void setAveragine(const PrecalculatedAveragine &avg)
set calculated averagine
FLASHDeconvAlgorithm(const FLASHDeconvAlgorithm &)=default
copy constructor
double max_rt_
Definition: FLASHDeconvAlgorithm.h:169
FLASHDeconvAlgorithm * targetFD_
Definition: FLASHDeconvAlgorithm.h:195
double getMzFromMzBin_(Size mass_bin, double bin_width) const
get mz value for input mz bin
DoubleList bin_width_
bin size for first stage of mass selection - for fast convolution, binning is used
Definition: FLASHDeconvAlgorithm.h:191
FLASHDeconvAlgorithm & operator=(const FLASHDeconvAlgorithm &fd)=default
assignment operator
double isolation_window_size_
default precursor isolation window size.
Definition: FLASHDeconvAlgorithm.h:246
void removeChargeErrorPeakGroups_(DeconvolvedSpectrum &dspec)
filter out charge error masses
DoubleList min_isotope_cosine_
cosine threshold between observed and theoretical isotope patterns for each MS level
Definition: FLASHDeconvAlgorithm.h:193
Matrix< int > harmonic_bin_offset_matrix_
This stores the patterns for harmonic reduction in binned dimension.
Definition: FLASHDeconvAlgorithm.h:235
static Size getBinNumber_(double value, double min_value, double bin_width)
static function that converts value to bin
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...
static float getCosine(const std::vector< float > &a, int a_start, int a_end, const IsotopeDistribution &b, int b_size, int offset, int min_iso_size)
double intensity_threshold_
peak intensity threshold subject to analysis
Definition: FLASHDeconvAlgorithm.h:185
boost::dynamic_bitset mass_bins_
mass_bins_ stores the selected bins for this spectrum + overlapped spectrum (previous a few spectra).
Definition: FLASHDeconvAlgorithm.h:220
std::vector< int > bin_offsets_
This stores the "universal pattern" in binned dimension.
Definition: FLASHDeconvAlgorithm.h:233
bool registerPrecursor_(const std::vector< DeconvolvedSpectrum > &survey_scans, const std::map< int, std::vector< std::vector< float >>> &precursor_map_for_real_time_acquisition)
register the precursor peak as well as the precursor peak group (or mass) if possible for MSn (n>1) s...
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
void performSpectrumDeconvolution(const MSSpectrum &spec, const std::vector< DeconvolvedSpectrum > &survey_scans, int scan_number, const std::map< int, std::vector< std::vector< float >>> &precursor_map_for_FLASHIda)
main deconvolution function that generates the deconvolved target and decoy spectrum based on the ori...
Matrix< double > harmonic_filter_matrix_
This stores the patterns for harmonic reduction.
Definition: FLASHDeconvAlgorithm.h:227
double iso_da_distance_
isotope dalton distance
Definition: FLASHDeconvAlgorithm.h:230
boost::dynamic_bitset mz_bins_
mz_bins_ stores the binned log mz peaks
Definition: FLASHDeconvAlgorithm.h:222
double getMassFromMassBin_(Size mass_bin, double bin_width) const
get mass value for input mass bin
std::vector< LogMzPeak > log_mz_peaks_
Stores log mz peaks.
Definition: FLASHDeconvAlgorithm.h:216
double current_min_mass_
max mass is max_mass for MS1 and 50 for MS2
Definition: FLASHDeconvAlgorithm.h:183
std::vector< double > target_mono_masses_
Definition: FLASHDeconvAlgorithm.h:205
void scoreAndFilterPeakGroups_()
function for peak group scoring and filtering
double mz_bin_min_value_
Definition: FLASHDeconvAlgorithm.h:239
FLASHDeconvHelperStructs::PrecalculatedAveragine PrecalculatedAveragine
Definition: FLASHDeconvAlgorithm.h:64
DoubleList tolerance_
tolerance in ppm for each MS level
Definition: FLASHDeconvAlgorithm.h:189
static void removeOverlappingPeakGroups_(DeconvolvedSpectrum &dspec)
filter out overlapping masses
void setFilters_()
Make the universal pattern.
FLASHDeconvAlgorithm & operator=(FLASHDeconvAlgorithm &&fd)=default
move assignment operator
void generatePeakGroupsFromSpectrum_()
Generate peak groups from the input spectrum.
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: FLASHDeconvAlgorithm.h:173
log transformed peak. After deconvolution, all necessary information from deconvolution such as charg...
Definition: FLASHDeconvHelperStructs.h:165
Averagine patterns pre-calculated for speed up. Other variables are also calculated for fast cosine c...
Definition: FLASHDeconvHelperStructs.h:60
Definition: IsotopeDistribution.h:65
The representation of a 1D spectrum.
Definition: MSSpectrum.h:70
DecoyFlag
decoy flag. This flag specifies if a PeakGroup is a target, charge decoy, noise decoy,...
Definition: PeakGroup.h:59
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:62
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48