OpenMS  2.7.0
InternalCalibration.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-2021.
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: Chris Bielow $
32 // $Authors: Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
43 
44 #include <vector>
45 
46 namespace OpenMS
47 {
48 
49  class FeatureMap;
50 
61  class OPENMS_DLLAPI InternalCalibration
62  : public ProgressLogger
63  {
64  public:
65 
68 
71 
73  struct LockMass
74  {
75  double mz;
76  unsigned int ms_level;
77  int charge;
78 
79  LockMass(double mz_, int lvl_, int charge_)
80  : mz(mz_),
81  ms_level(lvl_),
82  charge(charge_)
83  {}
84  };
85 
109  const std::vector<InternalCalibration::LockMass>& ref_masses,
110  double tol_ppm,
111  bool lock_require_mono,
112  bool lock_require_iso,
113  CalibrationData& failed_lock_masses,
114  bool verbose = true);
115 
137  Size fillCalibrants(const FeatureMap& fm, double tol_ppm);
138 
154  Size fillCalibrants(const std::vector<PeptideIdentification>& pep_ids, double tol_ppm);
155 
165 
190  bool calibrate(PeakMap& exp,
191  const IntList& target_mslvl,
192  MZTrafoModel::MODELTYPE model_type,
193  double rt_chunk,
194  bool use_RANSAC,
195  double post_ppm_median,
196  double post_ppm_MAD,
197  const String& file_models = "",
198  const String& file_models_plot = "",
199  const String& file_residuals = "",
200  const String& file_residuals_plot = "",
201  const String& rscript_executable = "Rscript");
202 
211  static void applyTransformation(std::vector<Precursor>& pcs, const MZTrafoModel& trafo);
212 
222  static void applyTransformation(PeakMap::SpectrumType& spec, const IntList& target_mslvl, const MZTrafoModel& trafo);
223 
241  static void applyTransformation(PeakMap& exp, const IntList& target_mslvl, const MZTrafoModel& trafo);
242 
243  protected:
244 
247  {
248  CalibrantStats_(const double tol_ppm)
249  : tol_ppm_(tol_ppm)
250  {};
251  Size cnt_empty = 0;
252  Size cnt_nomz = 0;
253  Size cnt_nort = 0;
254  Size cnt_decal = 0;
255  Size cnt_total = 0;
256 
257  void print() const
258  {
259  if (cnt_empty > 0) OPENMS_LOG_WARN << "Warning: " << cnt_empty << "/" << cnt_total << " calibrations points were skipped, since they have no peptide sequence!" << std::endl;
260  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;
261  if (cnt_nort > 0) OPENMS_LOG_WARN << "Warning: " << cnt_nort << "/" << cnt_total << " calibrations points were skipped, since they have no RT value!" << std::endl;
262  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;
263  }
264 
265  private:
266  const double tol_ppm_;
267  };
268 
285  void fillID_( const PeptideIdentification& pep_id, const double tol_ppm, CalibrantStats_& stats);
286 
288  void fillIDs_(const std::vector<PeptideIdentification>& pep_ids, const double tol_ppm, CalibrantStats_& stats);
289 
291  bool isDecalibrated_(const PeptideIdentification& pep_id, const double mz_obs, const double tol_ppm, CalibrantStats_& stats, double& mz_ref);
292 
298  static void applyTransformation_(PeakMap::SpectrumType& spec, const MZTrafoModel& trafo);
299 
300  private:
302  }; // class InternalCalibration
303 
304 } // namespace OpenMS
305 
#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:460
A helper class, holding all calibration points.
Definition: CalibrationData.h:65
A container for features.
Definition: FeatureMap.h:105
A mass recalibration method using linear/quadratic interpolation (robust/weighted) of given reference...
Definition: InternalCalibration.h:63
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:301
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.
~InternalCalibration()
Destructor.
Definition: InternalCalibration.h:70
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 experiment.
Definition: MSExperiment.h:80
The representation of a 1D spectrum.
Definition: MSSpectrum.h:71
Create and apply models of a mass recalibration function.
Definition: MZTrafoModel.h:67
MODELTYPE
Definition: MZTrafoModel.h:99
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:65
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
A more convenient string class.
Definition: String.h:61
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:55
int verbose
Verbosity level ( "-v" is 1 and "-V" is 2 )
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
statistics when adding peptide calibrants
Definition: InternalCalibration.h:247
const double tol_ppm_
tolerance used for counting cnt_decal
Definition: InternalCalibration.h:266
void print() const
Definition: InternalCalibration.h:257
CalibrantStats_(const double tol_ppm)
Definition: InternalCalibration.h:248
helper class, describing a lock mass
Definition: InternalCalibration.h:74
double mz
m/z of the lock mass (incl. adducts)
Definition: InternalCalibration.h:75
unsigned int ms_level
MS level where it occurs.
Definition: InternalCalibration.h:76
LockMass(double mz_, int lvl_, int charge_)
Definition: InternalCalibration.h:79
int charge
charge of the ion (to find isotopes)
Definition: InternalCalibration.h:77