libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
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
"
34
#include "
../../trace/datapoint.h
"
35
#include "
pappsomspp/core/pappsoexception.h
"
36
#include "
pappsomspp/core/exception/exceptionoutofrange.h
"
37
#include <QDebug>
38
39
namespace
pappso
40
{
41
42
MsRunSlice::MsRunSlice
()
43
{
44
m_sliceNumber
= 0;
45
}
46
47
MsRunSlice::MsRunSlice
(
const
MsRunSlice
&other)
48
{
49
m_sliceNumber
= other.
m_sliceNumber
;
50
m_spectrumList
= other.
m_spectrumList
;
51
}
52
MsRunSlice::~MsRunSlice
()
53
{
54
}
55
56
MsRunSliceSPtr
57
MsRunSlice::makeMsRunSliceSp
()
const
58
{
59
return
std::make_shared<const MsRunSlice>(*
this
);
60
}
61
62
void
63
MsRunSlice::setSliceNumber
(
unsigned
int
slice_number)
64
{
65
m_sliceNumber
= slice_number;
66
}
67
68
unsigned
int
69
MsRunSlice::getSliceNumber
()
const
70
{
71
return
m_sliceNumber
;
72
}
73
74
std::size_t
75
MsRunSlice::size
()
const
76
{
77
return
m_spectrumList
.size();
78
}
79
80
void
81
MsRunSlice::setSize
(std::size_t
size
)
82
{
83
m_spectrumList
.resize(
size
);
84
}
85
void
86
MsRunSlice::clear
()
87
{
88
m_spectrumList
.clear();
89
m_sliceNumber
= 0;
90
}
91
92
void
93
MsRunSlice::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
109
MassSpectrum
&
110
MsRunSlice::getSpectrum
(std::size_t i)
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
}
125
const
MassSpectrum
&
126
MsRunSlice::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
142
void
143
MsRunSlice::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
154
QDataStream &
155
operator>>
(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
pappso::ExceptionOutOfRange
Definition
exceptionoutofrange.h:32
pappso::MassSpectrum
Class to represent a mass spectrum.
Definition
massspectrum.h:70
pappso::MsRunSlice
Definition
msrunslice.h:43
pappso::MsRunSlice::getSpectrum
const MassSpectrum & getSpectrum(std::size_t i) const
Definition
msrunslice.cpp:126
pappso::MsRunSlice::~MsRunSlice
virtual ~MsRunSlice()
Definition
msrunslice.cpp:52
pappso::MsRunSlice::m_sliceNumber
unsigned int m_sliceNumber
Definition
msrunslice.h:73
pappso::MsRunSlice::MsRunSlice
MsRunSlice()
Definition
msrunslice.cpp:42
pappso::MsRunSlice::makeMsRunSliceSp
MsRunSliceSPtr makeMsRunSliceSp() const
Definition
msrunslice.cpp:57
pappso::MsRunSlice::setSpectrum
void setSpectrum(std::size_t i, const MassSpectrum &spectrum)
set the mass spectrum for a given index (retention time)
Definition
msrunslice.cpp:93
pappso::MsRunSlice::setSliceNumber
void setSliceNumber(unsigned int slice_number)
Definition
msrunslice.cpp:63
pappso::MsRunSlice::appendToStream
void appendToStream(QDataStream &stream, std::size_t ipos) const
Definition
msrunslice.cpp:143
pappso::MsRunSlice::clear
void clear()
Definition
msrunslice.cpp:86
pappso::MsRunSlice::getSliceNumber
unsigned int getSliceNumber() const
Definition
msrunslice.cpp:69
pappso::MsRunSlice::setSize
void setSize(std::size_t size)
set number of spectrum (mz/intensity) stored in this slice
Definition
msrunslice.cpp:81
pappso::MsRunSlice::size
std::size_t size() const
Definition
msrunslice.cpp:75
pappso::MsRunSlice::m_spectrumList
std::vector< MassSpectrum > m_spectrumList
Definition
msrunslice.h:74
pappso::PappsoException
Definition
pappsoexception.h:41
pappso::PappsoException::qwhat
virtual const QString & qwhat() const
Definition
pappsoexception.h:66
datapoint.h
exceptionoutofrange.h
msrunslice.h
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition
aa.cpp:39
pappso::operator>>
QDataStream & operator>>(QDataStream &instream, MassSpectrum &massSpectrum)
Definition
massspectrum.cpp:353
pappso::MsRunSliceSPtr
std::shared_ptr< const MsRunSlice > MsRunSliceSPtr
Definition
msrunslice.h:40
pappsoexception.h
pappso::DataPoint
Definition
datapoint.h:22
pappsomspp
core
xicextractor
private
msrunslice.cpp
Generated on
for libpappsomspp by
1.17.0