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 "msrunslice.h"
32#include "../../trace/datapoint.h"
33#include "../../pappsoexception.h"
34#include "../../exception/exceptionoutofrange.h"
35#include <QDebug>
36
37namespace pappso
38{
39
41{
42 m_sliceNumber = 0;
43}
44
46{
49}
51{
52}
53
56{
57 return std::make_shared<const MsRunSlice>(*this);
58}
59
60void
61MsRunSlice::setSliceNumber(unsigned int slice_number)
62{
63 m_sliceNumber = slice_number;
64}
65
66unsigned int
68{
69 return m_sliceNumber;
70}
71
72std::size_t
74{
75 return m_spectrumList.size();
76}
77
78void
79MsRunSlice::setSize(std::size_t size)
80{
81 m_spectrumList.resize(size);
82}
83void
85{
86 m_spectrumList.clear();
87 m_sliceNumber = 0;
88}
89
90void
91MsRunSlice::setSpectrum(std::size_t i, const MassSpectrum &spectrum)
92{
93 try
94 {
95 m_spectrumList[i] = spectrum;
96 }
97 catch(std::exception &error)
98 {
99 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
101 QObject::tr("unable to access spectrum %1 (size=%2) %3")
102 .arg(i)
103 .arg(m_spectrumList.size())
104 .arg(error.what()));
105 }
106}
107
110{
111 try
112 {
113 return m_spectrumList.at(i);
114 }
115 catch(std::exception &error)
116 {
117 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
119 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__;
136 QObject::tr("unable to get spectrum %1 (size=%2) %3")
137 .arg(i)
138 .arg(m_spectrumList.size())
139 .arg(error.what()));
140 }
141}
142
143void
144MsRunSlice::appendToStream(QDataStream &outstream, std::size_t ipos) const
145{
146
147 for(auto &&spectrum : m_spectrumList)
148 {
149 outstream << (quint32)ipos;
150 outstream << spectrum;
151 ipos++;
152 }
153}
154
155QDataStream &
156operator>>(QDataStream &instream, MsRunSlice &slice)
157{
158
159 quint32 vector_size = 0;
160 quint32 slice_number = 0;
161 quint32 spectrum_position = 0;
162 DataPoint peak;
163
164 if(!instream.atEnd())
165 {
166 instream >> slice_number;
167 instream >> vector_size;
168 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
169 << " vector_size=" << vector_size;
170 slice.setSize(vector_size);
171
172 slice.setSliceNumber(slice_number);
173 while(!instream.atEnd())
174 {
175 instream >> spectrum_position;
176 MassSpectrum spectrum;
177 try
178 {
179 instream >> spectrum;
180 }
181 catch(PappsoException &error)
182 {
183 throw PappsoException(
184 QString("error in QDataStream unserialize operator>> of "
185 "MsRunSlice %2 on %3:\n%1")
186 .arg(error.qwhat())
187 .arg(spectrum_position)
188 .arg(vector_size));
189 }
190 slice.setSpectrum(spectrum_position, spectrum);
191
192 if(instream.status() != QDataStream::Ok)
193 {
194 throw PappsoException(
195 QString("error in QDataStream unserialize operator>> of "
196 "MsRunSlice :\nread datastream failed status=%1")
197 .arg(instream.status()));
198 }
199 }
200 }
201
202 if(slice.size() != vector_size)
203 {
204 throw PappsoException(
205 QString("error in QDataStream unserialize operator>> of MsRunSlice "
206 "slice.size() != vector_size :\n %1 %2:")
207 .arg(slice.size())
208 .arg(vector_size));
209 }
210
211 return instream;
212}
213
214
215} // namespace pappso
Class to represent a mass spectrum.
Definition: massspectrum.h:71
const MassSpectrum & getSpectrum(std::size_t i) const
Definition: msrunslice.cpp:126
virtual ~MsRunSlice()
Definition: msrunslice.cpp:50
unsigned int m_sliceNumber
Definition: msrunslice.h:73
MsRunSliceSPtr makeMsRunSliceSp() const
Definition: msrunslice.cpp:55
void setSpectrum(std::size_t i, const MassSpectrum &spectrum)
set the mass spectrum for a given index (retention time)
Definition: msrunslice.cpp:91
void setSliceNumber(unsigned int slice_number)
Definition: msrunslice.cpp:61
void appendToStream(QDataStream &stream, std::size_t ipos) const
Definition: msrunslice.cpp:144
unsigned int getSliceNumber() const
Definition: msrunslice.cpp:67
void setSize(std::size_t size)
set number of spectrum (mz/intensity) stored in this slice
Definition: msrunslice.cpp:79
std::size_t size() const
Definition: msrunslice.cpp:73
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