OpenMS  2.7.0
AScore.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-2021.
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: Petra Gutenbrunner $
32 // $Authors: David Wojnar, Timo Sachsenberg, Petra Gutenbrunner $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/CONCEPT/Types.h>
43 
44 #include <limits>
45 #include <vector>
46 
47 namespace OpenMS
48 {
49  class PeptideHit;
50  class AASequence;
51 
53  {
54  public:
55 
62  };
63 
72  class OPENMS_DLLAPI AScore: public DefaultParamHandler
73  {
74  friend struct PScore;
75 
76  public:
78  AScore();
79 
81  ~AScore() override;
82 
93  PeptideHit compute(const PeptideHit& hit, PeakSpectrum& real_spectrum);
94 
95  protected:
96  int compareMZ_(double mz1, double mz2) const;
97 
101  template <class InputIterator1, class InputIterator2, class OutputIterator>
102  OutputIterator getSpectrumDifference_(InputIterator1 first1, InputIterator1 last1,
103  InputIterator2 first2, InputIterator2 last2, OutputIterator result) const
104  {
105  while (first1 != last1 && first2 != last2)
106  {
107  double mz1 = first1->getMZ();
108  double mz2 = first2->getMZ();
109  int val = compareMZ_(mz1, mz2);
110 
111  if (val == -1)
112  {
113  *result = *first1;
114  ++result;
115  ++first1;
116  }
117  else if (val == 1)
118  {
119  ++first2;
120  }
121  else // check if more ions are within the same tolerance. If so, these can not be site determining ions
122  {
123  //check mz2 until no match
124  ++first2;
125  if (first2 != last2)
126  {
127  int ret = compareMZ_(mz1, first2->getMZ());
128  while (ret == 0 && first2 != last2)
129  {
130  ++first2;
131  ret = compareMZ_(mz1, first2->getMZ());
132  }
133  }
134 
135  //check mz1 until no match
136  ++first1;
137  if (first1 != last1)
138  {
139  int ret = compareMZ_(first1->getMZ(), mz2);
140  while (ret == 0 && first1 != last1)
141  {
142  ++first1;
143  ret = compareMZ_(first1->getMZ(), mz2);
144  }
145  }
146  }
147  }
148  return std::copy(first1, last1, result);
149  }
150 
152  void computeSiteDeterminingIons_(const std::vector<PeakSpectrum>& th_spectra, const ProbablePhosphoSites& candidates, std::vector<PeakSpectrum>& site_determining_ions) const;
153 
155  std::vector<Size> getSites_(const AASequence& without_phospho) const;
156 
158  std::vector<std::vector<Size>> computePermutations_(const std::vector<Size>& sites, Int n_phosphorylation_events) const;
159 
161  Size numberOfMatchedIons_(const PeakSpectrum& th, const PeakSpectrum& windows, Size depth) const;
162 
164  double peptideScore_(const std::vector<double>& scores) const;
165 
170  void determineHighestScoringPermutations_(const std::vector<std::vector<double>>& peptide_site_scores, std::vector<ProbablePhosphoSites>& sites, const std::vector<std::vector<Size>>& permutations, std::multimap<double, Size>& ranking) const;
171 
173  double computeBaseProbability_(double ppm_reference_mz) const;
174 
176  double computeCumulativeScore_(Size N, Size n, double p) const;
177 
179  Size numberOfPhosphoEvents_(const String& sequence) const;
180 
183 
185  std::vector<PeakSpectrum> createTheoreticalSpectra_(const std::vector<std::vector<Size>>& permutations, const AASequence& seq_without_phospho) const;
186 
188  std::vector<PeakSpectrum> peakPickingPerWindowsInSpectrum_(PeakSpectrum& real_spectrum) const;
189 
191  std::vector<std::vector<double>> calculatePermutationPeptideScores_(std::vector<PeakSpectrum>& th_spectra, const std::vector<PeakSpectrum>& windows_top10) const;
192 
194  std::multimap<double, Size> rankWeightedPermutationPeptideScores_(const std::vector<std::vector<double>>& peptide_site_scores) const;
195 
197  void updateMembers_() override;
198 
199  // variables:
206  };
207 
208 } // namespace OpenMS
Representation of a peptide/protein sequence.
Definition: AASequence.h:112
Implementation of the Ascore For a given peptide sequence and its MS/MS spectrum it identifies the mo...
Definition: AScore.h:73
std::vector< PeakSpectrum > createTheoreticalSpectra_(const std::vector< std::vector< Size >> &permutations, const AASequence &seq_without_phospho) const
Create theoretical spectra with all combinations with the number of phosphorylation events.
std::vector< std::vector< Size > > computePermutations_(const std::vector< Size > &sites, Int n_phosphorylation_events) const
calculate all n_phosphorylation_events sized sets of phospho sites (all versions of the peptides with...
std::vector< std::vector< double > > calculatePermutationPeptideScores_(std::vector< PeakSpectrum > &th_spectra, const std::vector< PeakSpectrum > &windows_top10) const
Create 10 scores for each theoretical spectrum (permutation), according to Beausoleil et al....
AScore()
Default constructor.
double computeCumulativeScore_(Size N, Size n, double p) const
Computes the cumulative binomial probabilities.
double unambiguous_score_
Score for unambiguous assignments (all sites phosphorylated)
Definition: AScore.h:204
AASequence removePhosphositesFromSequence_(const String &sequence) const
Create variant of the peptide with all phosphorylations removed.
std::multimap< double, Size > rankWeightedPermutationPeptideScores_(const std::vector< std::vector< double >> &peptide_site_scores) const
Rank weighted permutation scores ascending.
Size numberOfPhosphoEvents_(const String &sequence) const
Computes number of phospho events in a sequence.
~AScore() override
Destructor.
double peptideScore_(const std::vector< double > &scores) const
Computes the peptide score according to Beausoleil et al. page 1291.
std::vector< Size > getSites_(const AASequence &without_phospho) const
return all phospho sites
OutputIterator getSpectrumDifference_(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result) const
Definition: AScore.h:102
PeptideHit compute(const PeptideHit &hit, PeakSpectrum &real_spectrum)
Computes the AScore and returns all computed phospho-sites. The saved sequences contain only phospho ...
void computeSiteDeterminingIons_(const std::vector< PeakSpectrum > &th_spectra, const ProbablePhosphoSites &candidates, std::vector< PeakSpectrum > &site_determining_ions) const
Computes the site determining_ions for the given AS and sequences in candidates.
int compareMZ_(double mz1, double mz2) const
std::vector< PeakSpectrum > peakPickingPerWindowsInSpectrum_(PeakSpectrum &real_spectrum) const
Pick top 10 intensity peaks for each 100 Da windows.
void updateMembers_() override
Reimplemented from DefaultParamHandler.
double fragment_mass_tolerance_
Fragment mass tolerance for spectrum comparisons.
Definition: AScore.h:200
void determineHighestScoringPermutations_(const std::vector< std::vector< double >> &peptide_site_scores, std::vector< ProbablePhosphoSites > &sites, const std::vector< std::vector< Size >> &permutations, std::multimap< double, Size > &ranking) const
Finds the peptides with the highest PeptideScores and outputs all information for computing the AScor...
Size max_permutations_
Limit for number of sequence permutations that can be handled.
Definition: AScore.h:203
bool fragment_tolerance_ppm_
Is fragment mass tolerance given in ppm (or Da)?
Definition: AScore.h:201
double base_match_probability_
Probability of a match at a peak depth of 1.
Definition: AScore.h:205
Size numberOfMatchedIons_(const PeakSpectrum &th, const PeakSpectrum &windows, Size depth) const
Computes number of matched ions between windows and the given spectrum. All spectra have to be sorted...
Size max_peptide_length_
Limit for peptide lengths that can be analyzed.
Definition: AScore.h:202
double computeBaseProbability_(double ppm_reference_mz) const
Computes probability for a peak depth of one given spectra and mass_tolerance variables.
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:93
The representation of a 1D spectrum.
Definition: MSSpectrum.h:71
Representation of a peptide hit.
Definition: PeptideHit.h:57
A more convenient string class.
Definition: String.h:61
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:47
Size peak_depth
filtering level that gave rise to maximum discriminatory score
Definition: AScore.h:60
Size seq_2
index of permutation with site in unphosphorylated state
Definition: AScore.h:59
Size seq_1
index of best permutation with site in phosphorylated state
Definition: AScore.h:58
Size first
Definition: AScore.h:56
Size AScore
Definition: AScore.h:61
Size second
Definition: AScore.h:57
Definition: AScore.h:53
Implementation of the PScore PSM scoring algorithm.
Definition: PScore.h:50