libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::AaStringCodec Class Reference

#include <aastringcodec.h>

Public Member Functions

 AaStringCodec (const AaCode &aaCode)
 
 AaStringCodec (const AaStringCodec &other)
 
 ~AaStringCodec ()
 
std::size_t getLimitMax (std::size_t size) const
 get the maximum code number for a given peptide size
 
uint32_t code (const QString &aa_str) const
 get integer from amino acide suite string
 
uint32_t codeLlc (const QString &aa_str) const
 get the lowest common denominator integer from amino acide suite string
 
uint32_t codeLlc (std::vector< uint8_t >::const_iterator it_begin, std::size_t size) const
 get the lowest common denominator integer from amino acide code vector
 
QString decode (uint32_t code) const
 
double getMass (uint32_t code) const
 
std::vector< CodeToMassgenerateLlcCodeListUpToMaxPeptideSize (std::size_t size) const
 generates all possible combination of llc code mass llc : the lowest common code denominator for a given aa formula
 
std::vector< CodeToMassgenerateLlcCodeListByMaxPeptideSize (std::size_t size) const
 generates all possible combination of llc code mass llc : the lowest common code denominator for a given aa formula
 
bool codeOnlyContains (uint32_t code, const std::vector< uint8_t > &aa_ok) const
 
const AaCodegetAaCode () const
 

Private Member Functions

void recGenerateModel (std::vector< CodeToMass > &glist, std::vector< uint8_t > &model, std::size_t position) const
 recursive method to generate models
 
CodeToMass generateCodeMassFromModel (const std::vector< uint8_t > &model) const
 

Private Attributes

uint32_t m_base = 0
 
const AaCodem_aaCode
 
std::vector< uint32_t > m_units
 

Detailed Description

Definition at line 51 of file aastringcodec.h.

Constructor & Destructor Documentation

◆ AaStringCodec() [1/2]

AaStringCodec::AaStringCodec ( const AaCode aaCode)

Default constructor

Definition at line 33 of file aastringcodec.cpp.

33 : m_aaCode(aaCode)
34{
35
36 m_base = m_aaCode.getSize() + 1;
37 m_units.resize(10);
38 uint32_t unit = 1;
39 for(auto &this_unit : m_units)
40 {
41 this_unit = unit;
42 unit *= m_base;
43 }
44}
std::size_t getSize() const
Definition aacode.cpp:74
std::vector< uint32_t > m_units
const AaCode & m_aaCode

References pappso::AaCode::getSize(), m_aaCode, m_base, and m_units.

◆ AaStringCodec() [2/2]

AaStringCodec::AaStringCodec ( const AaStringCodec other)

Copy constructor

Parameters
otherTODO

Definition at line 46 of file aastringcodec.cpp.

47 : m_aaCode(other.m_aaCode)
48{
49 m_base = other.m_base;
50 m_units = other.m_units;
51}

References m_base, and m_units.

◆ ~AaStringCodec()

AaStringCodec::~AaStringCodec ( )

Destructor

Definition at line 53 of file aastringcodec.cpp.

54{
55}

Member Function Documentation

◆ code()

uint32_t pappso::AaStringCodec::code ( const QString &  aa_str) const

get integer from amino acide suite string

Definition at line 59 of file aastringcodec.cpp.

60{
61
62 std::size_t pos = 0;
63 uint32_t code = 0;
64 for(auto &aa_char : aa_str)
65 {
66 code += m_aaCode.getAaCode(aa_char.toLatin1()) * m_units[pos];
67 pos++;
68 }
69 return code;
70}
uint8_t getAaCode(char aa_letter) const
Definition aacode.cpp:81
uint32_t code(const QString &aa_str) const
get integer from amino acide suite string

◆ codeLlc() [1/2]

uint32_t pappso::AaStringCodec::codeLlc ( const QString &  aa_str) const

get the lowest common denominator integer from amino acide suite string

Definition at line 73 of file aastringcodec.cpp.

