OpenMS  3.0.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-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: Chris Bielow $
32 // $Authors: Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
44 
45 #include <vector>
46 
47 namespace OpenMS
48 {
49 
50  class FeatureMap;
51 
62  class OPENMS_DLLAPI InternalCalibration
63  : public ProgressLogger
64  {
65  public:
66 
69 
71  ~InternalCalibration() override{}
72 
74  struct LockMass
75  {
76  double mz;
77  unsigned int ms_level;
78  int charge;
79 
80  LockMass(double mz_, int lvl_, int charge_)
81  : mz(mz_),
82  ms_level(lvl_),
83  charge(charge_)
84  {}
85  };
86 
109  Size fillCalibrants(const PeakMap& exp,
110  const std::vector<InternalCalibration::LockMass>& ref_masses,
111  double tol_ppm,
112  bool lock_require_mono,
113  bool lock_require_iso,
114  CalibrationData& failed_lock_masses,
115  bool verbose = true);
116 
138  Size fillCalibrants(const FeatureMap& fm, double tol_ppm);
139 
155  Size fillCalibrants(const std::vector<PeptideIdentification>& pep_ids, double tol_ppm);
156 
165  const CalibrationData& getCalibrationPoints() const;
166 
191  bool calibrate(PeakMap& exp,
192  const IntList& target_mslvl,
193  MZTrafoModel::MODELTYPE model_type,
194  double rt_chunk,
195  bool use_RANSAC,
196  double post_ppm_median,
197  double post_ppm_MAD,
198  const String& file_models = "",
199  const String& file_models_plot = "",
200  const String& file_residuals = "",
201  const String& file_residuals_plot = "",
202  const String& rscript_executable = "Rscript");
203 
212  static void applyTransformation(std::vector<Precursor>& pcs, const MZTrafoModel& trafo);
213 
223  static void applyTransformation(PeakMap::SpectrumType& spec, const IntList& target_mslvl, const MZTrafoModel& trafo);
224 
242  static void applyTransformation(PeakMap& exp, const IntList& target_mslvl, const MZTrafoModel& trafo);
243 
244  protected:
245 
248  {
249  CalibrantStats_(const double tol_ppm)
250  : tol_ppm_(tol_ppm)
251  {};
252  Size cnt_empty = 0;
253  Size cnt_nomz = 0;
254  Size cnt_nort = 0;
255  Size cnt_decal = 0;
256  Size cnt_total = 0;
257 
258  void print() const
259  {
260  if (cnt_empty > 0) OPENMS_LOG_WARN << "Warning: " << cnt_empty << "/" << cnt_total << " calibrations points were skipped, since they have no peptide sequence!" << std::endl;
261  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;
262  if (cnt_nort > 0) OPENMS_LOG_WARN << "Warning: " << cnt_nort << "/" << cnt_total << " calibrations points were skipped, since they have no RT value!" << std::endl;
263  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;
264  }
265 
266  private:
267  const double tol_ppm_;
268  };
269 
286  void fillID_( const PeptideIdentification& pep_id, const double tol_ppm, CalibrantStats_& stats);
287 
289  void fillIDs_(const std::vector<PeptideIdentification>& pep_ids, const double tol_ppm, CalibrantStats_& stats);
290 
292  bool isDecalibrated_(const PeptideIdentification& pep_id, const double mz_obs, const double tol_ppm, CalibrantStats_& stats, double& mz_ref);
293 
299  static void applyTransformation_(PeakMap::SpectrumType& spec, const MZTrafoModel& trafo);
300 
301  private:
303  }; // class InternalCalibration
304 
305 } // namespace OpenMS
306 
LogStream.h
OpenMS::InternalCalibration::CalibrantStats_::CalibrantStats_
CalibrantStats_(const double tol_ppm)
Definition: InternalCalibration.h:249
OpenMS::FileTypes::IDXML
OpenMS identification format (.idXML)
Definition: FileTypes.h:64
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:147
OpenMS::MZTrafoModel::setRANSACParams
static void setRANSACParams(const Math::RANSACParam &p)
Set the global (program wide) parameters for RANSAC.
OpenMS::StringUtils::toInt
static Int toInt(const String &this_s)
Definition: StringUtils.h:206
OpenMS::TextFile::end
ConstIterator end() const
Gives access to the underlying text buffer.
OpenMS::MSExperiment::set2DData
void set2DData(const Container &container)
Assignment of a data container with RT and MZ to an MSExperiment.
Definition: MSExperiment.h:239
FileHandler.h
FileTypes.h
TextFile.h
Size
OpenMS::InternalCalibration::CalibrantStats_::tol_ppm_
const double tol_ppm_
tolerance used for counting cnt_decal
Definition: InternalCalibration.h:267
OpenMS::MZTrafoModel::setRANSACSeed
static void setRANSACSeed(int seed)
Set RANSAC seed.
OpenMS::MzMLFile::store
void store(const String &filename, const PeakMap &map) const
Stores a map in an MzML file.
OpenMS::MZTrafoModel::setCoefficientLimits
static void setCoefficientLimits(double offset, double scale, double power)
Set coefficient boundaries for which the model coefficient must not exceed to be considered a valid m...
OpenMS::MZTrafoModel::MODELTYPE
MODELTYPE
Definition: MZTrafoModel.h:97
InternalCalibration.h
OpenMS::Math::RANSACParam
A simple struct to carry all the parameters required for a RANSAC run.
Definition: RANSAC.h:58
OpenMS::InternalCalibration::CalibrantStats_
statistics when adding peptide calibrants
Definition: InternalCalibration.h:247
OpenMS::MzMLFile
File adapter for MzML files.
Definition: MzMLFile.h:57
OpenMS::String
A more convenient string class.
Definition: String.h:58
MzMLFile.h
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:70
OpenMS::FileHandler::getTypeByContent
static FileTypes::Type getTypeByContent(const String &filename)
Determines the file type of a file by parsing the first few lines.
OpenMS::TextFile
This class provides some basic file handling methods for text files.
Definition: TextFile.h:46
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
IdXMLFile.h
FeatureXMLFile.h
OpenMS::InternalCalibration::LockMass
helper class, describing a lock mass
Definition: InternalCalibration.h:74
OpenMS::InternalCalibration::LockMass::charge
int charge
charge of the ion (to find isotopes)
Definition: InternalCalibration.h:78
OpenMS::InternalCalibration::LockMass::mz
double mz
m/z of the lock mass (incl. adducts)
Definition: InternalCalibration.h:76
OpenMS::IntList
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:55
OPENMS_LOG_WARN
#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
OpenMS::InternalCalibration
A mass recalibration method using linear/quadratic interpolation (robust/weighted) of given reference...
Definition: InternalCalibration.h:62
MZTrafoModel.h
OpenMS::String::hasSubstring
bool hasSubstring(const String &string) const
true if String contains the string, false otherwise
ListUtils.h
OpenMS::CalibrationData::getMetaValues
static StringList getMetaValues()
List of meta-values which are used internally (for conversion to PeakMap).
OpenMS::IdXMLFile::load
void load(const String &filename, std::vector< ProteinIdentification > &protein_ids, std::vector< PeptideIdentification > &peptide_ids)
Loads the identifications of an idXML file without identifier.
OpenMS::MZTrafoModel::enumToName
static const std::string & enumToName(MODELTYPE mt)
Convert enum to string.
OpenMS::InternalCalibration::calibrate
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.
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::FileTypes::FEATUREXML
OpenMS feature file (.featureXML)
Definition: FileTypes.h:63
OpenMS::ProgressLogger
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:52
ProgressLogger.h
OpenMS::MzMLFile::load
void load(const String &filename, PeakMap &map)
Loads a map from a MzML file. Spectra and chromatograms are sorted by default (this can be disabled u...
TransformationXMLFile.h
OpenMS::InternalCalibration::LockMass::LockMass
LockMass(double mz_, int lvl_, int charge_)
Definition: InternalCalibration.h:80
OpenMS::FileHandler
Facilitates file handling by file type recognition.
Definition: FileHandler.h:66
OpenMS::FeatureXMLFile::load
void load(const String &filename, FeatureMap &feature_map)
loads the file with name filename into map and calls updateRanges().
FeatureMap.h
OpenMS::FileTypes::Type
Type
Actual file types enum.
Definition: FileTypes.h:56
OpenMS::MZTrafoModel::LINEAR_WEIGHTED
Definition: MZTrafoModel.h:97
OpenMS::DataProcessing::CALIBRATION
Calibration of m/z positions.
Definition: DataProcessing.h:69
OpenMS::CalibrationData::empty
bool empty() const
Do we have any calibration points.
OpenMS::InternalCalibration::~InternalCalibration
~InternalCalibration() override
Destructor.
Definition: InternalCalibration.h:71
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:71
OpenMS::InternalCalibration::cal_data_
CalibrationData cal_data_
Definition: InternalCalibration.h:302
MSExperiment.h
OpenMS::TextFile::begin
ConstIterator begin() const
Gives access to the underlying text buffer.
OpenMS::Internal::ClassTest::verbose
int verbose
Verbosity level ( "-v" is 1 and "-V" is 2 )
OpenMS::MZTrafoModel::SIZE_OF_MODELTYPE
Definition: MZTrafoModel.h:97
OpenMS::StringUtils::toDouble
static double toDouble(const String &this_s)
Definition: StringUtils.h:216
OPENMS_LOG_ERROR
#define OPENMS_LOG_ERROR
Macro to be used if non-fatal error are reported (processing continues)
Definition: LogStream.h:455
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:98
OpenMS::PeptideIdentification
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:63
OpenMS::InternalCalibration::CalibrantStats_::print
void print() const
Definition: InternalCalibration.h:258
OpenMS::MZTrafoModel
Create and apply models of a mass recalibration function.
Definition: MZTrafoModel.h:64
OpenMS::FeatureXMLFile
This class provides Input/Output functionality for feature maps.
Definition: FeatureXMLFile.h:62
OpenMS::InternalCalibration::LockMass::ms_level
unsigned int ms_level
MS level where it occurs.
Definition: InternalCalibration.h:77
OpenMS::MZTrafoModel::nameToEnum
static MODELTYPE nameToEnum(const std::string &name)
Convert string to enum.
CalibrationData.h
OpenMS::Exception::MissingInformation
Not all required information provided.
Definition: Exception.h:186
OPENMS_LOG_INFO
#define OPENMS_LOG_INFO
Macro if a information, e.g. a status should be reported.
Definition: LogStream.h:465
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
OpenMS::CalibrationData
A helper class, holding all calibration points.
Definition: CalibrationData.h:64
OpenMS::TextFile::ConstIterator
std::vector< String >::const_iterator ConstIterator
Non-mutable iterator.
Definition: TextFile.h:56
OpenMS::MZTrafoModel::names_of_modeltype
static const std::string names_of_modeltype[]
strings corresponding to enum MODELTYPE
Definition: MZTrafoModel.h:98
OpenMS::TextFile::load
void load(const String &filename, bool trim_lines=false, Int first_n=-1, bool skip_empty_lines=false)
Loads data from a text file.
StandardTypes.h
OpenMS::InternalCalibration::fillCalibrants
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)
OpenMS::ProgressLogger::setLogType
void setLogType(LogType type) const
Sets the progress log that should be used. The default type is NONE!
TOPPBase.h
OpenMS::InternalCalibration::getCalibrationPoints
const CalibrationData & getCalibrationPoints() const
Get container of calibration points.
OpenMS::IdXMLFile
Used to load and store idXML files.
Definition: IdXMLFile.h:68