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
30namespace 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;
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() << "v_isotope_list.size()=" << v_isotope_list.size() << " "
84 << isotope_number << " " << askedIsotopeRank;
86 m_averageMz = 0;
87 if(askedIsotopeRank > v_isotope_list.size())
88 {
89 // there is no isotope at this rank
90 return;
91 // throw PappsoException(QObject::tr("askedIsotopeRank greater than
92 // v_isotope_list.size() %1 vs
93 // %2").arg(askedIsotopeRank).arg(v_isotope_list.size()));
94 }
95 else if(askedIsotopeRank < 1)
96 {
97 throw PappsoException(
98 QObject::tr("askedIsotopeRank must be 1 or more and not %1")
99 .arg(askedIsotopeRank));
100 }
101
102 unsigned int rank = 0;
103
104 recursiveDepletion(v_isotope_list, rank);
105
106 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
107}
108
109
110void
112 std::vector<PeptideNaturalIsotopeSp> &v_isotope_list, unsigned int rank)
113{
114 rank++;
115
117 m_averageMz = 0;
119 std::vector<PeptideNaturalIsotopeSp> peptide_list;
120 // select neighbors in the precision range :
121 MzRange mz_range(v_isotope_list[0].get()->getMz(m_z), mp_precision);
122
123 for(auto &isotope_sp : v_isotope_list)
124 {
125 if(mz_range.contains(isotope_sp.get()->getMz(m_z)))
126 {
127 peptide_list.push_back(isotope_sp);
128 m_abundanceRatio += isotope_sp.get()->getIntensityRatio(m_z);
129 m_averageMz += (isotope_sp.get()->getMz(m_z) *
130 isotope_sp.get()->getIntensityRatio(m_z));
131 }
132 }
133
134 if(peptide_list.size() > 0)
135 {
137
138 // depletion
139 auto it_remove = std::remove_if(
140 v_isotope_list.begin(),
141 v_isotope_list.end(),
142 [peptide_list](const PeptideNaturalIsotopeSp &isotope_sp) {
143 auto it =
144 std::find(peptide_list.begin(), peptide_list.end(), isotope_sp);
145 return (it != peptide_list.end());
146 });
147 v_isotope_list.erase(it_remove, v_isotope_list.end());
148
149 if(rank == m_isotopeRank)
150 {
151 m_peptideNaturalIsotopeSpList = peptide_list;
152 return;
153 }
154 else
155 {
156 unsigned int charge = m_z;
157 std::sort(v_isotope_list.begin(),
158 v_isotope_list.end(),
159 [charge](const PeptideNaturalIsotopeSp &m,
160 const PeptideNaturalIsotopeSp &n) {
161 return (m.get()->getIntensityRatio(charge) >
162 n.get()->getIntensityRatio(charge));
163 });
164 recursiveDepletion(v_isotope_list, rank);
165 }
166 }
167 else
168 {
170 m_averageMz = 0;
171 }
172}
173
176{
177 return std::make_shared<PeptideNaturalIsotopeAverage>(*this);
178}
179
181 const PeptideNaturalIsotopeAverage &other)
182 : mcsp_peptideSp(other.mcsp_peptideSp), mp_precision(other.mp_precision)
183{
184
185 qDebug();
187
188 m_averageMz = other.m_averageMz;
192 m_z = other.m_z;
193 qDebug();
194}
195
197{
198}
199
202{
203 return m_averageMz;
204}
205
208{
209 return m_abundanceRatio;
210}
211
212unsigned int
214{
215 return m_z;
216}
217
218unsigned int
220{
221 return m_isotopeLevel;
222}
223
224unsigned int
226{
227 return m_isotopeRank;
228}
229
230const std::vector<PeptideNaturalIsotopeSp> &
232{
234}
235
236const PeptideInterfaceSp &
238{
239 return mcsp_peptideSp;
240}
241
244{
245 return mp_precision;
246}
247
248bool
250{
251 // qDebug() << "PeptideNaturalIsotopeAverage::matchPeak";
252 // qDebug() << "PeptideNaturalIsotopeAverage::matchPeak precision " <<
253 // mp_precision.getDelta(200);
254 return (MzRange(getMz(), mp_precision).contains(peak_mz));
255}
256
257bool
259{
260 return (m_peptideNaturalIsotopeSpList.size() == 0);
261}
262
263QString
265{
266 return QString("%1 l%2 mz%3 z%4 N%5")
267 .arg(getPeptideInterfaceSp().get()->getSequence())
268 .arg(getPeptideInterfaceSp().get()->size())
269 .arg(getMz())
270 .arg(getCharge())
271 .arg(getIsotopeNumber());
272}
273} // namespace pappso
274
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:50
std::shared_ptr< const PeptideNaturalIsotopeAverage > PeptideNaturalIsotopeAverageSp
const pappso_double DIFFC12C13(1.0033548378)
peptide natural isotope model