86 namespace MRMTransitionGroupPickerMeta
315 template <
typename SpectrumT,
typename TransitionT>
328 auto &picked_chroms = picker_pool.picked_chroms;
329 auto &smoothed_chroms = picker_pool.smoothed_chroms;
330 auto &picked_input_chromatograms = picker_pool.picked_input_chromatograms;
333 picked_chroms.reserve(expected_chrom_count);
334 smoothed_chroms.reserve(expected_chrom_count);
335 picked_input_chromatograms.reserve(expected_chrom_count);
341 std::string native_id = chromatogram.
getNativeID();
346 !transition_group.
getTransition(native_id).isDetectingTransition() )
353 picker_.pickChromatogram(chromatogram, picked_chrom, smoothed_chrom);
355 picked_input_chromatograms.push_back(&chromatogram);
356 picked_chroms.push_back(std::move(picked_chrom));
357 smoothed_chroms.push_back(std::move(smoothed_chrom));
365 SpectrumT picked_chrom, smoothed_chrom;
368 picker_.pickChromatogram(chromatogram, picked_chrom, smoothed_chrom);
369 picked_chrom.sortByIntensity();
370 picked_input_chromatograms.push_back(&chromatogram);
371 picked_chroms.push_back(std::move(picked_chrom));
372 smoothed_chroms.push_back(std::move(smoothed_chrom));
376 auto& transition_total_xics = picker_pool.transition_total_xics;
377 transition_total_xics.reserve(transition_group.
getTransitions().size());
378 auto& transition_chromatograms = picker_pool.transition_chromatograms;
379 transition_chromatograms.reserve(transition_group.
getTransitions().size());
380 double detecting_total_xic = 0.0;
381 for (
const TransitionT& transition : transition_group.
getTransitions())
383 const SpectrumT& chromatogram = selectChromHelper_(transition_group, transition.getNativeID());
384 transition_chromatograms.push_back(&chromatogram);
385 const double transition_total_xic = std::accumulate(chromatogram.begin(), chromatogram.end(), 0.0,
386 [](
double total,
const auto& peak)
388 return total + peak.getIntensity();
390 transition_total_xics.push_back(transition_total_xic);
391 if (transition.isDetectingTransition())
393 detecting_total_xic += transition_total_xic;
397 auto& largest_peak_indices = picker_pool.largest_peak_indices;
398 if (boundary_selection_method_ ==
"largest")
400 largest_peak_indices.reserve(picked_chroms.size());
401 for (
const SpectrumT& chromatogram : picked_chroms)
403 largest_peak_indices.push_back(chromatogram.empty() ? -1 :
static_cast<int>(chromatogram.size() - 1));
411 int chr_idx, peak_idx, cnt = 0;
412 auto &features = picker_pool.features;
415 chr_idx = -1; peak_idx = -1;
417 if (boundary_selection_method_ ==
"largest")
419 findLargestPeakCached_(picked_chroms, largest_peak_indices, chr_idx, peak_idx);
421 else if (boundary_selection_method_ ==
"widest")
423 findWidestPeakIndices(picked_chroms, chr_idx, peak_idx);
426 if (chr_idx == -1 && peak_idx == -1)
428 OPENMS_LOG_DEBUG <<
"**** No more peaks left. Nr. chroms: " << picked_chroms.size() << std::endl;
433 MRMFeature mrm_feature = createMRMFeature(transition_group, picked_chroms, smoothed_chroms,
434 transition_total_xics, detecting_total_xic,
435 transition_chromatograms,
436 picked_input_chromatograms,
438 double total_xic = 0;
442 total_xic = mrm_feature.
getMetaValue(MRMTransitionGroupPickerMeta::totalXIC());
443 features.push_back(std::move(mrm_feature));
447 if (stop_after_feature_ > 0 && cnt > stop_after_feature_) {
451 if (intensity > 0 && intensity / total_xic < stop_after_intensity_ratio_)
453 OPENMS_LOG_DEBUG <<
"**** Minimum intensity ratio reached. Nr. chroms: " << picked_chroms.size() << std::endl;
459 for (
Size i = 0; i < features.size(); i++)
463 for (
Size j = 0; j < i; j++)
465 if ((
double)mrm_feature.
getMetaValue(MRMTransitionGroupPickerMeta::leftWidth()) >= (
double)features[j].getMetaValue(MRMTransitionGroupPickerMeta::leftWidth()) &&
466 (
double)mrm_feature.
getMetaValue(MRMTransitionGroupPickerMeta::rightWidth()) <= (
double)features[j].getMetaValue(MRMTransitionGroupPickerMeta::rightWidth()))
493 template <
typename SpectrumT,
typename TransitionT>
495 std::vector<SpectrumT>& picked_chroms,
496 const std::vector<SpectrumT>& smoothed_chroms,
500 std::vector<double> transition_total_xics;
501 transition_total_xics.reserve(transition_group.
getTransitions().size());
502 std::vector<const SpectrumT*> transition_chromatograms;
503 transition_chromatograms.reserve(transition_group.
getTransitions().size());
504 double detecting_total_xic = 0.0;
505 for (
const TransitionT& transition : transition_group.
getTransitions())
507 const SpectrumT& chromatogram = selectChromHelper_(transition_group, transition.getNativeID());
508 transition_chromatograms.push_back(&chromatogram);
509 const double transition_total_xic = std::accumulate(chromatogram.begin(), chromatogram.end(), 0.0,
510 [](
double total,
const auto& peak)
512 return total + peak.getIntensity();
514 transition_total_xics.push_back(transition_total_xic);
515 if (transition.isDetectingTransition())
517 detecting_total_xic += transition_total_xic;
521 std::vector<const SpectrumT*> picked_input_chromatograms;
522 picked_input_chromatograms.reserve(picked_chroms.size());
523 for (
const SpectrumT& picked_chrom : picked_chroms)
525 picked_input_chromatograms.push_back(&selectChromHelper_(transition_group, picked_chrom.getNativeID()));
528 return createMRMFeature(transition_group, picked_chroms, smoothed_chroms,
529 transition_total_xics, detecting_total_xic,
530 transition_chromatograms, picked_input_chromatograms,
554 template <
typename SpectrumT,
typename TransitionT>
556 std::vector<SpectrumT>& picked_chroms,
557 const std::vector<SpectrumT>& smoothed_chroms,
558 const std::vector<double>& transition_total_xics,
559 double detecting_total_xic,
560 const std::vector<const SpectrumT*>& transition_chromatograms,
561 const std::vector<const SpectrumT*>& picked_input_chromatograms,
570 double best_left = picked_chroms[chr_idx].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][peak_idx];
571 double best_right = picked_chroms[chr_idx].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][peak_idx];
572 double peak_apex = picked_chroms[chr_idx][peak_idx].getRT();
573 OPENMS_LOG_DEBUG <<
"**** Creating MRMFeature for peak " << peak_idx <<
" in chrom. " << chr_idx <<
" with " <<
574 picked_chroms[chr_idx][peak_idx] <<
" and borders " << best_left <<
" " <<
575 best_right <<
" (" << best_right - best_left <<
")" << std::endl;
577 if (use_consensus_ && recalculate_peaks_)
580 recalculatePeakBorders_(picked_chroms, best_left, best_right, recalculate_peaks_max_z_);
581 if (peak_apex < best_left || peak_apex > best_right)
584 peak_apex = (best_left + best_right) / 2.0;
590 struct CreateFeaturePool
592 std::vector<double> left_edges;
593 std::vector<double> right_edges;
594 void reset() { left_edges.clear(); right_edges.clear(); }
596 thread_local CreateFeaturePool create_feat_pool;
597 create_feat_pool.reset();
598 auto &left_edges = create_feat_pool.left_edges;
599 auto &right_edges = create_feat_pool.right_edges;
600 double min_left = best_left;
601 double max_right = best_right;
607 remove_overlapping_features(picked_chroms, best_left, best_right);
611 pickApex(picked_chroms, best_left, best_right, peak_apex,
612 min_left, max_right, left_edges, right_edges);
615 picked_chroms[chr_idx][peak_idx].setIntensity(0.0);
620 if (min_peak_width_ > 0.0 && std::fabs(best_right - best_left) < min_peak_width_)
625 if (compute_peak_quality_)
627 std::string outlier =
"none";
628 double qual = computeQuality_(transition_group, picked_chroms, picked_input_chromatograms,
629 chr_idx, best_left, best_right, outlier);
630 if (qual < min_qual_)
634 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::potentialOutlier(), outlier);
635 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::initialPeakQuality(), qual);
644 SpectrumT master_peak_container;
645 const SpectrumT& ref_chromatogram = *picked_input_chromatograms[chr_idx];
646 prepareMasterContainer_(ref_chromatogram, master_peak_container, min_left, max_right);
651 double total_intensity = 0;
double total_peak_apices = 0;
double total_xic = 0;
double total_mi = 0;
652 pickFragmentChromatograms(transition_group, picked_chroms, mrmFeature, smoothed_chroms,
653 best_left, best_right, use_consensus_,
654 total_intensity, total_xic, total_mi, total_peak_apices,
655 master_peak_container, left_edges, right_edges,
656 transition_total_xics, detecting_total_xic,
657 transition_chromatograms,
662 pickPrecursorChromatograms(transition_group,
663 picked_chroms, mrmFeature, smoothed_chroms,
664 best_left, best_right, use_consensus_,
665 total_intensity, master_peak_container, left_edges, right_edges,
668 mrmFeature.
setRT(peak_apex);
671 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::leftWidth(), best_left);
672 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::rightWidth(), best_right);
673 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::totalXIC(), total_xic);
674 if (compute_total_mi_)
676 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::totalMI(), total_mi);
678 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::peakApicesSum(), total_peak_apices);
696 template <
typename SpectrumT>
697 void pickApex(std::vector<SpectrumT>& picked_chroms,
698 const double best_left,
const double best_right,
const double peak_apex,
699 double &min_left,
double &max_right,
700 std::vector< double > & left_edges, std::vector< double > & right_edges)
702 for (
Size k = 0; k < picked_chroms.size(); k++)
704 double peak_apex_dist_min = std::numeric_limits<double>::max();
706 for (
Size i = 0; i < picked_chroms[k].size(); i++)
710 picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][i],
711 picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][i]);
712 if (pa_tmp.
apex_pos > 1e-11 && std::fabs(pa_tmp.
apex_pos - peak_apex) < peak_apex_dist_min)
714 peak_apex_dist_min = std::fabs(pa_tmp.
apex_pos - peak_apex);
720 double l = best_left;
721 double r = best_right;
724 l = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][min_dist];
725 r = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][min_dist];
726 picked_chroms[k][min_dist].setIntensity(0.0);
729 left_edges.push_back(l);
730 right_edges.push_back(r);
732 if (l < min_left) {min_left = l;}
733 if (r > max_right) {max_right = r;}
737 template <
typename SpectrumT,
typename TransitionT>
739 const std::vector<SpectrumT>& picked_chroms,
741 const std::vector<SpectrumT>& smoothed_chroms,
742 const double best_left,
const double best_right,
743 const bool use_consensus_,
744 double & total_intensity,
747 double & total_peak_apices,
748 const SpectrumT & master_peak_container,
749 const std::vector< double > & left_edges,
750 const std::vector< double > & right_edges,
751 const std::vector<double>& transition_total_xics,
752 double detecting_total_xic,
753 const std::vector<const SpectrumT*>& transition_chromatograms,
757 total_xic += detecting_total_xic;
761 double local_left = best_left;
762 double local_right = best_right;
768 if (!transition_group.
getTransitions()[k].isDetectingTransition())
771 "When using non-consensus peak picker, all transitions need to be detecting transitions.");
773 local_left = left_edges[k];
774 local_right = right_edges[k];
777 const SpectrumT& chromatogram = *transition_chromatograms[k];
780 const double transition_total_xic = transition_total_xics[k];
783 double transition_total_mi = 0;
784 if (compute_total_mi_)
787 thread_local std::vector<unsigned int> chrom_vect_id_ranked;
788 thread_local std::vector<unsigned int> chrom_vect_det_ranked;
789 thread_local std::vector<double> chrom_vect_id;
790 thread_local std::vector<double> chrom_vect_det;
791 chrom_vect_id.clear(); chrom_vect_det.clear(); chrom_vect_id_ranked.clear(); chrom_vect_det_ranked.clear();
792 for (
typename SpectrumT::const_iterator it = chromatogram.begin(); it != chromatogram.end(); it++)
794 chrom_vect_id.push_back(it->getIntensity());
798 int transition_total_mi_norm = 0;
803 const SpectrumT& chromatogram_det = *transition_chromatograms[m];
804 chrom_vect_det.clear();
805 for (
typename SpectrumT::const_iterator it = chromatogram_det.begin(); it != chromatogram_det.end(); it++)
807 chrom_vect_det.push_back(it->getIntensity());
811 transition_total_mi_norm++;
814 if (transition_total_mi_norm > 0) { transition_total_mi /= transition_total_mi_norm; }
819 total_mi += transition_total_mi / transition_total_mi_norm;
823 SpectrumT used_chromatogram;
825 if (peak_integration_ ==
"original")
827 used_chromatogram = resampleChromatogram_(chromatogram, master_peak_container, local_left, local_right);
829 else if (peak_integration_ ==
"smoothed")
831 if (smoothed_chroms.size() <= k)
834 "Tried to calculate peak area and height without any smoothed chromatograms");
836 used_chromatogram = resampleChromatogram_(smoothed_chroms[k], master_peak_container, local_left, local_right);
841 std::string(
"Peak integration chromatogram ") + peak_integration_ +
" is not a valid method for MRMTransitionGroupPicker");
850 double peak_integral = pa.
area;
851 double peak_apex_int = pa.
height;
861 for (
const auto& p : used_chromatogram)
867 if (background_subtraction_ !=
"none")
869 double background{0};
870 double avg_noise_level{0};
871 if (background_subtraction_ ==
"original")
873 const double intensity_left = chromatogram.PosBegin(local_left)->getIntensity();
874 const double intensity_right = (chromatogram.PosEnd(local_right) - 1)->getIntensity();
875 const UInt n_points = std::distance(chromatogram.PosBegin(local_left), chromatogram.PosEnd(local_right));
876 avg_noise_level = (intensity_right + intensity_left) / 2;
877 background = avg_noise_level * n_points;
879 else if (background_subtraction_ ==
"exact")
882 background = pb.
area;
883 avg_noise_level = pb.
height;
885 peak_integral -= background;
886 peak_apex_int -= avg_noise_level;
887 if (peak_integral < 0) {peak_integral = 0;}
888 if (peak_apex_int < 0) {peak_apex_int = 0;}
890 f.
setMetaValue(MRMTransitionGroupPickerMeta::areaBackgroundLevel(), background);
891 f.
setMetaValue(MRMTransitionGroupPickerMeta::noiseBackgroundLevel(), avg_noise_level);
894 f.
setRT(picked_chroms[chr_idx][peak_idx].getPos());
900 f.
setMZ(chromatogram.getProduct().getMZ());
901 mrmFeature.
setMZ(chromatogram.getPrecursor().getMZ());
903 if (chromatogram.metaValueExists(
"product_mz"))
905 f.
setMetaValue(
"MZ", chromatogram.getMetaValue(
"product_mz"));
906 f.
setMZ(chromatogram.getMetaValue(
"product_mz"));
909 f.
setMetaValue(MRMTransitionGroupPickerMeta::nativeID(), chromatogram.getNativeID());
910 f.
setMetaValue(MRMTransitionGroupPickerMeta::peakApexInt(), peak_apex_int);
911 f.
setMetaValue(MRMTransitionGroupPickerMeta::totalXIC(), transition_total_xic);
912 if (compute_total_mi_)
914 f.
setMetaValue(MRMTransitionGroupPickerMeta::totalMI(), transition_total_mi);
917 if (transition_group.
getTransitions()[k].isQuantifyingTransition())
919 total_intensity += peak_integral;
920 total_peak_apices += peak_apex_int;
927 if (compute_peak_shape_metrics_)
946 mrmFeature.
addFeature(f, chromatogram.getNativeID());
950 template <
typename SpectrumT,
typename TransitionT>
952 const std::vector<SpectrumT>& picked_chroms,
954 const std::vector<SpectrumT>& smoothed_chroms,
955 const double best_left,
const double best_right,
956 const bool use_consensus_,
957 double & total_intensity,
958 const SpectrumT & master_peak_container,
959 const std::vector< double > & left_edges,
960 const std::vector< double > & right_edges,
972 double local_left = best_left;
973 double local_right = best_right;
974 if (!use_consensus_ && right_edges.size() > prec_idx && left_edges.size() > prec_idx)
976 local_left = left_edges[prec_idx];
977 local_right = right_edges[prec_idx];
980 SpectrumT used_chromatogram;
982 if (peak_integration_ ==
"original")
984 used_chromatogram = resampleChromatogram_(chromatogram, master_peak_container, local_left, local_right);
987 else if (peak_integration_ ==
"smoothed" && smoothed_chroms.size() <= prec_idx)
990 "Tried to calculate peak area and height without any smoothed chromatograms for precursors");
992 else if (peak_integration_ ==
"smoothed")
994 used_chromatogram = resampleChromatogram_(smoothed_chroms[prec_idx], master_peak_container, local_left, local_right);
999 std::string(
"Peak integration chromatogram ") + peak_integration_ +
" is not a valid method for MRMTransitionGroupPicker");
1008 double peak_integral = pa.
area;
1009 double peak_apex_int = pa.
height;
1014 if (!use_consensus_)
1017 for (
const auto& p : used_chromatogram)
1023 if (background_subtraction_ !=
"none")
1025 double background{0};
1026 double avg_noise_level{0};
1027 if ((peak_integration_ ==
"smoothed") && smoothed_chroms.size() <= prec_idx)
1030 "Tried to calculate background estimation without any smoothed chromatograms");
1032 else if (background_subtraction_ ==
"original")
1034 const double intensity_left = chromatogram.PosBegin(local_left)->getIntensity();
1035 const double intensity_right = (chromatogram.PosEnd(local_right) - 1)->getIntensity();
1036 const UInt n_points = std::distance(chromatogram.PosBegin(local_left), chromatogram.PosEnd(local_right));
1037 avg_noise_level = (intensity_right + intensity_left) / 2;
1038 background = avg_noise_level * n_points;
1040 else if (background_subtraction_ ==
"exact")
1043 background = pb.
area;
1044 avg_noise_level = pb.
height;
1046 peak_integral -= background;
1047 peak_apex_int -= avg_noise_level;
1048 if (peak_integral < 0) {peak_integral = 0;}
1049 if (peak_apex_int < 0) {peak_apex_int = 0;}
1051 f.
setMetaValue(MRMTransitionGroupPickerMeta::areaBackgroundLevel(), background);
1052 f.
setMetaValue(MRMTransitionGroupPickerMeta::noiseBackgroundLevel(), avg_noise_level);
1055 f.
setMZ(chromatogram.getPrecursor().getMZ());
1056 if (k == 0) {mrmFeature.
setMZ(chromatogram.getPrecursor().getMZ());}
1058 if (chromatogram.metaValueExists(
"precursor_mz"))
1060 f.
setMZ(chromatogram.getMetaValue(
"precursor_mz"));
1061 if (k == 0) {mrmFeature.
setMZ(chromatogram.getMetaValue(
"precursor_mz"));}
1064 f.
setRT(picked_chroms[chr_idx][peak_idx].getPos());
1069 f.
setMetaValue(MRMTransitionGroupPickerMeta::nativeID(), chromatogram.getNativeID());
1070 f.
setMetaValue(MRMTransitionGroupPickerMeta::peakApexInt(), peak_apex_int);
1072 if (use_precursors_ && transition_group.
getTransitions().empty())
1074 total_intensity += peak_integral;
1094 template <
typename SpectrumT>
1098 Size count_inside = 0;
1099 for (
Size k = 0; k < picked_chroms.size(); k++)
1101 for (
Size i = 0; i < picked_chroms[k].size(); i++)
1103 if (picked_chroms[k][i].getPos() >= best_left && picked_chroms[k][i].getPos() <= best_right)
1105 picked_chroms[k][i].setIntensity(0.0);
1111 Size count_overlap = 0;
1113 for (
Size k = 0; k < picked_chroms.size(); k++)
1115 for (
Size i = 0; i < picked_chroms[k].size(); i++)
1117 if (picked_chroms[k][i].getIntensity() <= 1e-11) {
continue; }
1119 double left = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][i];
1120 double right = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][i];
1121 if ((left > best_left && left < best_right)
1122 || (right > best_left && right < best_right))
1124 picked_chroms[k][i].setIntensity(0.0);
1129 OPENMS_LOG_DEBUG <<
" ** Removed " << count_inside <<
" peaks enclosed in and " <<
1130 count_overlap <<
" peaks overlapping with added feature." << std::endl;
1134 void findLargestPeak(
const std::vector<MSChromatogram >& picked_chroms,
int& chr_idx,
int& peak_idx);
1136 template <
typename SpectrumT>
1138 std::vector<int>& largest_peak_indices,
1140 int& peak_idx)
const
1143 "Cached largest peak indices must match picked chromatogram count.");
1144 double largest = 0.0;
1145 for (
Size k = 0; k < picked_chroms.size(); k++)
1147 int candidate_idx = largest_peak_indices[k];
1148 while (candidate_idx >= 0 && picked_chroms[k][candidate_idx].getIntensity() <= 0.0)
1152 largest_peak_indices[k] = candidate_idx;
1153 if (candidate_idx < 0)
1157 const double intensity = picked_chroms[k][candidate_idx].getIntensity();
1158 if (intensity > largest)
1160 largest = intensity;
1161 chr_idx =
static_cast<int>(k);
1162 peak_idx = candidate_idx;
1188 template <
typename SpectrumT,
typename TransitionT>
1201 throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"Did not find chromatogram for id '" + native_id +
"'.");
1221 template <
typename SpectrumT,
typename TransitionT>
1223 const std::vector<SpectrumT>& picked_chroms,
1224 const std::vector<const SpectrumT*>& picked_input_chromatograms,
1226 const double best_left,
1227 const double best_right,
1228 std::string& outlier)
1233 double resample_boundary = resample_boundary_;
1234 SpectrumT master_peak_container;
1235 const SpectrumT& ref_chromatogram = *picked_input_chromatograms[chr_idx];
1236 prepareMasterContainer_(ref_chromatogram, master_peak_container, best_left - resample_boundary, best_right + resample_boundary);
1239 auto &all_ints = pool.all_ints;
1241 for (
Size k = 0; k < picked_chroms.size(); k++)
1243 const SpectrumT& chromatogram = *picked_input_chromatograms[k];
1244 const SpectrumT used_chromatogram = resampleChromatogram_(chromatogram,
1245 master_peak_container, best_left - resample_boundary, best_right + resample_boundary);
1247 std::vector<double> int_here;
1248 for (
const auto& peak : used_chromatogram) int_here.push_back(peak.getIntensity());
1250 double tic = std::accumulate(int_here.begin(), int_here.end(), 0.0);
1251 if (tic > 1e-11) all_ints.push_back(int_here);
1255 auto &mean_shapes = pool.mean_shapes;
1256 auto &mean_coel = pool.mean_coel;
1257 mean_shapes.clear();
1259 for (
Size k = 0; k < all_ints.size(); k++)
1261 std::vector<double> shapes;
1262 std::vector<double> coel;
1263 for (
Size i = 0; i < all_ints.size(); i++)
1265 if (i == k) {
continue;}
1267 all_ints[k], all_ints[i], boost::numeric_cast<int>(all_ints[i].size()), 1);
1273 shapes.push_back(res_shape);
1274 coel.push_back(res_coelution);
1280 msc = std::for_each(shapes.begin(), shapes.end(), msc);
1281 double shapes_mean = msc.
mean();
1282 msc = std::for_each(coel.begin(), coel.end(), msc);
1283 double coel_mean = msc.
mean();
1287 mean_shapes.push_back(shapes_mean);
1288 mean_coel.push_back(coel_mean);
1294 int min_index_shape = std::distance(mean_shapes.begin(), std::min_element(mean_shapes.begin(), mean_shapes.end()));
1295 int max_index_coel = std::distance(mean_coel.begin(), std::max_element(mean_coel.begin(), mean_coel.end()));
1298 int missing_peaks = 0;
1299 int multiple_peaks = 0;
1302 auto &left_borders = pool.left_borders;
1303 auto &right_borders = pool.right_borders;
1304 left_borders.clear();
1305 right_borders.clear();
1306 for (
Size k = 0; k < picked_chroms.size(); k++)
1310 double max_int = -1;
1315 for (
Size i = 0; i < picked_chroms[k].size(); i++)
1317 if (picked_chroms[k][i].getPos() >= best_left && picked_chroms[k][i].getPos() <= best_right)
1320 if (picked_chroms[k][i].getIntensity() > max_int)
1322 max_int = picked_chroms[k][i].getIntensity() > max_int;
1323 l_tmp = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][i];
1324 r_tmp = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][i];
1329 if (l_tmp > 1e-11) left_borders.push_back(l_tmp);
1330 if (r_tmp > 1e-11) right_borders.push_back(r_tmp);
1332 if (pfound == 0) missing_peaks++;
1333 if (pfound > 1) multiple_peaks++;
1338 OPENMS_LOG_DEBUG <<
" Overall found missing : " << missing_peaks <<
" and multiple : " << multiple_peaks << std::endl;
1344 if (min_index_shape == max_index_coel)
1346 OPENMS_LOG_DEBUG <<
" Element " << min_index_shape <<
" is a candidate for removal ... " << std::endl;
1347 outlier =std::string(picked_chroms[min_index_shape].getNativeID());
1359 double shape_score = std::accumulate(mean_shapes.begin(), mean_shapes.end(), 0.0) / mean_shapes.size();
1360 double coel_score = std::accumulate(mean_coel.begin(), mean_coel.end(), 0.0) / mean_coel.size();
1361 coel_score = (coel_score - 1.0) / 2.0;
1363 double score = shape_score - coel_score - 1.0 * missing_peaks / picked_chroms.size();
1365 OPENMS_LOG_DEBUG <<
" Computed score " << score <<
" (from " << shape_score <<
1366 " - " << coel_score <<
" - " << 1.0 * missing_peaks / picked_chroms.size() <<
")" << std::endl;
1380 template <
typename SpectrumT>
1389 std::vector<double> left_borders;
1390 std::vector<double> right_borders;
1391 for (
Size k = 0; k < picked_chroms.size(); k++)
1393 double max_int = -1;
1396 for (
Size i = 0; i < picked_chroms[k].size(); i++)
1398 if (picked_chroms[k][i].getPos() >= best_left && picked_chroms[k][i].getPos() <= best_right)
1400 if (picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_ABUNDANCE][i] > max_int)
1402 max_int = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_ABUNDANCE][i];
1403 left = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][i];
1404 right = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][i];
1410 left_borders.push_back(left);
1411 right_borders.push_back(right);
1412 OPENMS_LOG_DEBUG <<
" * peak " << k <<
" left boundary " << left_borders.back() <<
" with inty " << max_int << std::endl;
1413 OPENMS_LOG_DEBUG <<
" * peak " << k <<
" right boundary " << right_borders.back() <<
" with inty " << max_int << std::endl;
1418 if (right_borders.empty())
1436 mean = std::accumulate(right_borders.begin(), right_borders.end(), 0.0) / (double) right_borders.size();
1437 stdev = std::sqrt(std::inner_product(right_borders.begin(), right_borders.end(), right_borders.begin(), 0.0)
1438 / right_borders.size() - mean * mean);
1439 std::sort(right_borders.begin(), right_borders.end());
1441 OPENMS_LOG_DEBUG <<
" - Recalculating right peak boundaries " << mean <<
" mean / best "
1442 << best_right <<
" std " << stdev <<
" : " << std::fabs(best_right - mean) / stdev
1443 <<
" coefficient of variation" << std::endl;
1446 if (std::fabs(best_right - mean) / stdev > max_z)
1448 best_right = right_borders[right_borders.size() / 2];
1449 OPENMS_LOG_DEBUG <<
" - CV too large: correcting right boundary to " << best_right << std::endl;
1453 mean = std::accumulate(left_borders.begin(), left_borders.end(), 0.0) / (double) left_borders.size();
1454 stdev = std::sqrt(std::inner_product(left_borders.begin(), left_borders.end(), left_borders.begin(), 0.0)
1455 / left_borders.size() - mean * mean);
1456 std::sort(left_borders.begin(), left_borders.end());
1458 OPENMS_LOG_DEBUG <<
" - Recalculating left peak boundaries " << mean <<
" mean / best "
1459 << best_left <<
" std " << stdev <<
" : " << std::fabs(best_left - mean) / stdev
1460 <<
" coefficient of variation" << std::endl;
1463 if (std::fabs(best_left - mean) / stdev > max_z)
1465 best_left = left_borders[left_borders.size() / 2];
1466 OPENMS_LOG_DEBUG <<
" - CV too large: correcting left boundary to " << best_left << std::endl;
1488 template <
typename PeakContainerT>
1490 PeakContainerT& master_peak_container,
1491 double left_boundary,
1492 double right_boundary)
1499 auto begin = ref_chromatogram.begin();
1500 while (begin != ref_chromatogram.end() && begin->getPos() < left_boundary) {begin++; }
1501 if (begin != ref_chromatogram.begin()) { begin--; }
1504 while (end != ref_chromatogram.end() && end->getPos() < right_boundary) {end++; }
1505 if (end != ref_chromatogram.end()) { end++; }
1508 master_peak_container.resize(distance(begin, end));
1509 auto it = master_peak_container.begin();
1510 for (
auto chrom_it = begin; chrom_it != end; chrom_it++, it++)
1512 it->setPos(chrom_it->getPos());
1526 template <
typename PeakContainerT>
1528 const PeakContainerT& master_peak_container,
1529 double left_boundary,
1530 double right_boundary)
1535 auto begin = chromatogram.begin();
1536 while (begin != chromatogram.end() && begin->getPos() < left_boundary) {begin++;}
1537 if (begin != chromatogram.begin()) { begin--; }
1540 while (end != chromatogram.end() && end->getPos() < right_boundary) {end++;}
1541 if (end != chromatogram.end()) { end++; }
1543 auto resampled_peak_container = master_peak_container;
1545 lresampler.
raster(begin, end, resampled_peak_container.begin(), resampled_peak_container.end());
1547 return resampled_peak_container;
#define OPENMS_LOG_DEBUG
Macro for debug information - includes file and line info.
Definition LogStream.h:591
const std::string & getNativeID() const
returns the native identifier for the spectrum, used by the acquisition software.
void setNativeID(const std::string &native_id)
sets the native identifier for the spectrum, used by the acquisition software.
Definition ConvexHull2D.h:49
void setHullPoints(const PointArrayType &points)
accessor for the outer(!) points (no checking is performed if this is actually a convex hull)
Representation of a coordinate in D-dimensional space.
Definition DPosition.h:32
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
A method or algorithm argument contains illegal values.
Definition Exception.h:630
An LC-MS feature.
Definition Feature.h:46
const std::vector< ConvexHull2D > & getConvexHulls() const
Non-mutable access to the convex hulls.
void setQuality(Size index, QualityType q)
Set the quality in dimension c.
void setOverallQuality(QualityType q)
Set the overall quality.
Linear Resampling of raw data with alignment.
Definition LinearResamplerAlign.h:76
void raster(PeakContainerT &container)
Applies the resampling algorithm to a container (MSSpectrum or MSChromatogram).
Definition LinearResamplerAlign.h:96
A multi-chromatogram MRM feature.
Definition MRMFeature.h:26
void addFeature(const Feature &feature, const std::string &key)
Adds an feature from a single chromatogram into the feature.
void addPrecursorFeature(const Feature &feature, const std::string &key)
Adds a precursor feature from a single chromatogram into the feature.
The MRMTransitionGroupPicker finds peaks in chromatograms that belong to the same precursors.
Definition MRMTransitionGroupPicker.h:284
void findLargestPeak(const std::vector< MSChromatogram > &picked_chroms, int &chr_idx, int &peak_idx)
Find largest peak in a vector of chromatograms.
void prepareMasterContainer_(const PeakContainerT &ref_chromatogram, PeakContainerT &master_peak_container, double left_boundary, double right_boundary)
Create an empty master peak container that has the correct mz / RT values set.
Definition MRMTransitionGroupPicker.h:1489
void findLargestPeakCached_(const std::vector< SpectrumT > &picked_chroms, std::vector< int > &largest_peak_indices, int &chr_idx, int &peak_idx) const
Definition MRMTransitionGroupPicker.h:1137
bool compute_total_mi_
Definition MRMTransitionGroupPicker.h:1560
std::string peak_integration_
Definition MRMTransitionGroupPicker.h:1553
bool compute_peak_quality_
Definition MRMTransitionGroupPicker.h:1558
bool use_precursors_
Definition MRMTransitionGroupPicker.h:1556
PeakContainerT resampleChromatogram_(const PeakContainerT &chromatogram, const PeakContainerT &master_peak_container, double left_boundary, double right_boundary)
Resample a container at the positions indicated by the master peak container.
Definition MRMTransitionGroupPicker.h:1527
void pickApex(std::vector< SpectrumT > &picked_chroms, const double best_left, const double best_right, const double peak_apex, double &min_left, double &max_right, std::vector< double > &left_edges, std::vector< double > &right_edges)
Apex-based peak picking.
Definition MRMTransitionGroupPicker.h:697
std::string background_subtraction_
Definition MRMTransitionGroupPicker.h:1554
const SpectrumT & selectChromHelper_(const MRMTransitionGroup< SpectrumT, TransitionT > &transition_group, const std::string &native_id)
Select matching precursor or fragment ion chromatogram.
Definition MRMTransitionGroupPicker.h:1189
double min_peak_width_
Definition MRMTransitionGroupPicker.h:1565
void remove_overlapping_features(std::vector< SpectrumT > &picked_chroms, double best_left, double best_right)
Remove overlapping features.
Definition MRMTransitionGroupPicker.h:1095
void recalculatePeakBorders_(const std::vector< SpectrumT > &picked_chroms, double &best_left, double &best_right, double max_z)
Recalculate the borders of the peak.
Definition MRMTransitionGroupPicker.h:1381
int stop_after_feature_
Definition MRMTransitionGroupPicker.h:1563
PeakPickerChromatogram picker_
Definition MRMTransitionGroupPicker.h:1576
double recalculate_peaks_max_z_
Definition MRMTransitionGroupPicker.h:1566
PeakIntegrator pi_
Definition MRMTransitionGroupPicker.h:1577
void findWidestPeakIndices(const std::vector< MSChromatogram > &picked_chroms, Int &chrom_idx, Int &point_idx) const
Given a vector of chromatograms, find the indices of the chromatogram containing the widest peak and ...
double min_qual_
Definition MRMTransitionGroupPicker.h:1561
double resample_boundary_
Definition MRMTransitionGroupPicker.h:1567
MRMFeature createMRMFeature(const MRMTransitionGroup< SpectrumT, TransitionT > &transition_group, std::vector< SpectrumT > &picked_chroms, const std::vector< SpectrumT > &smoothed_chroms, const int chr_idx, const int peak_idx)
Create a feature from picked chromatograms and a specified peak.
Definition MRMTransitionGroupPicker.h:494
~MRMTransitionGroupPicker() override
Destructor.
void pickFragmentChromatograms(const MRMTransitionGroup< SpectrumT, TransitionT > &transition_group, const std::vector< SpectrumT > &picked_chroms, MRMFeature &mrmFeature, const std::vector< SpectrumT > &smoothed_chroms, const double best_left, const double best_right, const bool use_consensus_, double &total_intensity, double &total_xic, double &total_mi, double &total_peak_apices, const SpectrumT &master_peak_container, const std::vector< double > &left_edges, const std::vector< double > &right_edges, const std::vector< double > &transition_total_xics, double detecting_total_xic, const std::vector< const SpectrumT * > &transition_chromatograms, const int chr_idx, const int peak_idx)
Definition MRMTransitionGroupPicker.h:738
MRMTransitionGroupPicker()
Constructor.
MRMFeature createMRMFeature(const MRMTransitionGroup< SpectrumT, TransitionT > &transition_group, std::vector< SpectrumT > &picked_chroms, const std::vector< SpectrumT > &smoothed_chroms, const std::vector< double > &transition_total_xics, double detecting_total_xic, const std::vector< const SpectrumT * > &transition_chromatograms, const std::vector< const SpectrumT * > &picked_input_chromatograms, const int chr_idx, const int peak_idx)
Create a feature from picked chromatograms and precomputed transition data.
Definition MRMTransitionGroupPicker.h:555
void updateMembers_() override
Synchronize members with param class.
double stop_after_intensity_ratio_
Definition MRMTransitionGroupPicker.h:1564
void pickTransitionGroup(MRMTransitionGroup< SpectrumT, TransitionT > &transition_group)
Pick a group of chromatograms belonging to the same peptide.
Definition MRMTransitionGroupPicker.h:316
MRMTransitionGroupPicker & operator=(const MRMTransitionGroupPicker &rhs)
Assignment operator is protected for algorithm.
bool use_consensus_
Definition MRMTransitionGroupPicker.h:1557
std::string boundary_selection_method_
Which method to use for selecting peaks' boundaries.
Definition MRMTransitionGroupPicker.h:1574
bool recalculate_peaks_
Definition MRMTransitionGroupPicker.h:1555
void pickPrecursorChromatograms(const MRMTransitionGroup< SpectrumT, TransitionT > &transition_group, const std::vector< SpectrumT > &picked_chroms, MRMFeature &mrmFeature, const std::vector< SpectrumT > &smoothed_chroms, const double best_left, const double best_right, const bool use_consensus_, double &total_intensity, const SpectrumT &master_peak_container, const std::vector< double > &left_edges, const std::vector< double > &right_edges, const int chr_idx, const int peak_idx)
Definition MRMTransitionGroupPicker.h:951
bool compute_peak_shape_metrics_
Definition MRMTransitionGroupPicker.h:1559
double computeQuality_(const MRMTransitionGroup< SpectrumT, TransitionT > &, const std::vector< SpectrumT > &picked_chroms, const std::vector< const SpectrumT * > &picked_input_chromatograms, const int chr_idx, const double best_left, const double best_right, std::string &outlier)
Compute transition group quality (higher score is better)
Definition MRMTransitionGroupPicker.h:1222
The representation of a group of transitions in a targeted proteomics experiment.
Definition MRMTransitionGroup.h:42
bool hasPrecursorChromatogram(const std::string &key) const
Definition MRMTransitionGroup.h:242
const std::vector< TransitionType > & getTransitions() const
Definition MRMTransitionGroup.h:116
ChromatogramType & getPrecursorChromatogram(const std::string &key)
Definition MRMTransitionGroup.h:247
const TransitionType & getTransition(const std::string &key)
Definition MRMTransitionGroup.h:149
ChromatogramType & getChromatogram(const std::string &key)
Definition MRMTransitionGroup.h:193
bool isInternallyConsistent() const
Check whether internal state is consistent, e.g. same number of chromatograms and transitions are pre...
Definition MRMTransitionGroup.h:291
bool chromatogramIdsMatch() const
Ensure that chromatogram native ids match their keys in the map.
Definition MRMTransitionGroup.h:300
const std::string & getTransitionGroupID() const
Definition MRMTransitionGroup.h:104
void addFeature(const MRMFeature &feature)
Definition MRMTransitionGroup.h:275
std::vector< ChromatogramType > & getPrecursorChromatograms()
Definition MRMTransitionGroup.h:211
std::vector< ChromatogramType > & getChromatograms()
Definition MRMTransitionGroup.h:160
bool hasChromatogram(const std::string &key) const
Definition MRMTransitionGroup.h:188
bool hasTransition(const std::string &key) const
Definition MRMTransitionGroup.h:144
The representation of a chromatogram.
Definition MSChromatogram.h:30
void sortByIntensity(bool reverse=false)
Lexicographically sorts the peaks by their intensity.
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1)
Definition Peak2D.h:179
void setRT(CoordinateType coordinate)
Mutable access to the RT coordinate (index 0)
Definition Peak2D.h:191
IntensityType getIntensity() const
Definition Peak2D.h:143
void setIntensity(IntensityType intensity)
Sets data point intensity (height)
Definition Peak2D.h:149
Compute the area, background and shape metrics of a peak.
Definition PeakIntegrator.h:87
Int points_across_half_height
Definition PeakIntegrator.h:224
double apex_pos
Definition PeakIntegrator.h:111
ConvexHull2D::PointArrayType hull_points
Definition PeakIntegrator.h:115
double width_at_5
Definition PeakIntegrator.h:146
Int points_across_baseline
Definition PeakIntegrator.h:220
double width_at_50
Definition PeakIntegrator.h:154
double end_position_at_50
Definition PeakIntegrator.h:178
double baseline_delta_2_height
Definition PeakIntegrator.h:216
double height
Definition PeakIntegrator.h:107
double end_position_at_10
Definition PeakIntegrator.h:174
double width_at_10
Definition PeakIntegrator.h:150
double total_width
Definition PeakIntegrator.h:182
double end_position_at_5
Definition PeakIntegrator.h:170
double start_position_at_50
Definition PeakIntegrator.h:166
double tailing_factor
Definition PeakIntegrator.h:196
double slope_of_baseline
Definition PeakIntegrator.h:211
double start_position_at_10
Definition PeakIntegrator.h:162
double asymmetry_factor
Definition PeakIntegrator.h:206
double start_position_at_5
Definition PeakIntegrator.h:158
double area
Definition PeakIntegrator.h:103
Definition PeakIntegrator.h:99
Definition PeakIntegrator.h:124
Definition PeakIntegrator.h:142
The PeakPickerChromatogram finds peaks a single chromatogram.
Definition PeakPickerChromatogram.h:44
Size ensureUniqueId()
Assigns a valid unique id, but only if the present one is invalid. Returns 1 if the unique id was cha...
functor to compute the mean and stddev of sequence using the std::foreach algorithm
Definition StatsHelpers.h:147
double mean() const
Definition StatsHelpers.h:184
int Int
Signed integer type.
Definition Types.h:72
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition openms/include/OpenMS/CONCEPT/Macros.h:94
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
PickerPoolShared & g_picker_pool_shared()
Definition MRMTransitionGroupPicker.h:80
OPENSWATHALGO_DLLAPI XCorrArrayType normalizedCrossCorrelation(std::vector< double > &data1, std::vector< double > &data2, const int maxdelay, const int lag)
OPENSWATHALGO_DLLAPI unsigned int computeAndAppendRank(const std::vector< double > &v, std::vector< unsigned int > &ranks)
OPENSWATHALGO_DLLAPI double rankedMutualInformation(std::vector< unsigned int > &ranked_data1, std::vector< unsigned int > &ranked_data2, const unsigned int max_rank1, const unsigned int max_rank2)
OPENSWATHALGO_DLLAPI XCorrArrayType::const_iterator xcorrArrayGetMaxPeak(const XCorrArrayType &array)
Find best peak in an cross-correlation (highest apex)
Definition MRMTransitionGroupPicker.h:39
std::vector< double > right_edges
Definition MRMTransitionGroupPicker.h:46
std::vector< double > transition_total_xics
Definition MRMTransitionGroupPicker.h:53
std::vector< double > mean_coel
Definition MRMTransitionGroupPicker.h:49
std::vector< double > mean_shapes
Definition MRMTransitionGroupPicker.h:48
std::vector< double > right_borders
Definition MRMTransitionGroupPicker.h:51
std::vector< double > left_borders
Definition MRMTransitionGroupPicker.h:50
std::vector< const MSChromatogram * > picked_input_chromatograms
Definition MRMTransitionGroupPicker.h:42
std::vector< MRMFeature > features
Definition MRMTransitionGroupPicker.h:44
std::vector< const MSChromatogram * > transition_chromatograms
Definition MRMTransitionGroupPicker.h:43
std::vector< MSChromatogram > picked_chroms
Definition MRMTransitionGroupPicker.h:40
std::vector< double > left_edges
Definition MRMTransitionGroupPicker.h:45
std::vector< MSChromatogram > smoothed_chroms
Definition MRMTransitionGroupPicker.h:41
std::vector< int > largest_peak_indices
Definition MRMTransitionGroupPicker.h:52
std::vector< std::vector< double > > all_ints
Definition MRMTransitionGroupPicker.h:47
void reset()
Definition MRMTransitionGroupPicker.h:55