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
29#include "aastringcodec.h"
30#include <QDebug>
31#include <algorithm>
32
33using namespace pappso;
34
36 std::size_t model_max_size,
37 PrecisionPtr precision)
38 : m_precision(precision), m_aaCode(aa_code), m_aaCodec(aa_code)
39{
40 m_base = m_aaCode.getSize() + 1;
41
42 std::vector<pappso::CodeToMass> code_to_mass =
44
45 for(auto &code_mass : code_to_mass)
46 {
47 aaCodeAndMassRange aaCodeMassRange;
48 aaCodeMassRange.code = code_mass.code;
49 double delta = precision->delta(code_mass.mass);
50 aaCodeMassRange.mz_range_low = code_mass.mass - delta;
51 aaCodeMassRange.mz = code_mass.mass;
52 aaCodeMassRange.mz_range_up = code_mass.mass + delta;
53
54 m_codeMassList.push_back(aaCodeMassRange);
55 }
56
57
58 std::sort(m_codeMassList.begin(),
59 m_codeMassList.end(),
60 [](const aaCodeAndMassRange &a, const aaCodeAndMassRange &b) {
61 return a.mz_range_low < b.mz_range_low;
62 });
63}
64
66 const AaStringCodeMassMatching &other)
67 : m_precision(other.m_precision),
68 m_aaCode(other.m_aaCode),
69 m_aaCodec(other.m_aaCode)
70{
71 m_base = m_aaCode.getSize() + 1;
72}
73
77
78
81{
82 return m_precision;
83}
84
85
86std::vector<uint32_t>
88{
89 std::vector<uint32_t> aa_code_list;
90
91 // auto it_aacode = m_codeMassList.begin();
92
93 auto it_aacode = std::upper_bound(
94 m_codeMassList.begin(),
95 m_codeMassList.end(),
96 mass,
97 [](double mass,
99 return mass_range.mz_range_up > mass;
100 });
101
102 bool previous_out_of_range = false;
103
104 while(it_aacode != m_codeMassList.end())
105 {
106 if(mass < it_aacode->mz_range_low)
107 {
108
109 if(previous_out_of_range)
110 break;
111 previous_out_of_range = true;
112 it_aacode++;
113 }
114 else
115 {
116 if(mass <= it_aacode->mz_range_up)
117 {
118 previous_out_of_range = false;
119 aa_code_list.push_back(it_aacode->code);
120 it_aacode++;
121 }
122 else
123 {
124 it_aacode++;
125 }
126 }
127 }
128 return aa_code_list;
129}
130
131std::vector<uint32_t>
133 double mass, const pappso::Aa &aa, int quantifier) const
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(
158 it_aacode->code, aamodCode, quantifier))
159 {
160 aa_code_list.push_back(it_aacode->code);
161 }
162
163 it_aacode++;
164 }
165 else
166 {
167 it_aacode++;
168 }
169 }
170 }
171 return aa_code_list;
172}
173
174
175std::vector<uint32_t>
177 std::vector<double> &mass_list) const
178{
179 std::sort(mass_list.begin(), mass_list.end(), [](double a, double b) {
180 return a < b;
181 });
182 std::vector<uint32_t> aa_code_list;
183
184 auto it_aacode = m_codeMassList.begin();
185 auto it_mass = mass_list.begin();
186
187 while((it_aacode != m_codeMassList.end()) && (it_mass != mass_list.end()))
188 {
189 if(*it_mass < it_aacode->mz_range_low)
190 {
191 it_mass++;
192 }
193 else
194 {
195 if(*it_mass <= it_aacode->mz_range_up)
196 {
197 aa_code_list.push_back(it_aacode->code);
198 it_aacode++;
199 }
200 else
201 {
202 it_aacode++;
203 }
204 }
205 }
206 return aa_code_list;
207}
208
209std::vector<uint32_t>
211 std::vector<uint32_t> &code_list) const
212{
213 std::sort(code_list.begin(), code_list.end(), [](uint32_t a, uint32_t b) {
214 return a < b;
215 });
216 std::vector<uint32_t> filtered_aa_code_list;
217
218 std::vector<uint8_t> aa_ok;
219
220 auto it = code_list.begin();
221 while(*it < m_base)
222 {
223 aa_ok.push_back((uint8_t)*it);
224 // qDebug() << (uint8_t)*it << " "
225 // << m_aaCode.getAa((uint8_t)*it).getLetter();
226 it++;
227 }
228
229 for(uint32_t code : code_list)
230 {
231 if(m_aaCodec.codeOnlyContains(code, aa_ok))
232 {
233 filtered_aa_code_list.push_back(code);
234 }
235 }
236 return filtered_aa_code_list;
237}
code and decodefrom amino acid string to integer
convert mass list to amino acid string code list
virtual const char & getLetter() const
Definition aabase.cpp:433
collection of integer code for each amino acid 0 => null 1 to 20 => amino acid sorted by there mass (...
Definition aacode.h:43
std::size_t getSize() const
Definition aacode.cpp:74
convert a list of mass to amino acid string codes
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
std::vector< CodeToMass > generateLlcCodeListUpToMaxPeptideSize(std::size_t size) const
generates all possible combination of llc code mass llc : the lowest common code denominator for a gi...
double getTotalModificationMass() const
get the sum of mass modifications
Definition aa.cpp:79
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