47 #include "../../utils.h"
48 #include "../../massspectrum/massspectrum.h"
80 bool removeZeroValDataPoints)
81 : m_smallestMz(minMz),
83 m_binningType(binningType),
84 m_decimalPlaces(decimalPlaces),
85 mp_precision(precisionPtr),
86 m_applyMzShift(applyMzShift),
88 m_removeZeroValDataPoints(removeZeroValDataPoints)
96 : m_smallestMz(other.m_smallestMz),
97 m_greatestMz(other.m_greatestMz),
98 m_binningType(other.m_binningType),
99 m_decimalPlaces(other.m_decimalPlaces),
100 mp_precision(other.mp_precision),
101 m_applyMzShift(other.m_applyMzShift),
102 m_mzShift(other.m_mzShift),
103 m_removeZeroValDataPoints(other.m_removeZeroValDataPoints)
291 errors += (
m_smallestMz == std::numeric_limits<double>::max() ? 1 : 0);
296 errors += (
m_greatestMz == std::numeric_limits<double>::min() ? 1 : 0);
307 <<
"The m/z integration parameters are not valid or do not apply...";
317 return (
m_smallestMz != std::numeric_limits<double>::max()) &&
328 std::vector<double> bins;
344 qFatal(
"Programming error.");
357 std::vector<double> bins;
422 double first_mz = ceil((min_mz * std::pow(10,
m_decimalPlaces)) - 0.49) /
434 std::vector<pappso::pappso_double> bins;
447 bins.push_back(previous_mz_bin);
456 while(previous_mz_bin <= last_mz)
473 double current_rounded_mz =
487 if(current_rounded_mz == previous_mz_bin)
496 <<
"Had to increment decimal places by one while creating the bins "
497 "in BinningType::ARBITRARY mode..";
500 bins.push_back(current_rounded_mz);
503 previous_mz_bin = current_rounded_mz;
509 QString fileName =
"/tmp/massSpecArbitraryBins.txt-at-" +
510 QDateTime::currentDateTime().toString(
"yyyyMMdd-HH-mm-ss");
512 qDebug() <<
"Writing the list of bins setup in the "
513 "mass spectrum in file "
516 QFile file(fileName);
517 file.open(QIODevice::WriteOnly);
519 QTextStream fileStream(&file);
521 for(
auto &&bin : bins)
522 fileStream << QString(
"%1\n").arg(bin, 0,
'f', 10);
548 std::vector<pappso::pappso_double> bins;
550 if(mass_spectrum_csp->size() < 2)
557 local_mass_spectrum.
sortMz();
578 std::vector<pappso::DataPoint>::const_iterator it =
579 local_mass_spectrum.begin();
589 while(it != local_mass_spectrum.end())
598 end_mz_out = start_mz_in + step;
609 bins.push_back(start_mz_in);
612 start_mz_in = end_mz_out;
623 QString fileName =
"/tmp/massSpecDataBasedBins.txt";
625 qDebug() <<
"Writing the list of bins setup in the "
626 "mass spectrum in file "
629 QFile file(fileName);
630 file.open(QIODevice::WriteOnly);
632 QTextStream fileStream(&file);
634 for(
auto &&bin : m_bins)
635 fileStream << QString(
"[%1-%2]\n")
636 .arg(bin.startMzIn, 0,
'f', 10)
637 .arg(bin.endMzOut, 0,
'f', 10);
642 qDebug() <<
"elements."
643 <<
"starting with mz" << m_bins.front().startMzIn <<
"ending with mz"
644 << m_bins.back().endMzOut;
657 for(
int iter = 0; iter < offset; ++iter)
661 text +=
"m/z integration parameters:\n";
667 QString::asprintf(
"Smallest (first) m/z: %.6f\n",
m_smallestMz));
672 text.append(QString::asprintf(
"Greatest (last) m/z: %.6f\n",
m_greatestMz));
678 std::map<BinningType, QString>::iterator it;
682 qFatal(
"Programming error.");
686 text.append(QString(
"Binning type: %1\n").arg(it->second.toLatin1().data()));
695 text.append(QString(
"Bin nominal size: %1\n")
701 text.append(QString(
"Bin size: %2\n")
710 QString(
"Apply m/z shift: %1\n").arg(
m_applyMzShift ?
"true" :
"false");
717 text += QString(
"m/z shift: %1").arg(
m_mzShift, 0,
'f', 6);
722 text += QString(
"Remove 0-val data points: %1\n")
Class to represent a mass spectrum.
void sortMz()
Sort the DataPoint instances of this spectrum.
The MzIntegrationParams class provides the parameters definining how m/z !
BinningType getBinningType() const
int getDecimalPlaces() const
pappso::pappso_double getSmallestMz() const
pappso::pappso_double m_smallestMz
MzIntegrationParams & operator=(const MzIntegrationParams &other)
BinningType m_binningType
pappso::pappso_double getGreatestMz() const
pappso::pappso_double m_greatestMz
pappso::PrecisionPtr getPrecision() const
bool isApplyMzShift() const
std::vector< double > createArbitraryBins()
void setPrecision(pappso::PrecisionPtr precisionPtr)
double getMzShift() const
void updateSmallestMz(pappso::pappso_double value)
void updateGreatestMz(pappso::pappso_double value)
bool isRemoveZeroValDataPoints() const
bool hasValidMzRange() const
QString toString(int offset=0, const QString &spacer=QString()) const
pappso::PrecisionPtr mp_precision
void setSmallestMz(pappso::pappso_double value)
bool m_removeZeroValDataPoints
void setBinningType(BinningType binningType)
void reset()
Reset the instance to default values.
std::vector< double > createDataBasedBins(pappso::MassSpectrumCstSPtr massSpectrum)
void setApplyMzShift(bool applyMzShift)
void setDecimalPlaces(int decimal_places)
std::vector< pappso::pappso_double > createBins()
void setMzShift(double value)
void setRemoveZeroValDataPoints(bool removeOrNot=true)
virtual ~MzIntegrationParams()
void setGreatestMz(pappso::pappso_double value)
pappso::pappso_double m_mzShift
virtual QString toString() const =0
virtual pappso_double getNominal() const final
virtual pappso_double delta(pappso_double value) const =0
static PrecisionPtr getPpmInstance(pappso_double value)
get a ppm precision pointer
static PrecisionPtr getDaltonInstance(pappso_double value)
get a Dalton precision pointer
static int zeroDecimalsInValue(pappso_double value)
0.11 would return 0 (no empty decimal) 2.001 would return 2 1000.0001254 would return 3
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
BinningType
Type of binning when performing integrations to a mass spectrum.
@ DATA_BASED
binning based on mass spectral data
@ ARBITRARY
binning based on arbitrary bin size value
double pappso_double
A type definition for doubles.
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
std::map< BinningType, QString > binningTypeMap
Map relating the BinningType to a textual representation.