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

code and decode amino acid string sequence to unique integer More...

#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
 
QStringList decode (const std::vector< uint32_t > &code_list) 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
 tell if a code only contains a list of amino acid
 
bool uniqueCodeContainsAminoAcid (uint32_t code, uint8_t aa_ok, int times) const
 tell if a unique code only contains one amino acid 1 or n times
 
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

code and decode amino acid string sequence to unique integer

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

tell if a code only contains a list of amino acid

Parameters
codethe code to valid
aa_oklist of required amino acids

Definition at line 269 of file aastringcodec.cpp.

271{
272
273 while(code > 0)
274 {
275 if(std::find(aa_ok.begin(), aa_ok.end(), (uint8_t)(code % m_base)) ==
276 aa_ok.end())
277 return false;
278
279 code /= m_base;
280 }
281 return true;
282}

◆ decode() [1/2]

QStringList pappso::AaStringCodec::decode ( const std::vector< uint32_t > &  code_list) const

Definition at line 136 of file aastringcodec.cpp.

137{
138 QStringList aa_string_list;
139 for(auto code : code_list)
140 {
141 aa_string_list << decode(code);
142 }
143 return aa_string_list;
144}
QString decode(uint32_t code) const

◆ decode() [2/2]

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:436
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 238 of file aastringcodec.cpp.

240{
241 CodeToMass code_mass;
242 std::size_t pos = 0;
243 for(auto aacode : model)
244 {
245 code_mass.mass += m_aaCode.getMass(aacode);
246
247 code_mass.code += (uint32_t)aacode * m_units[pos];
248 pos++;
249 }
250
251 // qDebug() << code_mass.code << " " << code_mass.mass;
252 return code_mass;
253}
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 192 of file aastringcodec.cpp.

194{
195 std::vector<CodeToMass> llc_list;
196 if(size == 0)
197 return llc_list;
198 std::vector<uint8_t> model;
199 model.resize(size, 0);
200
201 for(uint8_t i = 1; i < m_base; i++)
202 {
203 model[0] = i;
204 recGenerateModel(llc_list, model, 1);
205 }
206 return llc_list;
207}
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 163 of file aastringcodec.cpp.

165{
166 std::vector<CodeToMass> llc_list;
167 if(size == 0)
168 return llc_list;
169 std::vector<uint8_t> model;
170 for(uint8_t p = 1; p <= size; p++)
171 {
172 model.resize(p, 0);
173
174 for(uint8_t i = 1; i < m_base; i++)
175 {
176 model[0] = i;
177 if(p == 1)
178 {
179 llc_list.push_back(generateCodeMassFromModel(model));
180 }
181 else
182 {
183 recGenerateModel(llc_list, model, 1);
184 }
185 }
186 }
187 return llc_list;
188}
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 307 of file aastringcodec.cpp.

308{
309 return m_aaCode;
310}

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 257 of file aastringcodec.cpp.

258{
259
260 std::size_t code = 0;
261 for(std::size_t pos = 0; pos < size; pos++)
262 {
263 code += (std::size_t)(m_base - 1) * (std::size_t)m_units[pos];
264 }
265 return code;
266}

◆ getMass()

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

Definition at line 148 of file aastringcodec.cpp.

149{
150 double mass = 0;
151
152 while(code > 0)
153 {
154 mass += m_aaCode.getMass((uint8_t)(code % m_base));
155 code /= m_base;
156 }
157
158 return mass;
159}

◆ 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 210 of file aastringcodec.cpp.

213{
214 if(position == model.size())
215 return;
216
217 if(position == model.size() - 1)
218 {
219 uint8_t max = model[position - 1];
220 for(uint8_t i = 1; i <= max; i++)
221 {
222 model[position] = i;
223 glist.push_back(generateCodeMassFromModel(model));
224 }
225 }
226 else
227 {
228 uint8_t max = model[position - 1];
229 for(uint8_t i = 1; i <= max; i++)
230 {
231 model[position] = i;
232 recGenerateModel(glist, model, position + 1);
233 }
234 }
235}
@ max
maximum of intensities

References pappso::max.

◆ uniqueCodeContainsAminoAcid()

bool pappso::AaStringCodec::uniqueCodeContainsAminoAcid ( uint32_t  code,
uint8_t  aa_ok,
int  times 
) const

tell if a unique code only contains one amino acid 1 or n times

Parameters
codethe code to valid
aa_okthe amino acid the code must contains
timesthe number of aa_ok presence in code

Definition at line 285 of file aastringcodec.cpp.

288{
289
290 int number = 0;
291 while(code > 0)
292 {
293 if(aa_ok == (uint8_t)(code % m_base))
294 {
295 number++;
296 if(number == times)
297 return true;
298 }
299
300 code /= m_base;
301 }
302 return false;
303}

Member Data Documentation

◆ m_aaCode

const AaCode& pappso::AaStringCodec::m_aaCode
private

Definition at line 147 of file aastringcodec.h.

Referenced by AaStringCodec().

◆ m_base

uint32_t pappso::AaStringCodec::m_base = 0
private

Definition at line 146 of file aastringcodec.h.

Referenced by AaStringCodec(), and AaStringCodec().

◆ m_units

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

Definition at line 148 of file aastringcodec.h.

Referenced by AaStringCodec(), and AaStringCodec().


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