47#include "../../utils.h"
48#include "../../massspectrum/massspectrum.h"
56 qRegisterMetaType<pappso::MzIntegrationParams>(
"pappso::MzIntegrationParams");
58 qRegisterMetaType<pappso::MzIntegrationParams *>(
59 "pappso::MzIntegrationParams *");
87 bool removeZeroValDataPoints)
88 : m_smallestMz(minMz),
90 m_binningType(binningType),
91 m_decimalPlaces(decimalPlaces),
92 mp_precision(precisionPtr),
93 m_applyMzShift(applyMzShift),
95 m_removeZeroValDataPoints(removeZeroValDataPoints)
103 : m_smallestMz(other.m_smallestMz),
104 m_greatestMz(other.m_greatestMz),
105 m_binningType(other.m_binningType),
106 m_decimalPlaces(other.m_decimalPlaces),
107 mp_precision(other.mp_precision),
108 m_applyMzShift(other.m_applyMzShift),
109 m_mzShift(other.m_mzShift),
110 m_removeZeroValDataPoints(other.m_removeZeroValDataPoints)
298 errors += (
m_smallestMz == std::numeric_limits<double>::max() ? 1 : 0);
303 errors += (
m_greatestMz == std::numeric_limits<double>::min() ? 1 : 0);
314 <<
"The m/z integration parameters are not valid or do not apply...";
324 return (
m_smallestMz != std::numeric_limits<double>::max()) &&
335 std::vector<double> bins;
351 qFatal(
"Programming error.");
364 std::vector<double> bins;
414 qDebug() <<
"Now checking how many decimal places are needed.";
432 double first_mz = ceil((min_mz * std::pow(10,
m_decimalPlaces)) - 0.49) /
444 std::vector<pappso::pappso_double> bins;
457 bins.push_back(previous_mz_bin);
466 while(previous_mz_bin <= last_mz)
488 double current_rounded_mz =
502 if(current_rounded_mz == previous_mz_bin)
515 bins.push_back(current_rounded_mz);
518 previous_mz_bin = current_rounded_mz;
524 QString fileName =
"/tmp/massSpecArbitraryBins.txt-at-" +
525 QDateTime::currentDateTime().toString(
"yyyyMMdd-HH-mm-ss");
527 qDebug() <<
"Writing the list of bins setup in the "
528 "mass spectrum in file "
531 QFile file(fileName);
532 file.open(QIODevice::WriteOnly);
534 QTextStream fileStream(&file);
536 for(
auto &&bin : bins)
537 fileStream << QString(
"%1\n").arg(bin, 0,
'f', 10);
563 std::vector<pappso::pappso_double> bins;
565 if(mass_spectrum_csp->size() < 2)
572 local_mass_spectrum.
sortMz();
593 std::vector<pappso::DataPoint>::const_iterator it =
594 local_mass_spectrum.begin();
604 while(it != local_mass_spectrum.end())
613 end_mz_out = start_mz_in + step;
624 bins.push_back(start_mz_in);
627 start_mz_in = end_mz_out;
638 QString fileName =
"/tmp/massSpecDataBasedBins.txt";
640 qDebug() <<
"Writing the list of bins setup in the "
641 "mass spectrum in file "
644 QFile file(fileName);
645 file.open(QIODevice::WriteOnly);
647 QTextStream fileStream(&file);
649 for(
auto &&bin : m_bins)
650 fileStream << QString(
"[%1-%2]\n")
651 .arg(bin.startMzIn, 0,
'f', 10)
652 .arg(bin.endMzOut, 0,
'f', 10);
657 qDebug() <<
"elements."
658 <<
"starting with mz" << m_bins.front().startMzIn <<
"ending with mz"
659 << m_bins.back().endMzOut;
672 for(
int iter = 0; iter < offset; ++iter)
676 text +=
"m/z integration parameters:\n";
682 QString::asprintf(
"Smallest (first) m/z: %.6f\n",
m_smallestMz));
687 text.append(QString::asprintf(
"Greatest (last) m/z: %.6f\n",
m_greatestMz));
693 std::map<BinningType, QString>::iterator it;
697 qFatal(
"Programming error.");
701 text.append(QString(
"Binning type: %1\n").arg(it->second.toLatin1().data()));
710 text.append(QString(
"Bin nominal size: %1\n")
716 text.append(QString(
"Bin size: %2\n")
725 QString(
"Apply m/z shift: %1\n").arg(
m_applyMzShift ?
"true" :
"false");
732 text += QString(
"m/z shift: %1").arg(
m_mzShift, 0,
'f', 6);
737 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 !
Q_INVOKABLE BinningType getBinningType() const
Q_INVOKABLE int getDecimalPlaces() const
pappso::pappso_double getSmallestMz() const
pappso::pappso_double m_smallestMz
MzIntegrationParams & operator=(const MzIntegrationParams &other)
BinningType m_binningType
Q_INVOKABLE pappso::pappso_double getGreatestMz() const
pappso::pappso_double m_greatestMz
Q_INVOKABLE MzIntegrationParams()
Q_INVOKABLE pappso::PrecisionPtr getPrecision() const
Q_INVOKABLE bool isApplyMzShift() const
std::vector< double > createArbitraryBins()
Q_INVOKABLE void setPrecision(pappso::PrecisionPtr precisionPtr)
Q_INVOKABLE double getMzShift() const
Q_INVOKABLE void updateSmallestMz(pappso::pappso_double value)
Q_INVOKABLE void updateGreatestMz(pappso::pappso_double value)
Q_INVOKABLE bool isRemoveZeroValDataPoints() const
Q_INVOKABLE bool isValid() const
Q_INVOKABLE bool hasValidMzRange() const
Q_INVOKABLE QString toString(int offset=0, const QString &spacer=QString()) const
pappso::PrecisionPtr mp_precision
Q_INVOKABLE void setSmallestMz(pappso::pappso_double value)
bool m_removeZeroValDataPoints
Q_INVOKABLE void setBinningType(BinningType binningType)
Q_INVOKABLE void reset()
Reset the instance to default values.
std::vector< double > createDataBasedBins(pappso::MassSpectrumCstSPtr massSpectrum)
Q_INVOKABLE void setApplyMzShift(bool applyMzShift)
Q_INVOKABLE void setDecimalPlaces(int decimal_places)
Q_INVOKABLE std::vector< pappso::pappso_double > createBins()
Q_INVOKABLE void setMzShift(double value)
Q_INVOKABLE void setRemoveZeroValDataPoints(bool removeOrNot=true)
virtual ~MzIntegrationParams()
Q_INVOKABLE 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
int mzIntegrationParamsMetaTypeId
int mzIntegrationParamsPtrMetaTypeId
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.