libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
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 "
pappsomspp/core/pappsoexception.h
"
39
#include <QObject>
40
// #include <experimental/map>
41
42
43
namespace
pappso
44
{
45
namespace
spectree
46
{
47
48
// for std::map
49
template
<
class
K,
class
T,
class
C,
class
A,
class
Predicate>
50
void
51
erase_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
60
BucketClustering::BucketClustering
()
61
{
62
}
63
64
std::size_t
65
BucketClustering::size
()
const
66
{
67
return
m_bucketMap
.size();
68
}
69
70
71
std::size_t
72
BucketClustering::getItemCartCount
()
const
73
{
74
return
m_itemCartCount
;
75
}
76
77
78
void
79
BucketClustering::addItemCart
(
const
ItemCart
&spectrum_int)
80
{
81
// qDebug() << " " << m_bucketMap.size();
82
m_itemCartCount
++;
83
for
(std::size_t mass : spectrum_int.
getItemList
())
84
{
85
std::pair<std::map<std::size_t, Bucket>::iterator,
bool
> ret;
86
ret =
m_bucketMap
.insert(std::pair<std::size_t, Bucket>(mass,
Bucket
(mass)));
87
if
(ret.second ==
false
)
88
{
89
}
90
else
91
{
92
}
93
94
ret.first->second.push_back(spectrum_int.
getId
());
95
}
96
97
// Param.defineHighestMassValue(max_mass);
98
// return clusters;
99
}
100
std::vector<Bucket>
101
BucketClustering::asSortedList
()
const
102
{
103
qDebug() <<
" "
<<
m_bucketMap
.size();
104
if
(
m_bucketMap
.size() == 0)
105
{
106
throw
pappso::PappsoException
(QObject::tr(
"bucket map is empty"
));
107
}
108
std::vector<Bucket> bucketList;
109
bucketList.reserve(
m_bucketMap
.size());
110
111
112
for
(
auto
&&map_pair :
m_bucketMap
)
113
{
114
if
(map_pair.second.size() > 1)
115
bucketList.push_back(map_pair.second);
116
}
117
// m_bucketMap.clear();
118
119
std::sort(bucketList.begin(), bucketList.end());
120
121
qDebug() <<
" "
<<
m_bucketMap
.size();
122
return
bucketList;
123
}
124
125
void
126
BucketClustering::removeBucketsWithinCartIdRange
(std::size_t spectrum_idx_begin,
127
std::size_t spectrum_idx_end)
128
{
129
130
qDebug() <<
"spectrum_idx_begin="
<< spectrum_idx_begin
131
<<
" spectrum_idx_end="
<< spectrum_idx_end;
132
erase_if
(
m_bucketMap
, [spectrum_idx_begin, spectrum_idx_end](
const
auto
&item) {
133
return
((item.second.front() >= spectrum_idx_begin) &&
134
(item.second.back() <= spectrum_idx_end));
135
});
136
}
137
138
}
// namespace spectree
139
}
// namespace pappso
bucketclustering.h
pappso::PappsoException
Definition
pappsoexception.h:41
pappso::spectree::BucketClustering::BucketClustering
BucketClustering()
Definition
bucketclustering.cpp:60
pappso::spectree::BucketClustering::m_itemCartCount
std::size_t m_itemCartCount
Definition
bucketclustering.h:121
pappso::spectree::BucketClustering::addItemCart
void addItemCart(const ItemCart &item_cart)
add ItemCart to Bucket list Each item in the cart is a key to build dedicated buckets for one item Th...
Definition
bucketclustering.cpp:79
pappso::spectree::BucketClustering::asSortedList
std::vector< Bucket > asSortedList() const
Definition
bucketclustering.cpp:101
pappso::spectree::BucketClustering::getItemCartCount
std::size_t getItemCartCount() const
Definition
bucketclustering.cpp:72
pappso::spectree::BucketClustering::size
std::size_t size() const
Definition
bucketclustering.cpp:65
pappso::spectree::BucketClustering::m_bucketMap
std::map< std::size_t, Bucket > m_bucketMap
Definition
bucketclustering.h:119
pappso::spectree::BucketClustering::removeBucketsWithinCartIdRange
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
Definition
bucketclustering.cpp:126
pappso::spectree::Bucket
Definition
bucket.h:56
pappso::spectree::ItemCart
container for spectree items
Definition
itemcart.h:55
pappso::spectree::ItemCart::getItemList
const std::vector< std::size_t > & getItemList() const
Definition
itemcart.cpp:77
pappso::spectree::ItemCart::getId
std::size_t getId() const
Definition
itemcart.cpp:63
pappso::spectree
Definition
bucket.cpp:43
pappso::spectree::erase_if
void erase_if(std::map< K, T, C, A > &c, Predicate pred)
Definition
bucketclustering.cpp:51
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition
aa.cpp:39
pappso::PeptideIonNter::c
@ c
Definition
peptide.h:81
pappso::QualifiedMassSpectrumParameter::last
@ last
Definition
qualifiedmassspectrum.h:72
pappsoexception.h
pappsomspp
core
processing
spectree
bucketclustering.cpp
Generated on
for libpappsomspp by
1.17.0