libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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"
37#include <QDebug>
38
39namespace pappso
40{
41
46
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
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__;
102 throw pappso::ExceptionOutOfRange(QObject::tr("unable to access spectrum %1 (size=%2) %3")
103 .arg(i)
104 .arg(m_spectrumList.size())
105 .arg(error.what()));
106 }
107}
108
111{
112 try
113 {
114 return m_spectrumList.at(i);
115 }
116 catch(std::exception &error)
117 {
118 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
119 throw pappso::ExceptionOutOfRange(QObject::tr("unable to get spectrum %1 (size=%2) %3")
120 .arg(i)
121 .arg(m_spectrumList.size())
122 .arg(error.what()));
123 }
124}
125const MassSpectrum &
126MsRunSlice::getSpectrum(std::size_t i) const
127{
128 try
129 {
130 return m_spectrumList.at(i);
131 }
132 catch(std::exception &error)
133 {
134 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
135 throw pappso::ExceptionOutOfRange(QObject::tr("unable to get spectrum %1 (size=%2) %3")
136 .arg(i)
137 .arg(m_spectrumList.size())
138 .arg(error.what()));
139 }
140}
141
142void
143MsRunSlice::appendToStream(QDataStream &outstream, std::size_t ipos) const
144{
145
146 for(auto &&spectrum : m_spectrumList)
147 {
148 outstream << (quint32)ipos;
149 outstream << spectrum;
150 ipos++;
151 }
152}
153
154QDataStream &
155operator>>(QDataStream &instream, MsRunSlice &slice)
156{
157
158 quint32 vector_size = 0;
159 quint32 slice_number = 0;
160 quint32 spectrum_position = 0;
161 DataPoint peak;
162
163 if(!instream.atEnd())
164 {
165 instream >> slice_number;
166 instream >> vector_size;
167 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
168 << " vector_size=" << vector_size;
169 slice.setSize(vector_size);
170
171 slice.setSliceNumber(slice_number);
172 while(!instream.atEnd())
173 {
174 instream >> spectrum_position;
175 MassSpectrum spectrum;
176 try
177 {
178 instream >> spectrum;
179 }
180 catch(PappsoException &error)
181 {
182 throw PappsoException(QString("error in QDataStream unserialize operator>> of "
183 "MsRunSlice %2 on %3:\n%1")
184 .arg(error.qwhat())
185 .arg(spectrum_position)
186 .arg(vector_size));
187 }
188 slice.setSpectrum(spectrum_position, spectrum);
189
190 if(instream.status() != QDataStream::Ok)
191 {
192 throw PappsoException(QString("error in QDataStream unserialize operator>> of "
193 "MsRunSlice :\nread datastream failed status=%1")
194 .arg(instream.status()));
195 }
196 }
197 }
198
199 if(slice.size() != vector_size)
200 {
201 throw PappsoException(QString("error in QDataStream unserialize operator>> of MsRunSlice "
202 "slice.size() != vector_size :\n %1 %2:")
203 .arg(slice.size())
204 .arg(vector_size));
205 }
206
207 return instream;
208}
209
210
211} // namespace pappso
Class to represent a mass spectrum.
const MassSpectrum & getSpectrum(std::size_t i) const
virtual ~MsRunSlice()
unsigned int m_sliceNumber
Definition msrunslice.h:73
MsRunSliceSPtr makeMsRunSliceSp() const
void setSpectrum(std::size_t i, const MassSpectrum &spectrum)
set the mass spectrum for a given index (retention time)
void setSliceNumber(unsigned int slice_number)
void appendToStream(QDataStream &stream, std::size_t ipos) const
unsigned int getSliceNumber() const
void setSize(std::size_t size)
set number of spectrum (mz/intensity) stored in this slice
std::size_t size() const
std::vector< MassSpectrum > m_spectrumList
Definition msrunslice.h:74
virtual const QString & qwhat() const
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