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
62{
63
64 m_asciiTable = other.m_asciiTable;
65
66 m_aaCollection = other.m_aaCollection;
67}
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') return m_leucine;
136 auto it = std::find_if(m_aaCollection.begin(), m_aaCollection.end(), [aa_letter](const Aa &aa) {
137 if(aa.getLetter() == aa_letter)
138 return true;
139 return false;
140 });
141 if(it != m_aaCollection.end())
142 {
143 return *it;
144 }
146 QObject::tr("error, %1 amino acid not found in m_aaCollection").arg(aa_letter));
147}
148
149
150const pappso::Aa &
151pappso::AaCode::getAa(uint8_t aa_code) const
152{
153 if(aa_code == 0)
154 {
156 QObject::tr("error, 0 is null : no amino acid").arg(aa_code));
157 }
158 else if(aa_code > 19)
159 {
161 QObject::tr("error, %1 amino acid code not found in m_aaCollection").arg(aa_code));
162 }
163 return m_aaCollection[aa_code - 1];
164}
165
166
167void
169{
170
171 auto it = std::find_if(m_aaCollection.begin(), m_aaCollection.end(), [aa_letter](const Aa &aa) {
172 if(aa.getLetter() == aa_letter)
173 return true;
174 return false;
175 });
176 if(it != m_aaCollection.end())
177 {
178 it->addAaModification(aaModification);
179 }
180 else
181 {
183 QObject::tr("error, %1 amino acid not found in m_aaCollection").arg(aa_letter));
184 }
185
186 updateNumbers();
187}
188
189
190void
192{
193
194 std::sort(m_aaCollection.begin(), m_aaCollection.end(), [](const Aa &aa1, const Aa &aa2) {
195 return aa1.getMass() < aa2.getMass();
196 });
197
198 std::size_t n = 1;
199 for(const Aa &aa : m_aaCollection)
200 {
201 // qDebug() << aa.getLetter() << " " << n;
202 m_asciiTable[aa.getLetter()] = n;
203 n++;
204 }
205 m_asciiTable['L'] = m_asciiTable['I'];
206
207 updateMass();
208}
209
210void
212{
213 m_massCollection.resize(1);
214
215 for(const Aa &aa : m_aaCollection)
216 {
217 m_massCollection.push_back(aa.getMass());
218 }
219}
220
221
222double
223pappso::AaCode::getMass(uint8_t aa_code) const
224{
225 return m_massCollection[aa_code];
226}
227
228double
229pappso::AaCode::getMass(char aa_letter) const
230{
231 try
232 {
233 return m_massCollection[this->getAaCode(aa_letter)];
234 }
235
236 catch(const pappso::PappsoException &err)
237 {
239 QObject::tr("getMass(char aa_letter) failed :\n%1").arg(err.qwhat()));
240 }
241}
242
243uint8_t
245{
246 double delta = precision->delta(mass);
247 double mass_min = mass - delta;
248 double mass_max = mass + delta;
249 uint8_t aa_code = 0;
250 for(uint8_t i = 1; i < m_massCollection.size(); i++)
251 {
252 if(m_massCollection.at(i) >= mass_min)
253 {
254 if(m_massCollection.at(i) <= mass_max)
255 {
256 aa_code = i;
257 }
258 break;
259 }
260 }
261 return aa_code;
262}
263
264const std::vector<Aa> &
266{
267 return m_aaCollection;
268}
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:191
void addAaModification(char aa_letter, AaModificationP aaModification)
add a modification on an amino acid for example carbamido on C
Definition aacode.cpp:168
std::vector< uint8_t > m_asciiTable
Definition aacode.h:110
void updateMass()
update mass cache
Definition aacode.cpp:211
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:244
const std::vector< Aa > & getAaCollection() const
Definition aacode.cpp:265
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:223
std::size_t getSize() const
Definition aacode.cpp:74
std::vector< Aa > m_aaCollection
Definition aacode.h:112
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