All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
IDMapper.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: Marc Sturm, Hendrik Weisser, Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
15 
17 
20 
21 #include <algorithm>
22 #include <limits>
23 
24 namespace OpenMS
25 {
26  class AnnotatedMSRun;
40  class OPENMS_DLLAPI IDMapper :
41  public DefaultParamHandler
42  {
43 public:
44  enum Measure {MEASURE_PPM = 0, MEASURE_DA};
45 
48 
50  IDMapper(const IDMapper& cp);
51 
53  IDMapper& operator=(const IDMapper& rhs);
54 
70  void annotate(AnnotatedMSRun& map, const PeptideIdentificationList& peptide_ids, const std::vector<ProteinIdentification>& protein_ids, const bool clear_ids = false, const bool map_ms1 = false);
71 
87  void annotate(AnnotatedMSRun& map, const FeatureMap& fmap, const bool clear_ids = false, const bool map_ms1 = false);
88 
108  void annotate(FeatureMap& map, const PeptideIdentificationList& ids, const std::vector<ProteinIdentification>& protein_ids, bool use_centroid_rt = false, bool use_centroid_mz = false, const PeakMap& spectra = PeakMap());
109 
127  const std::vector<ProteinIdentification>& protein_ids,
128  bool measure_from_subelements = false,
129  bool annotate_ids_with_subelements = false,
130  const PeakMap& spectra = PeakMap());
131 
132 
137  {
138  std::vector<Size> no_precursors;
139  std::vector<Size> identified;
140  std::vector<Size> unidentified;
141  };
142 
159  const PeptideIdentificationList& ids,
160  double mz_tol = 0.001,
161  double rt_tol = 0.001)
162  {
164  for (Size spectrum_index = 0; spectrum_index < spectra.size(); ++spectrum_index)
165  {
166  const MSSpectrum& spectrum = spectra[spectrum_index];
167  if (!spectrum.getPrecursors().empty())
168  {
169  bool identified(false);
170  const std::vector<Precursor>& precursors = spectrum.getPrecursors();
171 
172  // check if precursor has been identified
173  for (Size i_p = 0; i_p < precursors.size(); ++i_p)
174  {
175  // check by precursor mass and spectrum RT
176  double mz_p = precursors[i_p].getMZ();
177  double rt_s = spectrum.getRT();
178 
179  for (Size i_id = 0; i_id != ids.size(); ++i_id)
180  {
181  const PeptideIdentification& pid = ids[i_id];
182 
183  // do not count empty ids as identification of a spectrum
184  if (pid.getHits().empty()) continue;
185 
186  double mz_id = pid.getMZ();
187  double rt_id = pid.getRT();
188 
189  if ( fabs(mz_id - mz_p) < mz_tol && fabs(rt_s - rt_id) < rt_tol )
190  {
191  identified = true;
192  break;
193  }
194  }
195  }
196  if (!identified)
197  {
198  ret.unidentified.push_back(spectrum_index);
199  }
200  else
201  {
202  ret.identified.push_back(spectrum_index);
203  }
204  }
205  else
206  {
207  ret.no_precursors.push_back(spectrum_index);
208  }
209  }
210  return ret;
211  }
212 
213 
214 protected:
215  void updateMembers_() override;
216 
225 
229  double getAbsoluteMZTolerance_(const double mz) const;
230 
232  bool isMatch_(const double rt_distance, const double mz_theoretical, const double mz_observed) const;
233 
235  void checkHits_(const PeptideIdentificationList& ids) const;
236 
240  void getIDDetails_(const PeptideIdentification& id, double& rt_pep, DoubleList& mz_values, IntList& charges, bool use_avg_mass = false) const;
241 
244 
247  bool checkMassType_(const std::vector<DataProcessing>& processing) const;
248 
249  };
250 
251 } // namespace OpenMS
252 
Class for storing MS run data with peptide and protein identifications.
Definition: AnnotatedMSRun.h:36
A container for consensus elements.
Definition: ConsensusMap.h:68
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
size_t size() const noexcept
Definition: ExposedVector.h:128
A container for features.
Definition: FeatureMap.h:82
Annotates an MSExperiment, FeatureMap or ConsensusMap with peptide identifications.
Definition: IDMapper.h:42
void getIDDetails_(const PeptideIdentification &id, double &rt_pep, DoubleList &mz_values, IntList &charges, bool use_avg_mass=false) const
std::vector< Size > unidentified
Definition: IDMapper.h:140
Measure measure_
Measure used for m/z.
Definition: IDMapper.h:222
void annotate(FeatureMap &map, const PeptideIdentificationList &ids, const std::vector< ProteinIdentification > &protein_ids, bool use_centroid_rt=false, bool use_centroid_mz=false, const PeakMap &spectra=PeakMap())
Mapping method for feature maps.
void increaseBoundingBox_(DBoundingBox< 2 > &box)
increase a bounding box by the given RT and m/z tolerances
void annotate(AnnotatedMSRun &map, const FeatureMap &fmap, const bool clear_ids=false, const bool map_ms1=false)
Mapping method for peak maps.
double getAbsoluteMZTolerance_(const double mz) const
void annotate(ConsensusMap &map, const PeptideIdentificationList &ids, const std::vector< ProteinIdentification > &protein_ids, bool measure_from_subelements=false, bool annotate_ids_with_subelements=false, const PeakMap &spectra=PeakMap())
Mapping method for consensus maps.
void annotate(AnnotatedMSRun &map, const PeptideIdentificationList &peptide_ids, const std::vector< ProteinIdentification > &protein_ids, const bool clear_ids=false, const bool map_ms1=false)
Mapping method for peak maps.
bool isMatch_(const double rt_distance, const double mz_theoretical, const double mz_observed) const
check if distance constraint is fulfilled (using rt_tolerance_, mz_tolerance_ and measure_)
IDMapper & operator=(const IDMapper &rhs)
Assignment.
double mz_tolerance_
Allowed m/z deviation.
Definition: IDMapper.h:220
void checkHits_(const PeptideIdentificationList &ids) const
helper function that checks if all peptide hits are annotated with RT and MZ meta values
IDMapper()
Default constructor.
std::vector< Size > no_precursors
Definition: IDMapper.h:138
bool checkMassType_(const std::vector< DataProcessing > &processing) const
IDMapper(const IDMapper &cp)
Copy C'Tor.
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
bool ignore_charge_
Ignore charge states during matching?
Definition: IDMapper.h:224
std::vector< Size > identified
Definition: IDMapper.h:139
Measure
Definition: IDMapper.h:44
static PeptideIdentificationListState mapPrecursorsToIdentifications(const PeakMap &spectra, const PeptideIdentificationList &ids, double mz_tol=0.001, double rt_tol=0.001)
Mapping of peptide identifications to spectra This helper function partitions all spectra into those ...
Definition: IDMapper.h:158
double rt_tolerance_
Allowed RT deviation.
Definition: IDMapper.h:218
Result of a partitioning by identification state with mapPrecursorsToIdentifications().
Definition: IDMapper.h:137
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:49
Size size() const noexcept
The number of spectra.
Definition: MSExperiment.h:128
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
double getRT() const
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
double getRT() const
returns the RT of the MS2 spectrum where the identification occurred
const std::vector< PeptideHit > & getHits() const
returns the peptide hits as const
double getMZ() const
returns the MZ of the MS2 spectrum
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
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
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:36
MSExperiment PeakMap
Two-dimensional map of raw data points or peaks.
Definition: StandardTypes.h:35
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19