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
32using namespace pappso;
33
35 std::size_t model_max_size,
36 PrecisionPtr precision)
37 : m_aaCode(aa_code), m_aaCodec(aa_code)
38{
39 m_base = m_aaCode.getSize() + 1;
40
41 std::vector<pappso::CodeToMass> code_to_mass =
43
44 for(auto &code_mass : code_to_mass)
45 {
46 aaCodeAndMassRange aaCodeMassRange;
47 aaCodeMassRange.code = code_mass.code;
48 double delta = precision->delta(code_mass.mass);
49 aaCodeMassRange.mz_range_low = code_mass.mass - delta;
50 aaCodeMassRange.mz = code_mass.mass;
51 aaCodeMassRange.mz_range_up = code_mass.mass + delta;
52
53 m_codeMassList.push_back(aaCodeMassRange);
54 }
55
56
57 std::sort(m_codeMassList.begin(),
58 m_codeMassList.end(),
59 [](const aaCodeAndMassRange &a, const aaCodeAndMassRange &b) {
60 return a.mz_range_low < b.mz_range_low;
61 });
62}
63
65 const AaStringCodeMassMatching &other)
66 : m_aaCode(other.m_aaCode), m_aaCodec(other.m_aaCode)
67{
68 m_base = m_aaCode.getSize() + 1;
69}
70
74
75std::vector<uint32_t>
77 std::vector<double> &mass_list) const
78{
79 std::sort(mass_list.begin(), mass_list.end(), [](double a, double b) {
80 return a < b;
81 });
82 std::vector<uint32_t> aa_code_list;
83
84 auto it_aacode = m_codeMassList.begin();
85 auto it_mass = mass_list.begin();
86
87 while((it_aacode != m_codeMassList.end()) && (it_mass != mass_list.end()))
88 {
89 if(*it_mass < it_aacode->mz_range_low)
90 {
91 it_mass++;
92 }
93 else
94 {
95 if(*it_mass <= it_aacode->mz_range_up)
96 {
97 aa_code_list.push_back(it_aacode->code);
98 it_aacode++;
99 }
100 else
101 {
102 it_aacode++;
103 }
104 }
105 }
106 return aa_code_list;
107}
108
109std::vector<uint32_t>
111 std::vector<uint32_t> &code_list) const
112{
113 std::sort(code_list.begin(), code_list.end(), [](uint32_t a, uint32_t b) {
114 return a < b;
115 });
116 std::vector<uint32_t> filtered_aa_code_list;
117
118 std::vector<uint8_t> aa_ok;
119
120 auto it = code_list.begin();
121 while(*it < m_base)
122 {
123 aa_ok.push_back((uint8_t)*it);
124 // qDebug() << (uint8_t)*it << " "
125 // << m_aaCode.getAa((uint8_t)*it).getLetter();
126 it++;
127 }
128
129 for(uint32_t code : code_list)
130 {
131 if(m_aaCodec.codeOnlyContains(code, aa_ok))
132 {
133 filtered_aa_code_list.push_back(code);
134 }
135 }
136 return filtered_aa_code_list;
137}
code and decodefrom amino acid string to integer
convert mass list to amino acid string code list
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
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...
AaStringCodeMassMatching(const AaCode &aa_code, std::size_t model_max_size, PrecisionPtr precision)
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...
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