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