74{
75 std::vector<uint8_t> llc_vec;
76
77 for(auto &aa_char : aa_str)
78 {
79 llc_vec.push_back(m_aaCode.getAaCode(aa_char.toLatin1()));
80 }
81 std::sort(llc_vec.begin(), llc_vec.end(), std::greater<uint8_t>());
82
83
84 std::size_t pos = 0;
85 uint32_t code = 0;
86 for(auto &aa_code : llc_vec)
87 {
88 code += (uint32_t)aa_code * m_units[pos];
89 pos++;
90 }
91 return code;
92}

Referenced by pappso::ProteinIntegerCode::computePeptideCodeFragments().

◆ codeLlc() [2/2]

uint32_t pappso::AaStringCodec::codeLlc ( std::vector< uint8_t >::const_iterator  it_begin,
std::size_t  size 
) const

get the lowest common denominator integer from amino acide code vector

Definition at line 95 of file aastringcodec.cpp.

97{
98 std::vector<uint8_t> llc_vec;
99
100 for(std::size_t i = 0; i < size; i++)
101 {
102 llc_vec.push_back(*it_begin);
103 it_begin++;
104 }
105 std::sort(llc_vec.begin(), llc_vec.end(), std::greater<uint8_t>());
106
107
108 std::size_t pos = 0;
109 uint32_t code = 0;
110 for(auto &aa_code : llc_vec)
111 {
112 code += (uint32_t)aa_code * m_units[pos];
113 pos++;
114 }
115 return code;
116}

◆ codeOnlyContains()

bool pappso::AaStringCodec::codeOnlyContains ( uint32_t  code,
const std::vector< uint8_t > &  aa_ok 
) const

Definition at line 257 of file aastringcodec.cpp.

259{
260
261 while(code > 0)
262 {
263 if(std::find(aa_ok.begin(), aa_ok.end(), (uint8_t)(code % m_base)) ==
264 aa_ok.end())
265 return false;
266
267 code /= m_base;
268 }
269 return true;
270}

◆ decode()

QString pappso::AaStringCodec::decode ( uint32_t  code) const

Definition at line 120 of file aastringcodec.cpp.

121{
122 QString aa_suite;
123
124 while(code > 0)
125 {
126 aa_suite.append(m_aaCode.getAa((uint8_t)(code % m_base)).getLetter());
127 code /= m_base;
128 }
129
130 // qDebug() << aa_suite;
131
132 return aa_suite;
133}
virtual const char & getLetter() const
Definition aabase.cpp:434
const Aa & getAa(char aa_letter) const
Definition aacode.cpp:89

◆ generateCodeMassFromModel()

pappso::CodeToMass pappso::AaStringCodec::generateCodeMassFromModel ( const std::vector< uint8_t > &  model) const
private

Definition at line 226 of file aastringcodec.cpp.

228{
229 CodeToMass code_mass;
230 std::size_t pos = 0;
231 for(auto aacode : model)
232 {
233 code_mass.mass += m_aaCode.getMass(aacode);
234
235 code_mass.code += (uint32_t)aacode * m_units[pos];
236 pos++;
237 }
238
239 // qDebug() << code_mass.code << " " << code_mass.mass;
240 return code_mass;
241}
double getMass(uint8_t aa_code) const
Definition aacode.cpp:186

References pappso::CodeToMass::code, and pappso::CodeToMass::mass.

◆ generateLlcCodeListByMaxPeptideSize()

std::vector< CodeToMass > pappso::AaStringCodec::generateLlcCodeListByMaxPeptideSize ( std::size_t  size) const

generates all possible combination of llc code mass llc : the lowest common code denominator for a given aa formula

generate only for this peptide size

Definition at line 180 of file aastringcodec.cpp.

182{
183 std::vector<CodeToMass> llc_list;
184 if(size == 0)
185 return llc_list;
186 std::vector<uint8_t> model;
187 model.resize(size, 0);
188
189 for(uint8_t i = 1; i < m_base; i++)
190 {
191 model[0] = i;
192 recGenerateModel(llc_list, model, 1);
193 }
194 return llc_list;
195}
void recGenerateModel(std::vector< CodeToMass > &glist, std::vector< uint8_t > &model, std::size_t position) const
recursive method to generate models

