libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
Loading...
Searching...
No Matches
timsdatafastmap.cpp
Go to the documentation of this file.
1
/**
2
* \file pappsomspp/vendors/tims/timsdatafastmap.h
3
* \date 16/12/2023
4
* \author Olivier Langella
5
* \brief replacement fot std::map dedicated to tims data for fast computations
6
*/
7
8
/*******************************************************************************
9
* Copyright (c) 2023 Olivier Langella
10
*<Olivier.Langella@universite-paris-saclay.fr>.
11
*
12
* This file is part of the PAPPSOms++ library.
13
*
14
* PAPPSOms++ is free software: you can redistribute it and/or modify
15
* it under the terms of the GNU General Public License as published by
16
* the Free Software Foundation, either version 3 of the License, or
17
* (at your option) any later version.
18
*
19
* PAPPSOms++ is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
* GNU General Public License for more details.
23
*
24
* You should have received a copy of the GNU General Public License
25
* along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
26
*
27
******************************************************************************/
28
29
#include "
timsdatafastmap.h
"
30
#include <QDebug>
31
#include "
pappsomspp/core/exception/exceptionoutofrange.h
"
32
33
namespace
pappso
34
{
35
36
37
std::map<QThread *, TimsDataFastMap>
TimsDataFastMap::m_preAllocatedFastMapPerThread
= {};
38
39
pappso::TimsDataFastMap &
40
TimsDataFastMap::getTimsDataFastMapInstance
()
41
{
42
43
auto
it =
TimsDataFastMap::m_preAllocatedFastMapPerThread
.insert(
44
{QThread::currentThread(),
TimsDataFastMap
()});
45
46
if
(it.second)
47
{
48
it.first->second.mapTofIndexIntensity.resize(500000);
49
}
50
return
it.first->second;
51
}
52
53
TimsDataFastMap::TimsDataFastMap
()
54
{
55
// map.resize(500000);
56
}
57
58
std::size_t
59
TimsDataFastMap::accumulateIntensity
(quint32 key, std::size_t intensity)
60
{
61
qDebug();
62
try
63
{
64
TimsDataFastMapElement
&map_element =
mapTofIndexIntensity
.at(key);
65
66
if
(map_element.
first_access
)
67
{
68
map_element.
first_access
=
false
;
69
map_element.
count
= intensity;
70
tofIndexList
.push_back(key);
71
}
72
else
73
{
74
map_element.
count
+= intensity;
75
}
76
qDebug();
77
return
map_element.
count
;
78
}
79
catch
(std::out_of_range &error)
80
{
81
throw
pappso::ExceptionOutOfRange
(
82
QObject::tr(
"out of range exception for tof index %1 "
).arg(key));
83
}
84
}
85
86
std::size_t
87
TimsDataFastMap::readIntensity
(quint32 key)
88
{
89
TimsDataFastMapElement
&map_element =
mapTofIndexIntensity
.at(key);
90
// FIXME: why set first_access to true below?
91
map_element.
first_access
=
true
;
92
return
map_element.
count
;
93
}
94
95
void
96
TimsDataFastMap::downsizeMzRawMap
(std::size_t mzindex_merge_window)
97
{
98
std::vector<std::pair<quint32, std::size_t>> temp_vector;
99
for
(quint32 tof_index :
tofIndexList
)
100
{
101
temp_vector.push_back({tof_index,
readIntensity
(tof_index)});
102
}
103
104
tofIndexList
.clear();
105
106
for
(
auto
&pair_tof_intensity : temp_vector)
107
{
108
109
quint32 mzkey = (pair_tof_intensity.first / mzindex_merge_window);
110
mzkey = (mzkey * mzindex_merge_window) + (mzindex_merge_window / 2);
111
112
accumulateIntensity
(mzkey, pair_tof_intensity.second);
113
}
114
}
115
116
void
117
TimsDataFastMap::builtInCentroid
()
118
{
119
qDebug() <<
"tofIndexList.size()="
<<
tofIndexList
.size();
120
if
(
tofIndexList
.size() > 2)
121
{
122
std::vector<quint32> tof_index_list_tmp =
tofIndexList
;
123
std::sort(tof_index_list_tmp.begin(), tof_index_list_tmp.end());
124
125
tofIndexList
.clear();
126
127
quint32 previous_tof_index = tof_index_list_tmp[0];
128
std::size_t previous_intensity =
readIntensity
(previous_tof_index);
129
for
(std::size_t i = 1; i < tof_index_list_tmp.size(); i++)
130
{
131
quint32 tof_index = tof_index_list_tmp[i];
132
if
(previous_tof_index == tof_index - 1)
133
{
134
std::size_t intensity =
readIntensity
(tof_index);
135
if
(previous_intensity > intensity)
136
{
137
// flush writing current accumulated intensity
138
accumulateIntensity
(previous_tof_index, previous_intensity + intensity);
139
previous_intensity = 0;
140
previous_tof_index = tof_index;
141
}
142
else
143
{
144
// accumulate while intensity increases
145
previous_intensity += intensity;
146
previous_tof_index = tof_index;
147
}
148
}
149
else
150
{
151
// write accumulated intensity :
152
if
(previous_intensity > 0)
153
{
154
// flush
155
accumulateIntensity
(previous_tof_index, previous_intensity);
156
}
157
previous_tof_index = tof_index;
158
previous_intensity =
readIntensity
(tof_index);
159
}
160
}
161
162
// write remaining intensity :
163
if
(previous_intensity > 0)
164
{
165
// flush
166
accumulateIntensity
(previous_tof_index, previous_intensity);
167
}
168
}
169
170
qDebug() <<
"tofIndexList.size()="
<<
tofIndexList
.size();
171
}
172
173
void
174
TimsDataFastMap::removeArtefactualSpike
()
175
{
176
177
std::vector<quint32> tof_index_list_tmp =
tofIndexList
;
178
tofIndexList
.clear();
179
for
(quint32 tof_index : tof_index_list_tmp)
180
{
181
if
((tof_index > 0) &&
mapTofIndexIntensity
[tof_index - 1].first_access &&
182
mapTofIndexIntensity
[tof_index + 1].first_access &&
183
(
mapTofIndexIntensity
[tof_index].count == 10))
184
{
185
// this measure is too small and alone : remove it
186
mapTofIndexIntensity
[tof_index].first_access =
true
;
187
}
188
else
189
{
190
tofIndexList
.push_back(tof_index);
191
}
192
}
193
}
194
195
const
std::vector<quint32> &
196
TimsDataFastMap::getTofIndexList
()
const
197
{
198
return
tofIndexList
;
199
}
200
201
void
202
TimsDataFastMap::clear
()
203
{
204
tofIndexList
.clear();
205
}
206
207
208
}
// namespace pappso
pappso::ExceptionOutOfRange
Definition
exceptionoutofrange.h:32
pappso::TimsDataFastMap::accumulateIntensity
std::size_t accumulateIntensity(quint32 tofIndex, std::size_t intensity)
accumulates intesity for the given tof index
Definition
timsdatafastmap.cpp:59
pappso::TimsDataFastMap::removeArtefactualSpike
void removeArtefactualSpike()
Definition
timsdatafastmap.cpp:174
pappso::TimsDataFastMap::getTofIndexList
const std::vector< quint32 > & getTofIndexList() const
Definition
timsdatafastmap.cpp:196
pappso::TimsDataFastMap::builtInCentroid
void builtInCentroid()
simple filter to agregate counts on neigbhor mobility slots (+1)
Definition
timsdatafastmap.cpp:117
pappso::TimsDataFastMap::TimsDataFastMap
TimsDataFastMap()
Definition
timsdatafastmap.cpp:53
pappso::TimsDataFastMap::readIntensity
std::size_t readIntensity(quint32)
reads intensity for a tof_index
Definition
timsdatafastmap.cpp:87
pappso::TimsDataFastMap::tofIndexList
std::vector< quint32 > tofIndexList
Definition
timsdatafastmap.h:104
pappso::TimsDataFastMap::downsizeMzRawMap
void downsizeMzRawMap(std::size_t mzindex_merge_window)
downsize mz resolution to lower the number of real mz computations
Definition
timsdatafastmap.cpp:96
pappso::TimsDataFastMap::getTimsDataFastMapInstance
static TimsDataFastMap & getTimsDataFastMapInstance()
Definition
timsdatafastmap.cpp:40
pappso::TimsDataFastMap::m_preAllocatedFastMapPerThread
static std::map< QThread *, TimsDataFastMap > m_preAllocatedFastMapPerThread
Definition
timsdatafastmap.h:48
pappso::TimsDataFastMap::mapTofIndexIntensity
std::vector< TimsDataFastMapElement > mapTofIndexIntensity
Definition
timsdatafastmap.h:106
pappso::TimsDataFastMap::clear
void clear()
Definition
timsdatafastmap.cpp:202
exceptionoutofrange.h
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition
aa.cpp:39
pappso::TimsDataFastMap::TimsDataFastMapElement
Definition
timsdatafastmap.h:55
pappso::TimsDataFastMap::TimsDataFastMapElement::count
std::size_t count
Definition
timsdatafastmap.h:57
pappso::TimsDataFastMap::TimsDataFastMapElement::first_access
bool first_access
Definition
timsdatafastmap.h:56
timsdatafastmap.h
pappsomspp
core
vendors
tims
timsdatafastmap.cpp
Generated on
for libpappsomspp by
1.17.0