pappsomspp
Library for mass spectrometry
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 >> &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 More...
 
pappso_double totalIonCurrent () const
 Compute the total ion current of this mass spectrum. More...
 
pappso_double tic () const
 Compute the total ion current of this mass spectrum. More...
 
pappso_double tic (double mzStart, double mzEnd)
 
const DataPointmaxIntensityDataPoint () const
 Find the DataPoint instance having the greatest intensity (y) value. More...
 
const DataPointlowestIntensityDataPoint () const
 Find the DataPoint instance having the smallest intensity (y) value. More...
 
void sortMz ()
 Sort the DataPoint instances of this spectrum. More...
 
bool equals (const MassSpectrum &other, PrecisionPtr precision) const
 Tells if this MassSpectrum is equal to massSpectrum. More...
 
MassSpectrum filterSum (const MzRange &mass_range) const
 
void debugPrintValues () const
 
- Public Member Functions inherited from pappso::Trace
 Trace ()
 
 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 Trace &other)
 
size_t initialize (const std::map< pappso_double, pappso_double > &map)
 
virtual Traceoperator= (const Trace &x)
 
virtual Traceoperator= (Trace &&x)
 
TraceSPtr makeTraceSPtr () const
 
TraceCstSPtr makeTraceCstSPtr () const
 
std::vector< pappso_doublexToVector () const
 
std::vector< pappso_doubleyToVector () const
 
std::map< pappso_double, pappso_doubletoMap () const
 
DataPoint containsX (pappso_double value, PrecisionPtr precision_p=nullptr) const
 
const DataPointminYDataPoint () const
 
const DataPointmaxYDataPoint () 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 sortX ()
 
void unique ()
 
std::vector< pappso_doublexValues ()
 
std::vector< pappso_doubleyValues ()
 
virtual Tracefilter (const FilterInterface &filter) final
 apply a filter on this trace More...
 
QString toString () const
 

Additional Inherited Members

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

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 89 of file massspectrum.h.

Constructor & Destructor Documentation

◆ MassSpectrum() [1/7]

pappso::MassSpectrum::MassSpectrum ( )

Definition at line 75 of file massspectrum.cpp.

75  : Trace(std::move(other))
76 {
77 }

◆ MassSpectrum() [2/7]

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

Definition at line 80 of file massspectrum.cpp.

80  : Trace(other)
81 {
82  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()";
83 }
84 

◆ MassSpectrum() [3/7]

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

Definition at line 90 of file massspectrum.cpp.

◆ MassSpectrum() [4/7]

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

Definition at line 86 of file massspectrum.cpp.

