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 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
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 DataPoint & maxIntensityDataPoint () const
 Find the DataPoint instance having the greatest intensity (y) value.
const DataPoint & minIntensityDataPoint () 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 Trace & operator= (const Trace &x)
virtual Trace & operator= (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_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 & minXDataPoint () const
const DataPoint & maxXDataPoint () const
const DataPoint & minYDataPoint () const
const DataPoint & maxYDataPoint () 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 (Enums::SortType sort_type, Enums::SortOrder sort_order=Enums::SortOrder::ascending)
void sortX (Enums::SortOrder sort_order=Enums::SortOrder::ascending)
void sortY (Enums::SortOrder sort_order=Enums::SortOrder::ascending)
void unique ()
std::size_t removeZeroYDataPoints ()
virtual Trace & filter (const FilterInterface &filter) final
 apply a filter on this trace
QString toString () const
QJsonObject toJsonObject (const QString &x_label="x", const QString &y_label="y") const
 serialize a PAPPSO trace object to JSON
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
 Return a reference to the DataPoint instance that has its x member equal to value.
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 69 of file massspectrum.h.

Constructor & Destructor Documentation

◆ MassSpectrum() [1/8]

pappso::MassSpectrum::MassSpectrum ( )

Definition at line 59 of file massspectrum.cpp.

60{
61}

Referenced by MassSpectrum(), MassSpectrum(), equals(), filterSum(), operator=(), and operator=().

◆ MassSpectrum() [2/8]

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

Definition at line 64 of file massspectrum.cpp.

65 : Trace::Trace(data_point_vector)
66{
67}

References pappso::Trace::Trace().

◆ MassSpectrum() [3/8]

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

Definition at line 69 of file massspectrum.cpp.

70 : Trace::Trace(data_point_vector)
71{
72}

References pappso::Trace::Trace().

◆ MassSpectrum() [4/8]

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

Definition at line 78 of file massspectrum.cpp.

78 : Trace(other)
79{
80}

References pappso::Trace::Trace().

◆ MassSpectrum() [5/8]

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

Definition at line 74 of file massspectrum.cpp.

74 : Trace(other)
75{
76}

References pappso::Trace::Trace().

◆ MassSpectrum() [6/8]

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

Definition at line 83 of file massspectrum.cpp.

83 : Trace(std::move(other))
84{
85}

References pappso::Trace::Trace().

◆ MassSpectrum() [7/8]

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

Definition at line 88 of file massspectrum.cpp.

88 : Trace(other)
89{
90 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()";
91}

References MassSpectrum(), and pappso::Trace::Trace().

◆ MassSpectrum() [8/8]

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

Definition at line 94 of file massspectrum.cpp.

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

References MassSpectrum(), and pappso::Trace::Trace().

◆ ~MassSpectrum()

pappso::MassSpectrum::~MassSpectrum ( )
virtual

Definition at line 104 of file massspectrum.cpp.

105{
106}

Member Function Documentation

◆ debugPrintValues()

void pappso::MassSpectrum::debugPrintValues ( ) const

Definition at line 327 of file massspectrum.cpp.

328{
329
330 qDebug() << size();
331 for(std::size_t i = 0; i < size(); i++)
332 {
333 qDebug() << "(" << this->operator[](i).x << "," << this->operator[](i).y << ")";
334 }
335}

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

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

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

◆ filterSum()

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

Definition at line 261 of file massspectrum.cpp.

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

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

◆ makeMassSpectrumCstSPtr()

MassSpectrumCstSPtr pappso::MassSpectrum::makeMassSpectrumCstSPtr ( ) const

Definition at line 135 of file massspectrum.cpp.

136{
137 return std::make_shared<const MassSpectrum>(*this);
138}

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

395{
396 return filter.filter(*this);
397}
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition trace.cpp:1185

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

181{
182 return Trace::maxYDataPoint();
183}
const DataPoint & maxYDataPoint() const
Definition trace.cpp:966

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

193{
194 return Trace::minYDataPoint();
195}
const DataPoint & minYDataPoint() const
Definition trace.cpp:950

References pappso::Trace::minYDataPoint().

◆ operator=() [1/4]

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

Definition at line 110 of file massspectrum.cpp.

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

References MassSpectrum().

◆ operator=() [2/4]

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

Reimplemented from pappso::Trace.

Definition at line 182 of file trace.cpp.

667{
668 assign(other.begin(), other.end());
669
670 return *this;
671}

◆ operator=() [3/4]

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

Definition at line 120 of file massspectrum.cpp.

121{
122 vector<DataPoint>::operator=(std::move(other));
123 return *this;
124}

References MassSpectrum().

◆ operator=() [4/4]

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

Reimplemented from pappso::Trace.

Definition at line 183 of file trace.cpp.

676{
677 vector<DataPoint>::operator=(std::move(other));
678 return *this;
679}

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

205{
206 Trace::sortX();
207}
void sortX(Enums::SortOrder sort_order=Enums::SortOrder::ascending)
Definition trace.cpp:1071

References pappso::Trace::sortX().

Referenced by pappso::MzIntegrationParams::createDataBasedBins(), pappso::MzIntegrationParams::createDataBasedBinsOld(), 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 161 of file massspectrum.cpp.

162{
163 return totalIonCurrent();
164}
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 168 of file massspectrum.cpp.

169{
170 return Trace::sumY(mzStart, mzEnd);
171}
pappso_double sumY() const
Definition trace.cpp:1010

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

151{
152 return Trace::sumY();
153}

References pappso::Trace::sumY().

Referenced by tic().


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