| OpenMS 2.5.0

FalseDiscoveryRate.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: Andreas Bertsch, Chris Bielow $
33 // --------------------------------------------------------------------------
34
35 #pragma once
36
37 #include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
38 #include <OpenMS/METADATA/ID/IdentificationData.h>
39 #include <OpenMS/METADATA/PeptideIdentification.h>
40 #include <OpenMS/METADATA/ProteinIdentification.h>
41 #include <OpenMS/KERNEL/ConsensusMap.h>
42
43 #include <boost/unordered_map.hpp>
44
45 #include <vector>
46 #include <unordered_set>
47
48 namespace OpenMS
49 {
50
51 struct ScoreToTgtDecLabelPairs;
52
77 class OPENMS_DLLAPI FalseDiscoveryRate :
78 public DefaultParamHandler
79 {
80 public:
82 FalseDiscoveryRate();
83
90 void apply(std::vector<PeptideIdentification>& fwd_ids, std::vector<PeptideIdentification>& rev_ids) const;
91
97 void apply(std::vector<PeptideIdentification>& id) const;
98
105 void apply(std::vector<ProteinIdentification>& fwd_ids, std::vector<ProteinIdentification>& rev_ids) const;
106
112 void apply(std::vector<ProteinIdentification>& ids) const;
113
119 void applyEstimated(std::vector<ProteinIdentification>& ids) const;
120
130 double applyEvaluateProteinIDs(const std::vector<ProteinIdentification>& ids, double pepCutoff = 1.0, UInt fpCutoff = 50, double diffWeight = 0.2);
131 double applyEvaluateProteinIDs(const ProteinIdentification& ids, double pepCutoff = 1.0, UInt fpCutoff = 50, double diffWeight = 0.2);
132
134 void applyBasic(std::vector<PeptideIdentification> & ids);
136 void applyBasic(ConsensusMap & cmap, bool use_unassigned_peptides = true);
138 void applyBasic(ProteinIdentification & id, bool groups_too = true);
139
142 double rocN(const std::vector<PeptideIdentification>& ids, Size fp_cutoff) const;
143
146 double rocN(const std::vector<PeptideIdentification>& ids, Size fp_cutoff, const String& identifier) const;
147
150 double rocN(const ConsensusMap& ids, Size fp_cutoff) const;
151
154 double rocN(const ConsensusMap& ids, Size fp_cutoff, const String& identifier) const;
155
164 IdentificationData::ScoreTypeRef applyToQueryMatches(IdentificationData& id_data, IdentificationData::ScoreTypeRef score_ref) const;
165
166
167 private:
168
170 FalseDiscoveryRate(const FalseDiscoveryRate&);
171
173 FalseDiscoveryRate& operator=(const FalseDiscoveryRate&);
174
176 void calculateFDRs_(std::map<double, double>& score_to_fdr, std::vector<double>& target_scores, std::vector<double>& decoy_scores, bool q_value, bool higher_score_better) const;
177
179 void handleQueryMatch_(
180 IdentificationData::QueryMatchRef match_ref,
181 IdentificationData::ScoreTypeRef score_ref,
182 std::vector<double>& target_scores,
183 std::vector<double>& decoy_scores,
184 std::map<IdentificationData::IdentifiedMoleculeRef, bool>& molecule_to_decoy,
185 std::map<IdentificationData::QueryMatchRef, double>& match_to_score) const;
186
189 void calculateEstimatedQVal_(std::map<double, double> &scores_to_FDR,
190 ScoreToTgtDecLabelPairs &scores_labels,
191 bool higher_score_better) const;
192
198 void calculateFDRBasic_(std::map<double,double>& scores_to_FDR, ScoreToTgtDecLabelPairs& scores_labels, bool qvalue, bool higher_score_better) const;
199
200 //TODO the next two methods could potentially be merged for speed (they iterate over the same structure)
201 //But since they have different cutoff types and it is more generic, I leave it like this.
203 double diffEstimatedEmpirical_(const ScoreToTgtDecLabelPairs& scores_labels, double pepCutoff = 1.0) const;
204
207 double rocN_(const ScoreToTgtDecLabelPairs& scores_labels, Size fpCutoff = 50) const;
208
211 double trapezoidal_area_xEqy(double exp1, double exp2, double act1, double act2) const;
212
214 double trapezoidal_area(double x1, double x2, double y1, double y2) const;
215
216 };
217
218 } // namespace OpenMS
219
ProteinIdentification.h
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::FalseDiscoveryRate
Calculates false discovery rates (FDR) from identifications.
Definition: FalseDiscoveryRate.h:77
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:91
OpenMS::IdentificationDataInternal::IteratorWrapper
Wrapper that adds operator< to iterators, so they can be used as (part of) keys in maps/sets or multi...
Definition: MetaData.h:43
OpenMS::ProteinIdentification
Representation of a protein identification run.
Definition: ProteinIdentification.h:71
ConsensusMap.h
IdentificationData.h
PeptideIdentification.h
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
DefaultParamHandler.h
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::ConsensusMap
A container for consensus elements.
Definition: ConsensusMap.h:79
OpenMS::ScoreToTgtDecLabelPairs
Definition: IDScoreGetterSetter.h:53
OpenMS::IdentificationData
Representation of spectrum identification results and associated data.
Definition: IdentificationData.h:89
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127