All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
InternalCalibration.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: Chris Bielow $
6 // $Authors: Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
19 
20 #include <vector>
21 
22 namespace OpenMS
23 {
24 
25  class FeatureMap;
26 
33  class OPENMS_DLLAPI InternalCalibration
34  : public ProgressLogger
35  {
36  public:
37 
40 
42  ~InternalCalibration() override{}
43 
45  struct LockMass
46  {
47  double mz;
48  unsigned int ms_level;
49  int charge;
50 
51  LockMass(double mz_, int lvl_, int charge_)
52  : mz(mz_),
53  ms_level(lvl_),
54  charge(charge_)
55  {}
56  };
57 
81  const std::vector<InternalCalibration::LockMass>& ref_masses,
82  double tol_ppm,
83  bool lock_require_mono,
84  bool lock_require_iso,
85  CalibrationData& failed_lock_masses,
86  bool verbose = true);
87 
109  Size fillCalibrants(const FeatureMap& fm, double tol_ppm);
110 
126  Size fillCalibrants(const PeptideIdentificationList& pep_ids, double tol_ppm);
127 
137 
162  bool calibrate(PeakMap& exp,
163  const IntList& target_mslvl,
164  MZTrafoModel::MODELTYPE model_type,
165  double rt_chunk,
166  bool use_RANSAC,
167  double post_ppm_median,
168  double post_ppm_MAD,
169  const String& file_models = "",
170  const String& file_models_plot = "",
171  const String& file_residuals = "",
172  const String& file_residuals_plot = "",
173  const String& rscript_executable = "Rscript");
174 
183  static void applyTransformation(std::vector<Precursor>& pcs, const MZTrafoModel& trafo);
184 
194  static void applyTransformation(PeakMap::SpectrumType& spec, const IntList& target_mslvl, const MZTrafoModel& trafo);
195 
213  static void applyTransformation(PeakMap& exp, const IntList& target_mslvl, const MZTrafoModel& trafo);
214 
215  protected:
216 
219  {
220  CalibrantStats_(const double tol_ppm)
221  : tol_ppm_(tol_ppm)
222  {};
223  Size cnt_empty = 0;
224  Size cnt_nomz = 0;
225  Size cnt_nort = 0;
226  Size cnt_decal = 0;
227  Size cnt_total = 0;
228 
229  void print() const
230  {
231  if (cnt_empty > 0) OPENMS_LOG_WARN << "Warning: " << cnt_empty << "/" << cnt_total << " calibrations points were skipped, since they have no peptide sequence!" << std::endl;
232  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;
233  if (cnt_nort > 0) OPENMS_LOG_WARN << "Warning: " << cnt_nort << "/" << cnt_total << " calibrations points were skipped, since they have no RT value!" << std::endl;
234  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;
235  }
236 
237  private:
238  const double tol_ppm_;
239  };
240 
257  void fillID_( const PeptideIdentification& pep_id, const double tol_ppm, CalibrantStats_& stats);
258 
260  void fillIDs_(const PeptideIdentificationList& pep_ids, const double tol_ppm, CalibrantStats_& stats);
261 
263  bool isDecalibrated_(const PeptideIdentification& pep_id, const double mz_obs, const double tol_ppm, CalibrantStats_& stats, double& mz_ref);
264 
270  static void applyTransformation_(PeakMap::SpectrumType& spec, const MZTrafoModel& trafo);
271 
272  private:
274  }; // class InternalCalibration
275 
276 } // namespace OpenMS
277 
#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:82
A mass recalibration method using linear/quadratic interpolation (robust/weighted) of given reference...
Definition: InternalCalibration.h:35
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)
Size fillCalibrants(const PeptideIdentificationList &pep_ids, double tol_ppm)
Extract calibrants from identifications.
CalibrationData cal_data_
Definition: InternalCalibration.h:273
~InternalCalibration() override
Destructor.
Definition: InternalCalibration.h:42
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)
void fillIDs_(const PeptideIdentificationList &pep_ids, const double tol_ppm, CalibrantStats_ &stats)
calls fillID_ on all PeptideIDs
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.
static void applyTransformation(PeakMap &exp, const IntList &target_mslvl, const MZTrafoModel &trafo)
Transform spectra from a whole map (data+precursor)
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:49
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
Container for peptide identifications from multiple spectra.
Definition: PeptideIdentificationList.h:66
Represents the set of candidates (SpectrumMatches) identified for a single precursor spectrum.
Definition: PeptideIdentification.h:63
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:219
const double tol_ppm_
tolerance used for counting cnt_decal
Definition: InternalCalibration.h:238
void print() const
Definition: InternalCalibration.h:229
CalibrantStats_(const double tol_ppm)
Definition: InternalCalibration.h:220
helper class, describing a lock mass
Definition: InternalCalibration.h:46
double mz
m/z of the lock mass (incl. adducts)
Definition: InternalCalibration.h:47
unsigned int ms_level
MS level where it occurs.
Definition: InternalCalibration.h:48
LockMass(double mz_, int lvl_, int charge_)
Definition: InternalCalibration.h:51
int charge
charge of the ion (to find isotopes)
Definition: InternalCalibration.h:49