libpappsomspp
Library for mass spectrometry
msrunxicextractorinterface.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/xicextractor/msrunxicextractor.cpp
3 * \date 07/05/2018
4 * \author Olivier Langella
5 * \brief base interface to build XICs on an MsRun file
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2018 Olivier Langella <Olivier.Langella@u-psud.fr>.
10 *
11 * This file is part of the PAPPSOms++ library.
12 *
13 * PAPPSOms++ is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * PAPPSOms++ is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
25 *
26 * Contributors:
27 * Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and
28 *implementation
29 ******************************************************************************/
30
32#include <QThreadPool>
33#include <QtConcurrent>
34#include "../processing/uimonitor/uimonitorvoid.h"
35
36namespace pappso
37{
38
39
41 MsRunReaderSPtr &msrun_reader)
42 : msp_msrun_reader(msrun_reader)
43{
44}
45
46
48 const MsRunXicExtractorInterface &other)
49 : msp_msrun_reader(other.msp_msrun_reader)
50{
52}
53
55{
56}
57
58void
60{
61 m_xicExtractMethod = method;
62}
63
64void
66 double range_in_seconds)
67{
68 m_retentionTimeAroundTarget = range_in_seconds;
69}
70
71const MsRunIdCstSPtr &
73{
74 return msp_msrun_reader.get()->getMsRunId();
75}
76
77const MsRunReaderSPtr &
79{
80 return msp_msrun_reader;
81}
82
83void
86{
88}
89
90
91void
93 UiMonitorInterface &monitor, std::vector<XicCoordSPtr> &xic_coord_list)
94{
95 qDebug();
96 // get the number of available threads :
97 int number_of_threads = QThreadPool::globalInstance()->maxThreadCount();
98
99 if(number_of_threads == 1)
100 {
101 extractXicCoordSPtrList(monitor, xic_coord_list);
102 }
103 else
104 {
105 monitor.setStatus(QObject::tr("parallelized extraction of %1 XICs")
106 .arg(xic_coord_list.size()));
107
108 std::size_t chunck_size = xic_coord_list.size() / number_of_threads;
109 chunck_size += 1;
110 if(chunck_size < 1000)
111 chunck_size = 1000;
112
113 struct parallelExtractChunck
114 {
115 std::vector<XicCoordSPtr>::iterator it_xic_coord_begin;
116 std::vector<XicCoordSPtr>::iterator it_xic_coord_end;
117 };
118
119 std::vector<parallelExtractChunck> chunck_list;
120 qDebug();
121 for(auto it = xic_coord_list.begin(); it != xic_coord_list.end();)
122 {
123 qDebug() << "chunck_size=" << chunck_size;
124 parallelExtractChunck chunck;
125 chunck.it_xic_coord_begin = it;
126 for(std::size_t i = 0; i < chunck_size && it != xic_coord_list.end();
127 i++)
128 {
129 it++;
130 }
131 chunck.it_xic_coord_end = it;
132 chunck_list.push_back(chunck);
133 }
134 qDebug();
135 auto self = this;
136
137 qDebug();
138 std::function<std::size_t(const parallelExtractChunck &)> extractChunck =
139 [self](const parallelExtractChunck &extract_chunck) {
140 qDebug();
141 UiMonitorVoid monitor;
142 self->protectedExtractXicCoordSPtrList(
143 monitor,
144 extract_chunck.it_xic_coord_begin,
145 extract_chunck.it_xic_coord_end);
146 self->postExtractionProcess(monitor,
147 extract_chunck.it_xic_coord_begin,
148 extract_chunck.it_xic_coord_end);
149 qDebug();
150 return 1;
151 };
152 qDebug();
153 monitor.setTotalSteps(chunck_list.size());
154 UiMonitorInterface *monitorRef = &monitor;
155 std::function<void(std::size_t & result, const std::size_t &value)>
156 monitorExtract2 =
157 [monitorRef](std::size_t &result [[maybe_unused]],
158 const std::size_t &value
159 [[maybe_unused]]) { monitorRef->count(); };
160 qDebug();
161
162 QFuture<std::size_t> res =
163 QtConcurrent::mappedReduced<std::size_t>(chunck_list.begin(),
164 chunck_list.end(),
165 extractChunck,
166 monitorExtract2,
167 QtConcurrent::UnorderedReduce);
168 qDebug();
169
170 /*
171 QFuture<std::size_t> res =
172 QtConcurrent::mapped(chunck_list.begin(), chunck_list.end(),
173 extractChunck);
174 */
175 res.waitForFinished();
176 monitor.setTotalSteps(0);
177 }
178}
179
180void
182 UiMonitorInterface &monitor, std::vector<XicCoordSPtr> &xic_coord_list)
183{
184
185 monitor.setStatus(
186 QObject::tr("extracting %1 XICs").arg(xic_coord_list.size()));
187 monitor.setTotalSteps(xic_coord_list.size());
189 monitor, xic_coord_list.begin(), xic_coord_list.end());
190 monitor.setTotalSteps(0);
191 postExtractionProcess(monitor, xic_coord_list.begin(), xic_coord_list.end());
192}
193
194void
196 UiMonitorInterface &monitor,
197 std::vector<XicCoordSPtr>::iterator it_xic_coord_list_begin,
198 std::vector<XicCoordSPtr>::iterator it_xic_coord_list_end)
199{
200
201 if(mcsp_postExtractionTraceFilter != nullptr)
202 {
203 monitor.setStatus(
204 QObject::tr("filtering %1 XICs")
205 .arg(std::distance(it_xic_coord_list_begin, it_xic_coord_list_end)));
206 for(auto it = it_xic_coord_list_begin; it != it_xic_coord_list_end; it++)
207 {
208 mcsp_postExtractionTraceFilter.get()->filter(
209 *(it->get()->xicSptr.get()));
210 }
211 }
212}
213
214
215} // namespace pappso
virtual void extractXicCoordSPtrListParallelized(UiMonitorInterface &monitor, std::vector< XicCoordSPtr > &xic_coord_list) final
multithreaded XIC extraction
virtual void postExtractionProcess(UiMonitorInterface &monitor, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_begin, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_end)
possible post extraction process, eventually trace filters
void setPostExtractionTraceFilterCstSPtr(pappso::FilterInterfaceCstSPtr &filter)
filter interface to apply just after XIC extration on each trace
virtual void protectedExtractXicCoordSPtrList(UiMonitorInterface &monitor, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_begin, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_end)=0
virtual void extractXicCoordSPtrList(UiMonitorInterface &monitor, std::vector< XicCoordSPtr > &xic_coord_list) final
extract a list of XIC given a list of xic coordinates to extract
void setXicExtractMethod(XicExtractMethod method)
set the XIC extraction method
const MsRunReaderSPtr & getMsRunReaderSPtr() const
get the msrunreader currently used for XIC extraction
const MsRunIdCstSPtr & getMsRunId() const
void setRetentionTimeAroundTarget(double range_in_seconds)
set the retention time range in seconds around the target rt
pappso::FilterInterfaceCstSPtr mcsp_postExtractionTraceFilter
MsRunXicExtractorInterface(MsRunReaderSPtr &msrun_reader)
constructor is private, use the MsRunXicExtractorFactory
virtual void setStatus(const QString &status)=0
current status of the process
virtual void setTotalSteps(std::size_t total_number_of_steps)
use it if the number of steps is known in an algorithm the total number of steps is usefull to report...
virtual void count()=0
count steps report when a step is computed in an algorithm
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
std::shared_ptr< MsRunReader > MsRunReaderSPtr
Definition: msrunreader.h:56
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition: msrunid.h:46
std::shared_ptr< const FilterInterface > FilterInterfaceCstSPtr
XicExtractMethod
Definition: types.h:240