OpenMS
Loading...
Searching...
No Matches
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 <memory>
19#include <optional>
20#include <utility>
21#include <iostream>
22
23namespace OpenMS
24{
35 class OPENMS_DLLAPI SpectralDeconvolution : public DefaultParamHandler
36 {
37 public:
40
43
46
49
52
55
58
65 void performSpectrumDeconvolution(const MSSpectrum& spec, int scan_number, const PeakGroup& precursor_peak_group);
66
69
72
75
80 void setTargetMasses(const std::vector<double>& masses, bool exclude = false);
81
85 void calculateAveragine(bool use_RNA_averagine);
86
89 {
90 max_mass_dalton_tolerance_ = 100;
91 }
92
94 static int getNominalMass(double mass);
95
104 static float getCosine(const std::vector<float>& a, int a_start, int a_end, const IsotopeDistribution& b, int offset, int min_iso_len);
105
106
117 static float getIsotopeCosineAndIsoOffset(double mono_mass, const std::vector<float>& per_isotope_intensities, int& offset,
118 const PrecalculatedAveragine& avg, int iso_int_shift,
119 int window_width, const std::vector<double>& excluded_masses);
120
126 void setTargetDecoyType(PeakGroup::TargetDecoyType target_decoy_type, const DeconvolvedSpectrum& target_dspec_for_decoy_calcualtion);
127
129 const static int min_iso_size = 2;
130
131 protected:
132 void updateMembers_() override;
133
135 using MassRanges = std::vector<std::pair<double, double>>;
136
148
159 virtual std::optional<MassRanges> selectCandidateMassRanges_(const CandidateSelectionContext& context,
160 const DeconvolvedSpectrum* evidence, const std::vector<Size>& valid) const;
161
162 private:
164
166 int allowed_iso_error_ = -1;
167
169 int min_abs_charge_, max_abs_charge_;
173 double min_mass_, max_mass_;
181 double noise_iso_delta_ = .9444;
183 const static int min_support_peak_count_ = 2;
193 double min_qscore_ = .2;
194
197
199 PeakGroup::TargetDecoyType target_decoy_type_ = PeakGroup::TargetDecoyType::target;
200
203
205 struct OPENMS_DLLAPI Bitsets
206 {
207 struct Impl;
208 std::unique_ptr<Impl> impl;
210 Bitsets(const Bitsets& other);
211 Bitsets(Bitsets&& other) noexcept;
212 Bitsets& operator=(const Bitsets& other);
213 Bitsets& operator=(Bitsets&& other) noexcept;
215 };
217
219 void restrictCandidateMassBins_(std::vector<std::pair<double, double>> intervals);
220
222 std::vector<Size> scorePeakGroups_();
223
225 std::vector<double> target_mono_masses_;
226
228 std::vector<double> excluded_masses_;
229
233
235 std::vector<LogMzPeak> log_mz_peaks_;
239 std::vector<double> universal_pattern_;
242
247
251
254
257
259 int target_precursor_charge_ = 0;
260 double target_precursor_mz_ = 0;
261
263 double max_mass_dalton_tolerance_ = .16;
264
271 static double getBinValue_(Size bin, double min_value, double bin_mul_factor);
272
279 static Size getBinNumber_(double value, double min_value, double bin_mul_factor);
280
283
288 void binLogMzPeaks_(Size bin_number, std::vector<float>& binned_log_mz_peak_intensities);
289
291 double getMassFromMassBin_(Size mass_bin, double bin_mul_factor) const;
292
294 double getMzFromMzBin_(Size mass_bin, double bin_mul_factor) const;
295
298
300 static void removeOverlappingPeakGroups_(DeconvolvedSpectrum& dspec, double tol, PeakGroup::TargetDecoyType target_decoy_type = PeakGroup::TargetDecoyType::target);
301
306 Matrix<int> updateMassBins_(const std::vector<float>& mz_intensities);
307
312 Matrix<int> filterMassBins_(const std::vector<float>& mass_intensities);
313
318 void updateCandidateMassBins_(std::vector<float>& mass_intensities, const std::vector<float>& mz_intensities);
319
323 void getCandidatePeakGroups_(const Matrix<int>& per_mass_abs_charge_ranges);
324
327
330
333
335 void removeExcludedMasses_(DeconvolvedSpectrum& dspec, std::vector<double> excluded_masses, double tol) const;
336
338
341
344
346 void registerPrecursorForMSn_(const PeakGroup& precursor_peak_group);
347
348 bool isPeakGroupInExcludedMassForDecoyRuns_(const PeakGroup& peak_group, double tol, int offset = 0) const;
349 };
350 } // 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:280
Pre-binned averagine isotope-distribution cache used by FLASHDeconv for fast cosine-similarity scorin...
Definition FLASHHelperClasses.h:53
Definition IsotopeDistribution.h:40
The representation of a 1D spectrum.
Definition MSSpectrum.h:45
A 2D matrix class with efficient buffer access for NumPy interoperability.
Definition Matrix.h:35
Class describing a deconvolved mass. A mass contains multiple (LogMz) peaks of different charges and ...
Definition PeakGroup.h:29
TargetDecoyType
Definition PeakGroup.h:37
FLASHDeconv algorithm: ultrafast mass deconvolution algorithm for top down mass spectrometry dataset ...
Definition SpectralDeconvolution.h:36
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:196
std::vector< double > excluded_masses_
mass bins that are excluded for FLASHIda global targeting mode
Definition SpectralDeconvolution.h:228
int max_charge
Current maximum charge magnitude.
Definition SpectralDeconvolution.h:145
std::vector< std::pair< double, double > > MassRanges
Neutral apex-mass intervals used to restrict candidate construction.
Definition SpectralDeconvolution.h:135
FLASHHelperClasses::PrecalculatedAveragine PrecalculatedAveragine
Definition SpectralDeconvolution.h:38
Bitsets bitsets_
Definition SpectralDeconvolution.h:216
FLASHHelperClasses::PrecalculatedAveragine avg_
precalculated averagine distributions for fast averagine generation
Definition SpectralDeconvolution.h:202
double getMassFromMassBin_(Size mass_bin, double bin_mul_factor) const
get mass value for input mass bin: used for debugging
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 restrictCandidateMassBins_(std::vector< std::pair< double, double > > intervals)
Restrict mass bins using merged apex-mass intervals.
void prepareNoiseDecoySpectrum_(const MSSpectrum &spec)
prepare noise decoy spectrum by filtering signal peaks
std::vector< Size > scorePeakGroups_()
Refine and score groups independently, returning valid indices in construction order.
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:237
double current_max_mass_
max mass is controlled by precursor mass for MSn n>1; otherwise just max_mass
Definition SpectralDeconvolution.h:177
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:171
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...
SpectralDeconvolution & operator=(const SpectralDeconvolution &fd)=default
assignment operator
void removeChargeErrorPeakGroups_(DeconvolvedSpectrum &dspec, const PeakGroup::TargetDecoyType &target_decoy_type) const
filter out charge error masses
int min_charge
Minimum charge magnitude.
Definition SpectralDeconvolution.h:144
std::vector< double > excluded_masses_for_decoy_runs_
Definition SpectralDeconvolution.h:232
Matrix< int > binned_harmonic_patterns
This stores the patterns for harmonic reduction in binned dimension.
Definition SpectralDeconvolution.h:246
const PrecalculatedAveragine & getAveragine()
get calculated averagine. Call after calculateAveragine is called.
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:187
~SpectralDeconvolution()=default
destructor
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...
uint ms_level_
current ms Level
Definition SpectralDeconvolution.h:253
double getMzFromMzBin_(Size mass_bin, double bin_mul_factor) const
get mz value for input mz bin: used for debugging
SpectralDeconvolution & operator=(SpectralDeconvolution &&fd)=default
move assignment operator
double max_mass
Current maximum neutral mass.
Definition SpectralDeconvolution.h:143
void setToleranceEstimation()
when estimating tolerance, max_mass_dalton_tolerance_ should be large
Definition SpectralDeconvolution.h:88
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:249
int current_max_charge_
current_max_charge_: controlled by precursor charge for MSn n>1; otherwise just max_abs_charge_
Definition SpectralDeconvolution.h:175
double max_mass_
Definition SpectralDeconvolution.h:173
Matrix< int > updateMassBins_(const std::vector< float > &mz_intensities)
Update binned_log_masses_. It select candidate mass bins using the universal pattern,...
void setAveragine(const PrecalculatedAveragine &avg)
set calculated averagine
const PrecalculatedAveragine & averagine
Configured averagine.
Definition SpectralDeconvolution.h:140
std::vector< double > excluded_peak_masses_for_decoy_runs_
previously deconvolved masses excluded for decoy mass generation
Definition SpectralDeconvolution.h:231
std::vector< double > universal_pattern_
This stores the "universal pattern".
Definition SpectralDeconvolution.h:239
double tolerance
Relative m/z tolerance.
Definition SpectralDeconvolution.h:141
std::vector< int > binned_universal_pattern_
This stores the "universal pattern" in binned dimension.
Definition SpectralDeconvolution.h:244
virtual std::optional< MassRanges > selectCandidateMassRanges_(const CandidateSelectionContext &context, const DeconvolvedSpectrum *evidence, const std::vector< Size > &valid) const
Optionally restrict construction, without protecting candidates from filtering. The default returns n...
DoubleList min_isotope_cosine_
Isotope cosine threshold for each MS level.
Definition SpectralDeconvolution.h:189
FLASHHelperClasses::LogMzPeak LogMzPeak
Definition SpectralDeconvolution.h:39
DeconvolvedSpectrum & getDeconvolvedSpectrum()
return deconvolved spectrum
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:191
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:256
static float getCosine(const std::vector< float > &a, int a_start, int a_end, const IsotopeDistribution &b, int offset, int min_iso_len)
Matrix< int > filterMassBins_(const std::vector< float > &mass_intensities)
Subfunction of updateMassBins_.
bool positive
Ionization mode.
Definition SpectralDeconvolution.h:146
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:235
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:179
std::vector< double > target_mono_masses_
monoisotopic masses that are targeted for FLASHIda global targeting mode
Definition SpectralDeconvolution.h:225
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:250
DoubleList tolerance_
tolerance in ppm for each MS level
Definition SpectralDeconvolution.h:185
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:169
double isotope_distance
Isotope spacing in Da.
Definition SpectralDeconvolution.h:142
Matrix< double > harmonic_pattern_matrix_
This stores the patterns for harmonic reduction.
Definition SpectralDeconvolution.h:241
Read-only construction settings; spectrum peaks and candidate bins remain private.
Definition SpectralDeconvolution.h:139
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 TypeAliases.h:31
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Value-semantic holder for the implementation's bitsets.
Definition SpectralDeconvolution.h:206
Bitsets(Bitsets &&other) noexcept
Bitsets & operator=(const Bitsets &other)
std::unique_ptr< Impl > impl
Definition SpectralDeconvolution.h:208
Bitsets & operator=(Bitsets &&other) noexcept