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,
75  std::vector<XicCoordSPtr>::iterator it_xic_coord_list_begin,
76  std::vector<XicCoordSPtr>::iterator it_xic_coord_list_end)
77 {
78 
79  // sort xic by mz:
80  std::sort(it_xic_coord_list_begin,
81  it_xic_coord_list_end,
82  [](XicCoordSPtr &a, XicCoordSPtr &b) {
83  return a.get()->rtTarget < b.get()->rtTarget;
84  });
85 
86  for(auto it = it_xic_coord_list_begin; it != it_xic_coord_list_end; it++)
87  {
88  // XicCoord *p_xic_coord = sp_xic_coord.get();
89  extractOneXicCoord(*(it->get()));
90  monitor.count();
91  if(monitor.shouldIstop())
92  {
94  QObject::tr("Xic extraction process interrupted"));
95  }
96  }
97 }
98 
99 
100 void
102 {
103  FilterResampleKeepXRange keep_range(xic_coord.mzRange.lower(),
104  xic_coord.mzRange.upper());
105  std::shared_ptr<Xic> msrunxic_sp = xic_coord.xicSptr;
106 
107  double rt_begin = xic_coord.rtTarget - m_retentionTimeAroundTarget;
108  double rt_end = xic_coord.rtTarget + m_retentionTimeAroundTarget;
109 
110 
111  auto itpoints = m_msrun_points.begin();
112 
113  // find startint retention time :
114  while((itpoints != m_msrun_points.end()) && (itpoints->rt < rt_begin))
115  {
116  itpoints++;
117  }
118  MassSpectrumSPtr spectrum;
119  DataPoint peak;
120  while((itpoints != m_msrun_points.end()) && (itpoints->rt <= rt_end))
121  {
122  spectrum =
123  msp_msrun_reader.get()->massSpectrumSPtr(itpoints->spectrum_index);
124  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
125  // << spectrum->size(); spectrum->debugPrintValues();
126 
127  qDebug() << " spectrum->size()=" << spectrum->size();
128  keep_range.filter(*(spectrum.get()));
129  qDebug() << " spectrum->size()=" << spectrum->size();
130 
131  peak.x = itpoints->rt;
132 
134  {
135  peak.y = 0;
136  if(spectrum->size() > 0)
137  {
138  peak.y = maxYDataPoint(spectrum->begin(), spectrum->end())->y;
139 
140  qDebug() << " peak.y=" << peak.y
141  << " spectrum->size()=" << spectrum->size();
142  }
143  }
144  else
145  {
146  peak.y = sumYTrace(spectrum->begin(), spectrum->end(), 0);
147  }
148  msrunxic_sp->push_back(peak);
149 
150  itpoints++;
151  }
152 }
153 
154 void
156  std::vector<Xic *> &xic_list,
157  const std::vector<MzRange> &mass_range_list,
158  pappso::pappso_double rt_begin,
159  pappso::pappso_double rt_end)
160 {
161  qDebug();
162 
163  std::vector<DataPoint> peak_for_mass;
164  for(const MzRange &mass_range : mass_range_list)
165  {
166  peak_for_mass.push_back(DataPoint());
167  qDebug() << " mass_range=" << mass_range.getMz();
168  }
169 
170 
171  qDebug();
172 
173  auto itpoints = m_msrun_points.begin();
174 
175  while((itpoints != m_msrun_points.end()) && (itpoints->rt < rt_begin))
176  {
177  itpoints++;
178  }
179 
180  MassSpectrumCstSPtr spectrum;
181  while((itpoints != m_msrun_points.end()) && (itpoints->rt <= rt_end))
182  {
183  spectrum =
184  msp_msrun_reader.get()->massSpectrumCstSPtr(itpoints->spectrum_index);
185 
186  for(DataPoint &peak : peak_for_mass)
187  {
188  peak.x = itpoints->rt;
189  peak.y = 0;
190  }
191 
192 
193  // iterate through the m/z-intensity pairs
194  for(auto &&spectrum_point : *(spectrum.get()))
195  {
196  // qDebug() << "getXicFromPwizMSDataFile it->mz " << it->mz <<
197  // " it->intensity" << it->intensity;
198  for(std::size_t i = 0; i < mass_range_list.size(); i++)
199  {
200  if(mass_range_list[i].contains(spectrum_point.x))
201  {
203  {
204  if(peak_for_mass[i].y < spectrum_point.y)
205  {
206  peak_for_mass[i].y = spectrum_point.y;
207  }
208  }
209  else
210  {
211  peak_for_mass[i].y += spectrum_point.y;
212  }
213  }
214  }
215  }
216 
217  for(std::size_t i = 0; i < mass_range_list.size(); i++)
218  {
219  // qDebug() << "getXicFromPwizMSDataFile push_back " <<
220  // peak_for_mass[i].rt;
221  xic_list[i]->push_back(peak_for_mass[i]);
222  }
223 
224  itpoints++;
225  }
226 
227 
228  qDebug();
229 } // namespace pappso
230 
231 
232 } // 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:184
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