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;
430 double first_mz = ceil((min_mz * std::pow(10,
m_decimalPlaces)) - 0.49) /
442 std::vector<pappso::pappso_double> bins;
455 bins.push_back(previous_mz_bin);
464 while(previous_mz_bin <= last_mz)
486 double current_rounded_mz =
500 if(current_rounded_mz == previous_mz_bin)
513 bins.push_back(current_rounded_mz);
516 previous_mz_bin = current_rounded_mz;
522 QString fileName =
"/tmp/massSpecArbitraryBins.txt-at-" +
523 QDateTime::currentDateTime().toString(
"yyyyMMdd-HH-mm-ss");
525 qDebug() <<
"Writing the list of bins setup in the "
526 "mass spectrum in file "
529 QFile file(fileName);
530 file.open(QIODevice::WriteOnly);
532 QTextStream fileStream(&file);
534 for(
auto &&bin : bins)
535 fileStream << QString(
"%1\n").arg(bin, 0,
'f', 10);
561 std::vector<pappso::pappso_double> bins;
563 if(mass_spectrum_csp->size() < 2)
570 local_mass_spectrum.
sortMz();
591 std::vector<pappso::DataPoint>::const_iterator it =
592 local_mass_spectrum.begin();
602 while(it != local_mass_spectrum.end())
611 end_mz_out = start_mz_in + step;
622 bins.push_back(start_mz_in);
625 start_mz_in = end_mz_out;
636 QString fileName =
"/tmp/massSpecDataBasedBins.txt";
638 qDebug() <<
"Writing the list of bins setup in the "
639 "mass spectrum in file "
642 QFile file(fileName);
643 file.open(QIODevice::WriteOnly);
645 QTextStream fileStream(&file);
647 for(
auto &&bin : m_bins)
648 fileStream << QString(
"[%1-%2]\n")
649 .arg(bin.startMzIn, 0,
'f', 10)
650 .arg(bin.endMzOut, 0,
'f', 10);
655 qDebug() <<
"elements."
656 <<
"starting with mz" << m_bins.front().startMzIn <<
"ending with mz"
657 << m_bins.back().endMzOut;
670 for(
int iter = 0; iter < offset; ++iter)
674 text +=
"m/z integration parameters:\n";
680 QString::asprintf(
"Smallest (first) m/z: %.6f\n",
m_smallestMz));
685 text.append(QString::asprintf(
"Greatest (last) m/z: %.6f\n",
m_greatestMz));
691 std::map<BinningType, QString>::iterator it;
695 qFatal(
"Programming error.");
699 text.append(QString(
"Binning type: %1\n").arg(it->second.toLatin1().data()));
708 text.append(QString(
"Bin nominal size: %1\n")
714 text.append(QString(
"Bin size: %2\n")
723 QString(
"Apply m/z shift: %1\n").arg(
m_applyMzShift ?
"true" :
"false");
730 text += QString(
"m/z shift: %1").arg(
m_mzShift, 0,
'f', 6);
735 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.