OpenMS
InternalCalibration.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Chris Bielow $
6 // $Authors: Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
18 
19 #include <vector>
20 
21 namespace OpenMS
22 {
23 
24  class FeatureMap;
25 
32  class OPENMS_DLLAPI InternalCalibration
33  : public ProgressLogger
34  {
35  public:
36 
39 
41  ~InternalCalibration() override{}
42 
44  struct LockMass
45  {
46  double mz;
47  unsigned int ms_level;
48  int charge;
49 
50  LockMass(double mz_, int lvl_, int charge_)
51  : mz(mz_),
52  ms_level(lvl_),
53  charge(charge_)
54  {}
55  };
56 
80  const std::vector<InternalCalibration::LockMass>& ref_masses,
81  double tol_ppm,
82  bool lock_require_mono,
83  bool lock_require_iso,
84  CalibrationData& failed_lock_masses,
85  bool verbose = true);
86 
108  Size fillCalibrants(const FeatureMap& fm, double tol_ppm);
109 
125  Size fillCalibrants(const std::vector<PeptideIdentification>& pep_ids, double tol_ppm);
126 
136 
161  bool calibrate(PeakMap& exp,
162  const IntList& target_mslvl,
163  MZTrafoModel::MODELTYPE model_type,
164  double rt_chunk,
165  bool use_RANSAC,
166  double post_ppm_median,
167  double post_ppm_MAD,
168  const String& file_models = "",
169  const String& file_models_plot = "",
170  const String& file_residuals = "",
171  const String& file_residuals_plot = "",
172  const String& rscript_executable = "Rscript");
173 
182  static void applyTransformation(std::vector<Precursor>& pcs, const MZTrafoModel& trafo);
183 
193  static void applyTransformation(PeakMap::SpectrumType& spec, const IntList& target_mslvl, const MZTrafoModel& trafo);
194 
212  static void applyTransformation(PeakMap& exp, const IntList& target_mslvl, const MZTrafoModel& trafo);
213 
214  protected:
215 
218  {
219  CalibrantStats_(const double tol_ppm)
220  : tol_ppm_(tol_ppm)
221  {};
222  Size cnt_empty = 0;
223  Size cnt_nomz = 0;
224  Size cnt_nort = 0;
225  Size cnt_decal = 0;
226  Size cnt_total = 0;
227 
228  void print() const
229  {
230  if (cnt_empty > 0) OPENMS_LOG_WARN << "Warning: " << cnt_empty << "/" << cnt_total << " calibrations points were skipped, since they have no peptide sequence!" << std::endl;
231  if (cnt_nomz > 0) OPENMS_LOG_WARN << "Warning: " << cnt_nomz << "/" << cnt_total << " calibrations points were skipped, since they have no m/z value!" << std::endl;
232  if (cnt_nort > 0) OPENMS_LOG_WARN << "Warning: " << cnt_nort << "/" << cnt_total << " calibrations points were skipped, since they have no RT value!" << std::endl;
233  if (cnt_decal > 0) OPENMS_LOG_WARN << "Warning: " << cnt_decal << "/" << cnt_total << " calibrations points were skipped, since their theoretical weight is more than " << tol_ppm_ << " ppm away from their measured mass!" << std::endl;
234  }
235 
236  private:
237  const double tol_ppm_;
238  };
239 
256  void fillID_( const PeptideIdentification& pep_id, const double tol_ppm, CalibrantStats_& stats);
257 
259  void fillIDs_(const std::vector<PeptideIdentification>& pep_ids, const double tol_ppm, CalibrantStats_& stats);
260 
262  bool isDecalibrated_(const PeptideIdentification& pep_id, const double mz_obs, const double tol_ppm, CalibrantStats_& stats, double& mz_ref);
263 
269  static void applyTransformation_(PeakMap::SpectrumType& spec, const MZTrafoModel& trafo);
270 
271  private:
273  }; // class InternalCalibration
274 
275 } // namespace OpenMS
276 
#define OPENMS_LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged.
Definition: LogStream.h:444
A helper class, holding all calibration points.
Definition: CalibrationData.h:39
A container for features.
Definition: FeatureMap.h:80
A mass recalibration method using linear/quadratic interpolation (robust/weighted) of given reference...
Definition: InternalCalibration.h:34
static void applyTransformation_(PeakMap::SpectrumType &spec, const MZTrafoModel &trafo)
Calibrate m/z of a spectrum, ignoring precursors!
Size fillCalibrants(const FeatureMap &fm, double tol_ppm)
Extract calibrants from identifications.
static void applyTransformation(PeakMap::SpectrumType &spec, const IntList &target_mslvl, const MZTrafoModel &trafo)
Transform a spectrum (data+precursor)
CalibrationData cal_data_
Definition: InternalCalibration.h:272
~InternalCalibration() override
Destructor.
Definition: InternalCalibration.h:41
Size fillCalibrants(const PeakMap &exp, const std::vector< InternalCalibration::LockMass > &ref_masses, double tol_ppm, bool lock_require_mono, bool lock_require_iso, CalibrationData &failed_lock_masses, bool verbose=true)
Extract calibrants from Raw data (mzML)
bool calibrate(PeakMap &exp, const IntList &target_mslvl, MZTrafoModel::MODELTYPE model_type, double rt_chunk, bool use_RANSAC, double post_ppm_median, double post_ppm_MAD, const String &file_models="", const String &file_models_plot="", const String &file_residuals="", const String &file_residuals_plot="", const String &rscript_executable="Rscript")
Apply calibration to data.
static void applyTransformation(std::vector< Precursor > &pcs, const MZTrafoModel &trafo)
Transform a precursor's m/z.
InternalCalibration()
Default constructor.
const CalibrationData & getCalibrationPoints() const
Get container of calibration points.
bool isDecalibrated_(const PeptideIdentification &pep_id, const double mz_obs, const double tol_ppm, CalibrantStats_ &stats, double &mz_ref)
determine if sequence is within tol_ppm and update stats; fills mz_ref with the theoretical m/z of th...
void fillID_(const PeptideIdentification &pep_id, const double tol_ppm, CalibrantStats_ &stats)
Add(no prior clear) calibrants to internal list.
Size fillCalibrants(const std::vector< PeptideIdentification > &pep_ids, double tol_ppm)
Extract calibrants from identifications.
static void applyTransformation(PeakMap &exp, const IntList &target_mslvl, const MZTrafoModel &trafo)
Transform spectra from a whole map (data+precursor)
void fillIDs_(const std::vector< PeptideIdentification > &pep_ids, const double tol_ppm, CalibrantStats_ &stats)
calls fillID_ on all PeptideIDs
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
Create and apply models of a mass recalibration function.
Definition: MZTrafoModel.h:39
MODELTYPE
Definition: MZTrafoModel.h:71
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:39
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:27
A more convenient string class.
Definition: String.h:34
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:29
int verbose
Verbosity level ( "-v" is 1 and "-V" is 2 )
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
statistics when adding peptide calibrants
Definition: InternalCalibration.h:218
const double tol_ppm_
tolerance used for counting cnt_decal
Definition: InternalCalibration.h:237
void print() const
Definition: InternalCalibration.h:228
CalibrantStats_(const double tol_ppm)
Definition: InternalCalibration.h:219
helper class, describing a lock mass
Definition: InternalCalibration.h:45
double mz
m/z of the lock mass (incl. adducts)
Definition: InternalCalibration.h:46
unsigned int ms_level
MS level where it occurs.
Definition: InternalCalibration.h:47
LockMass(double mz_, int lvl_, int charge_)
Definition: InternalCalibration.h:50
int charge
charge of the ion (to find isotopes)
Definition: InternalCalibration.h:48