libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
aastringcodemassmatching.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/amino_acid/aastringcodemassmatching.cpp
3 * \date 10/05/2023
4 * \author Olivier Langella
5 * \brief convert mass list to amino acid string code list
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#include <QDebug>
32#include <algorithm>
33
34using namespace pappso;
35
37 std::size_t model_max_size,
38 PrecisionPtr precision)
39 : m_precision(precision), m_aaCode(aa_code), m_aaCodec(aa_code)
40{
41 m_base = m_aaCode.getSize() + 1;
42
43 std::vector<pappso::CodeToMass> code_to_mass =
44 m_aaCodec.generateLlcCodeListUpToMaxPeptideSize(model_max_size);
45
46 for(auto &code_mass : code_to_mass)
47 {
48 aaCodeAndMassRange aaCodeMassRange;
49 aaCodeMassRange.code = code_mass.code;
50 double delta = precision->delta(code_mass.mass);
51 aaCodeMassRange.mz_range_low = code_mass.mass - delta;
52 aaCodeMassRange.mz = code_mass.mass;
53 aaCodeMassRange.mz_range_up = code_mass.mass + delta;
54
55 m_codeMassList.push_back(aaCodeMassRange);
56 }
57
58
59 std::sort(m_codeMassList.begin(),
60 m_codeMassList.end(),
61 [](const aaCodeAndMassRange &a, const aaCodeAndMassRange &b) {
62 return a.mz_range_low < b.mz_range_low;
63 });
64}
65
71
75
76
82
83
84std::vector<uint32_t>
86{
87 std::vector<uint32_t> aa_code_list;
88
89 // auto it_aacode = m_codeMassList.begin();
90
91 auto it_aacode = std::upper_bound(
92 m_codeMassList.begin(),
93 m_codeMassList.end(),
94 mass,
95 [](double mass, const pappso::AaStringCodeMassMatching::aaCodeAndMassRange &mass_range) {
96 return mass_range.mz_range_up > mass;
97 });
98
99 bool previous_out_of_range = false;
100
101 while(it_aacode != m_codeMassList.end())
102 {
103 if(mass < it_aacode->mz_range_low)
104 {
105
106 if(previous_out_of_range)
107 break;
108 previous_out_of_range = true;
109 it_aacode++;
110 }
111 else
112 {
113 if(mass <= it_aacode->mz_range_up)
114 {
115 previous_out_of_range = false;
116 aa_code_list.push_back(it_aacode->code);
117 it_aacode++;
118 }
119 else
120 {
121 it_aacode++;
122 }
123 }
124 }
125 return aa_code_list;
126}
127
128std::vector<uint32_t>
130 const pappso::Aa &aa,
131 int quantifier) const
132{
133 try
134 {
135 std::vector<uint32_t> aa_code_list;
136
137 double total_modification_mass = aa.getTotalModificationMass();
138 total_modification_mass *= quantifier;
139 mass = mass - total_modification_mass;
140 if(mass < 0)
141 return aa_code_list;
142
143 uint8_t aamodCode = m_aaCode.getAaCode(aa.getLetter());
144
145 auto it_aacode = m_codeMassList.begin();
146
147 while(it_aacode != m_codeMassList.end())
148 {
149 if(mass < it_aacode->mz_range_low)
150 {
151 it_aacode++;
152 }
153 else
154 {
155 if(mass <= it_aacode->mz_range_up)
156 {
157 if(m_aaCodec.uniqueCodeContainsAminoAcid(it_aacode->code, aamodCode, quantifier))
158 {
159 aa_code_list.push_back(it_aacode->code);
160 }
161
162 it_aacode++;
163 }
164 else
165 {
166 it_aacode++;
167 }
168 }
169 }
170 return aa_code_list;
171 }
172 catch(const pappso::PappsoException &err)
173 {
175 QObject::tr("getAaCodeFromMassWearingModification failed :\n%1").arg(err.qwhat()));
176 }
177}
178
179
180std::vector<uint32_t>
182{
183 std::sort(mass_list.begin(), mass_list.end(), [](double a, double b) { return a < b; });
184 std::vector<uint32_t> aa_code_list;
185
186 auto it_aacode = m_codeMassList.begin();
187 auto it_mass = mass_list.begin();
188
189 while((it_aacode != m_codeMassList.end()) && (it_mass != mass_list.end()))
190 {
191 if(*it_mass < it_aacode->mz_range_low)
192 {
193 it_mass++;
194 }
195 else
196 {
197 if(*it_mass <= it_aacode->mz_range_up)
198 {
199 aa_code_list.push_back(it_aacode->code);
200 it_aacode++;
201 }
202 else
203 {
204 it_aacode++;
205 }
206 }
207 }
208 return aa_code_list;
209}
210
211std::vector<uint32_t>
212pappso::AaStringCodeMassMatching::filterCodeList(std::vector<uint32_t> &code_list) const
213{
214 std::sort(code_list.begin(), code_list.end(), [](uint32_t a, uint32_t b) { return a < b; });
215 std::vector<uint32_t> filtered_aa_code_list;
216
217 std::vector<uint8_t> aa_ok;
218
219 auto it = code_list.begin();
220 while(*it < m_base)
221 {
222 aa_ok.push_back((uint8_t)*it);
223 // qDebug() << (uint8_t)*it << " "
224 // << m_aaCode.getAa((uint8_t)*it).getLetter();
225 it++;
226 }
227
228 for(uint32_t code : code_list)
229 {
230 if(m_aaCodec.codeOnlyContains(code, aa_ok))
231 {
232 filtered_aa_code_list.push_back(code);
233 }
234 }
235 return filtered_aa_code_list;
236}
collection of integer code for each amino acid 0 => null 1 to 20 => amino acid sorted by there mass (...
Definition aacode.h:44
std::vector< aaCodeAndMassRange > m_codeMassList
std::vector< uint32_t > filterCodeList(std::vector< uint32_t > &code_list) const
filter a list of amino acid string code find elementary amino acids (one base only) in the list and r...
std::vector< uint32_t > getAaCodeFromMass(double mass) const
get amino acid string code from a single mass delta
AaStringCodeMassMatching(const AaCode &aa_code, std::size_t model_max_size, PrecisionPtr precision)
std::vector< uint32_t > getAaCodeFromMassWearingModification(double mass, const Aa &aa, int quantifier) const
get amino acid string code from a single mass delta wearing a specific modification
std::vector< uint32_t > getAaCodeFromMassList(std::vector< double > &mass_list) const
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 PrecisionBase * PrecisionPtr
Definition precision.h:122