libpappsomspp
Library for mass spectrometry
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>
32
33namespace pappso
34{
35
36
37std::map<QThread *, TimsDataFastMap>
39
42{
43
45 {QThread::currentThread(), TimsDataFastMap()});
46
47 if(it.second)
48 {
49 it.first->second.mapTofIndexIntensity.resize(500000);
50 }
51 return it.first->second;
52}
53
55{
56 // map.resize(500000);
57}
58
59std::size_t
60TimsDataFastMap::accumulateIntensity(quint32 key, std::size_t intensity)
61{
62 qDebug();
63 try
64 {
65 TimsDataFastMapElement &map_element = mapTofIndexIntensity.at(key);
66
67 if(map_element.first_access)
68 {
69 map_element.first_access = false;
70 map_element.count = intensity;
71 tofIndexList.push_back(key);
72 }
73 else
74 {
75 map_element.count += intensity;
76 }
77 qDebug();
78 return map_element.count;
79 }
80 catch(std::out_of_range &error)
81 {
83 QObject::tr("out of range exception for tof index %1 ").arg(key));
84 }
85}
86
87std::size_t
89{
90 TimsDataFastMapElement &map_element = mapTofIndexIntensity.at(key);
91 // FIXME: why set first_access to true below?
92 map_element.first_access = true;
93 return map_element.count;
94}
95
96void
97TimsDataFastMap::downsizeMzRawMap(std::size_t mzindex_merge_window)
98{
99 std::vector<std::pair<quint32, std::size_t>> temp_vector;
100 for(quint32 tof_index : tofIndexList)
101 {
102 temp_vector.push_back({tof_index, readIntensity(tof_index)});
103 }
104
105 tofIndexList.clear();
106
107 for(auto &pair_tof_intensity : temp_vector)
108 {
109
110 quint32 mzkey = (pair_tof_intensity.first / mzindex_merge_window);
111 mzkey = (mzkey * mzindex_merge_window) + (mzindex_merge_window / 2);
112
113 accumulateIntensity(mzkey, pair_tof_intensity.second);
114 }
115}
116
117void
119{
120 qDebug() << "tofIndexList.size()=" << tofIndexList.size();
121 if(tofIndexList.size() > 2)
122 {
123 std::vector<quint32> tof_index_list_tmp = tofIndexList;
124 std::sort(tof_index_list_tmp.begin(), tof_index_list_tmp.end());
125
126 tofIndexList.clear();
127
128 quint32 previous_tof_index = tof_index_list_tmp[0];
129 std::size_t previous_intensity = readIntensity(previous_tof_index);
130 for(std::size_t i = 1; i < tof_index_list_tmp.size(); i++)
131 {
132 quint32 tof_index = tof_index_list_tmp[i];
133 if(previous_tof_index == tof_index - 1)
134 {
135 std::size_t intensity = readIntensity(tof_index);
136 if(previous_intensity > intensity)
137 {
138 // flush writing current accumulated intensity
139 accumulateIntensity(previous_tof_index,
140 previous_intensity + intensity);
141 previous_intensity = 0;
142 previous_tof_index = tof_index;
143 }
144 else
145 {
146 // accumulate while intensity increases
147 previous_intensity += intensity;
148 previous_tof_index = tof_index;
149 }
150 }
151 else
152 {
153 // write accumulated intensity :
154 if(previous_intensity > 0)
155 {
156 // flush
157 accumulateIntensity(previous_tof_index, previous_intensity);
158 }
159 previous_tof_index = tof_index;
160 previous_intensity = readIntensity(tof_index);
161 }
162 }
163
164 // write remaining intensity :
165 if(previous_intensity > 0)
166 {
167 // flush
168 accumulateIntensity(previous_tof_index, previous_intensity);
169 }
170 }
171
172 qDebug() << "tofIndexList.size()=" << tofIndexList.size();
173}
174
175void
177{
178
179 std::vector<quint32> tof_index_list_tmp = tofIndexList;
180 tofIndexList.clear();
181 for(quint32 tof_index : tof_index_list_tmp)
182 {
183 if((tof_index > 0) && mapTofIndexIntensity[tof_index - 1].first_access &&
184 mapTofIndexIntensity[tof_index + 1].first_access &&
185 (mapTofIndexIntensity[tof_index].count == 10))
186 {
187 // this measure is too small and alone : remove it
188 mapTofIndexIntensity[tof_index].first_access = true;
189 }
190 else
191 {
192 tofIndexList.push_back(tof_index);
193 }
194 }
195}
196
197const std::vector<quint32> &
199{
200 return tofIndexList;
201}
202
203void
205{
206 tofIndexList.clear();
207}
208
209
210} // namespace pappso
replacement for std::map
std::size_t accumulateIntensity(quint32 tofIndex, std::size_t intensity)
accumulates intesity for the given tof index
const std::vector< quint32 > & getTofIndexList() const
void builtInCentroid()
simple filter to agregate counts on neigbhor mobility slots (+1)
std::size_t readIntensity(quint32)
reads intensity for a tof_index
std::vector< quint32 > tofIndexList
void downsizeMzRawMap(std::size_t mzindex_merge_window)
downsize mz resolution to lower the number of real mz computations
static TimsDataFastMap & getTimsDataFastMapInstance()
static std::map< QThread *, TimsDataFastMap > m_preAllocatedFastMapPerThread
std::vector< TimsDataFastMapElement > mapTofIndexIntensity
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
replacement fot std::map dedicated to tims data for fast computations