libpappsomspp
Library for mass spectrometry
msrunxicextractor.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/xicextractor/private/msrunxicextractorpwiz.cpp
3 * \date 07/05/2018
4 * \author Olivier Langella
5 * \brief simple proteowizard based XIC extractor
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
31#include "msrunxicextractor.h"
32#include <QDebug>
33#include <QObject>
34
35#include "../../pappsoexception.h"
36#include "../../exception/exceptioninterrupted.h"
37#include "../../processing/filters/filterresample.h"
38
39namespace pappso
40{
41
42
44 : pappso::MsRunXicExtractorInterface(msrun_reader)
45{
46
48 msp_msrun_reader.get()->readSpectrumCollection(get_msrun_points);
49
50 std::sort(m_msrun_points.begin(),
51 m_msrun_points.end(),
52 [](const MsRunXicExtractorPoints &a,
53 const MsRunXicExtractorPoints &b) { return a.rt < b.rt; });
54
55
56 if(m_msrun_points.size() == 0)
57 {
59 QObject::tr("error extracting XIC: no MS level 1 in data file"));
60 }
61}
63{
64}
65
66
69{
71}
72
73
74void
76 UiMonitorInterface &monitor,
77 std::vector<XicCoordSPtr>::iterator it_xic_coord_list_begin,
78 std::vector<XicCoordSPtr>::iterator it_xic_coord_list_end)
79{
80
81 // sort xic by mz:
82 std::sort(it_xic_coord_list_begin,
83 it_xic_coord_list_end,
85 return a.get()->rtTarget < b.get()->rtTarget;
86 });
87
88 for(auto it = it_xic_coord_list_begin; it != it_xic_coord_list_end; it++)
89 {
90 // XicCoord *p_xic_coord = sp_xic_coord.get();
91 extractOneXicCoord(*(it->get()));
92 monitor.count();
93 if(monitor.shouldIstop())
94 {
96 QObject::tr("Xic extraction process interrupted"));
97 }
98 }
99}
100
101
102void
104{
105 FilterResampleKeepXRange keep_range(xic_coord.mzRange.lower(),
106 xic_coord.mzRange.upper());
107 std::shared_ptr<Xic> msrunxic_sp = xic_coord.xicSptr;
108
109 double rt_begin = xic_coord.rtTarget - m_retentionTimeAroundTarget;
110 double rt_end = xic_coord.rtTarget + m_retentionTimeAroundTarget;
111
112
113 auto itpoints = m_msrun_points.begin();
114
115 // find startint retention time :
116 while((itpoints != m_msrun_points.end()) && (itpoints->rt < rt_begin))
117 {
118 itpoints++;
119 }
120 MassSpectrumSPtr spectrum;
121 DataPoint peak;
122 while((itpoints != m_msrun_points.end()) && (itpoints->rt <= rt_end))
123 {
124 spectrum =
125 msp_msrun_reader.get()->massSpectrumSPtr(itpoints->spectrum_index);
126 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
127 // << spectrum->size(); spectrum->debugPrintValues();
128
129 qDebug() << " spectrum->size()=" << spectrum->size();
130 keep_range.filter(*(spectrum.get()));
131 qDebug() << " spectrum->size()=" << spectrum->size();
132
133 peak.x = itpoints->rt;
134
136 {
137 peak.y = 0;
138 if(spectrum->size() > 0)
139 {
140 peak.y = maxYDataPoint(spectrum->begin(), spectrum->end())->y;
141
142 qDebug() << " peak.y=" << peak.y
143 << " spectrum->size()=" << spectrum->size();
144 }
145 }
146 else
147 {
148 peak.y = sumYTrace(spectrum->begin(), spectrum->end(), 0);
149 }
150 msrunxic_sp->push_back(peak);
151
152 itpoints++;
153 }
154}
155
156void
158 std::vector<Xic *> &xic_list,
159 const std::vector<MzRange> &mass_range_list,
160 pappso::pappso_double rt_begin,
162{
163 qDebug();
164
165 std::vector<DataPoint> peak_for_mass;
166 for(const MzRange &mass_range : mass_range_list)
167 {
168 peak_for_mass.push_back(DataPoint());
169 qDebug() << " mass_range=" << mass_range.getMz();
170 }
171
172
173 qDebug();
174
175 auto itpoints = m_msrun_points.begin();
176
177 while((itpoints != m_msrun_points.end()) && (itpoints->rt < rt_begin))
178 {
179 itpoints++;
180 }
181
182 MassSpectrumCstSPtr spectrum;
183 while((itpoints != m_msrun_points.end()) && (itpoints->rt <= rt_end))
184 {
185 spectrum =
186 msp_msrun_reader.get()->massSpectrumCstSPtr(itpoints->spectrum_index);
187
188 for(DataPoint &peak : peak_for_mass)
189 {
190 peak.x = itpoints->rt;
191 peak.y = 0;
192 }
193
194
195 // iterate through the m/z-intensity pairs
196 for(auto &&spectrum_point : *(spectrum.get()))
197 {
198 // qDebug() << "getXicFromPwizMSDataFile it->mz " << it->mz <<
199 // " it->intensity" << it->intensity;
200 for(std::size_t i = 0; i < mass_range_list.size(); i++)
201 {
202 if(mass_range_list[i].contains(spectrum_point.x))
203 {
205 {
206 if(peak_for_mass[i].y < spectrum_point.y)
207 {
208 peak_for_mass[i].y = spectrum_point.y;
209 }
210 }
211 else
212 {
213 peak_for_mass[i].y += spectrum_point.y;
214 }
215 }
216 }
217 }
218
219 for(std::size_t i = 0; i < mass_range_list.size(); i++)
220 {
221 // qDebug() << "getXicFromPwizMSDataFile push_back " <<
222 // peak_for_mass[i].rt;
223 xic_list[i]->push_back(peak_for_mass[i]);
224 }
225
226 itpoints++;
227 }
228
229
230 qDebug();
231} // namespace pappso
232
233
234} // namespace pappso
Trace & filter(Trace &trace) const override
class to read retention time points of MsRun
virtual void getXicFromPwizMSDataFile(std::vector< Xic * > &xic_list, const std::vector< MzRange > &mass_range_list, pappso::pappso_double rt_begin, pappso::pappso_double rt_end)
MsRunXicExtractor(const MsRunXicExtractor &other)
void extractOneXicCoord(XicCoord &xic_coord)
std::vector< MsRunXicExtractorPoints > m_msrun_points
virtual void protectedExtractXicCoordSPtrList(UiMonitorInterface &monitor, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_begin, std::vector< XicCoordSPtr >::iterator it_xic_coord_list_end) override
pappso_double lower() const
Definition: mzrange.h:71
pappso_double upper() const
Definition: mzrange.h:77
virtual bool shouldIstop()=0
should the procces be stopped ? If true, then cancel process Use this function at strategic point of ...
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::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:180
double pappso_double
A type definition for doubles.
Definition: types.h:50
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition: massspectrum.h:55
double sumYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double init)
calculate the sum of y value of a trace
Definition: trace.cpp:244
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:54
@ max
maximum of intensities
std::shared_ptr< XicCoord > XicCoordSPtr
Definition: xiccoord.h:43
pappso_double x
Definition: datapoint.h:23
pappso_double y
Definition: datapoint.h:24
coordinates of the XIC to extract and the resulting XIC after extraction
Definition: xiccoord.h:67
XicSPtr xicSptr
extracted xic
Definition: xiccoord.h:130
double rtTarget
the targeted retention time to extract around intended in seconds, and related to one msrun....
Definition: xiccoord.h:126
MzRange mzRange
the mass to extract
Definition: xiccoord.h:120