libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
locationsaver.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/specpeptidoms/locationsaver.cpp
3 * \date 24/03/2025
4 * \author Aurélien Berthier
5 * \brief save protein subsequences for 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 <algorithm>
33#include "locationsaver.h"
34#include "types.h"
35
37{
39 for(std::size_t i = 0; i < MAX_SAVED_ALIGNMENTS; i++)
40 {
41 m_locations_heap.push_back({0, 0, -1, MIN_ALIGNMENT_SCORE, ""});
42 }
43 // std::make_heap(m_locations_heap.begin(), m_locations_heap.end(),
44 // LocationSaver::locationCompare); ?
45 // m_tree_scores.reserve ?
46}
47
48bool
50{
51 return loc1.score > loc2.score;
52}
53
54// TODO : check complexity if m_tree_in_heap[tree] == true
55void
57 std::size_t beginning, std::size_t length, int tree, int score, const QString &protein)
58{
59 m_tree_scores.at(tree) = score;
60 if(m_tree_in_heap.at(tree))
61 {
62 for(std::vector<Location>::iterator iter = m_locations_heap.begin();
63 iter != m_locations_heap.end();
64 iter++)
65 {
66 if(iter->tree == tree)
67 {
68 iter->score = score;
69 iter->length = length;
70 }
71 }
72 std::make_heap(
74 }
75 else
76 {
77 if(m_locations_heap.begin()->tree >= 0)
78 {
79 m_tree_in_heap.at(m_locations_heap.begin()->tree) = false;
80 }
81 m_tree_in_heap.at(tree) = true;
82 std::pop_heap(
84 m_locations_heap.pop_back();
85 m_locations_heap.push_back({beginning, length, tree, score, protein});
86 std::push_heap(
88 }
89}
90
91std::vector<pappso::specpeptidoms::Location>
93{
94 std::vector<Location> locations;
95 locations.reserve(m_locations_heap.size());
96 for(std::vector<Location>::const_iterator iter = m_locations_heap.begin();
97 iter != m_locations_heap.end();
98 iter++)
99 {
100 if(iter->tree >= 0)
101 {
102 locations.push_back(*iter);
103 }
104 }
105 return locations;
106}
107
108std::size_t
110{
112 m_tree_in_heap.push_back(false);
113 return m_tree_scores.size() - 1;
114}
115
116int
118{
119 if(m_tree_scores.size() == 0)
120 {
121 return m_locations_heap.begin()->score;
122 }
123 else
124 {
125 return std::max(m_tree_scores.at(tree_id), m_locations_heap.begin()->score);
126 }
127}
128
132
133void
135{
136 for(auto iter = m_locations_heap.begin(); iter != m_locations_heap.end(); iter++)
137 {
138 *(iter) = {0, 0, -1, MIN_ALIGNMENT_SCORE, ""};
139 }
140 m_tree_scores.clear();
141 m_tree_in_heap.clear();
142}
int getMinScore(int tree_id) const
Returns the minimum score for a location with the provided tree_id to be saved in the heap.
static bool locationCompare(const Location &loc1, const Location &loc2)
void addLocation(std::size_t beginning, std::size_t length, int tree, int score, const QString &protein)
Adds a location to the locations heap. If a saved location has the same tree_id, it will replace it....
std::vector< Location > getLocations() const
Returns a vector containing the saved locations.
std::vector< Location > m_locations_heap
std::size_t getNextTree()
Creates a new alignment tree and returns its id.
const uint MAX_SAVED_ALIGNMENTS(5)
const int MIN_ALIGNMENT_SCORE(15)