libpappsomspp
Library for mass spectrometry
peptidenaturalisotopeaverage.cpp
Go to the documentation of this file.
1 
2 /*******************************************************************************
3  * Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
4  *
5  * This file is part of the PAPPSOms++ library.
6  *
7  * PAPPSOms++ is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * PAPPSOms++ is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
19  *
20  * Contributors:
21  * Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and
22  *implementation
23  ******************************************************************************/
24 
25 #include "../pappsoexception.h"
27 
29 
30 namespace pappso
31 {
32 
33 
35  const PeptideInterfaceSp &peptide,
36  unsigned int isotopeNumber,
37  unsigned int charge,
38  PrecisionPtr precision)
39  : mcsp_peptideSp(peptide),
40  m_isotopeLevel(isotopeNumber),
41  m_isotopeRank(1),
42  m_z(charge),
43  mp_precision(precision)
44 {
45 
47 
48  double diffC13 = ((double)isotopeNumber * DIFFC12C13) / (double)charge;
49 
50  m_averageMz = peptide.get()->getMz(charge) + diffC13;
51  m_abundanceRatio = 0;
52 }
53 
55  const PeptideInterfaceSp &peptide,
56  unsigned int askedIsotopeRank,
57  unsigned int isotopeLevel,
58  unsigned int charge,
59  PrecisionPtr precision)
61  askedIsotopeRank,
62  isotopeLevel,
63  charge,
64  precision)
65 {
66 }
67 
69  const PeptideNaturalIsotopeList &isotopeList,
70  unsigned int askedIsotopeRank,
71  unsigned int isotope_number,
72  unsigned int charge,
73  PrecisionPtr precision)
74  : mcsp_peptideSp(isotopeList.getPeptideInterfaceSp()),
75  m_isotopeLevel(isotope_number),
76  m_isotopeRank(askedIsotopeRank),
77  m_z(charge),
78  mp_precision(precision)
79 { // get the askedIsotopeRank :
80  std::vector<PeptideNaturalIsotopeSp> v_isotope_list(
81  isotopeList.getByIsotopeNumber(isotope_number, m_z));
82 
83  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
84  // << "v_isotope_list.size()=" << v_isotope_list.size() << " "
85  // << isotope_number << " " << askedIsotopeRank;
86  m_abundanceRatio = 0;
87  m_averageMz = 0;
88  if(askedIsotopeRank > v_isotope_list.size())
89  {
90  // there is no isotope at this rank
91  return;
92  // throw PappsoException(QObject::tr("askedIsotopeRank greater than
93  // v_isotope_list.size() %1 vs
94  // %2").arg(askedIsotopeRank).arg(v_isotope_list.size()));
95  }
96  else if(askedIsotopeRank < 1)
97  {
98  throw PappsoException(
99  QObject::tr("askedIsotopeRank must be 1 or more and not %1")
100  .arg(askedIsotopeRank));
101  }
102 
103  unsigned int rank = 0;
104 
105  recursiveDepletion(v_isotope_list, rank);
106 
107  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
108 }
109 
110 
111 void
113  std::vector<PeptideNaturalIsotopeSp> &v_isotope_list, unsigned int rank)
114 {
115  rank++;
116 
117  m_abundanceRatio = 0;
118  m_averageMz = 0;
120  std::vector<PeptideNaturalIsotopeSp> peptide_list;
121  // select neighbors in the precision range :
122  MzRange mz_range(v_isotope_list[0].get()->getMz(m_z), mp_precision);
123 
124  for(auto &isotope_sp : v_isotope_list)
125  {
126  if(mz_range.contains(isotope_sp.get()->getMz(m_z)))
127  {
128  peptide_list.push_back(isotope_sp);
129  m_abundanceRatio += isotope_sp.get()->getIntensityRatio(m_z);
130  m_averageMz += (isotope_sp.get()->getMz(m_z) *
131  isotope_sp.get()->getIntensityRatio(m_z));
132  }
133  }
134 
135  if(peptide_list.size() > 0)
136  {
138 
139  // depletion
140  auto it_remove = std::remove_if(
141  v_isotope_list.begin(),
142  v_isotope_list.end(),
143  [peptide_list](const PeptideNaturalIsotopeSp &isotope_sp) {
144  auto it =
145  std::find(peptide_list.begin(), peptide_list.end(), isotope_sp);
146  return (it != peptide_list.end());
147  });
148  v_isotope_list.erase(it_remove, v_isotope_list.end());
149 
150  if(rank == m_isotopeRank)
151  {
152  m_peptideNaturalIsotopeSpList = peptide_list;
153  return;
154  }
155  else
156  {
157  unsigned int charge = m_z;
158  std::sort(v_isotope_list.begin(),
159  v_isotope_list.end(),
160  [charge](const PeptideNaturalIsotopeSp &m,
161  const PeptideNaturalIsotopeSp &n) {
162  return (m.get()->getIntensityRatio(charge) >
163  n.get()->getIntensityRatio(charge));
164  });
165  recursiveDepletion(v_isotope_list, rank);
166  }
167  }
168  else
169  {
170  m_abundanceRatio = 0;
171  m_averageMz = 0;
172  }
173 }
174 
177 {
178  return std::make_shared<PeptideNaturalIsotopeAverage>(*this);
179 }
180 
182  const PeptideNaturalIsotopeAverage &other)
183  : mcsp_peptideSp(other.mcsp_peptideSp), mp_precision(other.mp_precision)
184 {
185 
186  qDebug();
188 
189  m_averageMz = other.m_averageMz;
193  m_z = other.m_z;
194  qDebug();
195 }
196 
198 {
199 }
200 
203 {
204  return m_averageMz;
205 }
206 
209 {
210  return m_abundanceRatio;
211 }
212 
213 unsigned int
215 {
216  return m_z;
217 }
218 
219 unsigned int
221 {
222  return m_isotopeLevel;
223 }
224 
225 unsigned int
227 {
228  return m_isotopeRank;
229 }
230 
231 const std::vector<PeptideNaturalIsotopeSp> &
233 {
235 }
236 
237 const PeptideInterfaceSp &
239 {
240  return mcsp_peptideSp;
241 }
242 
245 {
246  return mp_precision;
247 }
248 
249 bool
251 {
252  // qDebug() << "PeptideNaturalIsotopeAverage::matchPeak";
253  // qDebug() << "PeptideNaturalIsotopeAverage::matchPeak precision " <<
254  // mp_precision.getDelta(200);
255  return (MzRange(getMz(), mp_precision).contains(peak_mz));
256 }
257 
258 bool
260 {
261  return (m_peptideNaturalIsotopeSpList.size() == 0);
262 }
263 
264 QString
266 {
267  return QString("%1 l%2 mz%3 z%4 N%5")
268  .arg(getPeptideInterfaceSp().get()->getSequence())
269  .arg(getPeptideInterfaceSp().get()->size())
270  .arg(getMz())
271  .arg(getCharge())
272  .arg(getIsotopeNumber());
273 }
274 } // namespace pappso
bool contains(pappso_double) const
Definition: mzrange.cpp:120
std::vector< PeptideNaturalIsotopeSp > m_peptideNaturalIsotopeSpList
PeptideNaturalIsotopeAverage(const PeptideInterfaceSp &peptide, unsigned int isotopeNumber, unsigned int charge, PrecisionPtr precision)
fast constructor simple isotope build, not computing isotope ratio
const std::vector< PeptideNaturalIsotopeSp > & getComponents() const
virtual bool matchPeak(pappso_double peak_mz) const final
const PeptideInterfaceSp & getPeptideInterfaceSp() const
void recursiveDepletion(std::vector< PeptideNaturalIsotopeSp > &v_isotope_list, unsigned int rank)
PeptideNaturalIsotopeAverageSp makePeptideNaturalIsotopeAverageSp() const
std::vector< PeptideNaturalIsotopeSp > getByIsotopeNumber(unsigned int isotopeLevel, unsigned int charge) const
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
std::shared_ptr< const PeptideNaturalIsotope > PeptideNaturalIsotopeSp
std::shared_ptr< const PeptideInterface > PeptideInterfaceSp
double pappso_double
A type definition for doubles.
Definition: types.h:49
std::shared_ptr< const PeptideNaturalIsotopeAverage > PeptideNaturalIsotopeAverageSp
const pappso_double DIFFC12C13(1.0033548378)
peptide natural isotope model