libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
spectrumcollectionhandlerinterface.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/core/msrun/spectrumcollectionhandlerinterface.h
3 * \date 29/05/2018
4 * \author Olivier Langella
5 * \brief base interface to read MSrun files
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 ******************************************************************************/
27
28#include <QDebug>
29#include <QObject>
30
33
34namespace pappso
35{
36
37bool
42void
46void
48{
49}
50void
52{
53 m_isReadAhead = is_read_ahead;
54}
55
56bool
61
62bool
64{
65 if(needPeakList() == true)
66 {
67 if(ms_level < m_needPeakListByMsLevel.size())
68 {
69 return m_needPeakListByMsLevel[ms_level];
70 }
71 else
72 return true;
73 }
74 else
75 {
76 return false;
77 }
78}
79void
81 bool want_peak_list)
82{
83 if(ms_level < m_needPeakListByMsLevel.size())
84 {
85 m_needPeakListByMsLevel[ms_level] = want_peak_list;
86 }
87}
88
89bool
91{
92 return false;
93}
94
95
96void
98{
99 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
100 //<< "The data loading process ended.";
101}
102
103
104void
106{
107 // The vector[0] contains the number of spectra at MS
108 // The vector[1] contains the number of spectra at MS^2
109 // The vector[2] contains the number of spectra at MS^3
110 // ...
111
112 unsigned int ms_level = qspectrum.getMsLevel();
113 if(ms_level == 0)
114 return;
115 if(ms_level > m_countMsLevelSpectrum.size())
116 {
117 m_countMsLevelSpectrum.resize(ms_level);
118 }
119 m_countMsLevelSpectrum[ms_level - 1]++;
120}
121
122
123unsigned long
124MsRunSimpleStatistics::getMsLevelCount(unsigned int ms_level) const
125{
126 if(ms_level == 0)
127 return 0;
128 if(ms_level > m_countMsLevelSpectrum.size())
129 return 0;
130 return (m_countMsLevelSpectrum[ms_level - 1]);
131}
132
133
134unsigned long
136{
137 unsigned long total = 0;
138 for(unsigned long count : m_countMsLevelSpectrum)
139 {
140 total += count;
141 }
142 return total;
143}
144
145
150
151
156
157
158bool
160{
161 return false;
162}
163
164void
166{
167 qDebug() << " " << qspectrum.getMassSpectrumId().getNativeId();
168
169 QStringList native_id_list = qspectrum.getMassSpectrumId().getNativeId().split("=");
170 if(native_id_list.size() < 2)
171 {
172 return;
173 }
174 else
175 {
176 std::size_t scan_number = native_id_list.back().toULong();
177 m_mmap_scan2index.insert(std::pair<std::size_t, std::size_t>(
178 scan_number, qspectrum.getMassSpectrumId().getSpectrumIndex()));
179
180 qDebug() << "scan number " << scan_number << "=>"
181 << qspectrum.getMassSpectrumId().getSpectrumIndex();
182 }
183}
184
185std::size_t
187{
188
189 qDebug() << m_mmap_scan2index.size();
190
191 auto it = m_mmap_scan2index.find(scan_number);
192
193 if(it == m_mmap_scan2index.end())
194 {
195 throw ExceptionNotFound(QObject::tr("scan number %1 not found").arg(scan_number));
196 }
197
198 std::size_t index = it->second;
199
200 it++;
201 if((it != m_mmap_scan2index.end()) && (it->first == scan_number))
202 {
203 throw PappsoException(QObject::tr("scan number %1 found multiple times").arg(scan_number));
204 }
205 return index;
206}
207
208
213
214
219
220
221bool
223{
224 return false;
225}
226
227
228void
230{
231 qDebug() << " " << qspectrum.getMassSpectrumId().getNativeId();
232
233 m_retention_time_list.push_back(qspectrum.getRtInSeconds());
234}
235
236const std::vector<double> &
241
245
246
250
251
252bool
254{
255 return true;
256}
257
258
259void
261 const QualifiedMassSpectrum &qualified_mass_spectrum)
262{
263 // In this specialized reader we want to compute the total ion current
264 // chromatogram that plot the sum of all the ion intensities in the spectra as
265 // a function of the retention time.
266
267 uint spectrum_ms_level = qualified_mass_spectrum.getMsLevel();
268
269 if(spectrum_ms_level != 1)
270 return;
271
272 double sumY = qualified_mass_spectrum.getMassSpectrumSPtr()->sumY();
273
274 if(!sumY)
275 return;
276
277 double rt = qualified_mass_spectrum.getRtInMinutes();
278
279 m_ticChromTrace.push_back({rt, sumY});
280 /*
281 using Pair = std::pair<double, double>;
282 using Map = std::map<double, double>;
283 using Iterator = Map::iterator;
284
285 std::pair<Iterator, bool> res = m_ticChromMapTrace.insert(Pair(rt, sumY));
286
287 if(!res.second)
288 {
289 // One other same rt value was seen already (like in ion mobility mass
290 // spectrometry, for example). Only increment the y value.
291
292 res.first->second += sumY;
293 }
294 */
295}
296
297
298Trace
300{
301 // return m_ticChromMapTrace.toTrace();
302 return m_ticChromTrace;
303}
304
308
309
313
314
315bool
317{
318 return true;
319}
320
321void
323{
325}
326
327void
329 const QualifiedMassSpectrum &qualified_mass_spectrum)
330{
331 qDebug() << qualified_mass_spectrum.getMassSpectrumId().getNativeId();
332 m_qualifiedSpectrumList.push_back(qualified_mass_spectrum);
333}
334
335const std::vector<QualifiedMassSpectrum> &
340
341void
346} // namespace pappso
std::size_t getSpectrumIndex() const
const QString & getNativeId() const
const std::vector< QualifiedMassSpectrum > & getQualifiedMassSpectrumList() const
virtual void spectrumListHasSize(std::size_t size) override
virtual bool needPeakList() const override
tells if we need the peak list (if we want the binary data) for each spectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &qualified_mass_spectrum) override
std::vector< QualifiedMassSpectrum > m_qualifiedSpectrumList
const std::vector< double > & getRetentionTimeLine() const
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override
virtual bool needPeakList() const override
tells if we need the peak list (if we want the binary data) for each spectrum
virtual bool needPeakList() const override
tells if we need the peak list (if we want the binary data) for each spectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override
std::size_t getSpectrumIndexFromScanNumber(std::size_t scan_number) const
std::multimap< std::size_t, std::size_t > m_mmap_scan2index
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &qualified_mass_spectrum) override
virtual bool needPeakList() const override
tells if we need the peak list (if we want the binary data) for each spectrum
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum) override
std::vector< unsigned long > m_countMsLevelSpectrum
virtual bool needPeakList() const override
tells if we need the peak list (if we want the binary data) for each spectrum
unsigned long getMsLevelCount(unsigned int ms_level) const
Class representing a fully specified mass spectrum.
uint getMsLevel() const
Get the mass spectrum level.
pappso_double getRtInMinutes() const
Get the retention time in minutes.
const MassSpectrumId & getMassSpectrumId() const
Get the MassSpectrumId.
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.
pappso_double getRtInSeconds() const
Get the retention time in seconds.
virtual bool isReadAhead() const
tells if we want to read ahead spectrum
virtual bool needPeakList() const =0
tells if we need the peak list (if we want the binary data) for each spectrum
virtual bool needMsLevelPeakList(unsigned int ms_level) const final
tells if we need the peak list (if we want the binary data) for each spectrum, given an MS level
virtual void setReadAhead(bool is_read_ahead) final
use threads to read a spectrum by batch of batch_size
virtual void setNeedMsLevelPeakList(unsigned int ms_level, bool want_peak_list) final
tells if we need the peak list given
A simple container of DataPoint instances.
Definition trace.h:152
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
unsigned int uint
Definition types.h:67
base interface to read MSrun files