libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::MassSpectrum Class Reference

Class to represent a mass spectrum. More...

#include <massspectrum.h>

Inheritance diagram for pappso::MassSpectrum:
pappso::Trace

Public Member Functions

 MassSpectrum ()
 
 MassSpectrum (std::vector< std::pair< pappso_double, pappso_double > > &data_point_vector)
 
 MassSpectrum (std::vector< DataPoint > &data_point_vector)
 
 MassSpectrum (const MapTrace &other)
 
 MassSpectrum (const Trace &other)
 
 MassSpectrum (Trace &&other)
 
 MassSpectrum (const MassSpectrum &other)
 
 MassSpectrum (MassSpectrum &&other)
 
virtual ~MassSpectrum ()
 
virtual MassSpectrumoperator= (const MassSpectrum &other)
 
virtual MassSpectrumoperator= (MassSpectrum &&other)
 
MassSpectrumSPtr makeMassSpectrumSPtr () const
 
MassSpectrumCstSPtr makeMassSpectrumCstSPtr () const
 
virtual MassSpectrummassSpectrumFilter (const MassSpectrumFilterInterface &filter) final
 apply a filter on this MassSpectrum
 
pappso_double totalIonCurrent () const
 Compute the total ion current of this mass spectrum.
 
pappso_double tic () const
 Compute the total ion current of this mass spectrum.
 
pappso_double tic (double mzStart, double mzEnd)
 
const DataPointmaxIntensityDataPoint () const
 Find the DataPoint instance having the greatest intensity (y) value.
 
const DataPointminIntensityDataPoint () const
 Find the DataPoint instance having the smallest intensity (y) value.
 
void sortMz ()
 Sort the DataPoint instances of this spectrum.
 
bool equals (const MassSpectrum &other, PrecisionPtr precision) const
 Tells if this MassSpectrum is equal to massSpectrum.
 
MassSpectrum filterSum (const MzRange &mass_range) const
 
void debugPrintValues () const
 
virtual Traceoperator= (const Trace &x)
 
virtual Traceoperator= (Trace &&x)
 
