OpenMS
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 #include <boost/dynamic_bitset.hpp>
45 #include <iostream>
46 
47 namespace OpenMS
48 {
59  class OPENMS_DLLAPI FLASHDeconvAlgorithm : public DefaultParamHandler
60  {
61  public:
64 
67 
70 
72  FLASHDeconvAlgorithm(FLASHDeconvAlgorithm&& other) = default;
73 
75  FLASHDeconvAlgorithm& operator=(const FLASHDeconvAlgorithm& fd) = default;
76 
78  FLASHDeconvAlgorithm& operator=(FLASHDeconvAlgorithm&& fd) = default;
79 
81  ~FLASHDeconvAlgorithm() = default;
82 
90  void performSpectrumDeconvolution(const MSSpectrum& spec, const std::vector<DeconvolvedSpectrum>& survey_scans, int scan_number,
91  const std::map<int, std::vector<std::vector<float>>>& precursor_map_for_FLASHIda);
92 
94  DeconvolvedSpectrum& getDeconvolvedSpectrum();
95 
97  const PrecalculatedAveragine& getAveragine();
98 
100  void setAveragine(const PrecalculatedAveragine& avg);
101 
105  void setTargetMasses(const std::vector<double>& masses, bool exclude = false);
106 
110  void calculateAveragine(bool use_RNA_averagine);
111 
113  static int getNominalMass(double mass);
114 
124  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);
125 
126 
140  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,
141  int allowed_iso_error_for_second_best_cos = 0, PeakGroup::TargetDummyType target_dummy_type = PeakGroup::TargetDummyType::target);
142 
148  static void addMZsToExcludsionList(const DeconvolvedSpectrum& dspec, std::unordered_set<double>& excluded_mzs);
149 
155  void setTargetDummyType(PeakGroup::TargetDummyType target_dummy_type, DeconvolvedSpectrum& target_dspec_for_dummy_calcualtion);
156 
157  protected:
158  void updateMembers_() override;
159 
160  private:
162 
164  const static int min_iso_size_ = 2;
165 
167  int allowed_iso_error_ = 1;
168 
170  double min_rt_, max_rt_;
172  double min_mz_, max_mz_;
174  int min_abs_charge_, max_abs_charge_;
178  double min_mass_, max_mass_;
188  const static int min_support_peak_count_ = 2;
195 
197 
199  PeakGroup::TargetDummyType target_dummy_type_ = PeakGroup::TargetDummyType::target;
200 
203 
205  boost::dynamic_bitset<> target_mass_bins_;
206  std::vector<double> target_mono_masses_;
207 
209  std::vector<double> excluded_masses_;
210 
214  std::unordered_set<double> excluded_peak_mzs_;
215 
217  std::vector<LogMzPeak> log_mz_peaks_;
221  boost::dynamic_bitset<> mass_bins_;
223  boost::dynamic_bitset<> mz_bins_;
225  // std::vector<int> mz_bin_peak_index_;
226 
228  std::vector<double> filter_;
231 
234 
236  std::vector<int> bin_offsets_;
239 
243 
245  uint ms_level_;
246 
249 
256  static double getBinValue_(Size bin, double min_value, double bin_mul_factor);
257 
264  static Size getBinNumber_(double value, double min_value, double bin_mul_factor);
265 
267  void updateLogMzPeaks_();
268 
273  void updateMzBins_(Size bin_number, std::vector<float>& mz_bin_intensities);
274 
275 
277  double getMassFromMassBin_(Size mass_bin, double bin_mul_factor) const;
278 
280  double getMzFromMzBin_(Size mass_bin, double bin_mul_factor) const;
281 
283  void generatePeakGroupsFromSpectrum_();
284 
289  Matrix<int> updateMassBins_(const std::vector<float>& mz_intensities);
290 
295  Matrix<int> filterMassBins_(const std::vector<float>& mass_intensities);
296 
301  void updateCandidateMassBins_(std::vector<float>& mass_intensities, const std::vector<float>& mz_intensities);
302 
306  void getCandidatePeakGroups_(const Matrix<int>& per_mass_abs_charge_ranges);
307 
309  void setFilters_();
310 
312  void scoreAndFilterPeakGroups_();
313 
315  void removeChargeErrorPeakGroups_(DeconvolvedSpectrum& dspec) const;
316 
318  void removeOverlappingPeakGroups_(DeconvolvedSpectrum& dspec, double tol);
319 
328  bool registerPrecursor_(const std::vector<DeconvolvedSpectrum>& survey_scans, const std::map<int, std::vector<std::vector<float>>>& precursor_map_for_real_time_acquisition);
329  };
330 } // namespace OpenMS
double min_mz_
range of mz subject to analysis
Definition: FLASHDeconvAlgorithm.h:172
double current_max_mass_
max mass is controlled by precursor mass for MSn n>1; otherwise just max_mass
Definition: FLASHDeconvAlgorithm.h:182
FLASHDeconv algorithm: ultrafast mass deconvolution algorithm for top down mass spectrometry dataset ...
Definition: FLASHDeconvAlgorithm.h:59
Averagine patterns pre-calculated for speed up. Other variables are also calculated for fast cosine c...
Definition: FLASHDeconvHelperStructs.h:59
double min_mass_
mass ranges of deconvolution, set by users
Definition: FLASHDeconvAlgorithm.h:178
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:62
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:241
FLASHDeconvHelperStructs::PrecalculatedAveragine PrecalculatedAveragine
Definition: FLASHDeconvAlgorithm.h:62
double current_min_mass_
max mass is max_mass for MS1 and 50 for MS2
Definition: FLASHDeconvAlgorithm.h:184
int current_max_charge_
current_max_charge_: controlled by precursor charge for MSn n>1; otherwise just max_abs_charge_ ...
Definition: FLASHDeconvAlgorithm.h:180
Definition: IsotopeDistribution.h:64
boost::dynamic_bitset mz_bins_
mz_bins_ stores the binned log mz peaks
Definition: FLASHDeconvAlgorithm.h:223
bool is_positive_
is positive mode
Definition: FLASHDeconvAlgorithm.h:176
log transformed peak. After deconvolution, all necessary information from deconvolution such as charg...
Definition: FLASHDeconvHelperStructs.h:164
std::vector< double > filter_
mz_bin to peak index mz_bin_peak_index_[mz_bin] = peak index
Definition: FLASHDeconvAlgorithm.h:228
boost::dynamic_bitset previously_deconved_mass_bins_for_dummy_
mass bins that are previsouly deconvolved and excluded for dummy mass generation
Definition: FLASHDeconvAlgorithm.h:212
double isolation_window_size_
default precursor isolation window size.
Definition: FLASHDeconvAlgorithm.h:248
std::vector< double > target_mono_masses_
Definition: FLASHDeconvAlgorithm.h:206
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
int min_abs_charge_
min charge and max charge subject to analysis, set by users
Definition: FLASHDeconvAlgorithm.h:174
std::vector< LogMzPeak > log_mz_peaks_
Stores log mz peaks.
Definition: FLASHDeconvAlgorithm.h:217
TargetDummyType
target dummy type of PeakGroup. This specifies if a PeakGroup is a target (0), charge dummy (1)...
Definition: PeakGroup.h:58
DeconvolvedSpectrum deconvolved_spectrum_
selected_peak_groups_ stores the deconvolved mass peak groups
Definition: FLASHDeconvAlgorithm.h:219
double mz_bin_min_value_
Definition: FLASHDeconvAlgorithm.h:242
std::vector< double > excluded_masses_
mass bins that are excluded for FLASHIda global targeting mode
Definition: FLASHDeconvAlgorithm.h:209
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
Matrix< double > harmonic_filter_matrix_
This stores the patterns for harmonic reduction.
Definition: FLASHDeconvAlgorithm.h:230
uint ms_level_
current ms Level
Definition: FLASHDeconvAlgorithm.h:245
boost::dynamic_bitset mass_bins_
mass_bins_ stores the selected bins for this spectrum + overlapped spectrum (previous a few spectra)...
Definition: FLASHDeconvAlgorithm.h:221
std::vector< int > bin_offsets_
This stores the "universal pattern" in binned dimension.
Definition: FLASHDeconvAlgorithm.h:236
DoubleList tolerance_
tolerance in ppm for each MS level
Definition: FLASHDeconvAlgorithm.h:190
double iso_da_distance_
isotope dalton distance
Definition: FLASHDeconvAlgorithm.h:233
double min_rt_
range of RT subject to analysis (in seconds)
Definition: FLASHDeconvAlgorithm.h:170
boost::dynamic_bitset target_mass_bins_
mass bins that are targeted for FLASHIda global targeting mode
Definition: FLASHDeconvAlgorithm.h:205
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
DoubleList min_isotope_cosine_
cosine threshold between observed and theoretical isotope patterns for each MS level ...
Definition: FLASHDeconvAlgorithm.h:194
double intensity_threshold_
peak intensity threshold subject to analysis
Definition: FLASHDeconvAlgorithm.h:186
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
Matrix< int > harmonic_bin_offset_matrix_
This stores the patterns for harmonic reduction in binned dimension.
Definition: FLASHDeconvAlgorithm.h:238
std::unordered_set< double > excluded_peak_mzs_
Definition: FLASHDeconvAlgorithm.h:214
std::vector< double > previously_deconved_mono_masses_for_dummy_
Definition: FLASHDeconvAlgorithm.h:213
A class representing a deconvolved spectrum. DeconvolvedSpectrum consists of PeakGroups representing ...
Definition: DeconvolvedSpectrum.h:55
FLASHDeconvHelperStructs::PrecalculatedAveragine avg_
precalculated averagine distributions for fast averagine generation
Definition: FLASHDeconvAlgorithm.h:202
DeconvolvedSpectrum * target_dspec_for_dummy_calcualtion_
Definition: FLASHDeconvAlgorithm.h:196
DoubleList bin_mul_factors_
bin multiplication factor (log mz * bin_mul_factors_ = bin number) - for fast convolution, binning is used
Definition: FLASHDeconvAlgorithm.h:192
FLASHDeconvHelperStructs::LogMzPeak LogMzPeak
Definition: FLASHDeconvAlgorithm.h:63