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 "../../processing/filters/filterresample.h"
35 
36 namespace pappso
37 {
38 
39 
41  : pappso::MsRunXicExtractorInterface(msrun_reader)
42 {
43 
44  MsRunXicExtractorReadPoints get_msrun_points(m_msrun_points);
45  msp_msrun_reader.get()->readSpectrumCollection(get_msrun_points);
46 
47  std::sort(m_msrun_points.begin(),
48  m_msrun_points.end(),
49  [](const MsRunXicExtractorPoints &a,
50  const MsRunXicExtractorPoints &b) { return a.rt < b.rt; });
51 
52 
53  if(m_msrun_points.size() == 0)
54  {
56  QObject::tr("error extracting XIC: no MS level 1 in data file"));
57  }
58 }
60 {
61 }
62 
63 
66 {
68 }
69 
71 MsRunXicExtractor::getXicCstSPtr(const MzRange &mz_range,
72  pappso::pappso_double rt_begin,
73  pappso::pappso_double rt_end)
74 {
75  FilterResampleKeepXRange keep_range(mz_range.lower(), mz_range.upper());
76  std::shared_ptr<Xic> msrunxic_sp = std::make_shared<Xic>(Xic());
77 
78 
79  auto itpoints = m_msrun_points.begin();
80 
81  while((itpoints != m_msrun_points.end()) && (itpoints->rt < rt_begin))
82  {
83  itpoints++;
84  }
85  MassSpectrumSPtr spectrum;
86  DataPoint peak;
87  while((itpoints != m_msrun_points.end()) && (itpoints->rt <= rt_end))
88  {
89  spectrum =
90  msp_msrun_reader.get()->massSpectrumSPtr(itpoints->spectrum_index);
91  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
92  // << spectrum->size(); spectrum->debugPrintValues();
93 
94  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
95  << " spectrum->size()=" << spectrum->size();
96  keep_range.filter(*(spectrum.get()));
97  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
98  << " spectrum->size()=" << spectrum->size();
99 
100  peak.x = itpoints->rt;
101 
103  {
104  peak.y = 0;
105  if(spectrum->size() > 0)
106  {
107  peak.y = maxYDataPoint(spectrum->begin(), spectrum->end())->y;
108 
109  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
110  << " peak.y=" << peak.y
111  << " spectrum->size()=" << spectrum->size();
112  }
113  }
114  else
115  {
116  peak.y = sumYTrace(spectrum->begin(), spectrum->end(), 0);
117  }
118  msrunxic_sp->push_back(peak);
119 
120  itpoints++;
121  }
122 
123 
124  return (msrunxic_sp);
125 }
126 
127 std::vector<XicCstSPtr>
128 MsRunXicExtractor::getXicCstSPtrList(const std::vector<MzRange> &mz_range_list)
129 {
130 
131  std::vector<std::shared_ptr<Xic>> xic_list_return;
132  std::vector<Xic *> xic_list;
133  for(std::size_t i = 0; i < mz_range_list.size(); i++)
134  {
135  xic_list_return.push_back(std::make_shared<Xic>(Xic()));
136  xic_list.push_back(xic_list_return.back().get());
137  xic_list_return.back().get()->reserve(m_msrun_points.size());
138  }
139  getXicFromPwizMSDataFile(xic_list, mz_range_list, 0, 100000000);
140  std::vector<XicCstSPtr> xic_list_return_b;
141  for(auto &xic : xic_list_return)
142  {
143  xic_list_return_b.push_back(xic);
144  }
145  return xic_list_return_b;
146 }
147 
148 void
150  std::vector<Xic *> &xic_list,
151  const std::vector<MzRange> &mass_range_list,
152  pappso::pappso_double rt_begin,
153  pappso::pappso_double rt_end)
154 {
155  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
156 
157  std::vector<DataPoint> peak_for_mass;
158  for(const MzRange &mass_range : mass_range_list)
159  {
160  peak_for_mass.push_back(DataPoint());
161  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
162  << " mass_range=" << mass_range.getMz();
163  }
164 
165 
166  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
167 
168  auto itpoints = m_msrun_points.begin();
169 
170  while((itpoints != m_msrun_points.end()) && (itpoints->rt < rt_begin))
171  {
172  itpoints++;
173  }
174 
175  MassSpectrumCstSPtr spectrum;
176  while((itpoints != m_msrun_points.end()) && (itpoints->rt <= rt_end))
177  {
178  spectrum =
179  msp_msrun_reader.get()->massSpectrumCstSPtr(itpoints->spectrum_index);
180 
181  for(DataPoint &peak : peak_for_mass)
182  {
183  peak.x = itpoints->rt;
184  peak.y = 0;
185  }
186 
187 
188  // iterate through the m/z-intensity pairs
189  for(auto &&spectrum_point : *(spectrum.get()))
190  {
191  // qDebug() << "getXicFromPwizMSDataFile it->mz " << it->mz <<
192  // " it->intensity" << it->intensity;
193  for(std::size_t i = 0; i < mass_range_list.size(); i++)
194  {
195  if(mass_range_list[i].contains(spectrum_point.x))
196  {
198  {
199  if(peak_for_mass[i].y < spectrum_point.y)
200  {
201  peak_for_mass[i].y = spectrum_point.y;
202  }
203  }
204  else
205  {
206  peak_for_mass[i].y += spectrum_point.y;
207  }
208  }
209  }
210  }
211 
212  for(std::size_t i = 0; i < mass_range_list.size(); i++)
213  {
214  // qDebug() << "getXicFromPwizMSDataFile push_back " <<
215  // peak_for_mass[i].rt;
216  xic_list[i]->push_back(peak_for_mass[i]);
217  }
218 
219  itpoints++;
220  }
221 
222 
223  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
224 } // namespace pappso
225 
226 
227 } // namespace pappso
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:69
pappso::MassSpectrumCstSPtr
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
Definition: massspectrum.h:76
msrunxicextractor.h
pappso::DataPoint::y
pappso_double y
Definition: datapoint.h:23
pappso
Definition: aa.cpp:38
pappso::MsRunReaderSPtr
std::shared_ptr< MsRunReader > MsRunReaderSPtr
Definition: msrunreader.h:172
pappso::MsRunXicExtractor::MsRunXicExtractor
MsRunXicExtractor(MsRunReaderSPtr &msrun_reader)
Definition: msrunxicextractor.cpp:61
pappso::DataPoint
Definition: datapoint.h:20
pappso::MsRunXicExtractorInterface
Definition: msrunxicextractorinterface.h:63
pappso::MzRange
Definition: mzrange.h:66
pappso::sumYTrace
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:182
pappso::MsRunXicExtractorInterface::m_xicExtractMethod
XicExtractMethod m_xicExtractMethod
Definition: msrunxicextractorinterface.h:106
pappso::maxYDataPoint
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:127
pappso::XicCstSPtr
std::shared_ptr< const Xic > XicCstSPtr
Definition: xic.h:58
pappso::DataPoint::x
pappso_double x
Definition: datapoint.h:22
pappso::XicExtractMethod::max
@ max
maximum of intensities
pappso::MsRunXicExtractor::getXicCstSPtr
virtual XicCstSPtr getXicCstSPtr(const MzRange &mz_range, pappso::pappso_double rt_begin, pappso::pappso_double rt_end) override
get a XIC on this MsRun at the given mass range
Definition: msrunxicextractor.cpp:92
pappso::MsRunXicExtractorInterface::msp_msrun_reader
MsRunReaderSPtr msp_msrun_reader
Definition: msrunxicextractorinterface.h:105
pappso::MsRunXicExtractor::getXicCstSPtrList
virtual std::vector< XicCstSPtr > getXicCstSPtrList(const std::vector< MzRange > &mz_range_list) override
extract a list of XIC given a list of mass to extract
Definition: msrunxicextractor.cpp:149
pappso::MsRunXicExtractor::~MsRunXicExtractor
virtual ~MsRunXicExtractor()
Definition: msrunxicextractor.cpp:80
pappso::MsRunXicExtractor
Definition: msrunxicextractor.h:41
pappso::MsRunXicExtractor::getXicFromPwizMSDataFile
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)
Definition: msrunxicextractor.cpp:170
pappso::MsRunXicExtractor::m_msrun_points
std::vector< MsRunXicExtractorPoints > m_msrun_points
Definition: msrunxicextractor.h:46
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition: massspectrum.h:75
pappso::PappsoException
Definition: pappsoexception.h:62