libpappsomspp
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 >> &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 MassSpectrum & operator= (const MassSpectrum &other)
 
virtual MassSpectrum & operator= (MassSpectrum &&other)
 
MassSpectrumSPtr makeMassSpectrumSPtr () const
 
MassSpectrumCstSPtr makeMassSpectrumCstSPtr () const
 
virtual MassSpectrum & massSpectrumFilter (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 DataPoint & maxIntensityDataPoint () const
 Find the DataPoint instance having the greatest intensity (y) value. More...
 
const DataPoint & minIntensityDataPoint () 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< 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 Trace &other)
 
size_t initialize (const std::map< pappso_double, pappso_double > &map)
 
virtual Trace & operator= (const Trace &x)
 
virtual Trace & operator= (Trace &&x)
 
TraceSPtr makeTraceSPtr () const
 
TraceCstSPtr makeTraceCstSPtr () const
 
std::vector< pappso_double > xValues () const
 
std::vector< pappso_double > yValues () const
 
std::map< pappso_double, pappso_double > toMap () const
 
DataPoint containsX (pappso_double value, PrecisionPtr precision_p=nullptr) const
 
const DataPoint & minYDataPoint () const
 
const DataPoint & maxYDataPoint () 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 sortY ()
 
void unique ()
 
virtual Trace & filter (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 dataPointIteratorWithX (pappso_double value)
 
std::vector< DataPoint >::const_iterator dataPointCstIteratorWithX (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 70 of file massspectrum.h.

Constructor & Destructor Documentation

◆ MassSpectrum() [1/8]

pappso::MassSpectrum::MassSpectrum ( )

Definition at line 55 of file massspectrum.cpp.

56 {
57 }

◆ MassSpectrum() [2/8]

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

Definition at line 60 of file massspectrum.cpp.

62  : Trace::Trace(data_point_vector)
63 {
64 }

◆ MassSpectrum() [3/8]

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

Definition at line 66 of file massspectrum.cpp.

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

◆ MassSpectrum() [4/8]

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

Definition at line 75 of file massspectrum.cpp.

75  : Trace(other)
76 {
77 }

◆ MassSpectrum() [5/8]

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

Definition at line 71 of file massspectrum.cpp.

71  : Trace(other)
72 {
73 }

◆ MassSpectrum() [6/8]

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

Definition at line 80 of file massspectrum.cpp.

80  : Trace(std::move(other))
81 {
82 }

◆ MassSpectrum() [7/8]

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

Definition at line 85 of file massspectrum.cpp.

85  : Trace(other)
86 {
87  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()";
88 }

◆ MassSpectrum() [8/8]

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

Definition at line 91 of file massspectrum.cpp.

91  : Trace(std::move(other))
92 {
93  // Specify std::move so that && reference is passed to the Trace constructor
94  // that takes std::vector<DataPoint> && as rvalue reference.
95 
96  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
97  //<< "Moving MassSpectrum::MassSpectrum(MassSpectrum &&)";
98 }

◆ ~MassSpectrum()

pappso::MassSpectrum::~MassSpectrum ( )
virtual

Definition at line 101 of file massspectrum.cpp.

102 {
103 }

Member Function Documentation

◆ debugPrintValues()

void pappso::MassSpectrum::debugPrintValues ( ) const

Definition at line 327 of file massspectrum.cpp.

328 {
329 
330  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << size();
331  for(std::size_t i = 0; i < size(); i++)
332  {
333  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
334  qDebug() << "mz = " << this->operator[](i).x
335  << ", int = " << this->operator[](i).y;
336  }
337 
338  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
339 }

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

219 {
220  if(size() != other.size())
221  {
222  qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
223  << "The other mass spectrum size is not equal to *this size"
224  << "*this size:" << size() << "trace size:" << other.size();
225 
226  return false;
227  }
228 
230 
231  auto trace_it = other.begin();
232 
233  for(auto &&data_point : *this)
234  {
235  qDebug() << "first:" << data_point.x << "," << data_point.y
236  << " second:" << trace_it->x << "," << trace_it->y;
237 
238  if(!MzRange(data_point.x, precision).contains(trace_it->x))
239  {
240  qDebug() << "x:" << data_point.x << " != " << trace_it->x;
241  return false;
242  }
243 
244  if(!MzRange(data_point.y, precint).contains(trace_it->y))
245  {
246  qDebug() << "y:" << data_point.y << " != " << trace_it->y;
247  return false;
248  }
249 
250  trace_it++;
251  }
252 
253  return true;
254 }

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

◆ filterSum()

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

Definition at line 258 of file massspectrum.cpp.

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

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

◆ makeMassSpectrumCstSPtr()

MassSpectrumCstSPtr pappso::MassSpectrum::makeMassSpectrumCstSPtr ( ) const

Definition at line 132 of file massspectrum.cpp.

133 {
134  return std::make_shared<const MassSpectrum>(*this);
135 }

◆ makeMassSpectrumSPtr()

MassSpectrumSPtr pappso::MassSpectrum::makeMassSpectrumSPtr ( ) const

Definition at line 125 of file massspectrum.cpp.

126 {
127  return std::make_shared<MassSpectrum>(*this);
128 }

Referenced by pappso::PwizMsRunReader::qualifiedMassSpectrumFromPwizSpectrumPtr(), and pappso::XyMsRunReader::qualifiedMassSpectrumFromXyMSDataFile().

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

402 {
403  return filter.filter(*this);
404 }

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

178 {
179  return Trace::maxYDataPoint();
180 }

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

190 {
191  return Trace::minYDataPoint();
192 }

References pappso::Trace::minYDataPoint().

◆ operator=() [1/2]

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

Definition at line 107 of file massspectrum.cpp.

108 {
109  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()";
110 
111  assign(other.begin(), other.end());
112  return *this;
113 }

◆ operator=() [2/2]

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

Definition at line 117 of file massspectrum.cpp.

118 {
119  vector<DataPoint>::operator=(std::move(other));
120  return *this;
121 }

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

202 {
203  Trace::sortX();
204 }

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

159 {
160  return totalIonCurrent();
161 }

References totalIonCurrent().

◆ tic() [2/2]

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

Definition at line 165 of file massspectrum.cpp.

166 {
167  return Trace::sumY(mzStart, mzEnd);
168 }

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

148 {
149  return Trace::sumY();
150 }

References pappso::Trace::sumY().

Referenced by tic().


The documentation for this class was generated from the following files:
pappso::Trace::maxYDataPoint
const DataPoint & maxYDataPoint() const
Definition: trace.cpp:708
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:48
pappso::PrecisionFactory::getPpmInstance
static PrecisionPtr getPpmInstance(pappso_double value)
get a ppm precision pointer
Definition: precision.cpp:149
pappso::MassSpectrum::totalIonCurrent
pappso_double totalIonCurrent() const
Compute the total ion current of this mass spectrum.
Definition: massspectrum.cpp:147
pappso::Trace::Trace
Trace()
Definition: trace.cpp:375
pappso::MassSpectrum::MassSpectrum
MassSpectrum()
Definition: massspectrum.cpp:55
pappso::Trace::filter
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition: trace.cpp:837
pappso::Trace::sumY
pappso_double sumY() const
Definition: trace.cpp:741
pappso::PrecisionPtr
const PrecisionBase * PrecisionPtr
Definition: precision.h:122
pappso::Trace::sortX
void sortX()
Definition: trace.cpp:792
pappso::Trace::minYDataPoint
const DataPoint & minYDataPoint() const
Definition: trace.cpp:689