- Public Member Functions inherited from pappso::Trace
 Trace ()
 
 Trace (const QString &text)
 
 Trace (const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
 
 Trace (const std::vector< std::pair< pappso_double, pappso_double > > &dataPoints)
 
 Trace (const std::vector< DataPoint > &dataPoints)
 
 Trace (const std::vector< DataPoint > &&dataPoints)
 
 Trace (const MapTrace &map_trace)
 
 Trace (const Trace &other)
 
 Trace (const Trace &&other)
 
virtual ~Trace ()
 
size_t initialize (const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
 
size_t initialize (const QString &x_text, const QString &y_text)
 
size_t initialize (const QString &space_sep_text)
 
size_t initialize (const Trace &other)
 
size_t initialize (const std::map< pappso_double, pappso_double > &map)
 
TraceSPtr makeTraceSPtr () const
 
TraceCstSPtr makeTraceCstSPtr () const
 
size_t append (const DataPoint &data_point)
 appends a datapoint and return new size
 
std::vector< pappso_doublexValues () const
 
std::vector< pappso_doubleyValues () const
 
std::map< pappso_double, pappso_doubletoMap () const
 
DataPoint containsX (pappso_double value, PrecisionPtr precision_p=nullptr) const
 
const DataPointminXDataPoint () const
 
const DataPointmaxXDataPoint () const
 
const DataPointminYDataPoint () const
 
const DataPointmaxYDataPoint () const
 
pappso_double minX () const
 
pappso_double maxX () const
 
pappso_double minY () const
 
pappso_double maxY () const
 
pappso_double maxY (double mzStart, double mzEnd) const
 
pappso_double sumY () const
 
pappso_double sumY (double mzStart, double mzEnd) const
 
void sort (SortType sort_type, SortOrder sort_order=SortOrder::ascending)
 
void sortX (SortOrder sort_order=SortOrder::ascending)
 
void sortY (SortOrder sort_order=SortOrder::ascending)
 
void unique ()
 
std::size_t removeZeroYDataPoints ()
 
virtual Tracefilter (const FilterInterface &filter) final
 apply a filter on this trace
 
QString toString () const
 
QByteArray xAsBase64Encoded () const
 
QByteArray yAsBase64Encoded () const
 
std::vector< DataPoint >::const_iterator dataPointCstIteratorWithX (pappso_double value) const
 find datapoint with exactly x value
 

Additional Inherited Members

- Protected Member Functions inherited from pappso::Trace
std::size_t dataPointIndexWithX (pappso_double value) const
 
std::vector< DataPoint >::iterator dataPointIteratorWithX (pappso_double value)
 

Detailed Description

Class to represent a mass spectrum.

A mass spectrum is a collection of DataPoint instances. Moreover, it has internal data that represent the context of the acquisition of the data: retention time and drift time (if the experiment was an ion mobility mass spectrometry experiment).

A MassSpectrum cannot perform combinations. For combination of mass spectra, the class to use is MassSpectrumCombinator.

Definition at line 72 of file massspectrum.h.

Constructor & Destructor Documentation

◆ MassSpectrum() [1/8]

pappso::MassSpectrum::MassSpectrum ( )

Definition at line 61 of file massspectrum.cpp.

62{
63}

◆ MassSpectrum() [2/8]

pappso::MassSpectrum::MassSpectrum ( std::vector< std::pair< pappso_double, pappso_double > > &  data_point_vector)

Definition at line 66 of file massspectrum.cpp.

68 : Trace::Trace(data_point_vector)
69{
70}

◆ MassSpectrum() [3/8]

pappso::MassSpectrum::MassSpectrum ( std::vector< DataPoint > &  data_point_vector)

Definition at line 72 of file massspectrum.cpp.

73 : Trace::Trace(data_point_vector)
74{
75}

◆ MassSpectrum() [4/8]

pappso::MassSpectrum::MassSpectrum ( const MapTrace other)

Definition at line 81 of file massspectrum.cpp.

81 : Trace(other)
82{
83}

◆ MassSpectrum() [5/8]

pappso::MassSpectrum::MassSpectrum ( const Trace other)

Definition at line 77 of file massspectrum.cpp.

77 : Trace(other)
78{
79}

◆ MassSpectrum() [6/8]

pappso::MassSpectrum::MassSpectrum ( Trace &&  other)

Definition at line 86 of file massspectrum.cpp.

86 : Trace(std::move(other))
87{
88}

◆ MassSpectrum() [7/8]

pappso::MassSpectrum::MassSpectrum ( const MassSpectrum other)

Definition at line 91 of file massspectrum.cpp.

91 : Trace(other)
92{
93 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()";
94}

◆ MassSpectrum() [8/8]

pappso::MassSpectrum::MassSpectrum ( MassSpectrum &&  other)

Definition at line 97 of file massspectrum.cpp.

97 : Trace(std::move(other))
98{
99 // Specify std::move so that && reference is passed to the Trace constructor
100 // that takes std::vector<DataPoint> && as rvalue reference.
101
102 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
103 //<< "Moving MassSpectrum::MassSpectrum(MassSpectrum &&)";
104}

◆ ~MassSpectrum()

pappso::MassSpectrum::~MassSpectrum ( )
virtual

Definition at line 107 of file massspectrum.cpp.

108{
109}

Member Function Documentation

◆ debugPrintValues()

void pappso::MassSpectrum::debugPrintValues ( ) const

Definition at line 333 of file massspectrum.cpp.

334{
335
336 qDebug() << size();
337 for(std::size_t i = 0; i < size(); i++)
338 {
339 qDebug() << "(" << this->operator[](i).x << "," << this->operator[](i).y
340 << ")";
341 }
342}

◆ equals()

bool pappso::MassSpectrum::equals ( const MassSpectrum other,
PrecisionPtr  precision 
) const

Tells if this MassSpectrum is equal to massSpectrum.

To compare this to massSpectrum, a tolerance is applied to both the x and y values, that is defined using precision.

Parameters
massSpectrumMass spectrum to compare to this.
precisionPrecision to be used to perform the comparison of the x and y values of the data points in this and \massSpectrum mass spectra.

Definition at line 224 of file massspectrum.cpp.

225{
226 if(size() != other.size())
227 {
228 qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
229 << "The other mass spectrum size is not equal to *this size"
230 << "*this size:" << size() << "trace size:" << other.size();
231
232 return false;
233 }
234
236
237 auto trace_it = other.begin();
238
239 for(auto &&data_point : *this)
240 {
241 qDebug() << "first:" << data_point.x << "," << data_point.y
242 << " second:" << trace_it->x << "," << trace_it->y;
243
244 if(!MzRange(data_point.x, precision).contains(trace_it->x))
245 {
246 qDebug() << "x:" << data_point.x << " != " << trace_it->x;
247 return false;
248 }
249
250 if(!MzRange(data_point.y, precint).contains(trace_it->y))
251 {
252 qDebug() << "y:" << data_point.y << " != " << trace_it->y;
253 return false;
254 }
255
256 trace_it++;
257 }
258
259 return true;
260}
static PrecisionPtr getPpmInstance(pappso_double value)
get a ppm precision pointer
const PrecisionBase * PrecisionPtr
Definition precision.h:122

References pappso::MzRange::contains(), and pappso::PrecisionFactory::getPpmInstance().

◆ filterSum()

MassSpectrum pappso::MassSpectrum::filterSum ( const MzRange mass_range) const

Definition at line 264 of file massspectrum.cpp.

265{
266 MassSpectrum massSpectrum;
267
268 std::vector<DataPoint>::const_iterator it = begin();
269 std::vector<DataPoint>::const_iterator itEnd = end();
270
271 std::vector<DataPoint>::const_reverse_iterator itRev = rbegin();
272 std::vector<DataPoint>::const_reverse_iterator itRevEnd = rend();
273
274 pappso_double lower = range.lower();
275 pappso_double upper = range.upper();
276
277 while((it != itEnd) && (it->x <= itRev->x) && (itRev != itRevEnd))
278 {
279 pappso_double sumX = it->x + itRev->x;
280
281 if(sumX < lower)
282 {
283 it++;
284 }
285 else if(sumX > upper)
286 {
287 itRev++;
288 }
289 else
290 {
291 massSpectrum.push_back(*it);
292 massSpectrum.push_back(*itRev);
293
294 std::vector<DataPoint>::const_reverse_iterator itRevIn = itRev;
295 itRevIn++;
296
297 // FIXME Attention buggy code FR 20180626.
298 sumX = it->x + itRevIn->x;
299 while((sumX > lower) && (it->x <= itRevIn->x) &&
300 (itRevIn != itRevEnd))
301 {
302 sumX = it->x + itRevIn->x;
303 // trace.push_back(*it);
304 massSpectrum.push_back(*itRevIn);
305 itRevIn++;
306 }
307 it++;
308 }
309 }
310
311 // Sort all the data points in increasing order by x
312 std::sort(massSpectrum.begin(),
313 massSpectrum.end(),
314 [](const DataPoint &a, const DataPoint &b) { return (a.x < b.x); });
315
316 // Remove all the but the first element of a series of elements that are
317 // considered equal. Sort of deduplication.
318 std::vector<DataPoint>::iterator itEndFix =
319 std::unique(massSpectrum.begin(),
320 massSpectrum.end(),
321 [](const DataPoint &a, const DataPoint &b) {
322 // Return true if both elements should be considered equal.
323 return (a.x == b.x) && (a.y == b.y);
324 });
325
326 massSpectrum.resize(std::distance(massSpectrum.begin(), itEndFix));
327
328 return massSpectrum;
329}
double pappso_double
A type definition for doubles.
Definition types.h:50

References pappso::a, pappso::b, pappso::MzRange::lower(), and pappso::MzRange::upper().

◆ makeMassSpectrumCstSPtr()

MassSpectrumCstSPtr pappso::MassSpectrum::makeMassSpectrumCstSPtr ( ) const

Definition at line 138 of file massspectrum.cpp.

139{
140 return std::make_shared<const MassSpectrum>(*this);
141}

◆ makeMassSpectrumSPtr()

◆ massSpectrumFilter()

MassSpectrum & pappso::MassSpectrum::massSpectrumFilter ( const MassSpectrumFilterInterface filter)
finalvirtual

apply a filter on this MassSpectrum

Parameters
filterto process the MassSpectrum
Returns
reference on the modified MassSpectrum

Definition at line 404 of file massspectrum.cpp.

405{
406 return filter.filter(*this);
407}
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition trace.cpp:1210

References pappso::Trace::filter().

Referenced by pappso::XtandemSpectrumProcess::process().

◆ maxIntensityDataPoint()

const DataPoint & pappso::MassSpectrum::maxIntensityDataPoint ( ) const

Find the DataPoint instance having the greatest intensity (y) value.

Returns
<const DataPoint &> The data point having the maximum intensity (y) value of the whole mass spectrum.

Definition at line 183 of file massspectrum.cpp.

184{
185 return Trace::maxYDataPoint();
186}
const DataPoint & maxYDataPoint() const
Definition trace.cpp:976

References pappso::Trace::maxYDataPoint().

◆ minIntensityDataPoint()

const DataPoint & pappso::MassSpectrum::minIntensityDataPoint ( ) const

Find the DataPoint instance having the smallest intensity (y) value.

Returns
<const DataPoint &> The data point having the minimum intensity (y) value of the whole mass spectrum.

Definition at line 195 of file massspectrum.cpp.

196{
197 return Trace::minYDataPoint();
198}
const DataPoint & minYDataPoint() const
Definition trace.cpp:957

References pappso::Trace::minYDataPoint().

◆ operator=() [1/4]

MassSpectrum & pappso::MassSpectrum::operator= ( const MassSpectrum other)
virtual

Definition at line 113 of file massspectrum.cpp.

114{
115 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()";
116
117 assign(other.begin(), other.end());
118 return *this;
119}

◆ operator=() [2/4]

Trace & pappso::Trace::operator= ( const Trace x)
virtual

Reimplemented from pappso::Trace.

Definition at line 179 of file trace.cpp.

658{
659 assign(other.begin(), other.end());
660
661 return *this;
662}

◆ operator=() [3/4]

MassSpectrum & pappso::MassSpectrum::operator= ( MassSpectrum &&  other)
virtual

Definition at line 123 of file massspectrum.cpp.

124{
125 vector<DataPoint>::operator=(std::move(other));
126 return *this;
127}

◆ operator=() [4/4]

Trace & pappso::Trace::operator= ( Trace &&  x)
virtual

Reimplemented from pappso::Trace.

Definition at line 180 of file trace.cpp.

667{
668 vector<DataPoint>::operator=(std::move(other));
669 return *this;
670}

References pappso::a, and pappso::b.

◆ sortMz()

void pappso::MassSpectrum::sortMz ( )

Sort the DataPoint instances of this spectrum.

The DataPoint instances are sorted according to the x value (the m/z value) and in increasing order.

Definition at line 207 of file massspectrum.cpp.

208{
209 Trace::sortX();
210}
void sortX(SortOrder sort_order=SortOrder::ascending)
Definition trace.cpp:1086

References pappso::Trace::sortX().

Referenced by pappso::MzIntegrationParams::createDataBasedBins(), and pappso::PwizMsRunReader::qualifiedMassSpectrumFromPwizSpectrumPtr().

◆ tic() [1/2]

pappso_double pappso::MassSpectrum::tic ( ) const

Compute the total ion current of this mass spectrum.

Convenience function that returns totalIonCurrent();

Definition at line 164 of file massspectrum.cpp.

165{
166 return totalIonCurrent();
167}
pappso_double totalIonCurrent() const
Compute the total ion current of this mass spectrum.

References totalIonCurrent().

◆ tic() [2/2]

pappso_double pappso::MassSpectrum::tic ( double  mzStart,
double  mzEnd 
)

Definition at line 171 of file massspectrum.cpp.

172{
173 return Trace::sumY(mzStart, mzEnd);
174}
pappso_double sumY() const
Definition trace.cpp:1023

References pappso::Trace::sumY().

◆ totalIonCurrent()

pappso_double pappso::MassSpectrum::totalIonCurrent ( ) const

Compute the total ion current of this mass spectrum.

The sum of all the separate ion currents carried by the ions of different m/z contributing to a complete mass massSpectrum or in a specified m/z range of a mass massSpectrum. MS:1000285

Returns
<pappso_double> The total ion current.

Definition at line 153 of file massspectrum.cpp.

154{
155 return Trace::sumY();
156}

References pappso::Trace::sumY().

Referenced by tic().


The documentation for this class was generated from the following files: