| OpenMS 2.5.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-2020.
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
37 #include <OpenMS/KERNEL/StandardTypes.h>
38 #include <OpenMS/KERNEL/MSExperiment.h>
39 #include <OpenMS/KERNEL/FeatureMap.h>
40 #include <OpenMS/KERNEL/ConsensusMap.h>
41
42 #include <OpenMS/DATASTRUCTURES/ListUtils.h>
43
44 #include <OpenMS/CONCEPT/LogStream.h>
45
46 #include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
47
48 #include <algorithm>
49 #include <limits>
50
51 namespace OpenMS
52 {
66 class OPENMS_DLLAPI IDMapper :
67 public DefaultParamHandler
68 {
69 public:
70 enum Measure {MEASURE_PPM = 0, MEASURE_DA};
71
73 IDMapper();
74
76 IDMapper(const IDMapper& cp);
77
79 IDMapper& operator=(const IDMapper& rhs);
80
96 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);
97
113 void annotate(PeakMap& map, FeatureMap fmap, const bool clear_ids = false, const bool map_ms1 = false);
114
133 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());
134
151 void annotate(ConsensusMap& map, const std::vector<PeptideIdentification>& ids,
152 const std::vector<ProteinIdentification>& protein_ids,
153 bool measure_from_subelements = false,
154 bool annotate_ids_with_subelements = false,
155 const PeakMap& spectra = PeakMap());
156
157
161 struct SpectraIdentificationState
162 {
163 std::vector<Size> no_precursors;
164 std::vector<Size> identified;
165 std::vector<Size> unidentified;
166 };
167
183 static SpectraIdentificationState mapPrecursorsToIdentifications(const PeakMap& spectra,
184 const std::vector<PeptideIdentification>& ids,
185 double mz_tol = 0.001,
186 double rt_tol = 0.001)
187 {
188 SpectraIdentificationState ret;
189 for (Size spectrum_index = 0; spectrum_index < spectra.size(); ++spectrum_index)
190 {
191 const MSSpectrum& spectrum = spectra[spectrum_index];
192 if (!spectrum.getPrecursors().empty())
193 {
194 bool identified(false);
195 const std::vector<Precursor>& precursors = spectrum.getPrecursors();
196
197 // check if precursor has been identified
198 for (Size i_p = 0; i_p < precursors.size(); ++i_p)
199 {
200 // check by precursor mass and spectrum RT
201 double mz_p = precursors[i_p].getMZ();
202 double rt_s = spectrum.getRT();
203
204 for (Size i_id = 0; i_id != ids.size(); ++i_id)
205 {
206 const PeptideIdentification& pid = ids[i_id];
207
208 // do not count empty ids as identification of a spectrum
209 if (pid.getHits().empty()) continue;
210
211 double mz_id = pid.getMZ();
212 double rt_id = pid.getRT();
213
214 if ( fabs(mz_id - mz_p) < mz_tol && fabs(rt_s - rt_id) < rt_tol )
215 {
216 identified = true;
217 break;
218 }
219 }
220 }
221 if (!identified)
222 {
223 ret.unidentified.push_back(spectrum_index);
224 }
225 else
226 {
227 ret.identified.push_back(spectrum_index);
228 }
229 }
230 else
231 {
232 ret.no_precursors.push_back(spectrum_index);
233 }
234 }
235 return ret;
236 }
237
238
239 protected:
240 void updateMembers_() override;
241
243 double rt_tolerance_;
245 double mz_tolerance_;
247 Measure measure_;
249 bool ignore_charge_;
250
254 double getAbsoluteMZTolerance_(const double mz) const;
255
257 bool isMatch_(const double rt_distance, const double mz_theoretical, const double mz_observed) const;
258
260 void checkHits_(const std::vector<PeptideIdentification>& ids) const;
261
265 void getIDDetails_(const PeptideIdentification& id, double& rt_pep, DoubleList& mz_values, IntList& charges, bool use_avg_mass = false) const;
266
268 void increaseBoundingBox_(DBoundingBox<2>& box);
269
272 bool checkMassType_(const std::vector<DataProcessing>& processing) const;
273
274 };
275
276 } // namespace OpenMS
277
OpenMS::IDMapper::SpectraIdentificationState::identified
std::vector< Size > identified
Definition: IDMapper.h:164
OpenMS::IDMapper::Measure
Measure
Definition: IDMapper.h:70
OpenMS::IntList
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:55
OpenMS::MSSpectrum::getRT
double getRT() const
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:91
OpenMS::IDMapper::SpectraIdentificationState
Result of a partitioning by identification state with mapPrecursorsToIdentifications().
Definition: IDMapper.h:161
OpenMS::IDMapper::mz_tolerance_
double mz_tolerance_
Allowed m/z deviation.
Definition: IDMapper.h:245
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
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:183
OpenMS::PeakMap
MSExperiment PeakMap
Two-dimensional map of raw data points or peaks.
Definition: StandardTypes.h:61
OpenMS::IDMapper::measure_
Measure measure_
Measure used for m/z.
Definition: IDMapper.h:247
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:95
OpenMS::IDMapper::SpectraIdentificationState::no_precursors
std::vector< Size > no_precursors
Definition: IDMapper.h:163
StandardTypes.h
OpenMS::SpectrumSettings::getPrecursors
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
ConsensusMap.h
OpenMS::DBoundingBox< 2 >
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
FeatureMap.h
OpenMS::DoubleList
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:62
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
MSExperiment.h
LogStream.h
DefaultParamHandler.h
OpenMS::IDMapper
Annotates an MSExperiment, FeatureMap or ConsensusMap with peptide identifications.
Definition: IDMapper.h:66
OpenMS::MSExperiment::size
Size size() const
Definition: MSExperiment.h:127
OpenMS::PeptideIdentification::getHits
const std::vector< PeptideHit > & getHits() const
returns the peptide hits as const
OpenMS::PeptideIdentification
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:62
OpenMS::ConsensusMap
A container for consensus elements.
Definition: ConsensusMap.h:79
OpenMS::IDMapper::rt_tolerance_
double rt_tolerance_
Allowed RT deviation.
Definition: IDMapper.h:243
OpenMS::PeptideIdentification::getMZ
double getMZ() const
returns the MZ of the MS2 spectrum
OpenMS::IDMapper::ignore_charge_
bool ignore_charge_
Ignore charge states during matching?
Definition: IDMapper.h:249
OpenMS::IDMapper::SpectraIdentificationState::unidentified
std::vector< Size > unidentified
Definition: IDMapper.h:165
ListUtils.h
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::PeptideIdentification::getRT
double getRT() const
returns the RT of the MS2 spectrum where the identification occurred