OpenMS
PeptideAndProteinQuant.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-2023.
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: Hendrik Weisser $
32 // $Authors: Hendrik Weisser $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
43 
44 
45 namespace OpenMS
46 {
54  class OPENMS_DLLAPI PeptideAndProteinQuant :
55  public DefaultParamHandler
56  {
57 public:
58 
60  typedef std::map<UInt64, double> SampleAbundances;
61 
63  struct PeptideData
64  {
66  std::map<Int, std::map<Int, SampleAbundances>> abundances;
67 
69  std::map<Int, std::map<Int, SampleAbundances>> psm_counts;
70 
73 
76 
78  std::set<String> accessions;
79 
81  Size psm_count = 0;
82 
84  PeptideData() = default;
85  };
86 
88  typedef std::map<AASequence, PeptideData> PeptideQuant;
89 
91  struct ProteinData
92  {
94  std::map<String, SampleAbundances> abundances;
95 
96  std::map<String, SampleAbundances> psm_counts;
97 
100 
103 
106 
108  Size psm_count = 0;
109 
111  ProteinData() = default;
112  };
113 
115  typedef std::map<String, ProteinData> ProteinQuant;
116 
118  struct Statistics
119  {
122 
125 
128 
130  Size quant_proteins, too_few_peptides;
131 
133  Size quant_peptides, total_peptides;
134 
136  Size quant_features, total_features, blank_features, ambig_features;
137 
140  n_samples(0), quant_proteins(0), too_few_peptides(0),
141  quant_peptides(0), total_peptides(0), quant_features(0),
142  total_features(0), blank_features(0), ambig_features(0) {}
143  };
144 
147 
150 
156  void readQuantData(FeatureMap& features, const ExperimentalDesign& ed);
157 
163  void readQuantData(ConsensusMap& consensus, const ExperimentalDesign& ed);
164 
170  void readQuantData(std::vector<ProteinIdentification>& proteins,
171  std::vector<PeptideIdentification>& peptides,
172  const ExperimentalDesign& ed);
173 
183  void quantifyPeptides(const std::vector<PeptideIdentification>& peptides =
184  std::vector<PeptideIdentification>());
185 
186 
192  void quantifyProteins(const ProteinIdentification& proteins =
194 
197 
200 
203 
206  const ProteinQuant& protein_quants,
207  ProteinIdentification& proteins,
208  bool remove_unquantified = true);
209 
210 private:
211 
214 
217 
220 
221 
228  PeptideHit getAnnotation_(std::vector<PeptideIdentification>& peptides);
229 
238  void quantifyFeature_(const FeatureHandle& feature,
239  size_t fraction,
240  size_t sample,
241  const PeptideHit& hit);
242 
250  bool getBest_(
251  const std::map<Int, std::map<Int, SampleAbundances>> & peptide_abundances,
252  std::pair<size_t, size_t> & best);
253 
259  template <typename T>
260  void orderBest_(const std::map<T, SampleAbundances> & abundances,
261  std::vector<T>& result)
262  {
263  typedef std::pair<Size, double> PairType;
264  std::multimap<PairType, T, std::greater<PairType> > order;
265  for (typename std::map<T, SampleAbundances>::const_iterator ab_it =
266  abundances.begin(); ab_it != abundances.end(); ++ab_it)
267  {
268  double total = 0.0;
269  for (SampleAbundances::const_iterator samp_it = ab_it->second.begin();
270  samp_it != ab_it->second.end(); ++samp_it)
271  {
272  total += samp_it->second;
273  }
274  if (total <= 0.0) continue; // not quantified
275  PairType key = std::make_pair(ab_it->second.size(), total);
276  order.insert(std::make_pair(key, ab_it->first));
277  }
278  result.clear();
279  for (typename std::multimap<PairType, T, std::greater<PairType> >::
280  iterator ord_it = order.begin(); ord_it != order.end(); ++ord_it)
281  {
282  result.push_back(ord_it->second);
283  }
284  }
285 
286 
287 
292 
305  String getAccession_(const std::set<String>& pep_accessions,
306  std::map<String, String>& accession_to_leader);
307 
313  void countPeptides_(std::vector<PeptideIdentification>& peptides);
314 
316  void updateMembers_() override;
317 
318  }; // class
319 
320 } // namespace
321 
A container for consensus elements.
Definition: ConsensusMap.h:92
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
Representation of an experimental design in OpenMS. Instances can be loaded with the ExperimentalDesi...
Definition: ExperimentalDesign.h:245
Representation of a Peak2D, RichPeak2D or Feature .
Definition: FeatureHandle.h:60
A container for features.
Definition: FeatureMap.h:106
Helper class for peptide and protein quantification based on feature data annotated with IDs.
Definition: PeptideAndProteinQuant.h:56
void readQuantData(ConsensusMap &consensus, const ExperimentalDesign &ed)
Read quantitative data from a consensus map.
void annotateQuantificationsToProteins(const ProteinQuant &protein_quants, ProteinIdentification &proteins, bool remove_unquantified=true)
Annotate protein quant results as meta data to protein ids.
std::map< AASequence, PeptideData > PeptideQuant
Mapping: peptide sequence (modified) -> peptide data.
Definition: PeptideAndProteinQuant.h:88
void readQuantData(FeatureMap &features, const ExperimentalDesign &ed)
Read quantitative data from a feature map.
void countPeptides_(std::vector< PeptideIdentification > &peptides)
Count the number of identifications (best hits only) of each peptide sequence.
void quantifyPeptides(const std::vector< PeptideIdentification > &peptides=std::vector< PeptideIdentification >())
Compute peptide abundances.
std::map< String, ProteinData > ProteinQuant
Mapping: protein accession -> protein data.
Definition: PeptideAndProteinQuant.h:115
const ProteinQuant & getProteinResults()
Get protein abundance data.
void quantifyFeature_(const FeatureHandle &feature, size_t fraction, size_t sample, const PeptideHit &hit)
Gather quantitative information from a feature.
bool getBest_(const std::map< Int, std::map< Int, SampleAbundances >> &peptide_abundances, std::pair< size_t, size_t > &best)
Determine fraction and charge state of a peptide with the highest number of abundances.
PeptideQuant pep_quant_
Peptide quantification data.
Definition: PeptideAndProteinQuant.h:216
const PeptideQuant & getPeptideResults()
Get peptide abundance data.
~PeptideAndProteinQuant() override
Destructor.
Definition: PeptideAndProteinQuant.h:149
void updateMembers_() override
Clear all data when parameters are set.
void normalizePeptides_()
Normalize peptide abundances across samples by (multiplicative) scaling to equal medians.
String getAccession_(const std::set< String > &pep_accessions, std::map< String, String > &accession_to_leader)
Get the "canonical" protein accession from the list of protein accessions of a peptide.
void quantifyProteins(const ProteinIdentification &proteins=ProteinIdentification())
Compute protein abundances.
Statistics stats_
Processing statistics for output in the end.
Definition: PeptideAndProteinQuant.h:213
PeptideHit getAnnotation_(std::vector< PeptideIdentification > &peptides)
Get the "canonical" annotation (a single peptide hit) of a feature/consensus feature from the associa...
const Statistics & getStatistics()
Get summary statistics.
void orderBest_(const std::map< T, SampleAbundances > &abundances, std::vector< T > &result)
Order keys (charges/peptides for peptide/protein quantification) according to how many samples they a...
Definition: PeptideAndProteinQuant.h:260
std::map< UInt64, double > SampleAbundances
Mapping: sample ID -> abundance.
Definition: PeptideAndProteinQuant.h:60
ProteinQuant prot_quant_
Protein quantification data.
Definition: PeptideAndProteinQuant.h:219
PeptideAndProteinQuant()
Constructor.
void readQuantData(std::vector< ProteinIdentification > &proteins, std::vector< PeptideIdentification > &peptides, const ExperimentalDesign &ed)
Read quantitative data from identification results (for quantification via spectral counting).
Representation of a peptide hit.
Definition: PeptideHit.h:57
Representation of a protein identification run.
Definition: ProteinIdentification.h:76
A more convenient string class.
Definition: String.h:60
int Int
Signed integer type.
Definition: Types.h:102
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
Quantitative and associated data for a peptide.
Definition: PeptideAndProteinQuant.h:64
SampleAbundances total_psm_counts
spectral counting-based abundances
Definition: PeptideAndProteinQuant.h:75
SampleAbundances total_abundances
mapping: sample -> total abundance
Definition: PeptideAndProteinQuant.h:72
std::set< String > accessions
protein accessions for this peptide
Definition: PeptideAndProteinQuant.h:78
std::map< Int, std::map< Int, SampleAbundances > > abundances
mapping: fraction -> charge -> sample -> abundance
Definition: PeptideAndProteinQuant.h:66
std::map< Int, std::map< Int, SampleAbundances > > psm_counts
mapping: fraction -> charge -> sample -> abundance
Definition: PeptideAndProteinQuant.h:69
Quantitative and associated data for a protein.
Definition: PeptideAndProteinQuant.h:92
SampleAbundances total_psm_counts
spectral counting-based abundances
Definition: PeptideAndProteinQuant.h:102
SampleAbundances total_abundances
mapping: sample -> total abundance
Definition: PeptideAndProteinQuant.h:99
std::map< String, SampleAbundances > abundances
mapping: peptide (unmodified) -> sample -> abundance
Definition: PeptideAndProteinQuant.h:94
std::map< String, SampleAbundances > psm_counts
Definition: PeptideAndProteinQuant.h:96
SampleAbundances total_distinct_peptides
number of distinct peptide sequences
Definition: PeptideAndProteinQuant.h:105
Statistics for processing summary.
Definition: PeptideAndProteinQuant.h:119
Size quant_proteins
protein statistics
Definition: PeptideAndProteinQuant.h:130
Size quant_peptides
peptide statistics
Definition: PeptideAndProteinQuant.h:133
Size n_samples
number of samples (or assays in mzTab terms)
Definition: PeptideAndProteinQuant.h:121
Size n_fractions
number of fractions
Definition: PeptideAndProteinQuant.h:124
Statistics()
constructor
Definition: PeptideAndProteinQuant.h:139
Size n_ms_files
number of MS files
Definition: PeptideAndProteinQuant.h:127
Size ambig_features
Definition: PeptideAndProteinQuant.h:136