OpenMS  3.0.0
IDMapper.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: Marc Sturm, Hendrik Weisser, Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
41 
43 
45 
46 #include <algorithm>
47 #include <limits>
48 
49 namespace OpenMS
50 {
64  class OPENMS_DLLAPI IDMapper :
65  public DefaultParamHandler
66  {
67 public:
68  enum Measure {MEASURE_PPM = 0, MEASURE_DA};
69 
71  IDMapper();
72 
74  IDMapper(const IDMapper& cp);
75 
77  IDMapper& operator=(const IDMapper& rhs);
78 
94  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);
95 
111  void annotate(PeakMap& map, FeatureMap fmap, const bool clear_ids = false, const bool map_ms1 = false);
112 
131  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());
132 
149  void annotate(ConsensusMap& map, const std::vector<PeptideIdentification>& ids,
150  const std::vector<ProteinIdentification>& protein_ids,
151  bool measure_from_subelements = false,
152  bool annotate_ids_with_subelements = false,
153  const PeakMap& spectra = PeakMap());
154 
155 
160  {
161  std::vector<Size> no_precursors;
162  std::vector<Size> identified;
163  std::vector<Size> unidentified;
164  };
165 
182  const std::vector<PeptideIdentification>& ids,
183  double mz_tol = 0.001,
184  double rt_tol = 0.001)
185  {
187  for (Size spectrum_index = 0; spectrum_index < spectra.size(); ++spectrum_index)
188  {
189  const MSSpectrum& spectrum = spectra[spectrum_index];
190  if (!spectrum.getPrecursors().empty())
191  {
192  bool identified(false);
193  const std::vector<Precursor>& precursors = spectrum.getPrecursors();
194 
195  // check if precursor has been identified
196  for (Size i_p = 0; i_p < precursors.size(); ++i_p)
197  {
198  // check by precursor mass and spectrum RT
199  double mz_p = precursors[i_p].getMZ();
200  double rt_s = spectrum.getRT();
201 
202  for (Size i_id = 0; i_id != ids.size(); ++i_id)
203  {
204  const PeptideIdentification& pid = ids[i_id];
205 
206  // do not count empty ids as identification of a spectrum
207  if (pid.getHits().empty()) continue;
208 
209  double mz_id = pid.getMZ();
210  double rt_id = pid.getRT();
211 
212  if ( fabs(mz_id - mz_p) < mz_tol && fabs(rt_s - rt_id) < rt_tol )
213  {
214  identified = true;
215  break;
216  }
217  }
218  }
219  if (!identified)
220  {
221  ret.unidentified.push_back(spectrum_index);
222  }
223  else
224  {
225  ret.identified.push_back(spectrum_index);
226  }
227  }
228  else
229  {
230  ret.no_precursors.push_back(spectrum_index);
231  }
232  }
233  return ret;
234  }
235 
236 
237 protected:
238  void updateMembers_() override;
239 
248 
252  double getAbsoluteMZTolerance_(const double mz) const;
253 
255  bool isMatch_(const double rt_distance, const double mz_theoretical, const double mz_observed) const;
256 
258  void checkHits_(const std::vector<PeptideIdentification>& ids) const;
259 
263  void getIDDetails_(const PeptideIdentification& id, double& rt_pep, DoubleList& mz_values, IntList& charges, bool use_avg_mass = false) const;
264 
266  void increaseBoundingBox_(DBoundingBox<2>& box);
267 
270  bool checkMassType_(const std::vector<DataProcessing>& processing) const;
271 
272  };
273 
274 } // namespace OpenMS
275 
LogStream.h
DefaultParamHandler.h
OpenMS::Param::ParamEntry::valid_strings
std::vector< std::string > valid_strings
Default: empty.
Definition: Param.h:111
OpenMS::FileTypes::IDXML
OpenMS identification format (.idXML)
Definition: FileTypes.h:64
OpenMS::IDMapper::ignore_charge_
bool ignore_charge_
Ignore charge states during matching?
Definition: IDMapper.h:247
ConsensusXMLFile.h
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:147
FileHandler.h
FileTypes.h
OpenMS::IDMapper::rt_tolerance_
double rt_tolerance_
Allowed RT deviation.
Definition: IDMapper.h:241
OpenMS::ConsensusXMLFile::store
void store(const String &filename, const ConsensusMap &consensus_map)
Stores a consensus map to file.
OpenMS::Param::setValue
void setValue(const std::string &key, const ParamValue &value, const std::string &description="", const std::vector< std::string > &tags=std::vector< std::string >())
Sets a value.
OpenMS::Exception::IllegalArgument
A method or algorithm argument contains illegal values.
Definition: Exception.h:648
OpenMS::Param::getEntry
const ParamEntry & getEntry(const std::string &key) const
Returns the whole parameter entry.
OpenMS::IDMapper::SpectraIdentificationState
Result of a partitioning by identification state with mapPrecursorsToIdentifications().
Definition: IDMapper.h:159
OpenMS::IDMapper::mz_tolerance_
double mz_tolerance_
Allowed m/z deviation.
Definition: IDMapper.h:243
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::DoubleList
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:62
ConsensusMap.h
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:70
OpenMS::SpectrumSettings::getPrecursors
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
OpenMS::FileTypes::CONSENSUSXML
OpenMS consensus map format (.consensusXML)
Definition: FileTypes.h:65
OpenMS::IDMapper::mapPrecursorsToIdentifications
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:181
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::FileTypes::MZQUANTML
mzQuantML (HUPO PSI AnalysisXML followup format) (.mzq)
Definition: FileTypes.h:76
IdXMLFile.h
FeatureXMLFile.h
OpenMS::MSSpectrum::getRT
double getRT() const
OpenMS::FileTypes::MZIDENTML
mzIdentML (HUPO PSI AnalysisXML followup format) (.mzid)
Definition: FileTypes.h:75
OpenMS::IntList
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:55
OpenMS::IDMapper::measure_
Measure measure_
Measure used for m/z.
Definition: IDMapper.h:245
ListUtils.h
OpenMS::MSExperiment::size
Size size() const
Definition: MSExperiment.h:120
OpenMS::IDMapper::annotate
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.
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
OpenMS::IDMapper::SpectraIdentificationState::unidentified
std::vector< Size > unidentified
Definition: IDMapper.h:163
OpenMS::PeptideIdentification::getHits
const std::vector< PeptideHit > & getHits() const
returns the peptide hits as const
OpenMS::MzQuantMLFile
File adapter for MzQuantML files.
Definition: MzQuantMLFile.h:51
OpenMS::MSQuantifications::getConsensusMaps
const std::vector< ConsensusMap > & getConsensusMaps() const
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::MzIdentMLFile
File adapter for MzIdentML files.
Definition: MzIdentMLFile.h:67
OpenMS::ConsensusMap::sortPeptideIdentificationsByMapIndex
void sortPeptideIdentificationsByMapIndex()
Sorts PeptideIdentifications of consensus features with respect to their map index.
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::FileTypes::FEATUREXML
OpenMS feature file (.featureXML)
Definition: FileTypes.h:63
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...
MSQuantifications.h
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::IDMapper::SpectraIdentificationState::no_precursors
std::vector< Size > no_precursors
Definition: IDMapper.h:161
OpenMS::FileTypes::Type
Type
Actual file types enum.
Definition: FileTypes.h:56
OpenMS::FileHandler::getType
static FileTypes::Type getType(const String &filename)
Tries to determine the file type (by name or content)
OpenMS::DBoundingBox< 2 >
OpenMS::DefaultParamHandler::setParameters
void setParameters(const Param &param)
Sets the parameters.
OpenMS::DefaultParamHandler::getParameters
const Param & getParameters() const
Non-mutable access to the parameters.
OpenMS::PeakMap
MSExperiment PeakMap
Two-dimensional map of raw data points or peaks.
Definition: StandardTypes.h:61
OpenMS::ConsensusMap
A container for consensus elements.
Definition: ConsensusMap.h:82
OpenMS::FeatureXMLFile::store
void store(const String &filename, const FeatureMap &feature_map)
stores the map feature_map in file with name filename.
OpenMS::ConsensusXMLFile::load
void load(const String &filename, ConsensusMap &map)
Loads a consensus map from file and calls updateRanges.
OpenMS::MzIdentMLFile::load
void load(const String &filename, std::vector< ProteinIdentification > &poid, std::vector< PeptideIdentification > &peid)
Loads the identifications from a MzIdentML file.
IDMapper.h
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:71
OpenMS::MzQuantMLFile::store
void store(const String &filename, const MSQuantifications &cmsq) const
Stores a map in a MzQuantML file.
MSExperiment.h
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:98
OpenMS::PeptideIdentification
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:63
OpenMS::PeptideIdentification::getMZ
double getMZ() const
returns the MZ of the MS2 spectrum
OpenMS::IDMapper::Measure
Measure
Definition: IDMapper.h:68
OpenMS::FeatureXMLFile
This class provides Input/Output functionality for feature maps.
Definition: FeatureXMLFile.h:62
MzQuantMLFile.h
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:69
OpenMS::IDMapper::SpectraIdentificationState::identified
std::vector< Size > identified
Definition: IDMapper.h:162
OpenMS::MSQuantifications
Definition: MSQuantifications.h:52
OpenMS::DataProcessing::IDENTIFICATION_MAPPING
Identification mapping
Definition: DataProcessing.h:74
OpenMS::IDMapper
Annotates an MSExperiment, FeatureMap or ConsensusMap with peptide identifications.
Definition: IDMapper.h:64
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
OpenMS::Param::getValue
const ParamValue & getValue(const std::string &key) const
Returns a value of a parameter.
OpenMS::MzQuantMLFile::load
void load(const String &filename, MSQuantifications &msq)
Loads a map from a MzQuantML file.
StandardTypes.h
MzIdentMLFile.h
TOPPBase.h
OpenMS::ConsensusXMLFile
This class provides Input functionality for ConsensusMaps and Output functionality for alignments and...
Definition: ConsensusXMLFile.h:58
OpenMS::IdXMLFile
Used to load and store idXML files.
Definition: IdXMLFile.h:68
OpenMS::PeptideIdentification::getRT
double getRT() const
returns the RT of the MS2 spectrum where the identification occurred