libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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>
35
36namespace pappso
37{
38
39
44
45
51
55
56void
61
62void
64{
65 m_retentionTimeAroundTarget = range_in_seconds;
66}
67
68const MsRunIdCstSPtr &
70{
71 return msp_msrun_reader.get()->getMsRunId();
72}
73
74const MsRunReaderSPtr &
79
80void
86
87
88void
90 UiMonitorInterface &monitor, std::vector<XicCoordSPtr> &xic_coord_list)
91{
92 qDebug();
93 // get the number of available threads :
94 int number_of_threads = QThreadPool::globalInstance()->maxThreadCount();
95
96 if(number_of_threads == 1)
97 {
98 extractXicCoordSPtrList(monitor, xic_coord_list);
99 }
100 else
101 {
102 monitor.setStatus(
103 QObject::tr("parallelized extraction of %1 XICs").arg(xic_coord_list.size()));
104
105 std::size_t chunck_size = xic_coord_list.size() / number_of_threads;
106 chunck_size += 1;
107 if(chunck_size < 1000)
108 chunck_size = 1000;
109
110 struct parallelExtractChunck
111 {
112 std::vector<XicCoordSPtr>::iterator it_xic_coord_begin;
113 std::vector<XicCoordSPtr>::iterator it_xic_coord_end;
114 };
115
116 std::vector<parallelExtractChunck> chunck_list;
117 qDebug();
118 for(auto it = xic_coord_list.begin(); it != xic_coord_list.end();)
119 {
120 qDebug() << "chunck_size=" << chunck_size;
121 parallelExtractChunck chunck;
122 chunck.it_xic_coord_begin = it;
123 for(std::size_t i = 0; i < chunck_size && it != xic_coord_list.end(); i++)
124 {
125 it++;
126 }
127 chunck.it_xic_coord_end = it;
128 chunck_list.push_back(chunck);
129 }
130 qDebug();
131 auto self = this;
132
133 qDebug();
134 std::function<std::size_t(const parallelExtractChunck &)> extractChunck =
135 [self](const parallelExtractChunck &extract_chunck) {
136 qDebug();
137 UiMonitorVoid monitor;
138 self->protectedExtractXicCoordSPtrList(
139 monitor, extract_chunck.it_xic_coord_begin, extract_chunck.it_xic_coord_end);
140 self->postExtractionProcess(
141 monitor, extract_chunck.it_xic_coord_begin, extract_chunck.it_xic_coord_end);
142 qDebug();
143 return 1;
144 };
145 qDebug();
146 monitor.setTotalSteps(chunck_list.size());
147 UiMonitorInterface *monitorRef = &monitor;
148 std::function<void(std::size_t &result, const std::size_t &value)> monitorExtract2 =
149 [monitorRef](std::size_t &result [[maybe_unused]],
150 const std::size_t &value [[maybe_unused]]) { monitorRef->count(); };
151 qDebug();
152
153 QFuture<std::size_t> res =
154 QtConcurrent::mappedReduced<std::size_t>(chunck_list.begin(),
155 chunck_list.end(),
156 extractChunck,
157 monitorExtract2,
158 QtConcurrent::UnorderedReduce);
159 qDebug();
160
161 /*
162 QFuture<std::size_t> res =
163 QtConcurrent::mapped(chunck_list.begin(), chunck_list.end(),
164 extractChunck);
165 */
166 res.waitForFinished();
167 monitor.setTotalSteps(0);
168 }
169}
170
171void
173 std::vector<XicCoordSPtr> &xic_coord_list)
174{
175 qDebug() << xic_coord_list.size();
176 monitor.setStatus(QObject::tr("extracting %1 XICs").arg(xic_coord_list.size()));
177 monitor.setTotalSteps(xic_coord_list.size());
178 protectedExtractXicCoordSPtrList(monitor, xic_coord_list.begin(), xic_coord_list.end());
179 monitor.setTotalSteps(0);
180 postExtractionProcess(monitor, xic_coord_list.begin(), xic_coord_list.end());
181}
182
183void
185 UiMonitorInterface &monitor,
186 std::vector<XicCoordSPtr>::iterator it_xic_coord_list_begin,
187 std::vector<XicCoordSPtr>::iterator it_xic_coord_list_end)
188{
189
190 if(mcsp_postExtractionTraceFilter != nullptr)
191 {
192 monitor.setStatus(QObject::tr("filtering %1 XICs")
193 .arg(std::distance(it_xic_coord_list_begin, it_xic_coord_list_end)));
194 for(auto it = it_xic_coord_list_begin; it != it_xic_coord_list_end; it++)
195 {
196 mcsp_postExtractionTraceFilter.get()->filter(*(it->get()->xicSptr.get()));
197 }
198 }
199}
200
201
202} // 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
const MsRunReaderSPtr & getMsRunReaderSPtr() const
get the msrunreader currently used for XIC extraction
void setXicExtractMethod(Enums::XicExtractMethod method)
set the XIC extraction method
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:57
@ filter
concerning filters (psm, peptide, protein validation)
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition msrunid.h:46
std::shared_ptr< const FilterInterface > FilterInterfaceCstSPtr