87 namespace MRMTransitionGroupPickerMeta
316 template <
typename SpectrumT,
typename TransitionT>
329 auto &picked_chroms = picker_pool.picked_chroms;
330 auto &smoothed_chroms = picker_pool.smoothed_chroms;
331 auto &picked_input_chromatograms = picker_pool.picked_input_chromatograms;
334 picked_chroms.reserve(expected_chrom_count);
335 smoothed_chroms.reserve(expected_chrom_count);
336 picked_input_chromatograms.reserve(expected_chrom_count);
342 std::string native_id = chromatogram.
getNativeID();
347 !transition_group.
getTransition(native_id).isDetectingTransition() )
354 picker_.pickChromatogram(chromatogram, picked_chrom, smoothed_chrom);
356 picked_input_chromatograms.push_back(&chromatogram);
357 picked_chroms.push_back(std::move(picked_chrom));
358 smoothed_chroms.push_back(std::move(smoothed_chrom));
366 SpectrumT picked_chrom, smoothed_chrom;
369 picker_.pickChromatogram(chromatogram, picked_chrom, smoothed_chrom);
370 picked_chrom.sortByIntensity();
371 picked_input_chromatograms.push_back(&chromatogram);
372 picked_chroms.push_back(std::move(picked_chrom));
373 smoothed_chroms.push_back(std::move(smoothed_chrom));
377 auto& transition_total_xics = picker_pool.transition_total_xics;
378 transition_total_xics.reserve(transition_group.
getTransitions().size());
379 auto& transition_chromatograms = picker_pool.transition_chromatograms;
380 transition_chromatograms.reserve(transition_group.
getTransitions().size());
381 double detecting_total_xic = 0.0;
382 for (
const TransitionT& transition : transition_group.
getTransitions())
384 const SpectrumT& chromatogram = selectChromHelper_(transition_group, transition.getNativeID());
385 transition_chromatograms.push_back(&chromatogram);
386 const double transition_total_xic = std::accumulate(chromatogram.begin(), chromatogram.end(), 0.0,
387 [](
double total,
const auto& peak)
389 return total + peak.getIntensity();
391 transition_total_xics.push_back(transition_total_xic);
392 if (transition.isDetectingTransition())
394 detecting_total_xic += transition_total_xic;
398 auto& largest_peak_indices = picker_pool.largest_peak_indices;
399 if (boundary_selection_method_ ==
"largest")
401 largest_peak_indices.reserve(picked_chroms.size());
402 for (
const SpectrumT& chromatogram : picked_chroms)
404 largest_peak_indices.push_back(chromatogram.empty() ? -1 :
static_cast<int>(chromatogram.size() - 1));
412 int chr_idx, peak_idx, cnt = 0;
413 auto &features = picker_pool.features;
416 chr_idx = -1; peak_idx = -1;
418 if (boundary_selection_method_ ==
"largest")
420 findLargestPeakCached_(picked_chroms, largest_peak_indices, chr_idx, peak_idx);
422 else if (boundary_selection_method_ ==
"widest")
424 findWidestPeakIndices(picked_chroms, chr_idx, peak_idx);
427 if (chr_idx == -1 && peak_idx == -1)
429 OPENMS_LOG_DEBUG <<
"**** No more peaks left. Nr. chroms: " << picked_chroms.size() << std::endl;
434 MRMFeature mrm_feature = createMRMFeature(transition_group, picked_chroms, smoothed_chroms,
435 transition_total_xics, detecting_total_xic,
436 transition_chromatograms,
437 picked_input_chromatograms,
439 double total_xic = 0;
443 total_xic = mrm_feature.
getMetaValue(MRMTransitionGroupPickerMeta::totalXIC());
444 features.push_back(std::move(mrm_feature));
448 if (stop_after_feature_ > 0 && cnt > stop_after_feature_) {
452 if (intensity > 0 && intensity / total_xic < stop_after_intensity_ratio_)
454 OPENMS_LOG_DEBUG <<
"**** Minimum intensity ratio reached. Nr. chroms: " << picked_chroms.size() << std::endl;
460 for (
Size i = 0; i < features.size(); i++)
464 for (
Size j = 0; j < i; j++)
466 if ((
double)mrm_feature.
getMetaValue(MRMTransitionGroupPickerMeta::leftWidth()) >= (
double)features[j].getMetaValue(MRMTransitionGroupPickerMeta::leftWidth()) &&
467 (
double)mrm_feature.
getMetaValue(MRMTransitionGroupPickerMeta::rightWidth()) <= (
double)features[j].getMetaValue(MRMTransitionGroupPickerMeta::rightWidth()))
494 template <
typename SpectrumT,
typename TransitionT>
496 std::vector<SpectrumT>& picked_chroms,
497 const std::vector<SpectrumT>& smoothed_chroms,
501 std::vector<double> transition_total_xics;
502 transition_total_xics.reserve(transition_group.
getTransitions().size());
503 std::vector<const SpectrumT*> transition_chromatograms;
504 transition_chromatograms.reserve(transition_group.
getTransitions().size());
505 double detecting_total_xic = 0.0;
506 for (
const TransitionT& transition : transition_group.
getTransitions())
508 const SpectrumT& chromatogram = selectChromHelper_(transition_group, transition.getNativeID());
509 transition_chromatograms.push_back(&chromatogram);
510 const double transition_total_xic = std::accumulate(chromatogram.begin(), chromatogram.end(), 0.0,
511 [](
double total,
const auto& peak)
513 return total + peak.getIntensity();
515 transition_total_xics.push_back(transition_total_xic);
516 if (transition.isDetectingTransition())
518 detecting_total_xic += transition_total_xic;
522 std::vector<const SpectrumT*> picked_input_chromatograms;
523 picked_input_chromatograms.reserve(picked_chroms.size());
524 for (
const SpectrumT& picked_chrom : picked_chroms)
526 picked_input_chromatograms.push_back(&selectChromHelper_(transition_group, picked_chrom.getNativeID()));
529 return createMRMFeature(transition_group, picked_chroms, smoothed_chroms,
530 transition_total_xics, detecting_total_xic,
531 transition_chromatograms, picked_input_chromatograms,
555 template <
typename SpectrumT,
typename TransitionT>
557 std::vector<SpectrumT>& picked_chroms,
558 const std::vector<SpectrumT>& smoothed_chroms,
559 const std::vector<double>& transition_total_xics,
560 double detecting_total_xic,
561 const std::vector<const SpectrumT*>& transition_chromatograms,
562 const std::vector<const SpectrumT*>& picked_input_chromatograms,
571 double best_left = picked_chroms[chr_idx].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][peak_idx];
572 double best_right = picked_chroms[chr_idx].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][peak_idx];
573 double peak_apex = picked_chroms[chr_idx][peak_idx].getRT();
574 OPENMS_LOG_DEBUG <<
"**** Creating MRMFeature for peak " << peak_idx <<
" in chrom. " << chr_idx <<
" with " <<
575 picked_chroms[chr_idx][peak_idx] <<
" and borders " << best_left <<
" " <<
576 best_right <<
" (" << best_right - best_left <<
")" << std::endl;
578 if (use_consensus_ && recalculate_peaks_)
581 recalculatePeakBorders_(picked_chroms, best_left, best_right, recalculate_peaks_max_z_);
582 if (peak_apex < best_left || peak_apex > best_right)
585 peak_apex = (best_left + best_right) / 2.0;
591 struct CreateFeaturePool
593 std::vector<double> left_edges;
594 std::vector<double> right_edges;
595 void reset() { left_edges.clear(); right_edges.clear(); }
597 thread_local CreateFeaturePool create_feat_pool;
598 create_feat_pool.reset();
599 auto &left_edges = create_feat_pool.left_edges;
600 auto &right_edges = create_feat_pool.right_edges;
601 double min_left = best_left;
602 double max_right = best_right;
608 remove_overlapping_features(picked_chroms, best_left, best_right);
612 pickApex(picked_chroms, best_left, best_right, peak_apex,
613 min_left, max_right, left_edges, right_edges);
616 picked_chroms[chr_idx][peak_idx].setIntensity(0.0);
621 if (min_peak_width_ > 0.0 && std::fabs(best_right - best_left) < min_peak_width_)
626 if (compute_peak_quality_)
628 std::string outlier =
"none";
629 double qual = computeQuality_(transition_group, picked_chroms, picked_input_chromatograms,
630 chr_idx, best_left, best_right, outlier);
631 if (qual < min_qual_)
635 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::potentialOutlier(), outlier);
636 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::initialPeakQuality(), qual);
645 SpectrumT master_peak_container;
646 const SpectrumT& ref_chromatogram = *picked_input_chromatograms[chr_idx];
647 prepareMasterContainer_(ref_chromatogram, master_peak_container, min_left, max_right);
652 double total_intensity = 0;
double total_peak_apices = 0;
double total_xic = 0;
double total_mi = 0;
653 pickFragmentChromatograms(transition_group, picked_chroms, mrmFeature, smoothed_chroms,
654 best_left, best_right, use_consensus_,
655 total_intensity, total_xic, total_mi, total_peak_apices,
656 master_peak_container, left_edges, right_edges,
657 transition_total_xics, detecting_total_xic,
658 transition_chromatograms,
663 pickPrecursorChromatograms(transition_group,
664 picked_chroms, mrmFeature, smoothed_chroms,
665 best_left, best_right, use_consensus_,
666 total_intensity, master_peak_container, left_edges, right_edges,
669 mrmFeature.
setRT(peak_apex);
672 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::leftWidth(), best_left);
673 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::rightWidth(), best_right);
674 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::totalXIC(), total_xic);
675 if (compute_total_mi_)
677 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::totalMI(), total_mi);
679 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::peakApicesSum(), total_peak_apices);
697 template <
typename SpectrumT>
698 void pickApex(std::vector<SpectrumT>& picked_chroms,
699 const double best_left,
const double best_right,
const double peak_apex,
700 double &min_left,
double &max_right,
701 std::vector< double > & left_edges, std::vector< double > & right_edges)
703 for (
Size k = 0; k < picked_chroms.size(); k++)
705 double peak_apex_dist_min = std::numeric_limits<double>::max();
707 for (
Size i = 0; i < picked_chroms[k].size(); i++)
711 picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][i],
712 picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][i]);
713 if (pa_tmp.
apex_pos > 1e-11 && std::fabs(pa_tmp.
apex_pos - peak_apex) < peak_apex_dist_min)
715 peak_apex_dist_min = std::fabs(pa_tmp.
apex_pos - peak_apex);
721 double l = best_left;
722 double r = best_right;
725 l = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][min_dist];
726 r = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][min_dist];
727 picked_chroms[k][min_dist].setIntensity(0.0);
730 left_edges.push_back(l);
731 right_edges.push_back(r);
733 if (l < min_left) {min_left = l;}
734 if (r > max_right) {max_right = r;}
738 template <
typename SpectrumT,
typename TransitionT>
740 const std::vector<SpectrumT>& picked_chroms,
742 const std::vector<SpectrumT>& smoothed_chroms,
743 const double best_left,
const double best_right,
744 const bool use_consensus_,
745 double & total_intensity,
748 double & total_peak_apices,
749 const SpectrumT & master_peak_container,
750 const std::vector< double > & left_edges,
751 const std::vector< double > & right_edges,
752 const std::vector<double>& transition_total_xics,
753 double detecting_total_xic,
754 const std::vector<const SpectrumT*>& transition_chromatograms,
758 total_xic += detecting_total_xic;
762 double local_left = best_left;
763 double local_right = best_right;
769 if (!transition_group.
getTransitions()[k].isDetectingTransition())
772 "When using non-consensus peak picker, all transitions need to be detecting transitions.");
774 local_left = left_edges[k];
775 local_right = right_edges[k];
778 const SpectrumT& chromatogram = *transition_chromatograms[k];
781 const double transition_total_xic = transition_total_xics[k];
784 double transition_total_mi = 0;
785 if (compute_total_mi_)
788 thread_local std::vector<unsigned int> chrom_vect_id_ranked;
789 thread_local std::vector<unsigned int> chrom_vect_det_ranked;
790 thread_local std::vector<double> chrom_vect_id;
791 thread_local std::vector<double> chrom_vect_det;
792 chrom_vect_id.clear(); chrom_vect_det.clear(); chrom_vect_id_ranked.clear(); chrom_vect_det_ranked.clear();
793 for (
typename SpectrumT::const_iterator it = chromatogram.begin(); it != chromatogram.end(); it++)
795 chrom_vect_id.push_back(it->getIntensity());
799 int transition_total_mi_norm = 0;
804 const SpectrumT& chromatogram_det = *transition_chromatograms[m];
805 chrom_vect_det.clear();
806 for (
typename SpectrumT::const_iterator it = chromatogram_det.begin(); it != chromatogram_det.end(); it++)
808 chrom_vect_det.push_back(it->getIntensity());
812 transition_total_mi_norm++;
815 if (transition_total_mi_norm > 0) { transition_total_mi /= transition_total_mi_norm; }
820 total_mi += transition_total_mi / transition_total_mi_norm;
824 SpectrumT used_chromatogram;
826 if (peak_integration_ ==
"original")
828 used_chromatogram = resampleChromatogram_(chromatogram, master_peak_container, local_left, local_right);
830 else if (peak_integration_ ==
"smoothed")
832 if (smoothed_chroms.size() <= k)
835 "Tried to calculate peak area and height without any smoothed chromatograms");
837 used_chromatogram = resampleChromatogram_(smoothed_chroms[k], master_peak_container, local_left, local_right);
842 std::string(
"Peak integration chromatogram ") + peak_integration_ +
" is not a valid method for MRMTransitionGroupPicker");
851 double peak_integral = pa.
area;
852 double peak_apex_int = pa.
height;
862 for (
const auto& p : used_chromatogram)
868 if (background_subtraction_ !=
"none")
870 double background{0};
871 double avg_noise_level{0};
872 if (background_subtraction_ ==
"original")
874 const double intensity_left = chromatogram.PosBegin(local_left)->getIntensity();
875 const double intensity_right = (chromatogram.PosEnd(local_right) - 1)->getIntensity();
876 const UInt n_points = std::distance(chromatogram.PosBegin(local_left), chromatogram.PosEnd(local_right));
877 avg_noise_level = (intensity_right + intensity_left) / 2;
878 background = avg_noise_level * n_points;
880 else if (background_subtraction_ ==
"exact")
883 background = pb.
area;
884 avg_noise_level = pb.
height;
886 peak_integral -= background;
887 peak_apex_int -= avg_noise_level;
888 if (peak_integral < 0) {peak_integral = 0;}
889 if (peak_apex_int < 0) {peak_apex_int = 0;}
891 f.
setMetaValue(MRMTransitionGroupPickerMeta::areaBackgroundLevel(), background);
892 f.
setMetaValue(MRMTransitionGroupPickerMeta::noiseBackgroundLevel(), avg_noise_level);
895 f.
setRT(picked_chroms[chr_idx][peak_idx].getPos());
901 f.
setMZ(chromatogram.getProduct().getMZ());
902 mrmFeature.
setMZ(chromatogram.getPrecursor().getMZ());
904 if (chromatogram.metaValueExists(
"product_mz"))
906 f.
setMetaValue(
"MZ", chromatogram.getMetaValue(
"product_mz"));
907 f.
setMZ(chromatogram.getMetaValue(
"product_mz"));
910 f.
setMetaValue(MRMTransitionGroupPickerMeta::nativeID(), chromatogram.getNativeID());
911 f.
setMetaValue(MRMTransitionGroupPickerMeta::peakApexInt(), peak_apex_int);
912 f.
setMetaValue(MRMTransitionGroupPickerMeta::totalXIC(), transition_total_xic);
913 if (compute_total_mi_)
915 f.
setMetaValue(MRMTransitionGroupPickerMeta::totalMI(), transition_total_mi);
918 if (transition_group.
getTransitions()[k].isQuantifyingTransition())
920 total_intensity += peak_integral;
921 total_peak_apices += peak_apex_int;
928 if (compute_peak_shape_metrics_)
947 mrmFeature.
addFeature(f, chromatogram.getNativeID());
951 template <
typename SpectrumT,
typename TransitionT>
953 const std::vector<SpectrumT>& picked_chroms,
955 const std::vector<SpectrumT>& smoothed_chroms,
956 const double best_left,
const double best_right,
957 const bool use_consensus_,
958 double & total_intensity,
959 const SpectrumT & master_peak_container,
960 const std::vector< double > & left_edges,
961 const std::vector< double > & right_edges,
973 double local_left = best_left;
974 double local_right = best_right;
975 if (!use_consensus_ && right_edges.size() > prec_idx && left_edges.size() > prec_idx)
977 local_left = left_edges[prec_idx];
978 local_right = right_edges[prec_idx];
981 SpectrumT used_chromatogram;
983 if (peak_integration_ ==
"original")
985 used_chromatogram = resampleChromatogram_(chromatogram, master_peak_container, local_left, local_right);
988 else if (peak_integration_ ==
"smoothed" && smoothed_chroms.size() <= prec_idx)
991 "Tried to calculate peak area and height without any smoothed chromatograms for precursors");
993 else if (peak_integration_ ==
"smoothed")
995 used_chromatogram = resampleChromatogram_(smoothed_chroms[prec_idx], master_peak_container, local_left, local_right);
1000 std::string(
"Peak integration chromatogram ") + peak_integration_ +
" is not a valid method for MRMTransitionGroupPicker");
1009 double peak_integral = pa.
area;
1010 double peak_apex_int = pa.
height;
1015 if (!use_consensus_)
1018 for (
const auto& p : used_chromatogram)
1024 if (background_subtraction_ !=
"none")
1026 double background{0};
1027 double avg_noise_level{0};
1028 if ((peak_integration_ ==
"smoothed") && smoothed_chroms.size() <= prec_idx)
1031 "Tried to calculate background estimation without any smoothed chromatograms");
1033 else if (background_subtraction_ ==
"original")
1035 const double intensity_left = chromatogram.PosBegin(local_left)->getIntensity();
1036 const double intensity_right = (chromatogram.PosEnd(local_right) - 1)->getIntensity();
1037 const UInt n_points = std::distance(chromatogram.PosBegin(local_left), chromatogram.PosEnd(local_right));
1038 avg_noise_level = (intensity_right + intensity_left) / 2;
1039 background = avg_noise_level * n_points;
1041 else if (background_subtraction_ ==
"exact")
1044 background = pb.
area;
1045 avg_noise_level = pb.
height;
1047 peak_integral -= background;
1048 peak_apex_int -= avg_noise_level;
1049 if (peak_integral < 0) {peak_integral = 0;}
1050 if (peak_apex_int < 0) {peak_apex_int = 0;}
1052 f.
setMetaValue(MRMTransitionGroupPickerMeta::areaBackgroundLevel(), background);
1053 f.
setMetaValue(MRMTransitionGroupPickerMeta::noiseBackgroundLevel(), avg_noise_level);
1056 f.
setMZ(chromatogram.getPrecursor().getMZ());
1057 if (k == 0) {mrmFeature.
setMZ(chromatogram.getPrecursor().getMZ());}
1059 if (chromatogram.metaValueExists(
"precursor_mz"))
1061 f.
setMZ(chromatogram.getMetaValue(
"precursor_mz"));
1062 if (k == 0) {mrmFeature.
setMZ(chromatogram.getMetaValue(
"precursor_mz"));}
1065 f.
setRT(picked_chroms[chr_idx][peak_idx].getPos());
1070 f.
setMetaValue(MRMTransitionGroupPickerMeta::nativeID(), chromatogram.getNativeID());
1071 f.
setMetaValue(MRMTransitionGroupPickerMeta::peakApexInt(), peak_apex_int);
1073 if (use_precursors_ && transition_group.
getTransitions().empty())
1075 total_intensity += peak_integral;
1095 template <
typename SpectrumT>
1099 Size count_inside = 0;
1100 for (
Size k = 0; k < picked_chroms.size(); k++)
1102 for (
Size i = 0; i < picked_chroms[k].size(); i++)
1104 if (picked_chroms[k][i].getPos() >= best_left && picked_chroms[k][i].getPos() <= best_right)
1106 picked_chroms[k][i].setIntensity(0.0);
1112 Size count_overlap = 0;
1114 for (
Size k = 0; k < picked_chroms.size(); k++)
1116 for (
Size i = 0; i < picked_chroms[k].size(); i++)
1118 if (picked_chroms[k][i].getIntensity() <= 1e-11) {
continue; }
1120 double left = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][i];
1121 double right = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][i];
1122 if ((left > best_left && left < best_right)
1123 || (right > best_left && right < best_right))
1125 picked_chroms[k][i].setIntensity(0.0);
1130 OPENMS_LOG_DEBUG <<
" ** Removed " << count_inside <<
" peaks enclosed in and " <<
1131 count_overlap <<
" peaks overlapping with added feature." << std::endl;
1135 void findLargestPeak(
const std::vector<MSChromatogram >& picked_chroms,
int& chr_idx,
int& peak_idx);
1137 template <
typename SpectrumT>
1139 std::vector<int>& largest_peak_indices,
1141 int& peak_idx)
const
1144 "Cached largest peak indices must match picked chromatogram count.");
1145 double largest = 0.0;
1146 for (
Size k = 0; k < picked_chroms.size(); k++)
1148 int candidate_idx = largest_peak_indices[k];
1149 while (candidate_idx >= 0 && picked_chroms[k][candidate_idx].getIntensity() <= 0.0)
1153 largest_peak_indices[k] = candidate_idx;
1154 if (candidate_idx < 0)
1158 const double intensity = picked_chroms[k][candidate_idx].getIntensity();
1159 if (intensity > largest)
1161 largest = intensity;
1162 chr_idx =
static_cast<int>(k);
1163 peak_idx = candidate_idx;
1189 template <
typename SpectrumT,
typename TransitionT>
1202 throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"Did not find chromatogram for id '" + native_id +
"'.");
1222 template <
typename SpectrumT,
typename TransitionT>
1224 const std::vector<SpectrumT>& picked_chroms,
1225 const std::vector<const SpectrumT*>& picked_input_chromatograms,
1227 const double best_left,
1228 const double best_right,
1229 std::string& outlier)
1234 double resample_boundary = resample_boundary_;
1235 SpectrumT master_peak_container;
1236 const SpectrumT& ref_chromatogram = *picked_input_chromatograms[chr_idx];
1237 prepareMasterContainer_(ref_chromatogram, master_peak_container, best_left - resample_boundary, best_right + resample_boundary);
1240 auto &all_ints = pool.all_ints;
1242 for (
Size k = 0; k < picked_chroms.size(); k++)
1244 const SpectrumT& chromatogram = *picked_input_chromatograms[k];
1245 const SpectrumT used_chromatogram = resampleChromatogram_(chromatogram,
1246 master_peak_container, best_left - resample_boundary, best_right + resample_boundary);
1248 std::vector<double> int_here;
1249 for (
const auto& peak : used_chromatogram) int_here.push_back(peak.getIntensity());
1251 double tic = std::accumulate(int_here.begin(), int_here.end(), 0.0);
1252 if (tic > 1e-11) all_ints.push_back(int_here);
1256 auto &mean_shapes = pool.mean_shapes;
1257 auto &mean_coel = pool.mean_coel;
1258 mean_shapes.clear();
1260 for (
Size k = 0; k < all_ints.size(); k++)
1262 std::vector<double> shapes;
1263 std::vector<double> coel;
1264 for (
Size i = 0; i < all_ints.size(); i++)
1266 if (i == k) {
continue;}
1274 shapes.push_back(res_shape);
1275 coel.push_back(res_coelution);
1281 msc = std::for_each(shapes.begin(), shapes.end(), msc);
1282 double shapes_mean = msc.
mean();
1283 msc = std::for_each(coel.begin(), coel.end(), msc);
1284 double coel_mean = msc.
mean();
1288 mean_shapes.push_back(shapes_mean);
1289 mean_coel.push_back(coel_mean);
1295 int min_index_shape = std::distance(mean_shapes.begin(), std::min_element(mean_shapes.begin(), mean_shapes.end()));
1296 int max_index_coel = std::distance(mean_coel.begin(), std::max_element(mean_coel.begin(), mean_coel.end()));
1299 int missing_peaks = 0;
1300 int multiple_peaks = 0;
1303 auto &left_borders = pool.left_borders;
1304 auto &right_borders = pool.right_borders;
1305 left_borders.clear();
1306 right_borders.clear();
1307 for (
Size k = 0; k < picked_chroms.size(); k++)
1311 double max_int = -1;
1316 for (
Size i = 0; i < picked_chroms[k].size(); i++)
1318 if (picked_chroms[k][i].getPos() >= best_left && picked_chroms[k][i].getPos() <= best_right)
1321 if (picked_chroms[k][i].getIntensity() > max_int)
1323 max_int = picked_chroms[k][i].getIntensity() > max_int;
1324 l_tmp = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][i];
1325 r_tmp = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][i];
1330 if (l_tmp > 1e-11) left_borders.push_back(l_tmp);
1331 if (r_tmp > 1e-11) right_borders.push_back(r_tmp);
1333 if (pfound == 0) missing_peaks++;
1334 if (pfound > 1) multiple_peaks++;
1339 OPENMS_LOG_DEBUG <<
" Overall found missing : " << missing_peaks <<
" and multiple : " << multiple_peaks << std::endl;
1345 if (min_index_shape == max_index_coel)
1347 OPENMS_LOG_DEBUG <<
" Element " << min_index_shape <<
" is a candidate for removal ... " << std::endl;
1348 outlier =std::string(picked_chroms[min_index_shape].getNativeID());
1360 double shape_score = std::accumulate(mean_shapes.begin(), mean_shapes.end(), 0.0) / mean_shapes.size();
1361 double coel_score = std::accumulate(mean_coel.begin(), mean_coel.end(), 0.0) / mean_coel.size();
1362 coel_score = (coel_score - 1.0) / 2.0;
1364 double score = shape_score - coel_score - 1.0 * missing_peaks / picked_chroms.size();
1366 OPENMS_LOG_DEBUG <<
" Computed score " << score <<
" (from " << shape_score <<
1367 " - " << coel_score <<
" - " << 1.0 * missing_peaks / picked_chroms.size() <<
")" << std::endl;
1381 template <
typename SpectrumT>
1390 std::vector<double> left_borders;
1391 std::vector<double> right_borders;
1392 for (
Size k = 0; k < picked_chroms.size(); k++)
1394 double max_int = -1;
1397 for (
Size i = 0; i < picked_chroms[k].size(); i++)
1399 if (picked_chroms[k][i].getPos() >= best_left && picked_chroms[k][i].getPos() <= best_right)
1401 if (picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_ABUNDANCE][i] > max_int)
1403 max_int = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_ABUNDANCE][i];
1404 left = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][i];
1405 right = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][i];
1411 left_borders.push_back(left);
1412 right_borders.push_back(right);
1413 OPENMS_LOG_DEBUG <<
" * peak " << k <<
" left boundary " << left_borders.back() <<
" with inty " << max_int << std::endl;
1414 OPENMS_LOG_DEBUG <<
" * peak " << k <<
" right boundary " << right_borders.back() <<
" with inty " << max_int << std::endl;
1419 if (right_borders.empty())
1437 mean = std::accumulate(right_borders.begin(), right_borders.end(), 0.0) / (double) right_borders.size();
1438 stdev = std::sqrt(std::inner_product(right_borders.begin(), right_borders.end(), right_borders.begin(), 0.0)
1439 / right_borders.size() - mean * mean);
1440 std::sort(right_borders.begin(), right_borders.end());
1442 OPENMS_LOG_DEBUG <<
" - Recalculating right peak boundaries " << mean <<
" mean / best "
1443 << best_right <<
" std " << stdev <<
" : " << std::fabs(best_right - mean) / stdev
1444 <<
" coefficient of variation" << std::endl;
1447 if (std::fabs(best_right - mean) / stdev > max_z)
1449 best_right = right_borders[right_borders.size() / 2];
1450 OPENMS_LOG_DEBUG <<
" - CV too large: correcting right boundary to " << best_right << std::endl;
1454 mean = std::accumulate(left_borders.begin(), left_borders.end(), 0.0) / (double) left_borders.size();
1455 stdev = std::sqrt(std::inner_product(left_borders.begin(), left_borders.end(), left_borders.begin(), 0.0)
1456 / left_borders.size() - mean * mean);
1457 std::sort(left_borders.begin(), left_borders.end());
1459 OPENMS_LOG_DEBUG <<
" - Recalculating left peak boundaries " << mean <<
" mean / best "
1460 << best_left <<
" std " << stdev <<
" : " << std::fabs(best_left - mean) / stdev
1461 <<
" coefficient of variation" << std::endl;
1464 if (std::fabs(best_left - mean) / stdev > max_z)
1466 best_left = left_borders[left_borders.size() / 2];
1467 OPENMS_LOG_DEBUG <<
" - CV too large: correcting left boundary to " << best_left << std::endl;
1489 template <
typename PeakContainerT>
1491 PeakContainerT& master_peak_container,
1492 double left_boundary,
1493 double right_boundary)
1500 auto begin = ref_chromatogram.begin();
1501 while (begin != ref_chromatogram.end() && begin->getPos() < left_boundary) {begin++; }
1502 if (begin != ref_chromatogram.begin()) { begin--; }
1505 while (end != ref_chromatogram.end() && end->getPos() < right_boundary) {end++; }
1506 if (end != ref_chromatogram.end()) { end++; }
1509 master_peak_container.resize(distance(begin, end));
1510 auto it = master_peak_container.begin();
1511 for (
auto chrom_it = begin; chrom_it != end; chrom_it++, it++)
1513 it->setPos(chrom_it->getPos());
1527 template <
typename PeakContainerT>
1529 const PeakContainerT& master_peak_container,
1530 double left_boundary,
1531 double right_boundary)
1536 auto begin = chromatogram.begin();
1537 while (begin != chromatogram.end() && begin->getPos() < left_boundary) {begin++;}
1538 if (begin != chromatogram.begin()) { begin--; }
1541 while (end != chromatogram.end() && end->getPos() < right_boundary) {end++;}
1542 if (end != chromatogram.end()) { end++; }
1544 auto resampled_peak_container = master_peak_container;
1546 lresampler.
raster(begin, end, resampled_peak_container.begin(), resampled_peak_container.end());
1548 return resampled_peak_container;
#define OPENMS_LOG_DEBUG
Definition LogStream.h:714
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:633
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:72
void raster(PeakContainerT &container)
Applies the resampling algorithm to a container (MSSpectrum or MSChromatogram).
Definition LinearResamplerAlign.h:92
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:285
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:1490
void findLargestPeakCached_(const std::vector< SpectrumT > &picked_chroms, std::vector< int > &largest_peak_indices, int &chr_idx, int &peak_idx) const
Definition MRMTransitionGroupPicker.h:1138
bool compute_total_mi_
Definition MRMTransitionGroupPicker.h:1561
std::string peak_integration_
Definition MRMTransitionGroupPicker.h:1554
bool compute_peak_quality_
Definition MRMTransitionGroupPicker.h:1559
bool use_precursors_
Definition MRMTransitionGroupPicker.h:1557
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:1528
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:698
std::string background_subtraction_
Definition MRMTransitionGroupPicker.h:1555
const SpectrumT & selectChromHelper_(const MRMTransitionGroup< SpectrumT, TransitionT > &transition_group, const std::string &native_id)
Select matching precursor or fragment ion chromatogram.
Definition MRMTransitionGroupPicker.h:1190
double min_peak_width_
Definition MRMTransitionGroupPicker.h:1566
void remove_overlapping_features(std::vector< SpectrumT > &picked_chroms, double best_left, double best_right)
Remove overlapping features.
Definition MRMTransitionGroupPicker.h:1096
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:1382
int stop_after_feature_
Definition MRMTransitionGroupPicker.h:1564
PeakPickerChromatogram picker_
Definition MRMTransitionGroupPicker.h:1577
double recalculate_peaks_max_z_
Definition MRMTransitionGroupPicker.h:1567
PeakIntegrator pi_
Definition MRMTransitionGroupPicker.h:1578
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:1562
double resample_boundary_
Definition MRMTransitionGroupPicker.h:1568
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:495
~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:739
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:556
void updateMembers_() override
Synchronize members with param class.
double stop_after_intensity_ratio_
Definition MRMTransitionGroupPicker.h:1565
void pickTransitionGroup(MRMTransitionGroup< SpectrumT, TransitionT > &transition_group)
Pick a group of chromatograms belonging to the same peptide.
Definition MRMTransitionGroupPicker.h:317
MRMTransitionGroupPicker & operator=(const MRMTransitionGroupPicker &rhs)
Assignment operator is protected for algorithm.
bool use_consensus_
Definition MRMTransitionGroupPicker.h:1558
std::string boundary_selection_method_
Which method to use for selecting peaks' boundaries.
Definition MRMTransitionGroupPicker.h:1575
bool recalculate_peaks_
Definition MRMTransitionGroupPicker.h:1556
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:952
bool compute_peak_shape_metrics_
Definition MRMTransitionGroupPicker.h:1560
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:1223
The representation of a group of transitions in a targeted proteomics experiment.
Definition MRMTransitionGroup.h:41
bool hasPrecursorChromatogram(const std::string &key) const
Definition MRMTransitionGroup.h:241
const std::vector< TransitionType > & getTransitions() const
Definition MRMTransitionGroup.h:115
ChromatogramType & getPrecursorChromatogram(const std::string &key)
Definition MRMTransitionGroup.h:246
const TransitionType & getTransition(const std::string &key)
Definition MRMTransitionGroup.h:148
ChromatogramType & getChromatogram(const std::string &key)
Definition MRMTransitionGroup.h:192
bool isInternallyConsistent() const
Check whether internal state is consistent, e.g. same number of chromatograms and transitions are pre...
Definition MRMTransitionGroup.h:290
bool chromatogramIdsMatch() const
Ensure that chromatogram native ids match their keys in the map.
Definition MRMTransitionGroup.h:299
const std::string & getTransitionGroupID() const
Definition MRMTransitionGroup.h:103
void addFeature(const MRMFeature &feature)
Definition MRMTransitionGroup.h:274
std::vector< ChromatogramType > & getPrecursorChromatograms()
Definition MRMTransitionGroup.h:210
std::vector< ChromatogramType > & getChromatograms()
Definition MRMTransitionGroup.h:159
bool hasChromatogram(const std::string &key) const
Definition MRMTransitionGroup.h:187
bool hasTransition(const std::string &key) const
Definition MRMTransitionGroup.h:143
The representation of a chromatogram.
Definition MSChromatogram.h:33
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:51
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
OpenMS looks in the< code > OPENMS_THERMO_MANAGED_DIR</code > environment variable first
Definition common-cmake-parameters.doxygen:199
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:91
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
PickerPoolShared & g_picker_pool_shared()
Definition MRMTransitionGroupPicker.h:81
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:40
std::vector< double > right_edges
Definition MRMTransitionGroupPicker.h:47
std::vector< double > transition_total_xics
Definition MRMTransitionGroupPicker.h:54
std::vector< double > mean_coel
Definition MRMTransitionGroupPicker.h:50
std::vector< double > mean_shapes
Definition MRMTransitionGroupPicker.h:49
std::vector< double > right_borders
Definition MRMTransitionGroupPicker.h:52
std::vector< double > left_borders
Definition MRMTransitionGroupPicker.h:51
std::vector< const MSChromatogram * > picked_input_chromatograms
Definition MRMTransitionGroupPicker.h:43
std::vector< MRMFeature > features
Definition MRMTransitionGroupPicker.h:45
std::vector< const MSChromatogram * > transition_chromatograms
Definition MRMTransitionGroupPicker.h:44
std::vector< MSChromatogram > picked_chroms
Definition MRMTransitionGroupPicker.h:41
std::vector< double > left_edges
Definition MRMTransitionGroupPicker.h:46
std::vector< MSChromatogram > smoothed_chroms
Definition MRMTransitionGroupPicker.h:42
std::vector< int > largest_peak_indices
Definition MRMTransitionGroupPicker.h:53
std::vector< std::vector< double > > all_ints
Definition MRMTransitionGroupPicker.h:48
void reset()
Definition MRMTransitionGroupPicker.h:56