605 qFatal() <<
"Programming error. The MzIntegrationParams::BinningLogic is "
614 qDebug() << qSetRealNumberPrecision(6) <<
"The smallest and greatest m/z values:" <<
m_smallestMz
631 double smallest_bin_size;
633 double half_way_mz = 0;
639 qDebug() <<
" Target min_mz:" << min_mz <<
"and max_mz:" << max_mz
640 <<
"half_way_mz:" << half_way_mz;
642 smallest_bin_size = bin_size;
647 smallest_bin_size = bin_size;
650 qDebug() << qSetRealNumberPrecision(6) <<
"The bin size was computed to be" << bin_size;
664 qDebug() <<
"With binSize" << bin_size
680 qDebug() << qSetRealNumberPrecision(10)
681 <<
"After having accounted for the decimals, new min/max values:"
682 <<
"Very first data point to start from:" << first_mz
683 <<
"Very last data point to reach : " << last_mz
688 std::vector<double> bins;
689 double previous_mz_bin;
696 qDebug() << qSetRealNumberPrecision(6) <<
"A lower anchor was set at" <<
m_lowerAnchorMz;
698 double lower_anchor_mz = std::round(
m_lowerAnchorMz * multiplier + 1e-9) / multiplier;
700 qDebug() << qSetRealNumberPrecision(6)
701 <<
"After decimals accounting, that lower anchor becomes:" << lower_anchor_mz;
704 double reverse_bin_creation_start_mz;
705 double reverse_bin_creation_stop_mz;
709 if(lower_anchor_mz < first_mz)
711 qDebug() <<
"Lower anchor m/z is smaller than min_mz.";
722 reverse_bin_creation_start_mz = first_mz;
723 reverse_bin_creation_stop_mz = lower_anchor_mz;
733 qDebug() <<
"Lower anchor m/z is greater than min_mz.";
735 reverse_bin_creation_start_mz = lower_anchor_mz;
736 reverse_bin_creation_stop_mz = first_mz;
740 first_mz = lower_anchor_mz;
743 QList<double> prepended_bins;
746 previous_mz_bin = reverse_bin_creation_start_mz;
753 qDebug() << qSetRealNumberPrecision(6)
754 <<
"The reverse_bin_creation_stop_mz value:" << reverse_bin_creation_stop_mz;
764 while(previous_mz_bin - reverse_bin_creation_stop_mz > smallest_bin_size)
766 qDebug() << qSetRealNumberPrecision(6)
767 <<
"previous_mz_bin - reverse_bin_creation_stop_mz:"
768 << previous_mz_bin - reverse_bin_creation_stop_mz;
776 double current_rounded_mz =
779 qDebug() << QString::asprintf(
780 "current_mz: %.6f and current_rounded_mz: %.6f and previous_mzBin: %.6f with delta: "
785 current_rounded_mz - previous_mz_bin);
790 if(current_rounded_mz == previous_mz_bin)
794 qDebug() <<
"It was required to increment decimal places to" <<
m_decimalPlaces;
808 prepended_bins.prepend(current_rounded_mz);
811 previous_mz_bin = current_rounded_mz;
817 bins.assign(prepended_bins.begin(), prepended_bins.end());
824 "/tmp/prependedMassSpecBins.txt-at-" +
825 QDateTime::currentDateTime().toString(
"yyyyMMdd-HH-mm-ss");
847 qDebug() << qSetRealNumberPrecision(6) <<
"An upper anchor was set at" <<
m_upperAnchorMz;
853 qDebug() << qSetRealNumberPrecision(6)
854 <<
"after decimals accounting, that upper anchor becomes:" << upper_anchor_mz;
856 if(upper_anchor_mz > last_mz)
858 qDebug() <<
"Since upper anchor m/z is greater than last_mz,"
859 "last_mz becomes upper_anchor_mz.";
861 last_mz = upper_anchor_mz;
885 previous_mz_bin = first_mz;
889 bins.push_back(previous_mz_bin);
891 qDebug() << qSetRealNumberPrecision(6) <<
"Pushed back first rounded mz:" << previous_mz_bin;
900 qDebug() <<
"Now starting the bin creation loop.";
902 while(previous_mz_bin <= last_mz)
919 double manual_delta = previous_mz_bin / 40000;
922 qDebug() << qSetRealNumberPrecision(50) <<
"The delta is:" << delta
923 <<
"and the corrected delta is:" << corrected_delta
924 <<
"while the manual delta is:" << manual_delta;
926 current_mz = previous_mz_bin + corrected_delta;
928 qDebug() << qSetRealNumberPrecision(6) <<
"previous mz bin: " << previous_mz_bin
929 <<
"and current mz: " << current_mz;
938 qDebug() << qSetRealNumberPrecision(50)
939 <<
"after rounding, current mz becomes: " << current_rounded_mz;
944 if(current_rounded_mz == previous_mz_bin)
948 qDebug() <<
"It was required to increment decimal places to" <<
m_decimalPlaces;
953 qDebug().noquote() <<
"Because current rounded mz is equal to previous mz bin, we had to "
954 "increment decimal places by one while creating the bins "
955 "in MzIntegrationParams::BinningType::ARBITRARY mode.";
958 bins.push_back(current_rounded_mz);
960 qDebug() << qSetRealNumberPrecision(50)
961 <<
"Pushed back current rounded mz:" << current_rounded_mz;
965 previous_mz_bin = current_rounded_mz;
972 QString file_name =
"/tmp/massSpecArbitraryBins.txt-at-" +
973 QDateTime::currentDateTime().toString(
"yyyyMMdd-HH-mm-ss");
975 qDebug() <<
"Writing the list of bins setup in the mass spectrum in file " << file_name;
981 qDebug() <<
"Prepared " << bins.size() <<
"arbitrary bins starting with mz" << bins.front()
982 <<
"ending with mz" << bins.back();
1000 QList<double> deltas;
1001 QList<double> resolutions;
1003 double left_mz_value = 0;
1004 double right_mz_value = 0;
1005 double mz_delta = 0;
1006 double resolution = 0;
1009 if(mass_spectrum_csp->size() < 3)
1011 std::vector<double> bins_vector(bins.constBegin(), bins.constEnd());
1019 mass_spectrum_copy.
sortMz();
1021 std::vector<pappso::DataPoint>::const_iterator iterator_const =
1022 mass_spectrum_copy.cbegin();
1025 left_mz_value = iterator_const->x;
1027 left_mz_value = ceil((left_mz_value * pow(10,
m_decimalPlaces)) - 0.49) /
1030 qDebug() << qSetRealNumberPrecision(6)
1031 <<
"left_mz_value in the template mass spectrum:" << left_mz_value;
1033 bins.append(left_mz_value);
1038 resolutions.append(0.0);
1042 while(iterator_const != mass_spectrum_copy.cend())
1044 right_mz_value = iterator_const->x;
1046 qDebug() << qSetRealNumberPrecision(6)
1047 <<
"right_mz_value:" << right_mz_value;
1054 bins.append(right_mz_value);
1056 mz_delta = right_mz_value - left_mz_value;
1057 deltas.append(mz_delta);
1058 Q_ASSERT(mz_delta != 0.0);
1060 resolution = right_mz_value / mz_delta;
1061 resolutions.append(resolution);
1063 left_mz_value = right_mz_value;
1073 std::vector<double> bins_vector(bins.constBegin(), bins.constEnd());
1078 "/tmp/massSpecDataBasedTemplateBinsWithDeltas.txt-at-" +
1079 QDateTime::currentDateTime().toString(
"yyyyMMdd-HH-mm-ss");
1110 bool uniform_deltas =
false;
1111 std::size_t deltas_count = deltas.size();
1113 double first_delta = deltas.at(1);
1114 double middle_delta = deltas.at(deltas_count / 2);
1115 double last_delta = deltas.at(deltas_count - 1);
1117 if(first_delta == middle_delta && middle_delta == last_delta)
1118 uniform_deltas =
true;
1126 bool uniform_resolutions =
false;
1127 std::size_t resolutions_count = resolutions.size();
1129 double first_resolution = resolutions.at(01);
1130 double middle_resolution = resolutions.at(resolutions_count / 2);
1131 double last_resolution = resolutions.at(resolutions_count - 1);
1133 if(first_resolution == middle_resolution &&
1134 middle_resolution == last_resolution)
1135 uniform_resolutions =
true;
1162 double first_bin_mz = bins.first();
1163 double last_bin_mz = bins.last();
1183 if(smallest_mz < first_bin_mz)
1194 double bin_mz = first_bin_mz;
1200 while(bin_mz > smallest_mz)
1202 double new_bin_mz = bin_mz - first_delta;
1203 bins.prepend(new_bin_mz);
1204 bin_mz = new_bin_mz;
1207 else if(uniform_resolutions)
1211 while(bin_mz > smallest_mz)
1213 double new_bin_mz = bin_mz - (bin_mz / first_resolution);
1214 bins.prepend(new_bin_mz);
1215 bin_mz = new_bin_mz;
1224 if(greatest_mz > last_bin_mz)
1232 double bin_mz = last_bin_mz;
1238 while(bin_mz < greatest_mz)
1240 double new_bin_mz = bin_mz + first_delta;
1241 bins.append(new_bin_mz);
1242 bin_mz = new_bin_mz;
1245 else if(uniform_resolutions)
1249 while(bin_mz > smallest_mz)
1251 double new_bin_mz = bin_mz + (bin_mz / first_resolution);
1252 bins.append(new_bin_mz);
1253 bin_mz = new_bin_mz;
1263 std::vector<double> full_bins_vector(bins.constBegin(), bins.constEnd());
1269 file_name =
"/tmp/massSpecDataBasedFullBinsWithDeltas.txt-at-" +
1270 QDateTime::currentDateTime().toString(
"yyyyMMdd-HH-mm-ss");
1272 qDebug() <<
"Writing the list of bins setup in the mass spectrum in file "
1283 return full_bins_vector;
1294 std::vector<double> bins;
1296 if(mass_spectrum_csp->size() < 2)
1303 sorted_mass_spectrum.
sortMz();
1317 double start_mz_in = min_mz;
1323 std::vector<pappso::DataPoint>::const_iterator it =
1324 sorted_mass_spectrum.begin();
1326 double prev_mz = it->x;
1334 while(it != sorted_mass_spectrum.end())
1336 double next_mz = it->x;
1342 double step = next_mz - prev_mz;
1343 end_mz_out = start_mz_in + step;
1354 bins.push_back(start_mz_in);
1357 start_mz_in = end_mz_out;
1368 QString fileName =
"/tmp/massSpecDataBasedBins.txt";
1370 qDebug() <<
"Writing the list of bins setup in the "
1371 "mass spectrum in file "
1374 QFile file(fileName);
1375 file.open(QIODevice::WriteOnly);
1377 QTextStream fileStream(&file);
1379 for(
auto &&bin : m_bins)
1380 fileStream << QString(
"[%1-%2]\n")
1381 .arg(bin.startMzIn, 0,
'f', 10)
1382 .arg(bin.endMzOut, 0,
'f', 10);
1387 qDebug() <<
"elements."
1388 <<
"starting with mz" << m_bins.front().startMzIn <<
"ending with mz"
1389 << m_bins.back().endMzOut;
1403 QString offset_lead;
1405 for(
int iter = 0; iter < offset; ++iter)
1406 offset_lead += spacer;
1408 QString text = offset_lead;
1409 text +=
"m/z integration parameters:\n";
1411 QString new_lead = QString(
"%1%2").arg(offset_lead, spacer);
1416 QString::asprintf(
"Smallest (first) m/z: %.6f\n",
m_smallestMz));
1420 text.append(QString::asprintf(
"Greatest (last) m/z: %.6f\n",
m_greatestMz));
1424 text.append(QString::asprintf(
"Lower anchor m/z: %.6f\n",
m_lowerAnchorMz));
1428 text.append(QString::asprintf(
"Upper anchor m/z: %.6f\n",
m_upperAnchorMz));
1431 text += QString(
"Remove 0-val data points: %1\n")
1435 text.append(
"Binning logic:\n");
1444 text.append(QString(
"Bin size model: %1\n").arg(
m_binSizeModel->toString()));
1499 if(engine ==
nullptr)
1501 qFatal() <<
"Cannot register class: engine is null";
1504 QJSValue pappso_root_property;
1505 QJSValue pappso_enums_property;
1507 if(engine->globalObject().hasProperty(
"pappso"))
1509 qDebug() <<
"Global object property 'pappso' already exists.";
1510 pappso_root_property = engine->globalObject().property(
"pappso");
1512 if(pappso_root_property.hasProperty(
"Enums"))
1514 pappso_enums_property = pappso_root_property.property(
"Enums");
1518 pappso_enums_property = engine->newObject();
1519 pappso_root_property.setProperty(
"Enums", pappso_enums_property);
1524 qDebug() <<
"Global object property 'pappso' not found.";
1525 pappso_root_property = engine->newObject();
1526 pappso_enums_property = engine->newObject();
1527 pappso_root_property.setProperty(
"Enums", pappso_enums_property);
1528 engine->globalObject().setProperty(
"pappso", pappso_root_property);
1531 QJSValue enumObject;
1534 enumObject = engine->newObject();
1536 enumObject.setProperty(
1538 enumObject.setProperty(
1541 enumObject.setProperty(
1545 pappso_enums_property.setProperty(
"BinningType", enumObject);
1548 enumObject = engine->newObject();
1549 enumObject.setProperty(
1553 enumObject.setProperty(
1554 "fromSettingsBinSizeModelPartial",
1557 enumObject.setProperty(
1558 "fromSettingsBinSizeModelFull",
1561 enumObject.setProperty(
1565 pappso_enums_property.setProperty(
"InitializationResult", enumObject);
1568 QJSValue jsMetaObject =
1569 engine->newQMetaObject(&MzIntegrationParams::staticMetaObject);
1570 engine->globalObject().setProperty(
"MzIntegrationParams", jsMetaObject);