libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
scenario.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/specpeptidoms/scenario.cpp
3 * \date 24/03/2025
4 * \author Aurélien Berthier
5 * \brief backtracking of 2nd alignment
6 *
7 * C++ implementation of the SpecPeptidOMS algorithm described in :
8 * (1) Benoist, É.; Jean, G.; Rogniaux, H.; Fertin, G.; Tessier, D. SpecPeptidOMS Directly and
9 * Rapidly Aligns Mass Spectra on Whole Proteomes and Identifies Peptides That Are Not Necessarily
10 * Tryptic: Implications for Peptidomics. J. Proteome Res. 2025.
11 * https://doi.org/10.1021/acs.jproteome.4c00870.
12 */
13
14/*
15 * Copyright (c) 2025 Aurélien Berthier
16 * <aurelien.berthier@ls2n.fr>
17 *
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 */
31
32#include "scenario.h"
33#include <QDebug>
35
36// TODO : reserve space for origin matrix
37// Scenario::Scenario()
38// {
39// }
40
41void
43 std::size_t current_column,
44 std::size_t previous_row,
45 std::size_t previous_column,
46 int score,
47 AlignType alignment_type)
48{
49 if(score > m_best_alignment.second)
50 {
51 m_best_alignment = {{current_row, current_column, alignment_type}, score};
52 }
53 try
54 {
55 m_origin_matrix.at(current_row).at(current_column) = {
56 previous_row, previous_column, alignment_type};
57 }
58 catch(const std::exception &error)
59 {
60 int max_column_size = 0;
61 if(current_row < m_origin_matrix.size())
62 {
63 max_column_size = m_origin_matrix.at(current_row).size();
64 }
66 QObject::tr(
67 "Scenario::saveOrigin failed for current_row %1 (size %2) current_column %3 (size %4)")
68 .arg(current_row)
69 .arg(m_origin_matrix.size())
70 .arg(current_column)
71 .arg(max_column_size));
72 }
73}
74
78
82
83void
84pappso::specpeptidoms::Scenario::reserve(std::size_t n_rows, std::size_t n_columns)
85{
86 m_origin_matrix = std::vector<std::vector<ScenarioCell>>(
87 n_rows, std::vector<ScenarioCell>(n_columns, {0, 0, AlignType::init}));
88}
89
90std::pair<std::vector<pappso::specpeptidoms::ScenarioCell>, int>
92{
93 std::pair<std::vector<ScenarioCell>, int> best_alignment;
94 ScenarioCell current_cell = m_best_alignment.first;
95 current_cell.alignment_type = AlignType::init;
96 while(current_cell.previous_column > 0 && current_cell.previous_row > 0)
97 {
98 best_alignment.first.push_back(current_cell);
99 current_cell = m_origin_matrix.at(current_cell.previous_row).at(current_cell.previous_column);
100 }
101 best_alignment.first.push_back(current_cell);
102 best_alignment.second = m_best_alignment.second;
103 return best_alignment;
104}
105
106int
111
112void
114{
115 // m_origin_matrix.clear();
116 m_best_alignment = {{0, 0, AlignType::init}, -15};
117}
118
119void
void saveOrigin(std::size_t current_row, std::size_t current_column, std::size_t previous_row, std::size_t previous_column, int score, AlignType alignment_type)
Stores the origin (cell location and alignment type) of the provided cell in the backtracking matrix.
Definition scenario.cpp:42
std::pair< ScenarioCell, int > m_best_alignment
Definition scenario.h:98
std::vector< std::vector< ScenarioCell > > m_origin_matrix
Definition scenario.h:97
void reserve(std::size_t n_rows, std::size_t n_columns)
Allocate new storage to the backtracking matrix if needed.
Definition scenario.cpp:84
std::pair< std::vector< ScenarioCell >, int > getBestAlignment() const
Returns the scenario cells corresponding to the best alignment and the best alignment's score.
Definition scenario.cpp:91