Loading...
Searching...
No Matches
proteinintegercode.cpp
Go to the documentation of this file.
/**
* \file protein/proteinintegercode.cpp
* \date 22/05/2023
* \author Olivier Langella
* \brief transform protein amino acid sequence into vectors of amino acid codes
*/
/*******************************************************************************
* Copyright (c) 2023 Olivier Langella
*<Olivier.Langella@universite-paris-saclay.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 "proteinintegercode.h"
#include "../exception/exceptionoutofrange.h"
using namespace pappso;
ProteinIntegerCode::ProteinIntegerCode(ProteinSp protein,
const AaStringCodec &codec,
std::size_t aa_str_max_size)
{
msp_protein = protein;
if(aa_str_max_size > 7)
{
throw ExceptionOutOfRange(
QObject::tr("aa_str_max_size exceeds max size"));
}
QString seq_str = protein.get()->getSequence();
m_seqAaCode.clear();
for(const QChar &aa_str : seq_str)
{
m_seqAaCode.push_back(codec.getAaCode().getAaCode(aa_str.toLatin1()));
}
for(std::size_t i = 2; i <= aa_str_max_size; i++)
{
m_peptideCodedFragments.push_back(computePeptideCodeFragments(codec, i));
}
}
ProteinIntegerCode::ProteinIntegerCode(const ProteinIntegerCode &other)
{
msp_protein = other.msp_protein;
m_seqAaCode = other.m_seqAaCode;
m_peptideCodedFragments = other.m_peptideCodedFragments;
}
ProteinIntegerCode::~ProteinIntegerCode()
{
}
std::vector<std::uint32_t>
pappso::ProteinIntegerCode::computePeptideCodeFragments(
const AaStringCodec &codec, std::size_t fragment_size) const
{
std::vector<std::uint32_t> fragments;
int max = (m_seqAaCode.size() - fragment_size);
if(max < 0)
return fragments;
auto it = m_seqAaCode.begin();
for(int i = 0; i <= max; i++)
{
fragments.push_back(codec.codeLlc(it, fragment_size));
it++;
}
return fragments;
}
const std::vector<std::uint32_t> &
pappso::ProteinIntegerCode::getPeptideCodedFragment(std::size_t size) const
{
if(size < 2)
{
throw ExceptionOutOfRange(QObject::tr("size too small"));
}
std::size_t indice = size - 2;
if(indice < m_peptideCodedFragments.size())
{
return m_peptideCodedFragments.at(indice);
}
throw ExceptionOutOfRange(QObject::tr("size too big"));
}
std::vector<std::pair<std::size_t, std::uint32_t>>
pappso::ProteinIntegerCode::match(
const std::vector<uint32_t> &code_list_in) const
{
std::vector<std::pair<std::size_t, std::uint32_t>> return_pos;
std::vector<uint32_t> code_list = code_list_in;
std::sort(code_list.begin(), code_list.end());
auto it_end = std::unique(code_list.begin(), code_list.end());
for(auto it_code = code_list.begin(); it_code != it_end; it_code++)
{
std::size_t size = 2;
for(auto &liste_protein_seq_code : m_peptideCodedFragments)
{
auto it_seq_position = std::find(liste_protein_seq_code.begin(),
liste_protein_seq_code.end(),
*it_code);
while(it_seq_position != liste_protein_seq_code.end())
{
// found
std::size_t position =
std::distance(liste_protein_seq_code.begin(), it_seq_position);
return_pos.push_back({size, position});
it_seq_position = std::find(
++it_seq_position, liste_protein_seq_code.end(), *it_code);
qDebug();
}
size++;
qDebug();
}
qDebug();
}
return return_pos;
}
pappso::AaCode::getAaCode
uint8_t getAaCode(char aa_letter) const
Definition aacode.cpp:81
pappso::AaStringCodec
Definition aastringcodec.h:52
pappso::AaStringCodec::getAaCode
const AaCode & getAaCode() const
Definition aastringcodec.cpp:273
pappso::AaStringCodec::codeLlc
uint32_t codeLlc(const QString &aa_str) const
get the lowest common denominator integer from amino acide suite string
Definition aastringcodec.cpp:73
pappso::ExceptionOutOfRange
Definition exceptionoutofrange.h:32
pappso::ProteinIntegerCode
Definition proteinintegercode.h:43
pappso::ProteinIntegerCode::~ProteinIntegerCode
~ProteinIntegerCode()
Definition proteinintegercode.cpp:69
pappso::ProteinIntegerCode::getPeptideCodedFragment
const std::vector< std::uint32_t > & getPeptideCodedFragment(std::size_t size) const
Definition proteinintegercode.cpp:95
pappso::ProteinIntegerCode::match
std::vector< std::pair< std::size_t, std::uint32_t > > match(const std::vector< uint32_t > &code_list) const
Definition proteinintegercode.cpp:113
pappso::ProteinIntegerCode::m_seqAaCode
std::vector< std::uint8_t > m_seqAaCode
Definition proteinintegercode.h:78
pappso::ProteinIntegerCode::ProteinIntegerCode
ProteinIntegerCode(ProteinSp protein, const AaStringCodec &codec, std::size_t aa_str_max_size=5)
Definition proteinintegercode.cpp:34
pappso::ProteinIntegerCode::m_peptideCodedFragments
std::vector< std::vector< std::uint32_t > > m_peptideCodedFragments
Definition proteinintegercode.h:79
pappso::ProteinIntegerCode::msp_protein
ProteinSp msp_protein
Definition proteinintegercode.h:76
pappso::ProteinIntegerCode::computePeptideCodeFragments
std::vector< std::uint32_t > computePeptideCodeFragments(const AaStringCodec &codec, std::size_t fragment_size) const
Definition proteinintegercode.cpp:74
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappso::ProteinSp
std::shared_ptr< const Protein > ProteinSp
shared pointer on a Protein object
Definition protein.h:47
pappso::XicExtractMethod::max
@ max
maximum of intensities
proteinintegercode.h
transform protein amino acid sequence into vectors of amino acid codes