◆ generateLlcCodeListUpToMaxPeptideSize()

std::vector< CodeToMass > pappso::AaStringCodec::generateLlcCodeListUpToMaxPeptideSize ( std::size_t  size) const

generates all possible combination of llc code mass llc : the lowest common code denominator for a given aa formula

generate from peptide size =1 to peptide size

Definition at line 151 of file aastringcodec.cpp.

153{
154 std::vector<CodeToMass> llc_list;
155 if(size == 0)
156 return llc_list;
157 std::vector<uint8_t> model;
158 for(uint8_t p = 1; p <= size; p++)
159 {
160 model.resize(p, 0);
161
162 for(uint8_t i = 1; i < m_base; i++)
163 {
164 model[0] = i;
165 if(p == 1)
166 {
167 llc_list.push_back(generateCodeMassFromModel(model));
168 }
169 else
170 {
171 recGenerateModel(llc_list, model, 1);
172 }
173 }
174 }
175 return llc_list;
176}
CodeToMass generateCodeMassFromModel(const std::vector< uint8_t > &model) const

Referenced by pappso::AaStringCodeMassMatching::AaStringCodeMassMatching().

◆ getAaCode()

const pappso::AaCode & pappso::AaStringCodec::getAaCode ( ) const

Definition at line 273 of file aastringcodec.cpp.

274{
275 return m_aaCode;
276}

Referenced by pappso::ProteinIntegerCode::ProteinIntegerCode().

◆ getLimitMax()

std::size_t pappso::AaStringCodec::getLimitMax ( std::size_t  size) const

get the maximum code number for a given peptide size

Definition at line 245 of file aastringcodec.cpp.

246{
247
248 std::size_t code = 0;
249 for(std::size_t pos = 0; pos < size; pos++)
250 {
251 code += (std::size_t)(m_base - 1) * (std::size_t)m_units[pos];
252 }
253 return code;
254}

◆ getMass()

double pappso::AaStringCodec::getMass ( uint32_t  code) const

Definition at line 136 of file aastringcodec.cpp.

137{
138 double mass = 0;
139
140 while(code > 0)
141 {
142 mass += m_aaCode.getMass((uint8_t)(code % m_base));
143 code /= m_base;
144 }
145
146 return mass;
147}

◆ recGenerateModel()

void pappso::AaStringCodec::recGenerateModel ( std::vector< CodeToMass > &  glist,
std::vector< uint8_t > &  model,
std::size_t  position 
) const
private

recursive method to generate models

Definition at line 198 of file aastringcodec.cpp.

201{
202 if(position == model.size())
203 return;
204
205 if(position == model.size() - 1)
206 {
207 uint8_t max = model[position - 1];
208 for(uint8_t i = 1; i <= max; i++)
209 {
210 model[position] = i;
211 glist.push_back(generateCodeMassFromModel(model));
212 }
213 }
214 else
215 {
216 uint8_t max = model[position - 1];
217 for(uint8_t i = 1; i <= max; i++)
218 {
219 model[position] = i;
220 recGenerateModel(glist, model, position + 1);
221 }
222 }
223}
@ max
maximum of intensities

References pappso::max.

Member Data Documentation

◆ m_aaCode

const AaCode& pappso::AaStringCodec::m_aaCode
private

Definition at line 130 of file aastringcodec.h.

Referenced by AaStringCodec().

◆ m_base

uint32_t pappso::AaStringCodec::m_base = 0
private

Definition at line 129 of file aastringcodec.h.

Referenced by AaStringCodec(), and AaStringCodec().

◆ m_units

std::vector<uint32_t> pappso::AaStringCodec::m_units
private

Definition at line 131 of file aastringcodec.h.

Referenced by AaStringCodec(), and AaStringCodec().


The documentation for this class was generated from the following files: