libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
aacode.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/amino_acid/aacode.cpp
3 * \date 03/05/2023
4 * \author Olivier Langella
5 * \brief give an integer code to each amino acid
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2023 Olivier Langella <Olivier.Langella@u-psud.fr>.
10 *
11 * This file is part of PAPPSOms-tools.
12 *
13 * PAPPSOms-tools is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * PAPPSOms-tools is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>.
25 *
26 ******************************************************************************/
27
31
32using namespace pappso;
33
35{
36 m_asciiTable.resize(90, 0);
37
38 m_aaCollection.push_back(Aa('A'));
39 m_aaCollection.push_back(Aa('C'));
40 m_aaCollection.push_back(Aa('D'));
41 m_aaCollection.push_back(Aa('E'));
42 m_aaCollection.push_back(Aa('F'));
43 m_aaCollection.push_back(Aa('G'));
44 m_aaCollection.push_back(Aa('H'));
45 m_aaCollection.push_back(Aa('I'));
46 m_aaCollection.push_back(Aa('K'));
47 m_aaCollection.push_back(Aa('M'));
48 m_aaCollection.push_back(Aa('N'));
49 m_aaCollection.push_back(Aa('P'));
50 m_aaCollection.push_back(Aa('Q'));
51 m_aaCollection.push_back(Aa('R'));
52 m_aaCollection.push_back(Aa('S'));
53 m_aaCollection.push_back(Aa('T'));
54 m_aaCollection.push_back(Aa('V'));
55 m_aaCollection.push_back(Aa('W'));
56 m_aaCollection.push_back(Aa('Y'));
57
59}
60
68
72
73std::size_t
75{
76 return 19;
77}
78
79
80uint8_t
81pappso::AaCode::getAaCode(char aa_letter) const
82{
83 // qDebug() << aa_letter << " " << (uint8_t)aa_letter;
84 // qDebug() << m_asciiTable[77];
85 uint8_t aa_code = m_asciiTable[aa_letter];
86
87 if(aa_code == 0)
88 {
90 QObject::tr("getAaCode(char aa_letter) error, %1 is null : no amino acid for letter \"%2\"")
91 .arg(aa_code)
92 .arg(aa_letter));
93 }
94 else if(aa_code >= m_massCollection.size())
95 {
97 QObject::tr("getAaCode(char aa_letter) error, %1 amino acid code not found in "
98 "m_aaCollection for letter \"%2\"")
99 .arg(aa_code)
100 .arg(aa_letter));
101 }
102 return aa_code;
103}
104
105uint8_t
107{
108
109 uint8_t aa_code = m_asciiTable[(char)aa];
110
111 if(aa_code == 0)
112 {
114 QObject::tr("getAaCode(pappso::Enums::AminoAcidChar aa) error, %1 is null : no amino acid "
115 "for letter \"%2\"")
116 .arg(aa_code)
117 .arg(char(aa)));
118 }
119 else if(aa_code >= m_massCollection.size())
120 {
122 QObject::tr("getAaCode(pappso::Enums::AminoAcidChar aa) error, %1 amino acid code not "
123 "found in m_aaCollection for letter \"%2\"")
124 .arg(aa_code)
125 .arg(char(aa)));
126 }
127 return aa_code;
128}
129
130
131const pappso::Aa &
132pappso::AaCode::getAa(char aa_letter) const
133{
134
135 if(aa_letter == 'L')
136 return m_leucine;
137 auto it = std::find_if(m_aaCollection.begin(), m_aaCollection.end(), [aa_letter](const Aa &aa) {
138 if(aa.getLetter() == aa_letter)
139 return true;
140 return false;
141 });
142 if(it != m_aaCollection.end())
143 {
144 return *it;
145 }
147 QObject::tr("error, %1 amino acid not found in m_aaCollection").arg(aa_letter));
148}
149
150
151const pappso::Aa &
152pappso::AaCode::getAa(uint8_t aa_code) const
153{
154 if(aa_code == 0)
155 {
157 QObject::tr("error, 0 is null : no amino acid").arg(aa_code));
158 }
159 else if(aa_code > 19)
160 {
162 QObject::tr("error, %1 amino acid code not found in m_aaCollection").arg(aa_code));
163 }
164 return m_aaCollection[aa_code - 1];
165}
166
167
168void
170{
171
172 auto it = std::find_if(m_aaCollection.begin(), m_aaCollection.end(), [aa_letter](const Aa &aa) {
173 if(aa.getLetter() == aa_letter)
174 return true;
175 return false;
176 });
177 if(it != m_aaCollection.end())
178 {
179 it->addAaModification(aaModification);
180 }
181 else
182 {
184 QObject::tr("error, %1 amino acid not found in m_aaCollection").arg(aa_letter));
185 }
186
188}
189
190
191void
193{
194
195 std::sort(m_aaCollection.begin(), m_aaCollection.end(), [](const Aa &aa1, const Aa &aa2) {
196 return aa1.getMass() < aa2.getMass();
197 });
198
199 std::size_t n = 1;
200 for(const Aa &aa : m_aaCollection)
201 {
202 // qDebug() << aa.getLetter() << " " << n;
203 m_asciiTable[aa.getLetter()] = n;
204 n++;
205 }
206 m_asciiTable['L'] = m_asciiTable['I'];
207
208 updateMass();
209}
210
211void
213{
214 m_massCollection.resize(1);
215
216 for(const Aa &aa : m_aaCollection)
217 {
218 m_massCollection.push_back(aa.getMass());
219 }
220}
221
222
223double
224pappso::AaCode::getMass(uint8_t aa_code) const
225{
226 return m_massCollection[aa_code];
227}
228
229double
230pappso::AaCode::getMass(char aa_letter) const
231{
232 try
233 {
234 return m_massCollection[this->getAaCode(aa_letter)];
235 }
236
237 catch(const pappso::PappsoException &err)
238 {
240 QObject::tr("getMass(char aa_letter) failed :\n%1").arg(err.qwhat()));
241 }
242}
243
244uint8_t
246{
247 double delta = precision->delta(mass);
248 double mass_min = mass - delta;
249 double mass_max = mass + delta;
250 uint8_t aa_code = 0;
251 for(uint8_t i = 1; i < m_massCollection.size(); i++)
252 {
253 if(m_massCollection.at(i) >= mass_min)
254 {
255 if(m_massCollection.at(i) <= mass_max)
256 {
257 aa_code = i;
258 }
259 break;
260 }
261 }
262 return aa_code;
263}
264
265const std::vector<Aa> &
collection of integer code for each amino acid 0 => null 1 to 20 => amino acid sorted by there mass (...
Definition aacode.h:44
void updateNumbers()
give a number (the code) to each amino acid sorted by mass
Definition aacode.cpp:192
void addAaModification(char aa_letter, AaModificationP aaModification)
add a modification on an amino acid for example carbamido on C
Definition aacode.cpp:169
std::vector< double > m_massCollection
Definition aacode.h:116
std::vector< uint8_t > m_asciiTable
Definition aacode.h:113
void updateMass()
update mass cache
Definition aacode.cpp:212
pappso::Aa m_leucine
Definition aacode.h:118
uint8_t getAaCodeByMass(double mass, PrecisionPtr precision) const
get the integer code of an amino acid given a mass and a precision
Definition aacode.cpp:245
const std::vector< Aa > & getAaCollection() const
Definition aacode.cpp:266
uint8_t getAaCode(char aa_letter) const
get the integer code of an amino acid with the one letter code
Definition aacode.cpp:81
double getMass(uint8_t aa_code) const
get the mass of the amino acid given its integer code the amino acid can bear some modification (if a...
Definition aacode.cpp:224
std::size_t getSize() const
number of amino acid coded letters in this aa code
Definition aacode.cpp:74
std::vector< Aa > m_aaCollection
Definition aacode.h:115
const Aa & getAa(char aa_letter) const
get the Aa object from the one letter code
Definition aacode.cpp:132
virtual const QString & qwhat() const
virtual pappso_double delta(pappso_double value) const =0
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
const AaModification * AaModificationP
const PrecisionBase * PrecisionPtr
Definition precision.h:122