OpenMS
Loading...
Searching...
No Matches
PeptideAndProteinQuant.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Hendrik Weisser $
6// $Authors: Hendrik Weisser $
7// --------------------------------------------------------------------------
8
9#pragma once
10
18
19#include <map>
20#include <set>
21#include <string>
22#include <unordered_map>
23#include <utility>
24#include <vector>
25
26namespace OpenMS
27{
35 class OPENMS_DLLAPI PeptideAndProteinQuant :
37 {
38public:
39
41 typedef std::map<UInt64, double> SampleAbundances;
42
44 typedef std::map<UInt, std::map<UInt, double>> FractionGroupAbundances;
45
48 {
50 std::map<Int, std::map<std::string, std::map<Int, std::map<UInt, double>>>> abundances;
51
53 std::map<Int, std::map<std::string, std::map<Int, UInt64>>> psm_counts;
54
57
60
63
65 std::set<std::string> accessions;
66
68 Size psm_count = 0;
69
71 PeptideData() = default;
72 };
73
75 typedef std::map<AASequence, PeptideData> PeptideQuant;
76
79 {
81 std::map<std::string, SampleAbundances> peptide_abundances;
82
84 std::map<std::string, FractionGroupAbundances> peptide_fraction_group_abundances;
85
86 std::map<std::string, SampleAbundances> peptide_psm_counts;
87
89 std::map<std::string, std::map<UInt, double>> channel_level_abundances;
90
92 std::map<std::string, UInt64> file_level_psm_counts;
93
96
99
102
105
107 Size psm_count = 0;
108
110 ProteinData() = default;
111 };
112
114 typedef std::map<std::string, ProteinData> ProteinQuant;
115
118 {
121
124
127
129 Size quant_proteins, too_few_peptides;
130
132 Size quant_peptides, total_peptides;
133
135 Size quant_features, total_features, blank_features, ambig_features;
136
139 n_samples(0), quant_proteins(0), too_few_peptides(0),
140 quant_peptides(0), total_peptides(0), quant_features(0),
141 total_features(0), blank_features(0), ambig_features(0) {}
142 };
143
146
149
155 void readQuantData(FeatureMap& features, const ExperimentalDesign& ed);
156
162 void readQuantData(ConsensusMap& consensus, const ExperimentalDesign& ed);
163
169 void readQuantData(std::vector<ProteinIdentification>& proteins,
171 const ExperimentalDesign& ed);
172
184
185
194
195
196 std::map<std::string, std::string> mapAccessionToLeader(const OpenMS::ProteinIdentification& proteins) const;
197
200
203
206
209 const ProteinQuant& protein_quants,
210 ProteinIdentification& proteins,
211 bool remove_unquantified = true);
212
213private:
214
219 {
220 std::size_t operator()(const std::pair<std::string, UInt>& p) const noexcept
221 {
222 const std::size_t h1 = std::hash<std::string>{}(p.first);
223 const std::size_t h2 = std::hash<UInt>{}(p.second);
224 // boost-style hash_combine
225 return h1 ^ (h2 + 0x9e3779b97f4a7c15ULL + (h1 << 6) + (h1 >> 2));
226 }
227 };
228
231 {
232 Size sample = 0;
233 UInt fraction_group = 0;
234 };
235
242 typedef std::unordered_map<std::string, std::vector<const PeptideQuant::value_type*>> UnmodifiedToEntriesIndex;
243
246
249
252 std::map<AASequence, Int> best_charge_by_peptidoform_;
253
256
259
264 std::unordered_map<std::pair<std::string, UInt>, DesignCell, FileLabelHash> design_cell_lookup_;
265
267 std::map<std::pair<UInt, UInt>, Size> fraction_group_label_to_sample_;
268
272 std::set<std::pair<UInt, UInt>> quantification_fraction_group_labels_;
273
274
282
293 void quantifyFeature_(const FeatureHandle& feature,
294 size_t fraction,
295 const std::string& filename,
296 const PeptideHit& hit,
297 UInt channel_or_label);
298
311 const std::map<Int, std::map<std::string, std::map<Int, std::map<UInt, double>>>>& peptide_abundances,
312 Int& best_charge) const;
313
327
333 template <typename T>
334 void orderBest_(const std::map<T, SampleAbundances> & abundances,
335 std::vector<T>& result)
336 {
337 typedef std::pair<Size, double> PairType;
338 std::multimap<PairType, T, std::greater<PairType> > order;
339 for (typename std::map<T, SampleAbundances>::const_iterator ab_it =
340 abundances.begin(); ab_it != abundances.end(); ++ab_it)
341 {
342 double total = 0.0;
343 for (SampleAbundances::const_iterator samp_it = ab_it->second.begin();
344 samp_it != ab_it->second.end(); ++samp_it)
345 {
346 total += samp_it->second;
347 }
348 if (total <= 0.0) continue; // not quantified
349 PairType key = std::make_pair(countQuantifiedSamples_(ab_it->second), total);
350 order.insert(std::make_pair(key, ab_it->first));
351 }
352 result.clear();
353 for (typename std::multimap<PairType, T, std::greater<PairType> >::
354 iterator ord_it = order.begin(); ord_it != order.end(); ++ord_it)
355 {
356 result.push_back(ord_it->second);
357 }
358 }
359
360
361
366
375
384 std::vector<std::string> selectPeptidesForQuantification_(const std::string& protein_accession,
385 Size top_n,
386 bool fix_peptides);
387
395 double aggregateAbundances_(const std::vector<double>& abundances,
396 const std::string& method) const;
397
407 void calculateProteinAbundances_(const std::string& protein_accession,
408 const std::vector<std::string>& selected_peptides,
409 const std::string& aggregate_method,
410 Size top_n,
411 bool include_all);
412
422 void calculateFractionGroupLevelProteinAbundances_(const std::string& protein_accession,
423 const std::vector<std::string>& selected_peptides,
424 const std::string& aggregate_method,
425 Size top_n,
426 bool include_all);
427
439 void calculateFileAndChannelLevelProteinAbundances_(const std::string& protein_accession,
440 const std::vector<std::string>& selected_peptides,
441 const std::string& aggregate_method,
442 Size top_n,
443 bool include_all,
444 const std::map<std::string, std::string>& accession_to_leader,
445 const UnmodifiedToEntriesIndex& unmod_to_entries);
446
453
466 std::string getAccession_(const std::set<std::string>& pep_accessions,
467 const std::map<std::string, std::string>& accession_to_leader) const;
468
475
489
498 const DesignCell& getDesignCellFromFilenameAndChannel_(const std::string& filename,
499 UInt channel_or_label) const;
500
510 Size getSampleIDFromFilenameAndChannel_(const std::string& filename,
511 UInt channel_or_label) const;
512
514 void updateMembers_() override;
515
516 }; // class
517
518} // namespace
A container for consensus elements.
Definition ConsensusMap.h:67
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
Representation of an experimental design in OpenMS. Instances can be loaded with the ExperimentalDesi...
Definition ExperimentalDesign.h:109
Representation of a Peak2D, RichPeak2D or Feature .
Definition FeatureHandle.h:36
A container for features.
Definition FeatureMap.h:78
Helper class for peptide and protein quantification based on feature data annotated with IDs.
Definition PeptideAndProteinQuant.h:37
void readQuantData(ConsensusMap &consensus, const ExperimentalDesign &ed)
Read quantitative data from a consensus map.
static Size countQuantifiedSamples_(const SampleAbundances &abundances)
Number of samples in which abundances is actually quantified.
const DesignCell & getDesignCellFromFilenameAndChannel_(const std::string &filename, UInt channel_or_label) const
Map (filename, channel) to its experimental-design cell.
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:75
void readQuantData(FeatureMap &features, const ExperimentalDesign &ed)
Read quantitative data from a feature map.
void buildSampleIDLookup_()
(Re)build design-cell lookups from experimental_design_.
std::unordered_map< std::string, std::vector< const PeptideQuant::value_type * > > UnmodifiedToEntriesIndex
Definition PeptideAndProteinQuant.h:242
bool getBestCharge_(const std::map< Int, std::map< std::string, std::map< Int, std::map< UInt, double > > > > &peptide_abundances, Int &best_charge) const
Select one charge state globally for a modified peptide.
ExperimentalDesign experimental_design_
Experimental design for filename/channel to sample mapping.
Definition PeptideAndProteinQuant.h:258
std::map< std::string, ProteinData > ProteinQuant
Mapping: protein accession -> protein data.
Definition PeptideAndProteinQuant.h:114
std::map< UInt, std::map< UInt, double > > FractionGroupAbundances
Mapping: experimental-design fraction group -> label/channel -> abundance.
Definition PeptideAndProteinQuant.h:44
void calculateFileAndChannelLevelProteinAbundances_(const std::string &protein_accession, const std::vector< std::string > &selected_peptides, const std::string &aggregate_method, Size top_n, bool include_all, const std::map< std::string, std::string > &accession_to_leader, const UnmodifiedToEntriesIndex &unmod_to_entries)
Calculate detailed protein abundances at channel level using selected peptides.
double aggregateAbundances_(const std::vector< double > &abundances, const std::string &method) const
Aggregate abundances using the specified mathematical method.
std::vector< std::string > selectPeptidesForQuantification_(const std::string &protein_accession, Size top_n, bool fix_peptides)
Select peptides for protein quantification based on filtering criteria.
void quantifyFeature_(const FeatureHandle &feature, size_t fraction, const std::string &filename, const PeptideHit &hit, UInt channel_or_label)
Gather quantitative information from a feature.
const PeptideQuant & getPeptideResults()
Get peptide abundance data.
void performIbaqNormalization_(const ProteinIdentification &proteins)
Perform iBAQ normalization on protein abundances.
std::map< std::string, std::string > mapAccessionToLeader(const OpenMS::ProteinIdentification &proteins) const
void countPeptides_(PeptideIdentificationList &peptides)
Count the number of identifications (best hits only) of each peptide sequence.
void quantifyPeptides(const PeptideIdentificationList &peptides=PeptideIdentificationList())
Compute peptide abundances.
std::map< AASequence, Int > best_charge_by_peptidoform_
Definition PeptideAndProteinQuant.h:252
PeptideQuant pep_quant_
Peptide quantification data.
Definition PeptideAndProteinQuant.h:248
void transferPeptideDataToProteins_(const ProteinIdentification &proteins)
Transfer peptide-level quantitative data to protein-level data structures.
void calculateFractionGroupLevelProteinAbundances_(const std::string &protein_accession, const std::vector< std::string > &selected_peptides, const std::string &aggregate_method, Size top_n, bool include_all)
Calculate protein abundances at experimental-design fraction-group/label grain.
~PeptideAndProteinQuant() override
Destructor.
Definition PeptideAndProteinQuant.h:148
std::string getAccession_(const std::set< std::string > &pep_accessions, const std::map< std::string, std::string > &accession_to_leader) const
Get the "canonical" protein accession from the list of protein accessions of a peptide.
Size getSampleIDFromFilenameAndChannel_(const std::string &filename, UInt channel_or_label) const
Map (filename, channel) to a sample using the precomputed design-cell lookup.
std::map< std::pair< UInt, UInt >, Size > fraction_group_label_to_sample_
Precomputed (fraction group, label) -> sample lookup used to normalize unit abundances.
Definition PeptideAndProteinQuant.h:267
void readQuantData(std::vector< ProteinIdentification > &proteins, PeptideIdentificationList &peptides, const ExperimentalDesign &ed)
Read quantitative data from identification results (for quantification via spectral counting).
void updateMembers_() override
Clear all data when parameters are set.
std::set< std::pair< UInt, UInt > > quantification_fraction_group_labels_
Definition PeptideAndProteinQuant.h:272
const ProteinQuant & getProteinResults()
Get protein abundance data.
std::unordered_map< std::pair< std::string, UInt >, DesignCell, FileLabelHash > design_cell_lookup_
Definition PeptideAndProteinQuant.h:264
void normalizePeptides_()
Normalize peptide abundances across samples by (multiplicative) scaling to equal medians.
void quantifyProteins(const ProteinIdentification &proteins=ProteinIdentification())
Compute protein abundances.
Statistics stats_
Processing statistics for output in the end.
Definition PeptideAndProteinQuant.h:245
const Statistics & getStatistics()
Get summary statistics.
void calculateProteinAbundances_(const std::string &protein_accession, const std::vector< std::string > &selected_peptides, const std::string &aggregate_method, Size top_n, bool include_all)
Calculate protein abundances for a single protein using selected peptides.
PeptideHit getAnnotation_(PeptideIdentificationList &peptides)
Get the "canonical" annotation (a single peptide hit) of a feature/consensus feature from the associa...
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:334
std::map< UInt64, double > SampleAbundances
Mapping: sample ID -> abundance.
Definition PeptideAndProteinQuant.h:41
ProteinQuant prot_quant_
Protein quantification data.
Definition PeptideAndProteinQuant.h:255
PeptideAndProteinQuant()
Constructor.
Experimental-design coordinates of one (basename, label) cell.
Definition PeptideAndProteinQuant.h:231
Represents a single spectrum match (candidate) for a specific tandem mass spectrum (MS/MS).
Definition PeptideHit.h:52
Container for peptide identifications from multiple spectra.
Definition PeptideIdentificationList.h:66
Representation of a protein identification run.
Definition ProteinIdentification.h:55
int Int
Signed integer type.
Definition Types.h:72
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Definition PeptideAndProteinQuant.h:219
std::size_t operator()(const std::pair< std::string, UInt > &p) const noexcept
Definition PeptideAndProteinQuant.h:220
Quantitative and associated data for a peptide.
Definition PeptideAndProteinQuant.h:48
std::map< Int, std::map< std::string, std::map< Int, UInt64 > > > psm_counts
mapping: fraction -> filename -> charge -> abundance
Definition PeptideAndProteinQuant.h:53
SampleAbundances total_psm_counts
spectral counting-based abundances
Definition PeptideAndProteinQuant.h:62
SampleAbundances total_abundances
mapping: sample -> total abundance
Definition PeptideAndProteinQuant.h:56
FractionGroupAbundances fraction_group_abundances
mapping: fraction group -> label/channel -> abundance
Definition PeptideAndProteinQuant.h:59
std::map< Int, std::map< std::string, std::map< Int, std::map< UInt, double > > > > abundances
mapping: fraction -> filename -> charge -> channel/label -> abundance
Definition PeptideAndProteinQuant.h:50
std::set< std::string > accessions
protein accessions for this peptide
Definition PeptideAndProteinQuant.h:65
Quantitative and associated data for a protein.
Definition PeptideAndProteinQuant.h:79
SampleAbundances total_psm_counts
spectral counting-based abundances
Definition PeptideAndProteinQuant.h:101
std::map< std::string, SampleAbundances > peptide_psm_counts
Definition PeptideAndProteinQuant.h:86
SampleAbundances total_abundances
mapping: sample -> total abundance
Definition PeptideAndProteinQuant.h:95
std::map< std::string, std::map< UInt, double > > channel_level_abundances
mapping: filename -> channel/label -> abundance
Definition PeptideAndProteinQuant.h:89
std::map< std::string, SampleAbundances > peptide_abundances
mapping: peptide (unmodified) -> sample -> abundance
Definition PeptideAndProteinQuant.h:81
std::map< std::string, UInt64 > file_level_psm_counts
mapping: filename -> PSM counts
Definition PeptideAndProteinQuant.h:92
FractionGroupAbundances fraction_group_abundances
mapping: fraction group -> label/channel -> total abundance
Definition PeptideAndProteinQuant.h:98
std::map< std::string, FractionGroupAbundances > peptide_fraction_group_abundances
mapping: peptide (unmodified) -> fraction group -> label/channel -> abundance
Definition PeptideAndProteinQuant.h:84
SampleAbundances total_distinct_peptides
number of distinct peptide sequences
Definition PeptideAndProteinQuant.h:104
Statistics for processing summary.
Definition PeptideAndProteinQuant.h:118
Size quant_proteins
protein statistics
Definition PeptideAndProteinQuant.h:129
Size quant_peptides
peptide statistics
Definition PeptideAndProteinQuant.h:132
Size n_samples
number of samples (or assays in mzTab terms)
Definition PeptideAndProteinQuant.h:120
Size n_fractions
number of fractions
Definition PeptideAndProteinQuant.h:123
Statistics()
constructor
Definition PeptideAndProteinQuant.h:138
Size n_ms_files
number of MS files
Definition PeptideAndProteinQuant.h:126
Size ambig_features
Definition PeptideAndProteinQuant.h:135