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),
104 m_applySavGolFilter(other.m_applySavGolFilter)
295 int nL,
int nR,
int m,
int lD,
bool convolveWithNr)
359 errors += (
m_smallestMz == std::numeric_limits<double>::max() ? 1 : 0);
364 errors += (
m_greatestMz == std::numeric_limits<double>::min() ? 1 : 0);
375 <<
"The m/z integration parameters are not valid or do not apply...";
385 return (
m_smallestMz != std::numeric_limits<double>::max()) &&
396 std::vector<double> bins;
412 qFatal(
"Programming error.");
425 std::vector<double> bins;
490 double first_mz = ceil((min_mz * std::pow(10,
m_decimalPlaces)) - 0.49) /
502 std::vector<pappso::pappso_double> bins;
515 bins.push_back(previous_mz_bin);
524 while(previous_mz_bin <= last_mz)
541 double current_rounded_mz =
555 if(current_rounded_mz == previous_mz_bin)
564 <<
"Had to increment decimal places by one while creating the bins "
565 "in BinningType::ARBITRARY mode..";
568 bins.push_back(current_rounded_mz);
571 previous_mz_bin = current_rounded_mz;
577 QString fileName =
"/tmp/massSpecArbitraryBins.txt-at-" +
578 QDateTime::currentDateTime().toString(
"yyyyMMdd-HH-mm-ss");
580 qDebug() <<
"Writing the list of bins setup in the "
581 "mass spectrum in file "
584 QFile file(fileName);
585 file.open(QIODevice::WriteOnly);
587 QTextStream fileStream(&file);
589 for(
auto &&bin : bins)
590 fileStream << QString(
"%1\n").arg(bin, 0,
'f', 10);
616 std::vector<pappso::pappso_double> bins;
618 if(mass_spectrum_csp->size() < 2)
625 local_mass_spectrum.
sortMz();
646 std::vector<pappso::DataPoint>::const_iterator it =
647 local_mass_spectrum.begin();
657 while(it != local_mass_spectrum.end())
666 end_mz_out = start_mz_in + step;
677 bins.push_back(start_mz_in);
680 start_mz_in = end_mz_out;
691 QString fileName =
"/tmp/massSpecDataBasedBins.txt";
693 qDebug() <<
"Writing the list of bins setup in the "
694 "mass spectrum in file "
697 QFile file(fileName);
698 file.open(QIODevice::WriteOnly);
700 QTextStream fileStream(&file);
702 for(
auto &&bin : m_bins)
703 fileStream << QString(
"[%1-%2]\n")
704 .arg(bin.startMzIn, 0,
'f', 10)
705 .arg(bin.endMzOut, 0,
'f', 10);
710 qDebug() <<
"elements."
711 <<
"starting with mz" << m_bins.front().startMzIn <<
"ending with mz"
712 << m_bins.back().endMzOut;
725 for(
int iter = 0; iter < offset; ++iter)
729 text +=
"m/z integration parameters:\n";
735 QString::asprintf(
"Smallest (first) m/z: %.6f\n",
m_smallestMz));
740 text.append(QString::asprintf(
"Greatest (last) m/z: %.6f\n",
m_greatestMz));
746 std::map<BinningType, QString>::iterator it;
750 qFatal(
"Programming error.");
754 text.append(QString(
"Binning type: %1\n").arg(it->second.toLatin1().data()));
763 text.append(QString(
"Bin nominal size: %1\n")
769 text.append(QString(
"Bin size: %2\n")
778 QString(
"Apply m/z shift: %1\n").arg(
m_applyMzShift ?
"true" :
"false");
785 text += QString(
"m/z shift: %1").arg(
m_mzShift, 0,
'f', 6);
790 text += QString(
"Remove 0-val data points: %1\n")
799 text.append(
"Savitzky-Golay parameters\n");
804 QString(
"nL = %1 ; nR = %2 ; m = %3 ; lD = %4 ; convolveWithNr = %5\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)
pappso::SavGolParams getSavGolParams() const
void setApplySavGolFilter(bool applySavGolFilter)
void updateGreatestMz(pappso::pappso_double value)
bool isRemoveZeroValDataPoints() const
bool isApplySavGolFilter() const
pappso::SavGolParams m_savGolParams
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)
void setSavGolParams(int nL=15, int nR=15, int m=4, int lD=0, bool convolveWithNr=false)
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.
Parameters for the Savitzky-Golay filter.
void initialize(int nLParam, int nRParam, int mParam, int lDParam, bool convolveWithNrParam)
int nR
number of data points on the right of the filtered point
int nL
number of data points on the left of the filtered point
bool convolveWithNr
set to false for best results