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("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("error, %1 amino acid code not found in m_aaCollection for letter \"%2\"")
98 .arg(aa_code)
99 .arg(aa_letter));
100 }
101 return aa_code;
102}
103
104uint8_t
106{
107
108 uint8_t aa_code = m_asciiTable[(char)aa];
109
110 if(aa_code == 0)
111 {
113 QObject::tr("error, %1 is null : no amino acid for letter \"%2\"")
114 .arg(aa_code)
115 .arg(char(aa)));
116 }
117 else if(aa_code >= m_massCollection.size())
118 {
120 QObject::tr("error, %1 amino acid code not found in m_aaCollection for letter \"%2\"")
121 .arg(aa_code)
122 .arg(char(aa)));
123 }
124 return aa_code;
125}
126
127
128const pappso::Aa &
129pappso::AaCode::getAa(char aa_letter) const
130{
131
132 auto it = std::find_if(m_aaCollection.begin(), m_aaCollection.end(), [aa_letter](const Aa &aa) {
133 if(aa.getLetter() == aa_letter)
134 return true;
135 return false;
136 });
137 if(it != m_aaCollection.end())
138 {
139 return *it;
140 }
142 QObject::tr("error, %1 amino acid not found in m_aaCollection").arg(aa_letter));
143}
144
145
146const pappso::Aa &
147pappso::AaCode::getAa(uint8_t aa_code) const
148{
149 if(aa_code == 0)
150 {
152 QObject::tr("error, 0 is null : no amino acid").arg(aa_code));
153 }
154 else if(aa_code > 19)
155 {
157 QObject::tr("error, %1 amino acid code not found in m_aaCollection").arg(aa_code));
158 }
159 return m_aaCollection[aa_code - 1];
160}
161
162
163void
165{
166
167 auto it = std::find_if(m_aaCollection.begin(), m_aaCollection.end(), [aa_letter](const Aa &aa) {
168 if(aa.getLetter() == aa_letter)
169 return true;
170 return false;
171 });
172 if(it != m_aaCollection.end())
173 {
174 it->addAaModification(aaModification);
175 }
176 else
177 {
179 QObject::tr("error, %1 amino acid not found in m_aaCollection").arg(aa_letter));
180 }
181
183}
184
185
186void
188{
189
190 std::sort(m_aaCollection.begin(), m_aaCollection.end(), [](const Aa &aa1, const Aa &aa2) {
191 return aa1.getMass() < aa2.getMass();
192 });
193
194 std::size_t n = 1;
195 for(const Aa &aa : m_aaCollection)
196 {
197 // qDebug() << aa.getLetter() << " " << n;
198 m_asciiTable[aa.getLetter()] = n;
199 n++;
200 }
201 m_asciiTable['L'] = m_asciiTable['I'];
202
203 updateMass();
204}
205
206void
208{
209 m_massCollection.resize(1);
210
211 for(const Aa &aa : m_aaCollection)
212 {
213 m_massCollection.push_back(aa.getMass());
214 }
215}
216
217
218double
219pappso::AaCode::getMass(uint8_t aa_code) const
220{
221 return m_massCollection[aa_code];
222}
223
224double
225pappso::AaCode::getMass(char aa_letter) const
226{
227 return m_massCollection[this->getAaCode(aa_letter)];
228}
229
230uint8_t
232{
233 double delta = precision->delta(mass);
234 double mass_min = mass - delta;
235 double mass_max = mass + delta;
236 uint8_t aa_code = 0;
237 for(uint8_t i = 1; i < m_massCollection.size(); i++)
238 {
239 if(m_massCollection.at(i) >= mass_min)
240 {
241 if(m_massCollection.at(i) <= mass_max)
242 {
243 aa_code = i;
244 }
245 break;
246 }
247 }
248 return aa_code;
249}
250
251const 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:187
void addAaModification(char aa_letter, AaModificationP aaModification)
add a modification on an amino acid for example carbamido on C
Definition aacode.cpp:164
std::vector< double > m_massCollection
Definition aacode.h:113
std::vector< uint8_t > m_asciiTable
Definition aacode.h:110
void updateMass()
update mass cache
Definition aacode.cpp:207
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:231
const std::vector< Aa > & getAaCollection() const
Definition aacode.cpp:252
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:219
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:129
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