86  : Trace(std::move(other))
87 {
88  // Specify std::move so that && reference is passed to the Trace constructor

◆ MassSpectrum() [5/7]

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

Definition at line 95 of file massspectrum.cpp.

97 {

◆ MassSpectrum() [6/7]

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

Definition at line 100 of file massspectrum.cpp.

103 {

◆ MassSpectrum() [7/7]

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

Definition at line 106 of file massspectrum.cpp.

113 {

◆ ~MassSpectrum()

pappso::MassSpectrum::~MassSpectrum ( )
virtual

Definition at line 116 of file massspectrum.cpp.

Member Function Documentation

◆ debugPrintValues()

void pappso::MassSpectrum::debugPrintValues ( ) const

Definition at line 342 of file massspectrum.cpp.

342  : massSpectrum)
343  {
344  outstream << peak;
345  }
346 
347  return outstream;
348 }
349 
350 
351 QDataStream &
352 operator>>(QDataStream &instream, MassSpectrum &massSpectrum)
353 {
354 

◆ 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 233 of file massspectrum.cpp.

234  {
235  qDebug() << "x:" << data_point.x << " != " << trace_it->x;
236  return false;
237  }
238 
239  if(!MzRange(data_point.y, precint).contains(trace_it->y))
240  {
241  qDebug() << "y:" << data_point.y << " != " << trace_it->y;
242  return false;
243  }
244 
245  trace_it++;
246  }
247 
248  return true;
249 }
250 
251 
253 MassSpectrum::filterSum(const MzRange &range) const
254 {
255  MassSpectrum massSpectrum;
256 
257  std::vector<DataPoint>::const_iterator it = begin();
258  std::vector<DataPoint>::const_iterator itEnd = end();
259 
260  std::vector<DataPoint>::const_reverse_iterator itRev = rbegin();
261  std::vector<DataPoint>::const_reverse_iterator itRevEnd = rend();
262 
263  pappso_double lower = range.lower();
264  pappso_double upper = range.upper();
265 
266  while((it != itEnd) && (it->x <= itRev->x) && (itRev != itRevEnd))
267  {
268  pappso_double sumX = it->x + itRev->x;
269 

◆ filterSum()

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

Definition at line 273 of file massspectrum.cpp.

275  {
276  itRev++;
277  }
278  else
279  {
280  massSpectrum.push_back(*it);
281  massSpectrum.push_back(*itRev);
282 
283  std::vector<DataPoint>::const_reverse_iterator itRevIn = itRev;
284  itRevIn++;
285 
286  // FIXME Attention buggy code FR 20180626.
287  sumX = it->x + itRevIn->x;
288  while((sumX > lower) && (it->x <= itRevIn->x) &&
289  (itRevIn != itRevEnd))
290  {
291  sumX = it->x + itRevIn->x;
292  // trace.push_back(*it);
293  massSpectrum.push_back(*itRevIn);
294  itRevIn++;
295  }
296  it++;
297  }
298  }
299 
300  // Sort all the data points in increasing order by x
301  std::sort(massSpectrum.begin(),
302  massSpectrum.end(),
303  [](const DataPoint &a, const DataPoint &b) { return (a.x < b.x); });
304 
305  // Remove all the but the first element of a series of elements that are
306  // considered equal. Sort of deduplication.
307  std::vector<DataPoint>::iterator itEndFix =
308  std::unique(massSpectrum.begin(),
309  massSpectrum.end(),
310  [](const DataPoint &a, const DataPoint &b) {
311  // Return true if both elements should be considered equal.
312  return (a.x == b.x) && (a.y == b.y);
313  });
314 
315  massSpectrum.resize(std::distance(massSpectrum.begin(), itEndFix));
316 
317  return massSpectrum;
318 }
319 
320 
321 void
323 {
324 
325  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << size();
326  for(std::size_t i = 0; i < size(); i++)
327  {
328  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
329  qDebug() << "mz = " << this->operator[](i).x
330  << ", int = " << this->operator[](i).y;
331  }
332 
333  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
334 }
335 
336 
337 QDataStream &
338 operator<<(QDataStream &outstream, const MassSpectrum &massSpectrum)

◆ lowestIntensityDataPoint()

const DataPoint & pappso::MassSpectrum::lowestIntensityDataPoint ( ) 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 204 of file massspectrum.cpp.

◆ makeMassSpectrumCstSPtr()

MassSpectrumCstSPtr pappso::MassSpectrum::makeMassSpectrumCstSPtr ( ) const

Definition at line 147 of file massspectrum.cpp.

References totalIonCurrent().

◆ makeMassSpectrumSPtr()

MassSpectrumSPtr pappso::MassSpectrum::makeMassSpectrumSPtr ( ) const

◆ 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 416 of file massspectrum.cpp.

◆ 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 192 of file massspectrum.cpp.

References pappso::Trace::sortX().

◆ operator=() [1/2]

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

Definition at line 122 of file massspectrum.cpp.

128 {

◆ operator=() [2/2]

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

Definition at line 132 of file massspectrum.cpp.

◆ 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 216 of file massspectrum.cpp.

216  {
217  qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
218  << "The other mass spectrum size is not equal to *this size"
219  << "*this size:" << size() << "trace size:" << other.size();

◆ 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 173 of file massspectrum.cpp.

173 {
174  return Trace::maxYDataPoint();
175 }
176 

References pappso::Trace::maxYDataPoint().

◆ tic() [2/2]

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

Definition at line 180 of file massspectrum.cpp.

References pappso::Trace::minYDataPoint().

◆ 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 162 of file massspectrum.cpp.

Referenced by makeMassSpectrumCstSPtr().


The documentation for this class was generated from the following files:
pappso::Trace::maxYDataPoint
const DataPoint & maxYDataPoint() const
Definition: trace.cpp:659
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:67
pappso::Trace::Trace
Trace()
Definition: trace.cpp:354
pappso::MassSpectrum::debugPrintValues
void debugPrintValues() const
Definition: massspectrum.cpp:342
pappso::PeptideIonNter::a
pappso::MassSpectrum::MassSpectrum
MassSpectrum()
Definition: massspectrum.cpp:75
pappso::MassSpectrum::filterSum
MassSpectrum filterSum(const MzRange &mass_range) const
Definition: massspectrum.cpp:273
pappso::operator>>
QDataStream & operator>>(QDataStream &instream, MassSpectrum &massSpectrum)
Definition: massspectrum.cpp:372
pappso::operator<<
QDataStream & operator<<(QDataStream &outstream, const MassSpectrum &massSpectrum)
Definition: massspectrum.cpp:358
pappso::PeptideIonNter::b