libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
bucketclustering.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/spectree/bucketclustering.cpp
3 * \date 13/12/2023
4 * \author Olivier Langella
5 * \brief rearrange itemcarts into buckets
6 *
7 * C++ implementation of algorithm already described in :
8 * 1. David, M., Fertin, G., Rogniaux, H. & Tessier, D. SpecOMS: A Full Open
9 * Modification Search Method Performing All-to-All Spectra Comparisons within
10 * Minutes. J. Proteome Res. 16, 3030–3038 (2017).
11 *
12 * https://www.theses.fr/2019NANT4092
13 */
14
15
16/*
17 * SpecTree
18 * Copyright (C) 2023 Olivier Langella
19 * <olivier.langella@universite-paris-saclay.fr>
20 *
21 * This program is free software: you can redistribute ipetide to spectrum
22 * alignmentt and/or modify it under the terms of the GNU General Public License
23 * as published by the Free Software Foundation, either version 3 of the
24 * License, or (at your option) any later version.
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * You should have received a copy of th^e GNU General Public License
32 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 *
34 */
35
36#include "bucketclustering.h"
37#include <algorithm>
38#include "../../pappsoexception.h"
39#include <QObject>
40//#include <experimental/map>
41
42
43namespace pappso
44{
45namespace spectree
46{
47
48// for std::map
49template <class K, class T, class C, class A, class Predicate>
50void
51erase_if(std::map<K, T, C, A> &c, Predicate pred)
52{
53 for(auto i = c.begin(), last = c.end(); i != last;)
54 if(pred(*i))
55 i = c.erase(i);
56 else
57 ++i;
58}
59
63
64std::size_t
66{
67 return m_bucketMap.size();
68}
69
70
71std::size_t
76
77
78void
80{
81 // qDebug() << " " << m_bucketMap.size();
83 for(std::size_t mass : spectrum_int.getItemList())
84 {
85 std::pair<std::map<std::size_t, Bucket>::iterator, bool> ret;
86 ret =
87 m_bucketMap.insert(std::pair<std::size_t, Bucket>(mass, Bucket(mass)));
88 if(ret.second == false)
89 {
90 }
91 else
92 {
93 }
94
95 ret.first->second.push_back(spectrum_int.getId());
96 }
97
98 // Param.defineHighestMassValue(max_mass);
99 // return clusters;
100}
101std::vector<Bucket>
103{
104 qDebug() << " " << m_bucketMap.size();
105 if(m_bucketMap.size() == 0)
106 {
107 throw pappso::PappsoException(QObject::tr("bucket map is empty"));
108 }
109 std::vector<Bucket> bucketList;
110 bucketList.reserve(m_bucketMap.size());
111
112
113 for(auto &&map_pair : m_bucketMap)
114 {
115 if(map_pair.second.size() > 1)
116 bucketList.push_back(map_pair.second);
117 }
118 // m_bucketMap.clear();
119
120 std::sort(bucketList.begin(), bucketList.end());
121
122 qDebug() << " " << m_bucketMap.size();
123 return bucketList;
124}
125
126void
128 std::size_t spectrum_idx_end)
129{
130
131 qDebug() << "spectrum_idx_begin=" << spectrum_idx_begin
132 << " spectrum_idx_end=" << spectrum_idx_end;
134 [spectrum_idx_begin, spectrum_idx_end](const auto &item) {
135 return ((item.second.front() >= spectrum_idx_begin) &&
136 (item.second.back() <= spectrum_idx_end));
137 });
138}
139
140} // namespace spectree
141} // namespace pappso
rearrange itemcarts into buckets
std::vector< Bucket > asSortedList() const
void addItemCart(const ItemCart &spectrum_int)
std::map< std::size_t, Bucket > m_bucketMap
void removeBucketsWithinCartIdRange(std::size_t spectrum_idx_begin, std::size_t spectrum_idx_end)
removes buckets only showing intra relations in the spectrum index range
const std::vector< std::size_t > & getItemList() const
Definition itemcart.cpp:77
std::size_t getId() const
Definition itemcart.cpp:63
void erase_if(std::map< K, T, C, A > &c, Predicate pred)
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39