47#include "../../utils.h"
48#include "../../massspectrum/massspectrum.h"
56 qRegisterMetaType<pappso::MzIntegrationParams>(
"pappso::MzIntegrationParams");
58 qRegisterMetaType<pappso::MzIntegrationParams *>(
"pappso::MzIntegrationParams *");
73 std::map<BinningType, QString>::const_iterator the_iterator_const =
75 (
const std::pair<BinningType, QString> &pair)
77 return pair.second == text;
81 return the_iterator_const->first;
104 bool removeZeroValDataPoints)
105 : m_smallestMz(minMz),
107 m_binningType(binningType),
108 m_decimalPlaces(decimalPlaces),
109 mp_binSizeModel(precisionPtr),
110 m_binSizeDivisor(binSizeDivisor),
111 m_removeZeroValDataPoints(removeZeroValDataPoints)
121 : m_smallestMz(other.m_smallestMz),
122 m_greatestMz(other.m_greatestMz),
123 m_binningType(other.m_binningType),
124 m_decimalPlaces(other.m_decimalPlaces),
125 mp_binSizeModel(other.mp_binSizeModel),
126 m_binSizeDivisor(other.m_binSizeDivisor),
127 m_removeZeroValDataPoints(other.m_removeZeroValDataPoints)
163 bool smallest_mz_set =
false;
164 bool greatest_mz_set =
false;
165 bool binning_type_set =
false;
166 bool decimal_places_set =
false;
167 bool bin_size_model_set =
false;
168 bool bin_size_divisor_set =
false;
169 bool remove_zero_data_points_set =
false;
171 QStringList string_list = text.split(
"\n");
173 for(
int iter = 0; iter < string_list.size(); ++iter)
175 QString iter_string = string_list.at(iter);
177 qDebug() <<
"Iterating in string:" << iter_string;
179 if(iter_string.contains(
"Smallest (first) m/z:"))
181 smallest_mz_set =
true;
182 m_smallestMz = iter_string.split(
':').last().toDouble();
184 else if(iter_string.contains(
"Greatest (last) m/z:"))
186 greatest_mz_set =
true;
187 m_greatestMz = iter_string.split(
':').last().toDouble();
189 else if(iter_string.contains(
"Decimal places:"))
191 decimal_places_set =
true;
194 else if(iter_string.contains(
"Binning type:"))
197 binning_type_set =
true;
199 else if(iter_string.contains(
"Bin size model:"))
202 bin_size_model_set =
true;
204 else if(iter_string.contains(
"Bin size divisor:"))
206 bin_size_divisor_set =
true;
209 else if(iter_string.contains(
"Remove 0-val data points:"))
211 remove_zero_data_points_set =
true;
220 if(smallest_mz_set && greatest_mz_set && decimal_places_set && binning_type_set &&
221 bin_size_model_set && bin_size_divisor_set && remove_zero_data_points_set)
224 if(decimal_places_set && binning_type_set &&
225 bin_size_model_set && bin_size_divisor_set && remove_zero_data_points_set)
228 if(binning_type_set &&
402 errors += (
m_smallestMz == std::numeric_limits<double>::max() ? 1 : 0);
407 errors += (
m_greatestMz == std::numeric_limits<double>::min() ? 1 : 0);
417 qDebug() <<
"The m/z integration parameters are not valid or do not apply...";
427 return (
m_smallestMz != std::numeric_limits<double>::max()) &&
438 std::vector<double> bins;
454 qFatal(
"Programming error.");
467 std::vector<double> bins;
558 std::vector<pappso::pappso_double> bins;
571 bins.push_back(previous_mz_bin);
580 while(previous_mz_bin <= last_mz)
612 double current_rounded_mz =
625 if(current_rounded_mz == previous_mz_bin)
637 bins.push_back(current_rounded_mz);
640 previous_mz_bin = current_rounded_mz;
646 QString fileName =
"/tmp/massSpecArbitraryBins.txt-at-" +
647 QDateTime::currentDateTime().toString(
"yyyyMMdd-HH-mm-ss");
649 qDebug() <<
"Writing the list of bins setup in the "
650 "mass spectrum in file "
653 QFile file(fileName);
654 file.open(QIODevice::WriteOnly);
656 QTextStream fileStream(&file);
658 for(
auto &&bin : bins)
659 fileStream << QString(
"%1\n").arg(bin, 0,
'f', 10);
684 std::vector<pappso::pappso_double> bins;
686 if(mass_spectrum_csp->size() < 2)
693 local_mass_spectrum.
sortMz();
713 std::vector<pappso::DataPoint>::const_iterator it = local_mass_spectrum.begin();
722 while(it != local_mass_spectrum.end())
730 end_mz_out = start_mz_in + step;
741 bins.push_back(start_mz_in);
744 start_mz_in = end_mz_out;
755 QString fileName =
"/tmp/massSpecDataBasedBins.txt";
757 qDebug() <<
"Writing the list of bins setup in the "
758 "mass spectrum in file "
761 QFile file(fileName);
762 file.open(QIODevice::WriteOnly);
764 QTextStream fileStream(&file);
766 for(
auto &&bin : m_bins)
767 fileStream << QString(
"[%1-%2]\n")
768 .arg(bin.startMzIn, 0,
'f', 10)
769 .arg(bin.endMzOut, 0,
'f', 10);
774 qDebug() <<
"elements."
775 <<
"starting with mz" << m_bins.front().startMzIn <<
"ending with mz"
776 << m_bins.back().endMzOut;
789 for(
int iter = 0; iter < offset; ++iter)
793 text +=
"m/z integration parameters:\n";
798 text.append(QString::asprintf(
"Smallest (first) m/z: %.6f\n",
m_smallestMz));
803 text.append(QString::asprintf(
"Greatest (last) m/z: %.6f\n",
m_greatestMz));
809 std::map<BinningType, QString>::iterator it;
813 qFatal(
"Programming error.");
817 text.append(QString(
"Binning type: %1\n").arg(it->second.toLatin1().data()));
855 text.append(QString::asprintf(
"Smallest (first) m/z:%.6f\n",
m_smallestMz));
857 text.append(QString::asprintf(
"Greatest (last) m/z:%.6f\n",
m_greatestMz));
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
Q_INVOKABLE void setBinSizeModel(pappso::PrecisionPtr bin_size_model)
pappso::pappso_double m_smallestMz
MzIntegrationParams & operator=(const MzIntegrationParams &other)
int getBinSizeDivisor() const
BinningType m_binningType
Q_INVOKABLE pappso::pappso_double getGreatestMz() const
InitializationResult initialize(const QString &text)
pappso::pappso_double m_greatestMz
Q_INVOKABLE MzIntegrationParams()
void setBinSizeDivisor(int divisor)
std::vector< double > createArbitraryBins()
@ FROM_SETTINGS_BIN_SIZE_MODEL_FULL
@ FROM_SETTINGS_BIN_SIZE_MODEL_PARTIAL
pappso::PrecisionPtr mp_binSizeModel
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 pappso::PrecisionPtr getBinSizeModel() const
Q_INVOKABLE bool hasValidMzRange() const
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 QString toString() const
Q_INVOKABLE void setDecimalPlaces(int decimal_places)
Q_INVOKABLE std::vector< pappso::pappso_double > createBins()
Q_INVOKABLE void setRemoveZeroValDataPoints(bool removeOrNot=true)
virtual ~MzIntegrationParams()
Q_INVOKABLE void setGreatestMz(pappso::pappso_double value)
virtual QString toString() const =0
virtual pappso_double getNominal() const final
virtual pappso_double delta(pappso_double value) const =0
virtual PrecisionUnit unit() const =0
static PrecisionPtr getResInstance(pappso_double value)
get a resolution precision pointer
static PrecisionPtr fromString(const QString &str)
get a precision pointer from a string
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 getBinningTypeFromString(const QString &text)
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.