libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
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
28
#include "
pappsomspp/core/amino_acid/aacode.h
"
29
#include "
pappsomspp/core/exception/exceptionnotfound.h
"
30
#include "
pappsomspp/core/exception/exceptionoutofrange.h
"
31
32
using namespace
pappso
;
33
34
AaCode::AaCode
()
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
58
updateNumbers
();
59
}
60
61
pappso::AaCode::AaCode
(
const
pappso::AaCode
&other)
62
{
63
64
m_asciiTable
= other.
m_asciiTable
;
65
66
m_aaCollection
= other.
m_aaCollection
;
67
}
68
69
AaCode::~AaCode
()
70
{
71
}
72
73
std::size_t
74
pappso::AaCode::getSize
()
const
75
{
76
return
19;
77
}
78
79
80
uint8_t
81
pappso::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
{
89
throw
pappso::ExceptionOutOfRange
(
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
{
96
throw
pappso::ExceptionOutOfRange
(
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
105
uint8_t
106
pappso::AaCode::getAaCode
(
pappso::Enums::AminoAcidChar
aa)
const
107
{
108
109
uint8_t aa_code =
m_asciiTable
[(char)aa];
110
111
if
(aa_code == 0)
112
{
113
throw
pappso::ExceptionOutOfRange
(
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
{
121
throw
pappso::ExceptionOutOfRange
(
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
131
const
pappso::Aa
&
132
pappso::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
}
146
throw
pappso::ExceptionNotFound
(
147
QObject::tr(
"error, %1 amino acid not found in m_aaCollection"
).arg(aa_letter));
148
}
149
150
151
const
pappso::Aa
&
152
pappso::AaCode::getAa
(uint8_t aa_code)
const
153
{
154
if
(aa_code == 0)
155
{
156
throw
pappso::ExceptionOutOfRange
(
157
QObject::tr(
"error, 0 is null : no amino acid"
).arg(aa_code));
158
}
159
else
if
(aa_code > 19)
160
{
161
throw
pappso::ExceptionOutOfRange
(
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
168
void
169
pappso::AaCode::addAaModification
(
char
aa_letter,
pappso::AaModificationP
aaModification)
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
{
183
throw
pappso::ExceptionNotFound
(
184
QObject::tr(
"error, %1 amino acid not found in m_aaCollection"
).arg(aa_letter));
185
}
186
187
updateNumbers
();
188
}
189
190
191
void
192
pappso::AaCode::updateNumbers
()
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
211
void
212
pappso::AaCode::updateMass
()
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
223
double
224
pappso::AaCode::getMass
(uint8_t aa_code)
const
225
{
226
return
m_massCollection
[aa_code];
227
}
228
229
double
230
pappso::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
{
239
throw
pappso::PappsoException
(
240
QObject::tr(
"getMass(char aa_letter) failed :\n%1"
).arg(err.
qwhat
()));
241
}
242
}
243
244
uint8_t
245
pappso::AaCode::getAaCodeByMass
(
double
mass,
pappso::PrecisionPtr
precision)
const
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
265
const
std::vector<Aa> &
266
pappso::AaCode::getAaCollection
()
const
267
{
268
return
m_aaCollection
;
269
}
aacode.h
pappso::AaCode
collection of integer code for each amino acid 0 => null 1 to 20 => amino acid sorted by there mass (...
Definition
aacode.h:44
pappso::AaCode::updateNumbers
void updateNumbers()
give a number (the code) to each amino acid sorted by mass
Definition
aacode.cpp:192
pappso::AaCode::~AaCode
~AaCode()
Definition
aacode.cpp:69
pappso::AaCode::addAaModification
void addAaModification(char aa_letter, AaModificationP aaModification)
add a modification on an amino acid for example carbamido on C
Definition
aacode.cpp:169
pappso::AaCode::m_massCollection
std::vector< double > m_massCollection
Definition
aacode.h:116
pappso::AaCode::m_asciiTable
std::vector< uint8_t > m_asciiTable
Definition
aacode.h:113
pappso::AaCode::updateMass
void updateMass()
update mass cache
Definition
aacode.cpp:212
pappso::AaCode::m_leucine
pappso::Aa m_leucine
Definition
aacode.h:118
pappso::AaCode::getAaCodeByMass
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
pappso::AaCode::AaCode
AaCode()
Definition
aacode.cpp:34
pappso::AaCode::getAaCollection
const std::vector< Aa > & getAaCollection() const
Definition
aacode.cpp:266
pappso::AaCode::getAaCode
uint8_t getAaCode(char aa_letter) const
get the integer code of an amino acid with the one letter code
Definition
aacode.cpp:81
pappso::AaCode::getMass
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
pappso::AaCode::getSize
std::size_t getSize() const
number of amino acid coded letters in this aa code
Definition
aacode.cpp:74
pappso::AaCode::m_aaCollection
std::vector< Aa > m_aaCollection
Definition
aacode.h:115
pappso::AaCode::getAa
const Aa & getAa(char aa_letter) const
get the Aa object from the one letter code
Definition
aacode.cpp:132
pappso::Aa
Definition
aa.h:45
pappso::ExceptionNotFound
Definition
exceptionnotfound.h:32
pappso::ExceptionOutOfRange
Definition
exceptionoutofrange.h:32
pappso::PappsoException
Definition
pappsoexception.h:41
pappso::PappsoException::qwhat
virtual const QString & qwhat() const
Definition
pappsoexception.h:66
pappso::PrecisionBase::delta
virtual pappso_double delta(pappso_double value) const =0
exceptionnotfound.h
exceptionoutofrange.h
pappso::Enums::AminoAcidChar
AminoAcidChar
Definition
types.h:187
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition
aa.cpp:39
pappso::AaModificationP
const AaModification * AaModificationP
Definition
aamodification.h:52
pappso::PrecisionPtr
const PrecisionBase * PrecisionPtr
Definition
precision.h:122
pappsomspp
core
amino_acid
aacode.cpp
Generated on
for libpappsomspp by
1.17.0