libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
spectrumcollectionhandlerinterface.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/msrun/msrunreader.cpp
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
31#include "../../pappsomspp/exception/exceptionnotfound.h"
33
34namespace pappso
35{
36
37bool
42void
46void
48 [[maybe_unused]] std::size_t size)
49{
50}
51void
53{
54 m_isReadAhead = is_read_ahead;
55}
56
57bool
62
63bool
65 unsigned int ms_level) const
66{
67 if(needPeakList() == true)
68 {
69 if(ms_level < m_needPeakListByMsLevel.size())
70 {
71 return m_needPeakListByMsLevel[ms_level];
72 }
73 else
74 return true;
75 }
76 else
77 {
78 return false;
79 }
80}
81void
83 unsigned int ms_level, bool want_peak_list)
84{
85 if(ms_level < m_needPeakListByMsLevel.size())
86 {
87 m_needPeakListByMsLevel[ms_level] = want_peak_list;
88 }
89}
90
91bool
93{
94 return false;
95}
96
97
98void
100{
101 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
102 //<< "The data loading process ended.";
103}
104
105
106void
108 const QualifiedMassSpectrum &qspectrum)
109{
110 // The vector[0] contains the number of spectra at MS
111 // The vector[1] contains the number of spectra at MS^2
112 // The vector[2] contains the number of spectra at MS^3
113 // ...
114
115 unsigned int ms_level = qspectrum.getMsLevel();
116 if(ms_level == 0)
117 return;
118 if(ms_level > m_countMsLevelSpectrum.size())
119 {
120 m_countMsLevelSpectrum.resize(ms_level);
121 }
122 m_countMsLevelSpectrum[ms_level - 1]++;
123}
124
125
126unsigned long
127MsRunSimpleStatistics::getMsLevelCount(unsigned int ms_level) const
128{
129 if(ms_level == 0)
130 return 0;
131 if(ms_level > m_countMsLevelSpectrum.size())
132 return 0;
133 return (m_countMsLevelSpectrum[ms_level - 1]);
134}
135
136
137unsigned long
139{
140 unsigned long total = 0;
141 for(unsigned long count : m_countMsLevelSpectrum)
142 {
143 total += count;
144 }
145 return total;
146}
147
148
153
154
159
160
161bool
163{
164 return false;
165}
166
167void
169 const QualifiedMassSpectrum &qspectrum)
170{
171 qDebug() << " " << qspectrum.getMassSpectrumId().getNativeId();
172
173 QStringList native_id_list =
174 qspectrum.getMassSpectrumId().getNativeId().split("=");
175 if(native_id_list.size() < 2)
176 {
177 return;
178 }
179 else
180 {
181 std::size_t scan_number = native_id_list.back().toULong();
182 m_mmap_scan2index.insert(std::pair<std::size_t, std::size_t>(
183 scan_number, qspectrum.getMassSpectrumId().getSpectrumIndex()));
184
185 qDebug() << "scan number " << scan_number << "=>"
186 << qspectrum.getMassSpectrumId().getSpectrumIndex();
187 }
188}
189
190std::size_t
192 std::size_t scan_number) const
193{
194
195 qDebug() << m_mmap_scan2index.size();
196
197 auto it = m_mmap_scan2index.find(scan_number);
198
199 if(it == m_mmap_scan2index.end())
200 {
201 throw ExceptionNotFound(
202 QObject::tr("scan number %1 not found").arg(scan_number));
203 }
204
205 std::size_t index = it->second;
206
207 it++;
208 if((it != m_mmap_scan2index.end()) && (it->first == scan_number))
209 {
210 throw PappsoException(
211 QObject::tr("scan number %1 found multiple times").arg(scan_number));
212 }
213 return index;
214}
215
216
221
222
227
228
229bool
231{
232 return false;
233}
234
235
236void
238 const QualifiedMassSpectrum &qspectrum)
239{
240 qDebug() << " " << qspectrum.getMassSpectrumId().getNativeId();
241
242 m_retention_time_list.push_back(qspectrum.getRtInSeconds());
243}
244
245const std::vector<double> &
250
254
255
259
260
261bool
263{
264 return true;
265}
266
267
268void
270 const QualifiedMassSpectrum &qualified_mass_spectrum)
271{
272 // In this specialized reader we want to compute the total ion current
273 // chromatogram that plot the sum of all the ion intensities in the spectra as
274 // a function of the retention time.
275
276 uint spectrum_ms_level = qualified_mass_spectrum.getMsLevel();
277
278 if(spectrum_ms_level != 1)
279 return;
280
281 double sumY = qualified_mass_spectrum.getMassSpectrumSPtr()->sumY();
282
283 if(!sumY)
284 return;
285
286 double rt = qualified_mass_spectrum.getRtInMinutes();
287
288 using Pair = std::pair<double, double>;
289 using Map = std::map<double, double>;
290 using Iterator = Map::iterator;
291
292 std::pair<Iterator, bool> res = m_ticChromMapTrace.insert(Pair(rt, sumY));
293
294 if(!res.second)
295 {
296 // One other same rt value was seen already (like in ion mobility mass
297 // spectrometry, for example). Only increment the y value.
298
299 res.first->second += sumY;
300 }
301}
302
303
304Trace
309
313
314
318
319
320bool
322{
323 return true;
324}
325
326void
328 [[maybe_unused]])
329{
331}
332
333void
335 const QualifiedMassSpectrum &qualified_mass_spectrum)
336{
337 qDebug() << qualified_mass_spectrum.getMassSpectrumId().getNativeId();
338 m_qualifiedSpectrumList.push_back(qualified_mass_spectrum);
339}
340
341const std::vector<QualifiedMassSpectrum> &
346
347void
352} // namespace pappso
Trace toTrace() const
Definition maptrace.cpp:219
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:148
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
@ rt
Retention time.
unsigned int uint
Definition types.h:57