libpappsomspp
Library for mass spectrometry
msrunslice.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/xicextractor/private/msrunslice.cpp
3 * \date 12/05/2018
4 * \author Olivier Langella
5 * \brief one mz slice (1 dalton) of an MsRun
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 <QObject>
32
33#include "msrunslice.h"
34#include "../../trace/datapoint.h"
35#include "../../pappsoexception.h"
36#include "../../exception/exceptionoutofrange.h"
37#include <QDebug>
38
39namespace pappso
40{
41
43{
44 m_sliceNumber = 0;
45}
46
48{
51}
53{
54}
55
58{
59 return std::make_shared<const MsRunSlice>(*this);
60}
61
62void
63MsRunSlice::setSliceNumber(unsigned int slice_number)
64{
65 m_sliceNumber = slice_number;
66}
67
68unsigned int
70{
71 return m_sliceNumber;
72}
73
74std::size_t
76{
77 return m_spectrumList.size();
78}
79
80void
81MsRunSlice::setSize(std::size_t size)
82{
83 m_spectrumList.resize(size);
84}
85void
87{
88 m_spectrumList.clear();
89 m_sliceNumber = 0;
90}
91
92void
93MsRunSlice::setSpectrum(std::size_t i, const MassSpectrum &spectrum)
94{
95 try
96 {
97 m_spectrumList[i] = spectrum;
98 }
99 catch(std::exception &error)
100 {
101 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
103 QObject::tr("unable to access spectrum %1 (size=%2) %3")
104 .arg(i)
105 .arg(m_spectrumList.size())
106 .arg(error.what()));
107 }
108}
109
112{
113 try
114 {
115 return m_spectrumList.at(i);
116 }
117 catch(std::exception &error)
118 {
119 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
121 QObject::tr("unable to get spectrum %1 (size=%2) %3")
122 .arg(i)
123 .arg(m_spectrumList.size())
124 .arg(error.what()));
125 }
126}
127const MassSpectrum &
128MsRunSlice::getSpectrum(std::size_t i) const
129{
130 try
131 {
132 return m_spectrumList.at(i);
133 }
134 catch(std::exception &error)
135 {
136 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
138 QObject::tr("unable to get spectrum %1 (size=%2) %3")
139 .arg(i)
140 .arg(m_spectrumList.size())
141 .arg(error.what()));
142 }
143}
144
145void
146MsRunSlice::appendToStream(QDataStream &outstream, std::size_t ipos) const
147{
148
149 for(auto &&spectrum : m_spectrumList)
150 {
151 outstream << (quint32)ipos;
152 outstream << spectrum;
153 ipos++;
154 }
155}
156
157QDataStream &
158operator>>(QDataStream &instream, MsRunSlice &slice)
159{
160
161 quint32 vector_size = 0;
162 quint32 slice_number = 0;
163 quint32 spectrum_position = 0;
164 DataPoint peak;
165
166 if(!instream.atEnd())
167 {
168 instream >> slice_number;
169 instream >> vector_size;
170 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
171 << " vector_size=" << vector_size;
172 slice.setSize(vector_size);
173
174 slice.setSliceNumber(slice_number);
175 while(!instream.atEnd())
176 {
177 instream >> spectrum_position;
178 MassSpectrum spectrum;
179 try
180 {
181 instream >> spectrum;
182 }
183 catch(PappsoException &error)
184 {
185 throw PappsoException(
186 QString("error in QDataStream unserialize operator>> of "
187 "MsRunSlice %2 on %3:\n%1")
188 .arg(error.qwhat())
189 .arg(spectrum_position)
190 .arg(vector_size));
191 }
192 slice.setSpectrum(spectrum_position, spectrum);
193
194 if(instream.status() != QDataStream::Ok)
195 {
196 throw PappsoException(
197 QString("error in QDataStream unserialize operator>> of "
198 "MsRunSlice :\nread datastream failed status=%1")
199 .arg(instream.status()));
200 }
201 }
202 }
203
204 if(slice.size() != vector_size)
205 {
206 throw PappsoException(
207 QString("error in QDataStream unserialize operator>> of MsRunSlice "
208 "slice.size() != vector_size :\n %1 %2:")
209 .arg(slice.size())
210 .arg(vector_size));
211 }
212
213 return instream;
214}
215
216
217} // namespace pappso
Class to represent a mass spectrum.
Definition: massspectrum.h:71
const MassSpectrum & getSpectrum(std::size_t i) const
Definition: msrunslice.cpp:128
virtual ~MsRunSlice()
Definition: msrunslice.cpp:52
unsigned int m_sliceNumber
Definition: msrunslice.h:73
MsRunSliceSPtr makeMsRunSliceSp() const
Definition: msrunslice.cpp:57
void setSpectrum(std::size_t i, const MassSpectrum &spectrum)
set the mass spectrum for a given index (retention time)
Definition: msrunslice.cpp:93
void setSliceNumber(unsigned int slice_number)
Definition: msrunslice.cpp:63
void appendToStream(QDataStream &stream, std::size_t ipos) const
Definition: msrunslice.cpp:146
unsigned int getSliceNumber() const
Definition: msrunslice.cpp:69
void setSize(std::size_t size)
set number of spectrum (mz/intensity) stored in this slice
Definition: msrunslice.cpp:81
std::size_t size() const
Definition: msrunslice.cpp:75
std::vector< MassSpectrum > m_spectrumList
Definition: msrunslice.h:74
virtual const QString & qwhat() const
one mz slice (1 dalton) of an MsRun
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
QDataStream & operator>>(QDataStream &instream, MassSpectrum &massSpectrum)
std::shared_ptr< const MsRunSlice > MsRunSliceSPtr
Definition: msrunslice.h:40