OpenMS
IDMapper.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, 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: Marc Sturm, Hendrik Weisser, Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
15 
17 
19 
20 #include <algorithm>
21 #include <limits>
22 
23 namespace OpenMS
24 {
38  class OPENMS_DLLAPI IDMapper :
39  public DefaultParamHandler
40  {
41 public:
42  enum Measure {MEASURE_PPM = 0, MEASURE_DA};
43 
46 
48  IDMapper(const IDMapper& cp);
49 
51  IDMapper& operator=(const IDMapper& rhs);
52 
68  void annotate(PeakMap& map, const std::vector<PeptideIdentification>& peptide_ids, const std::vector<ProteinIdentification>& protein_ids, const bool clear_ids = false, const bool map_ms1 = false);
69 
85  void annotate(PeakMap& map, FeatureMap fmap, const bool clear_ids = false, const bool map_ms1 = false);
86 
105  void annotate(FeatureMap& map, const std::vector<PeptideIdentification>& ids, const std::vector<ProteinIdentification>& protein_ids, bool use_centroid_rt = false, bool use_centroid_mz = false, const PeakMap& spectra = PeakMap());
106 
123  void annotate(ConsensusMap& map, const std::vector<PeptideIdentification>& ids,
124  const std::vector<ProteinIdentification>& protein_ids,
125  bool measure_from_subelements = false,
126  bool annotate_ids_with_subelements = false,
127  const PeakMap& spectra = PeakMap());
128 
129 
134  {
135  std::vector<Size> no_precursors;
136  std::vector<Size> identified;
137  std::vector<Size> unidentified;
138  };
139 
156  const std::vector<PeptideIdentification>& ids,
157  double mz_tol = 0.001,
158  double rt_tol = 0.001)
159  {
161  for (Size spectrum_index = 0; spectrum_index < spectra.size(); ++spectrum_index)
162  {
163  const MSSpectrum& spectrum = spectra[spectrum_index];
164  if (!spectrum.getPrecursors().empty())
165  {
166  bool identified(false);
167  const std::vector<Precursor>& precursors = spectrum.getPrecursors();
168 
169  // check if precursor has been identified
170  for (Size i_p = 0; i_p < precursors.size(); ++i_p)
171  {
172  // check by precursor mass and spectrum RT
173  double mz_p = precursors[i_p].getMZ();
174  double rt_s = spectrum.getRT();
175 
176  for (Size i_id = 0; i_id != ids.size(); ++i_id)
177  {
178  const PeptideIdentification& pid = ids[i_id];
179 
180  // do not count empty ids as identification of a spectrum
181  if (pid.getHits().empty()) continue;
182 
183  double mz_id = pid.getMZ();
184  double rt_id = pid.getRT();
185 
186  if ( fabs(mz_id - mz_p) < mz_tol && fabs(rt_s - rt_id) < rt_tol )
187  {
188  identified = true;
189  break;
190  }
191  }
192  }
193  if (!identified)
194  {
195  ret.unidentified.push_back(spectrum_index);
196  }
197  else
198  {
199  ret.identified.push_back(spectrum_index);
200  }
201  }
202  else
203  {
204  ret.no_precursors.push_back(spectrum_index);
205  }
206  }
207  return ret;
208  }
209 
210 
211 protected:
212  void updateMembers_() override;
213 
222 
226  double getAbsoluteMZTolerance_(const double mz) const;
227 
229  bool isMatch_(const double rt_distance, const double mz_theoretical, const double mz_observed) const;
230 
232  void checkHits_(const std::vector<PeptideIdentification>& ids) const;
233 
237  void getIDDetails_(const PeptideIdentification& id, double& rt_pep, DoubleList& mz_values, IntList& charges, bool use_avg_mass = false) const;
238 
241 
244  bool checkMassType_(const std::vector<DataProcessing>& processing) const;
245 
246  };
247 
248 } // namespace OpenMS
249 
A container for consensus elements.
Definition: ConsensusMap.h:66
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
A container for features.
Definition: FeatureMap.h:80
Annotates an MSExperiment, FeatureMap or ConsensusMap with peptide identifications.
Definition: IDMapper.h:40
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:137
Measure measure_
Measure used for m/z.
Definition: IDMapper.h:219
void increaseBoundingBox_(DBoundingBox< 2 > &box)
increase a bounding box by the given RT and m/z tolerances
double getAbsoluteMZTolerance_(const double mz) const
void checkHits_(const std::vector< PeptideIdentification > &ids) const
helper function that checks if all peptide hits are annotated with RT and MZ meta values
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:217
static SpectraIdentificationState mapPrecursorsToIdentifications(const PeakMap &spectra, const std::vector< PeptideIdentification > &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:155
void annotate(ConsensusMap &map, const std::vector< PeptideIdentification > &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.
IDMapper()
Default constructor.
std::vector< Size > no_precursors
Definition: IDMapper.h:135
bool checkMassType_(const std::vector< DataProcessing > &processing) const
IDMapper(const IDMapper &cp)
Copy C'Tor.
void annotate(PeakMap &map, FeatureMap fmap, const bool clear_ids=false, const bool map_ms1=false)
Mapping method for peak maps.
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
void annotate(FeatureMap &map, const std::vector< PeptideIdentification > &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.
bool ignore_charge_
Ignore charge states during matching?
Definition: IDMapper.h:221
std::vector< Size > identified
Definition: IDMapper.h:136
void annotate(PeakMap &map, const std::vector< PeptideIdentification > &peptide_ids, const std::vector< ProteinIdentification > &protein_ids, const bool clear_ids=false, const bool map_ms1=false)
Mapping method for peak maps.
Measure
Definition: IDMapper.h:42
double rt_tolerance_
Allowed RT deviation.
Definition: IDMapper.h:215
Result of a partitioning by identification state with mapPrecursorsToIdentifications().
Definition: IDMapper.h:134
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
Size size() const
The number of spectra.
Definition: MSExperiment.h:121
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
double getRT() const
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:39
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:101
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: FeatureDeconvolution.h:22