libpappsomspp
Library for mass spectrometry
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 "aacode.h"
29#include "../exception/exceptionnotfound.h"
30#include "../exception/exceptionoutofrange.h"
31
32using namespace pappso;
33
34AaCode::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
59}
60
62{
63
64 m_asciiTable = other.m_asciiTable;
65
66 m_aaCollection = other.m_aaCollection;
67}
68
70{
71}
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 return m_asciiTable[aa_letter];
86}
87
88const pappso::Aa &
89pappso::AaCode::getAa(char aa_letter) const
90{
91
92 auto it = std::find_if(m_aaCollection.begin(), m_aaCollection.end(), [aa_letter](const Aa &aa) {
93 if(aa.getLetter() == aa_letter)
94 return true;
95 return false;
96 });
97 if(it != m_aaCollection.end())
98 {
99 return *it;
100 }
102 QObject::tr("error, %1 amino acid not found in m_aaCollection").arg(aa_letter));
103}
104
105
106const pappso::Aa &
107pappso::AaCode::getAa(uint8_t aa_code) const
108{
109 if(aa_code == 0)
110 {
112 QObject::tr("error, 0 is null : no amino acid").arg(aa_code));
113 }
114 else if(aa_code > 19)
115 {
117 QObject::tr("error, %1 amino acid code not found in m_aaCollection").arg(aa_code));
118 }
119 return m_aaCollection[aa_code - 1];
120}
121
122
123void
125{
126
127 auto it = std::find_if(m_aaCollection.begin(), m_aaCollection.end(), [aa_letter](const Aa &aa) {
128 if(aa.getLetter() == aa_letter)
129 return true;
130 return false;
131 });
132 if(it != m_aaCollection.end())
133 {
134 it->addAaModification(aaModification);
135 }
136 else
137 {
139 QObject::tr("error, %1 amino acid not found in m_aaCollection").arg(aa_letter));
140 }
141
142 updateNumbers();
143}
144
145
146void
148{
149
150 std::sort(m_aaCollection.begin(), m_aaCollection.end(), [](const Aa &aa1, const Aa &aa2) {
151 return aa1.getMass() < aa2.getMass();
152 });
153
154 std::size_t n = 1;
155 for(const Aa &aa : m_aaCollection)
156 {
157 // qDebug() << aa.getLetter() << " " << n;
158 m_asciiTable[aa.getLetter()] = n;
159 n++;
160 }
161 m_asciiTable['L'] = m_asciiTable['I'];
162
163 updateMass();
164}
165
166void
168{
169 m_massCollection.resize(1);
170
171 for(const Aa &aa : m_aaCollection)
172 {
173 m_massCollection.push_back(aa.getMass());
174 }
175}
176
177
178double
179pappso::AaCode::getMass(uint8_t aa_code) const
180{
181 return m_massCollection[aa_code];
182}
183
184double
185pappso::AaCode::getMass(char aa_letter) const
186{
187 return m_massCollection[this->getAaCode(aa_letter)];
188}
189
190uint8_t
192{
193 double delta = precision->delta(mass);
194 double mass_min = mass - delta;
195 double mass_max = mass + delta;
196 uint8_t aa_code = 0;
197 for(uint8_t i = 1; i < m_massCollection.size(); i++)
198 {
199 if(m_massCollection.at(i) >= mass_min)
200 {
201 if(m_massCollection.at(i) <= mass_max)
202 {
203 aa_code = i;
204 }
205 break;
206 }
207 }
208 return aa_code;
209}
210
211const std::vector<Aa> &
213{
214 return m_aaCollection;
215}
give an integer code to each amino acid
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:147
void addAaModification(char aa_letter, AaModificationP aaModification)
add a modification on an amino acid for example carbamido on C
Definition: aacode.cpp:124
std::vector< uint8_t > m_asciiTable
Definition: aacode.h:105
void updateMass()
update mass cache
Definition: aacode.cpp:167
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:191
const std::vector< Aa > & getAaCollection() const
Definition: aacode.cpp:212
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:179
std::size_t getSize() const
Definition: aacode.cpp:74
std::vector< Aa > m_aaCollection
Definition: aacode.h:107
const Aa & getAa(char aa_letter) const
get the Aa object from the one letter code
Definition: aacode.cpp:89
Definition: aa.h:45
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