70 std::map<MzIntegrationParams::MzIntegrationParams::BinningType,
71 QString>::const_iterator the_iterator_const =
75 [text](
const std::pair<MzIntegrationParams::BinningType, QString> &pair) {
76 return pair.second == text;
80 return the_iterator_const->first;
100 int bin_size_divisor,
102 bool remove_zero_val_data_points,
136 return mz_integration_params_p;
147 return initialization_result;
158 bool binning_type_set =
false;
159 bool decimal_places_set =
false;
160 bool bin_size_model_set =
false;
161 bool bin_size_divisor_set =
false;
162 bool remove_zero_data_points_set =
false;
164 QStringList string_list = text.split(
"\n");
166 for(
int iter = 0; iter < string_list.size(); ++iter)
168 QString iter_string = string_list.at(iter);
172 if(iter_string.contains(
"Binning type:"))
176 binning_type_set =
true;
178 else if(iter_string.contains(
"Bin size model:"))
182 bin_size_model_set =
true;
184 else if(iter_string.contains(
"Bin size divisor:"))
187 bin_size_divisor_set =
true;
189 else if(iter_string.contains(
"Decimal places:"))
192 decimal_places_set =
true;
194 else if(iter_string.contains(
"Remove 0-val data points:"))
197 remove_zero_data_points_set =
true;
207 if(bin_size_model_set)
209 if(bin_size_divisor_set)
211 if(decimal_places_set)
214 if(remove_zero_data_points_set)
217 return initialization_result;
225 int bin_size_divisor,
227 bool remove_zero_val_data_points,
261 Q_ASSERT(other_p !=
nullptr);
272 if(
static_cast<bool>(
273 initialization_results &
277 if(
static_cast<bool>(
278 initialization_results &
282 if(
static_cast<bool>(
283 initialization_results &
287 if(
static_cast<bool>(
288 initialization_results &
475 errors += (
m_smallestMz == std::numeric_limits<double>::max() ? 1 : 0);
480 errors += (
m_greatestMz == std::numeric_limits<double>::min() ? 1 : 0);
485 qCritical() <<
"The m/z integration parameters are invalid.";
494 return (
m_smallestMz < std::numeric_limits<double>::max()) &&
503 std::vector<double> bins;
517 qFatal() <<
"Programming error. "
518 "Please use the createBins(pappso::MassSpectrumCstSPtr "
519 "mass_spectrum_csp) overload.";
530 std::vector<double> bins;
561 qFatal() <<
"Programming error. The MzIntegrationParams::BinningLogic is "
562 "not valid, cannot create bins.";
566 qDebug() << qSetRealNumberPrecision(6) <<
"The smallest and greatest m/z values:" <<
m_smallestMz
587 std::vector<double> bins;
597 qDebug() << qSetRealNumberPrecision(6)
598 <<
"The indicative bin size is being used:" << bin_size;
602 double half_way_mz = 0;
606 <<
"half_way_mz:" << half_way_mz;
608 qDebug() << qSetRealNumberPrecision(6)
609 <<
"The m/z range half way strategy is being used for bin size:" << bin_size;
615 qDebug() << qSetRealNumberPrecision(6) <<
"The normally computed bin size:" << bin_size;
618 qDebug() << qSetRealNumberPrecision(6) <<
"The bin size was computed to be" << bin_size;
632 qDebug() <<
"With binSize" << bin_size
645 qDebug() << qSetRealNumberPrecision(10)
646 <<
"After having accounted for the decimals, new min/max values:"
647 <<
"Very first data point to start from:" << first_mz
648 <<
"Very last data point to reach: " << last_mz;
650 double previous_mz_bin;
661 bins.push_back(first_mz);
668 bins.push_back(bin_size);
669 previous_mz_bin = bin_size;
673 previous_mz_bin = first_mz;
685 while(previous_mz_bin <= last_mz)
708 if(current_rounded_mz == previous_mz_bin)
712 qDebug() <<
"It was required to increment decimal places to" <<
m_decimalPlaces;
717 qDebug().noquote() <<
"Because current rounded mz is equal to previous mz bin, we had to "
718 "increment decimal places by one while creating the bins "
719 "in MzIntegrationParams::BinningType::ARBITRARY mode.";
722 bins.push_back(current_rounded_mz);
729 previous_mz_bin = current_rounded_mz;
736 QString file_name =
"/tmp/massSpecArbitraryBins.txt-at-" +
737 QDateTime::currentDateTime().toString(
"yyyyMMdd-HH-mm-ss");
739 qDebug() <<
"Writing the list of bins setup in the mass spectrum in file " << file_name;
745 qDebug() <<
"Prepared " << bins.size() <<
"arbitrary bins starting with mz" << bins.front()
746 <<
"ending with mz" << bins.back();
764 QList<double> deltas;
765 QList<double> resolutions;
767 double left_mz_value = 0;
768 double right_mz_value = 0;
770 double resolution = 0;
773 if(mass_spectrum_csp->size() < 3)
775 std::vector<double> bins_vector(bins.constBegin(), bins.constEnd());
783 mass_spectrum_copy.
sortMz();
785 std::vector<pappso::DataPoint>::const_iterator iterator_const =
786 mass_spectrum_copy.cbegin();
789 left_mz_value = iterator_const->x;
795 qDebug() << qSetRealNumberPrecision(6)
796 <<
"left_mz_value in the template mass spectrum:" << left_mz_value;
798 bins.append(left_mz_value);
803 resolutions.append(0.0);
807 while(iterator_const != mass_spectrum_copy.cend())
809 right_mz_value = iterator_const->x;
811 qDebug() << qSetRealNumberPrecision(6)
812 <<
"right_mz_value:" << right_mz_value;
818 bins.append(right_mz_value);
820 mz_delta = right_mz_value - left_mz_value;
821 deltas.append(mz_delta);
822 Q_ASSERT(mz_delta != 0.0);
824 resolution = right_mz_value / mz_delta;
825 resolutions.append(resolution);
827 left_mz_value = right_mz_value;
837 std::vector<double> bins_vector(bins.constBegin(), bins.constEnd());
842 "/tmp/massSpecDataBasedTemplateBinsWithDeltas.txt-at-" +
843 QDateTime::currentDateTime().toString(
"yyyyMMdd-HH-mm-ss");
874 bool uniform_deltas =
false;
875 std::size_t deltas_count = deltas.size();
877 double first_delta = deltas.at(1);
878 double middle_delta = deltas.at(deltas_count / 2);
879 double last_delta = deltas.at(deltas_count - 1);
881 if(first_delta == middle_delta && middle_delta == last_delta)
882 uniform_deltas =
true;
890 bool uniform_resolutions =
false;
891 std::size_t resolutions_count = resolutions.size();
893 double first_resolution = resolutions.at(01);
894 double middle_resolution = resolutions.at(resolutions_count / 2);
895 double last_resolution = resolutions.at(resolutions_count - 1);
897 if(first_resolution == middle_resolution &&
898 middle_resolution == last_resolution)
899 uniform_resolutions =
true;
916 double first_bin_mz = bins.first();
917 double last_bin_mz = bins.last();
945 double bin_mz = first_bin_mz;
953 double new_bin_mz = bin_mz - first_delta;
954 bins.prepend(new_bin_mz);
958 else if(uniform_resolutions)
964 double new_bin_mz = bin_mz - (bin_mz / first_resolution);
965 bins.prepend(new_bin_mz);
983 double bin_mz = last_bin_mz;
991 double new_bin_mz = bin_mz + first_delta;
992 bins.append(new_bin_mz);
996 else if(uniform_resolutions)
1002 double new_bin_mz = bin_mz + (bin_mz / first_resolution);
1003 bins.append(new_bin_mz);
1004 bin_mz = new_bin_mz;
1014 std::vector<double> full_bins_vector(bins.constBegin(), bins.constEnd());
1020 file_name =
"/tmp/massSpecDataBasedFullBinsWithDeltas.txt-at-" +
1021 QDateTime::currentDateTime().toString(
"yyyyMMdd-HH-mm-ss");
1023 qDebug() <<
"Writing the list of bins setup in the mass spectrum in file "
1034 return full_bins_vector;
1045 std::vector<double> bins;
1047 if(mass_spectrum_csp->size() < 2)
1054 sorted_mass_spectrum.
sortMz();
1068 double start_mz_in = min_mz;
1074 std::vector<pappso::DataPoint>::const_iterator it =
1075 sorted_mass_spectrum.begin();
1077 double prev_mz = it->x;
1085 while(it != sorted_mass_spectrum.end())
1087 double next_mz = it->x;
1093 double step = next_mz - prev_mz;
1094 end_mz_out = start_mz_in + step;
1105 bins.push_back(start_mz_in);
1108 start_mz_in = end_mz_out;
1119 QString fileName =
"/tmp/massSpecDataBasedBins.txt";
1121 qDebug() <<
"Writing the list of bins setup in the "
1122 "mass spectrum in file "
1125 QFile file(fileName);
1126 file.open(QIODevice::WriteOnly);
1128 QTextStream fileStream(&file);
1130 for(
auto &&bin : m_bins)
1131 fileStream << QString(
"[%1-%2]\n")
1132 .arg(bin.startMzIn, 0,
'f', 10)
1133 .arg(bin.endMzOut, 0,
'f', 10);
1138 qDebug() <<
"elements."
1139 <<
"starting with mz" << m_bins.front().startMzIn <<
"ending with mz"
1140 << m_bins.back().endMzOut;
1154 QString offset_lead;
1156 for(
int iter = 0; iter < offset; ++iter)
1157 offset_lead += spacer;
1159 QString text = offset_lead;
1160 text +=
"m/z integration parameters:\n";
1162 QString new_lead = QString(
"%1%2").arg(offset_lead, spacer);
1167 QString::asprintf(
"Smallest (first) m/z: %.6f\n",
m_smallestMz));
1171 text.append(QString::asprintf(
"Greatest (last) m/z: %.6f\n",
m_greatestMz));
1174 text += QString(
"Remove 0-val data points: %1\n")
1178 text.append(
"Binning logic:\n");
1187 text.append(QString(
"Bin size model: %1\n").arg(
m_binSizeModel->toString()));
1207 text.append(QString(
"Bin size model: %1\n").arg(
m_binSizeModel->toString()));
1220 const std::vector<double> bins)
const
1222 QString bins_with_delta;
1223 double previous_bin_value = 0;
1225 for(
auto &&value : bins)
1227 double delta = value - previous_bin_value;
1228 bins_with_delta += QString(
"%1 - %2\n")
1231 previous_bin_value = value;
1234 return bins_with_delta;
1242 if(engine ==
nullptr)
1244 qFatal() <<
"Cannot register class: engine is null";
1247 QJSValue pappso_root_property;
1248 QJSValue pappso_enums_property;
1250 if(engine->globalObject().hasProperty(
"pappso"))
1252 qDebug() <<
"Global object property 'pappso' already exists.";
1253 pappso_root_property = engine->globalObject().property(
"pappso");
1255 if(pappso_root_property.hasProperty(
"Enums"))
1257 pappso_enums_property = pappso_root_property.property(
"Enums");
1261 pappso_enums_property = engine->newObject();
1262 pappso_root_property.setProperty(
"Enums", pappso_enums_property);
1267 qDebug() <<
"Global object property 'pappso' not found.";
1268 pappso_root_property = engine->newObject();
1269 pappso_enums_property = engine->newObject();
1270 pappso_root_property.setProperty(
"Enums", pappso_enums_property);
1271 engine->globalObject().setProperty(
"pappso", pappso_root_property);
1274 QJSValue enumObject;
1277 enumObject = engine->newObject();
1279 enumObject.setProperty(
1281 enumObject.setProperty(
1284 enumObject.setProperty(
1288 pappso_enums_property.setProperty(
"BinningType", enumObject);
1291 enumObject = engine->newObject();
1292 enumObject.setProperty(
1296 enumObject.setProperty(
1297 "fromSettingsBinSizeModelPartial",
1300 enumObject.setProperty(
1301 "fromSettingsBinSizeModelFull",
1304 enumObject.setProperty(
1308 pappso_enums_property.setProperty(
"InitializationResult", enumObject);
1311 QJSValue jsMetaObject =
1312 engine->newQMetaObject(&MzIntegrationParams::staticMetaObject);
1313 engine->globalObject().setProperty(
"MzIntegrationParams", jsMetaObject);
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 integrations must be perform...
void binSizeDivisorChanged()
Q_INVOKABLE int getDecimalPlaces() const
@ REMOVE_ZERO_DATA_POINTS
Q_INVOKABLE MzIntegrationParams(QObject *parent=nullptr)
Q_INVOKABLE void updateGreatestMz(double value)
void binSizeModelChanged()
Q_INVOKABLE int getBinSizeDivisor() const
double m_indicativeBinSize
BinningType m_binningType
Q_INVOKABLE void setIndicativeBinSize(double value)
Q_INVOKABLE InitializationResult initialize(const QString &text)
std::vector< double > createDataBasedBinsOld(pappso::MassSpectrumCstSPtr massSpectrum)
Q_INVOKABLE void setBinSizeModel(pappso::PrecisionPtr bin_size_model_p)
Q_INVOKABLE void setBinSizeDivisor(int divisor)
std::vector< double > createArbitraryBins()
Q_INVOKABLE double getIndicativeBinSize() const
Q_INVOKABLE void setGreatestMz(double value)
Q_INVOKABLE void setSmallestMz(double value)
Q_INVOKABLE QString binsToStringWithDeltas(const std::vector< double > bins) const
Q_INVOKABLE bool isRemoveZeroValDataPoints() const
Q_INVOKABLE double getSmallestMz() const
pappso::PrecisionPtr m_binSizeModel
Q_INVOKABLE bool isValid() const
void indicativeBinSizeChanged()
Q_INVOKABLE BinningType getBinningType() const
Q_INVOKABLE pappso::PrecisionPtr getBinSizeModel() const
Q_INVOKABLE bool hasValidMzRange() const
@ DATA_BASED
binning based on mass spectral data
@ ARBITRARY
binning based on arbitrary bin size value
void decimalPlacesChanged()
static void registerJsConstructor(QJSEngine *engine)
void removeZeroValDataPointsChanged()
Q_INVOKABLE void updateSmallestMz(double value)
void binningTypeChanged()
Q_INVOKABLE MzIntegrationParams * clone(QObject *parent=nullptr) const
Q_INVOKABLE void setMzValues(double smallest, double greatest)
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< double > createBins()
Q_INVOKABLE void setRemoveZeroValDataPoints(bool removeOrNot=true)
virtual ~MzIntegrationParams()
Q_INVOKABLE double getGreatestMz() const
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 double roundValueToDecimalPlaces(double value, int decimal_places, bool round_up=true)
static bool writeToFile(const QString &text, const QString &file_name)
static int zeroDecimalsInValue(pappso_double value)
Determine the number of zero decimals between the decimal point and the first non-zero decimal.
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
MzIntegrationParams::BinningType getBinningTypeFromString(const QString &text)
std::map< MzIntegrationParams::BinningType, QString > binningTypeMap
Map relating the BinningType to a textual representation.
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
const PrecisionBase * PrecisionPtr