Loading...
Searching...
No Matches
aastringcodemassmatching.cpp
Go to the documentation of this file.
/**
* \file pappsomspp/amino_acid/aastringcodemassmatching.cpp
* \date 10/05/2023
* \author Olivier Langella
* \brief convert mass list to amino acid string code list
*/
/*******************************************************************************
* Copyright (c) 2023 Olivier Langella <Olivier.Langella@u-psud.fr>.
*
* This file is part of PAPPSOms-tools.
*
* PAPPSOms-tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAPPSOms-tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#include "aastringcodemassmatching.h"
#include "aastringcodec.h"
#include <QDebug>
#include <algorithm>
using namespace pappso;
AaStringCodeMassMatching::AaStringCodeMassMatching(const AaCode &aa_code,
std::size_t model_max_size,
PrecisionPtr precision)
: m_precision(precision), m_aaCode(aa_code), m_aaCodec(aa_code)
{
m_base = m_aaCode.getSize() + 1;
std::vector<pappso::CodeToMass> code_to_mass =
m_aaCodec.generateLlcCodeListUpToMaxPeptideSize(model_max_size);
for(auto &code_mass : code_to_mass)
{
aaCodeAndMassRange aaCodeMassRange;
aaCodeMassRange.code = code_mass.code;
double delta = precision->delta(code_mass.mass);
aaCodeMassRange.mz_range_low = code_mass.mass - delta;
aaCodeMassRange.mz = code_mass.mass;
aaCodeMassRange.mz_range_up = code_mass.mass + delta;
m_codeMassList.push_back(aaCodeMassRange);
}
std::sort(m_codeMassList.begin(),
m_codeMassList.end(),
[](const aaCodeAndMassRange &a, const aaCodeAndMassRange &b) {
return a.mz_range_low < b.mz_range_low;
});
}
AaStringCodeMassMatching::AaStringCodeMassMatching(
const AaStringCodeMassMatching &other)
: m_precision(other.m_precision),
m_aaCode(other.m_aaCode),
m_aaCodec(other.m_aaCode)
{
m_base = m_aaCode.getSize() + 1;
}
AaStringCodeMassMatching::~AaStringCodeMassMatching()
{
}
pappso::PrecisionPtr
pappso::AaStringCodeMassMatching::getPrecisionPtr() const
{
return m_precision;
}
std::vector<uint32_t>
pappso::AaStringCodeMassMatching::getAaCodeFromMass(double mass) const
{
std::vector<uint32_t> aa_code_list;
// auto it_aacode = m_codeMassList.begin();
auto it_aacode = std::upper_bound(
m_codeMassList.begin(),
m_codeMassList.end(),
mass,
[](double mass,
const pappso::AaStringCodeMassMatching::aaCodeAndMassRange &mass_range) {
return mass_range.mz_range_up > mass;
});
bool previous_out_of_range = false;
while(it_aacode != m_codeMassList.end())
{
if(mass < it_aacode->mz_range_low)
{
if(previous_out_of_range)
break;
previous_out_of_range = true;
it_aacode++;
}
else
{
if(mass <= it_aacode->mz_range_up)
{
previous_out_of_range = false;
aa_code_list.push_back(it_aacode->code);
it_aacode++;
}
else
{
it_aacode++;
}
}
}
return aa_code_list;
}
std::vector<uint32_t>
pappso::AaStringCodeMassMatching::getAaCodeFromMassWearingModification(
double mass, const pappso::Aa &aa, int quantifier) const
{
std::vector<uint32_t> aa_code_list;
double total_modification_mass = aa.getTotalModificationMass();
total_modification_mass *= quantifier;
mass = mass - total_modification_mass;
if(mass < 0)
return aa_code_list;
uint8_t aamodCode = m_aaCode.getAaCode(aa.getLetter());
auto it_aacode = m_codeMassList.begin();
while(it_aacode != m_codeMassList.end())
{
if(mass < it_aacode->mz_range_low)
{
it_aacode++;
}
else
{
if(mass <= it_aacode->mz_range_up)
{
if(m_aaCodec.uniqueCodeContainsAminoAcid(
it_aacode->code, aamodCode, quantifier))
{
aa_code_list.push_back(it_aacode->code);
}
it_aacode++;
}
else
{
it_aacode++;
}
}
}
return aa_code_list;
}
std::vector<uint32_t>
pappso::AaStringCodeMassMatching::getAaCodeFromMassList(
std::vector<double> &mass_list) const
{
std::sort(mass_list.begin(), mass_list.end(), [](double a, double b) {
return a < b;
});
std::vector<uint32_t> aa_code_list;
auto it_aacode = m_codeMassList.begin();
auto it_mass = mass_list.begin();
while((it_aacode != m_codeMassList.end()) && (it_mass != mass_list.end()))
{
if(*it_mass < it_aacode->mz_range_low)
{
it_mass++;
}
else
{
if(*it_mass <= it_aacode->mz_range_up)
{
aa_code_list.push_back(it_aacode->code);
it_aacode++;
}
else
{
it_aacode++;
}
}
}
return aa_code_list;
}
std::vector<uint32_t>
pappso::AaStringCodeMassMatching::filterCodeList(
std::vector<uint32_t> &code_list) const
{
std::sort(code_list.begin(), code_list.end(), [](uint32_t a, uint32_t b) {
return a < b;
});
std::vector<uint32_t> filtered_aa_code_list;
std::vector<uint8_t> aa_ok;
auto it = code_list.begin();
while(*it < m_base)
{
aa_ok.push_back((uint8_t)*it);
// qDebug() << (uint8_t)*it << " "
// << m_aaCode.getAa((uint8_t)*it).getLetter();
it++;
}
for(uint32_t code : code_list)
{
if(m_aaCodec.codeOnlyContains(code, aa_ok))
{
filtered_aa_code_list.push_back(code);
}
}
return filtered_aa_code_list;
}
aastringcodec.h
code and decodefrom amino acid string to integer
aastringcodemassmatching.h
convert mass list to amino acid string code list
pappso::AaBase::getLetter
virtual const char & getLetter() const
Definition aabase.cpp:436
pappso::AaCode
collection of integer code for each amino acid 0 => null 1 to 20 => amino acid sorted by there mass (...
Definition aacode.h:43
pappso::AaCode::getSize
std::size_t getSize() const
Definition aacode.cpp:74
pappso::AaStringCodeMassMatching
convert a list of mass to amino acid string codes
Definition aastringcodemassmatching.h:41
pappso::AaStringCodeMassMatching::m_codeMassList
std::vector< aaCodeAndMassRange > m_codeMassList
Definition aastringcodemassmatching.h:113
pappso::AaStringCodeMassMatching::filterCodeList
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...
Definition aastringcodemassmatching.cpp:210
pappso::AaStringCodeMassMatching::~AaStringCodeMassMatching
~AaStringCodeMassMatching()
Definition aastringcodemassmatching.cpp:74
pappso::AaStringCodeMassMatching::m_base
uint32_t m_base
Definition aastringcodemassmatching.h:103
pappso::AaStringCodeMassMatching::getAaCodeFromMass
std::vector< uint32_t > getAaCodeFromMass(double mass) const
get amino acid string code from a single mass delta
Definition aastringcodemassmatching.cpp:87
pappso::AaStringCodeMassMatching::getPrecisionPtr
PrecisionPtr getPrecisionPtr() const
Definition aastringcodemassmatching.cpp:80
pappso::AaStringCodeMassMatching::AaStringCodeMassMatching
AaStringCodeMassMatching(const AaCode &aa_code, std::size_t model_max_size, PrecisionPtr precision)
Definition aastringcodemassmatching.cpp:35
pappso::AaStringCodeMassMatching::getAaCodeFromMassWearingModification
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
Definition aastringcodemassmatching.cpp:132
pappso::AaStringCodeMassMatching::m_aaCodec
AaStringCodec m_aaCodec
Definition aastringcodemassmatching.h:100
pappso::AaStringCodeMassMatching::getAaCodeFromMassList
std::vector< uint32_t > getAaCodeFromMassList(std::vector< double > &mass_list) const
Definition aastringcodemassmatching.cpp:176
pappso::AaStringCodeMassMatching::m_aaCode
const AaCode & m_aaCode
Definition aastringcodemassmatching.h:98
pappso::AaStringCodec::generateLlcCodeListUpToMaxPeptideSize
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...
Definition aastringcodec.cpp:163
pappso::Aa
Definition aa.h:45
pappso::Aa::getTotalModificationMass
double getTotalModificationMass() const
get the sum of mass modifications
Definition aa.cpp:79
pappso::PrecisionBase
Definition precision.h:44
pappso::PrecisionBase::delta
virtual pappso_double delta(pappso_double value) const =0
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappso::PeptideIonNter::a
@ a
pappso::PeptideIonNter::b
@ b
pappso::AaStringCodeMassMatching::aaCodeAndMassRange
Definition aastringcodemassmatching.h:106
pappso::AaStringCodeMassMatching::aaCodeAndMassRange::mz_range_low
double mz_range_low
Definition aastringcodemassmatching.h:108
pappso::AaStringCodeMassMatching::aaCodeAndMassRange::mz
double mz
Definition aastringcodemassmatching.h:109
pappso::AaStringCodeMassMatching::aaCodeAndMassRange::code
std::uint32_t code
Definition aastringcodemassmatching.h:107
pappso::AaStringCodeMassMatching::aaCodeAndMassRange::mz_range_up
double mz_range_up
Definition aastringcodemassmatching.h:110