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;
461 std::vector<char> keep(features.size(), 0);
462 for (
Size i = 0; i < features.size(); i++)
466 for (
Size j = 0; j < i; j++)
468 if ((
double)mrm_feature.
getMetaValue(MRMTransitionGroupPickerMeta::leftWidth()) >= (
double)features[j].getMetaValue(MRMTransitionGroupPickerMeta::leftWidth()) &&
469 (
double)mrm_feature.
getMetaValue(MRMTransitionGroupPickerMeta::rightWidth()) <= (
double)features[j].getMetaValue(MRMTransitionGroupPickerMeta::rightWidth()))
474 for (
Size i = 0; i < features.size(); i++)
478 transition_group.
addFeature(std::move(features[i]));
500 template <
typename SpectrumT,
typename TransitionT>
502 std::vector<SpectrumT>& picked_chroms,
503 const std::vector<SpectrumT>& smoothed_chroms,
507 std::vector<double> transition_total_xics;
508 transition_total_xics.reserve(transition_group.
getTransitions().size());
509 std::vector<const SpectrumT*> transition_chromatograms;
510 transition_chromatograms.reserve(transition_group.
getTransitions().size());
511 double detecting_total_xic = 0.0;
512 for (
const TransitionT& transition : transition_group.
getTransitions())
514 const SpectrumT& chromatogram = selectChromHelper_(transition_group, transition.getNativeID());
515 transition_chromatograms.push_back(&chromatogram);
516 const double transition_total_xic = std::accumulate(chromatogram.begin(), chromatogram.end(), 0.0,
517 [](
double total,
const auto& peak)
519 return total + peak.getIntensity();
521 transition_total_xics.push_back(transition_total_xic);
522 if (transition.isDetectingTransition())
524 detecting_total_xic += transition_total_xic;
528 std::vector<const SpectrumT*> picked_input_chromatograms;
529 picked_input_chromatograms.reserve(picked_chroms.size());
530 for (
const SpectrumT& picked_chrom : picked_chroms)
532 picked_input_chromatograms.push_back(&selectChromHelper_(transition_group, picked_chrom.getNativeID()));
535 return createMRMFeature(transition_group, picked_chroms, smoothed_chroms,
536 transition_total_xics, detecting_total_xic,
537 transition_chromatograms, picked_input_chromatograms,
561 template <
typename SpectrumT,
typename TransitionT>
563 std::vector<SpectrumT>& picked_chroms,
564 const std::vector<SpectrumT>& smoothed_chroms,
565 const std::vector<double>& transition_total_xics,
566 double detecting_total_xic,
567 const std::vector<const SpectrumT*>& transition_chromatograms,
568 const std::vector<const SpectrumT*>& picked_input_chromatograms,
577 double best_left = picked_chroms[chr_idx].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][peak_idx];
578 double best_right = picked_chroms[chr_idx].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][peak_idx];
579 double peak_apex = picked_chroms[chr_idx][peak_idx].getRT();
580 OPENMS_LOG_DEBUG <<
"**** Creating MRMFeature for peak " << peak_idx <<
" in chrom. " << chr_idx <<
" with " <<
581 picked_chroms[chr_idx][peak_idx] <<
" and borders " << best_left <<
" " <<
582 best_right <<
" (" << best_right - best_left <<
")" << std::endl;
584 if (use_consensus_ && recalculate_peaks_)
587 recalculatePeakBorders_(picked_chroms, best_left, best_right, recalculate_peaks_max_z_);
588 if (peak_apex < best_left || peak_apex > best_right)
591 peak_apex = (best_left + best_right) / 2.0;
597 struct CreateFeaturePool
599 std::vector<double> left_edges;
600 std::vector<double> right_edges;
601 void reset() { left_edges.clear(); right_edges.clear(); }
603 thread_local CreateFeaturePool create_feat_pool;
604 create_feat_pool.reset();
605 auto &left_edges = create_feat_pool.left_edges;
606 auto &right_edges = create_feat_pool.right_edges;
607 double min_left = best_left;
608 double max_right = best_right;
614 remove_overlapping_features(picked_chroms, best_left, best_right);
618 pickApex(picked_chroms, best_left, best_right, peak_apex,
619 min_left, max_right, left_edges, right_edges);
622 picked_chroms[chr_idx][peak_idx].setIntensity(0.0);
627 if (min_peak_width_ > 0.0 && std::fabs(best_right - best_left) < min_peak_width_)
632 if (compute_peak_quality_)
634 std::string outlier =
"none";
635 double qual = computeQuality_(transition_group, picked_chroms, picked_input_chromatograms,
636 chr_idx, best_left, best_right, outlier);
637 if (qual < min_qual_)
641 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::potentialOutlier(), outlier);
642 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::initialPeakQuality(), qual);
651 SpectrumT master_peak_container;
652 const SpectrumT& ref_chromatogram = *picked_input_chromatograms[chr_idx];
653 prepareMasterContainer_(ref_chromatogram, master_peak_container, min_left, max_right);
658 double total_intensity = 0;
double total_peak_apices = 0;
double total_xic = 0;
double total_mi = 0;
659 pickFragmentChromatograms(transition_group, picked_chroms, mrmFeature, smoothed_chroms,
660 best_left, best_right, use_consensus_,
661 total_intensity, total_xic, total_mi, total_peak_apices,
662 master_peak_container, left_edges, right_edges,
663 transition_total_xics, detecting_total_xic,
664 transition_chromatograms,
669 pickPrecursorChromatograms(transition_group,
670 picked_chroms, mrmFeature, smoothed_chroms,
671 best_left, best_right, use_consensus_,
672 total_intensity, master_peak_container, left_edges, right_edges,
675 mrmFeature.
setRT(peak_apex);
678 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::leftWidth(), best_left);
679 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::rightWidth(), best_right);
680 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::totalXIC(), total_xic);
681 if (compute_total_mi_)
683 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::totalMI(), total_mi);
685 mrmFeature.
setMetaValue(MRMTransitionGroupPickerMeta::peakApicesSum(), total_peak_apices);
703 template <
typename SpectrumT>
704 void pickApex(std::vector<SpectrumT>& picked_chroms,
705 const double best_left,
const double best_right,
const double peak_apex,
706 double &min_left,
double &max_right,
707 std::vector< double > & left_edges, std::vector< double > & right_edges)
709 for (
Size k = 0; k < picked_chroms.size(); k++)
711 double peak_apex_dist_min = std::numeric_limits<double>::max();
713 for (
Size i = 0; i < picked_chroms[k].size(); i++)
717 picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][i],
718 picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][i]);
719 if (pa_tmp.
apex_pos > 1e-11 && std::fabs(pa_tmp.
apex_pos - peak_apex) < peak_apex_dist_min)
721 peak_apex_dist_min = std::fabs(pa_tmp.
apex_pos - peak_apex);
727 double l = best_left;
728 double r = best_right;
731 l = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][min_dist];
732 r = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][min_dist];
733 picked_chroms[k][min_dist].setIntensity(0.0);
736 left_edges.push_back(l);
737 right_edges.push_back(r);
739 if (l < min_left) {min_left = l;}
740 if (r > max_right) {max_right = r;}
744 template <
typename SpectrumT,
typename TransitionT>
746 const std::vector<SpectrumT>& picked_chroms,
748 const std::vector<SpectrumT>& smoothed_chroms,
749 const double best_left,
const double best_right,
750 const bool use_consensus_,
751 double & total_intensity,
754 double & total_peak_apices,
755 const SpectrumT & master_peak_container,
756 const std::vector< double > & left_edges,
757 const std::vector< double > & right_edges,
758 const std::vector<double>& transition_total_xics,
759 double detecting_total_xic,
760 const std::vector<const SpectrumT*>& transition_chromatograms,
764 total_xic += detecting_total_xic;
768 double local_left = best_left;
769 double local_right = best_right;
775 if (!transition_group.
getTransitions()[k].isDetectingTransition())
778 "When using non-consensus peak picker, all transitions need to be detecting transitions.");
780 local_left = left_edges[k];
781 local_right = right_edges[k];
784 const SpectrumT& chromatogram = *transition_chromatograms[k];
787 const double transition_total_xic = transition_total_xics[k];
790 double transition_total_mi = 0;
791 if (compute_total_mi_)
794 thread_local std::vector<unsigned int> chrom_vect_id_ranked;
795 thread_local std::vector<unsigned int> chrom_vect_det_ranked;
796 thread_local std::vector<double> chrom_vect_id;
797 thread_local std::vector<double> chrom_vect_det;
798 chrom_vect_id.clear(); chrom_vect_det.clear(); chrom_vect_id_ranked.clear(); chrom_vect_det_ranked.clear();
799 for (
typename SpectrumT::const_iterator it = chromatogram.begin(); it != chromatogram.end(); it++)
801 chrom_vect_id.push_back(it->getIntensity());
805 int transition_total_mi_norm = 0;
810 const SpectrumT& chromatogram_det = *transition_chromatograms[m];
811 chrom_vect_det.clear();
812 for (
typename SpectrumT::const_iterator it = chromatogram_det.begin(); it != chromatogram_det.end(); it++)
814 chrom_vect_det.push_back(it->getIntensity());
818 transition_total_mi_norm++;
821 if (transition_total_mi_norm > 0) { transition_total_mi /= transition_total_mi_norm; }
826 total_mi += transition_total_mi / transition_total_mi_norm;
830 SpectrumT used_chromatogram;
832 if (peak_integration_ ==
"original")
834 used_chromatogram = resampleChromatogram_(chromatogram, master_peak_container, local_left, local_right);
836 else if (peak_integration_ ==
"smoothed")
838 if (smoothed_chroms.size() <= k)
841 "Tried to calculate peak area and height without any smoothed chromatograms");
843 used_chromatogram = resampleChromatogram_(smoothed_chroms[k], master_peak_container, local_left, local_right);
848 std::string(
"Peak integration chromatogram ") + peak_integration_ +
" is not a valid method for MRMTransitionGroupPicker");
857 double peak_integral = pa.
area;
858 double peak_apex_int = pa.
height;
868 for (
const auto& p : used_chromatogram)
874 if (background_subtraction_ !=
"none")
876 double background{0};
877 double avg_noise_level{0};
878 if (background_subtraction_ ==
"original")
880 const double intensity_left = chromatogram.PosBegin(local_left)->getIntensity();
881 const double intensity_right = (chromatogram.PosEnd(local_right) - 1)->getIntensity();
882 const UInt n_points = std::distance(chromatogram.PosBegin(local_left), chromatogram.PosEnd(local_right));
883 avg_noise_level = (intensity_right + intensity_left) / 2;
884 background = avg_noise_level * n_points;
886 else if (background_subtraction_ ==
"exact")
889 background = pb.
area;
890 avg_noise_level = pb.
height;
892 peak_integral -= background;
893 peak_apex_int -= avg_noise_level;
894 if (peak_integral < 0) {peak_integral = 0;}
895 if (peak_apex_int < 0) {peak_apex_int = 0;}
897 f.
setMetaValue(MRMTransitionGroupPickerMeta::areaBackgroundLevel(), background);
898 f.
setMetaValue(MRMTransitionGroupPickerMeta::noiseBackgroundLevel(), avg_noise_level);
901 f.
setRT(picked_chroms[chr_idx][peak_idx].getPos());
907 f.
setMZ(chromatogram.getProduct().getMZ());
908 mrmFeature.
setMZ(chromatogram.getPrecursor().getMZ());
910 if (chromatogram.metaValueExists(
"product_mz"))
912 f.
setMetaValue(
"MZ", chromatogram.getMetaValue(
"product_mz"));
913 f.
setMZ(chromatogram.getMetaValue(
"product_mz"));
916 f.
setMetaValue(MRMTransitionGroupPickerMeta::nativeID(), chromatogram.getNativeID());
917 f.
setMetaValue(MRMTransitionGroupPickerMeta::peakApexInt(), peak_apex_int);
918 f.
setMetaValue(MRMTransitionGroupPickerMeta::totalXIC(), transition_total_xic);
919 if (compute_total_mi_)
921 f.
setMetaValue(MRMTransitionGroupPickerMeta::totalMI(), transition_total_mi);
924 if (transition_group.
getTransitions()[k].isQuantifyingTransition())
926 total_intensity += peak_integral;
927 total_peak_apices += peak_apex_int;
934 if (compute_peak_shape_metrics_)
953 mrmFeature.
addFeature(std::move(f), chromatogram.getNativeID());
957 template <
typename SpectrumT,
typename TransitionT>
959 const std::vector<SpectrumT>& picked_chroms,
961 const std::vector<SpectrumT>& smoothed_chroms,
962 const double best_left,
const double best_right,
963 const bool use_consensus_,
964 double & total_intensity,
965 const SpectrumT & master_peak_container,
966 const std::vector< double > & left_edges,
967 const std::vector< double > & right_edges,
979 double local_left = best_left;
980 double local_right = best_right;
981 if (!use_consensus_ && right_edges.size() > prec_idx && left_edges.size() > prec_idx)
983 local_left = left_edges[prec_idx];
984 local_right = right_edges[prec_idx];
987 SpectrumT used_chromatogram;
989 if (peak_integration_ ==
"original")
991 used_chromatogram = resampleChromatogram_(chromatogram, master_peak_container, local_left, local_right);
994 else if (peak_integration_ ==
"smoothed" && smoothed_chroms.size() <= prec_idx)
997 "Tried to calculate peak area and height without any smoothed chromatograms for precursors");
999 else if (peak_integration_ ==
"smoothed")
1001 used_chromatogram = resampleChromatogram_(smoothed_chroms[prec_idx], master_peak_container, local_left, local_right);
1006 std::string(
"Peak integration chromatogram ") + peak_integration_ +
" is not a valid method for MRMTransitionGroupPicker");
1015 double peak_integral = pa.
area;
1016 double peak_apex_int = pa.
height;
1021 if (!use_consensus_)
1024 for (
const auto& p : used_chromatogram)
1030 if (background_subtraction_ !=
"none")
1032 double background{0};
1033 double avg_noise_level{0};
1034 if ((peak_integration_ ==
"smoothed") && smoothed_chroms.size() <= prec_idx)
1037 "Tried to calculate background estimation without any smoothed chromatograms");
1039 else if (background_subtraction_ ==
"original")
1041 const double intensity_left = chromatogram.PosBegin(local_left)->getIntensity();
1042 const double intensity_right = (chromatogram.PosEnd(local_right) - 1)->getIntensity();
1043 const UInt n_points = std::distance(chromatogram.PosBegin(local_left), chromatogram.PosEnd(local_right));
1044 avg_noise_level = (intensity_right + intensity_left) / 2;
1045 background = avg_noise_level * n_points;
1047 else if (background_subtraction_ ==
"exact")
1050 background = pb.
area;
1051 avg_noise_level = pb.
height;
1053 peak_integral -= background;
1054 peak_apex_int -= avg_noise_level;
1055 if (peak_integral < 0) {peak_integral = 0;}
1056 if (peak_apex_int < 0) {peak_apex_int = 0;}
1058 f.
setMetaValue(MRMTransitionGroupPickerMeta::areaBackgroundLevel(), background);
1059 f.
setMetaValue(MRMTransitionGroupPickerMeta::noiseBackgroundLevel(), avg_noise_level);
1062 f.
setMZ(chromatogram.getPrecursor().getMZ());
1063 if (k == 0) {mrmFeature.
setMZ(chromatogram.getPrecursor().getMZ());}
1065 if (chromatogram.metaValueExists(
"precursor_mz"))
1067 f.
setMZ(chromatogram.getMetaValue(
"precursor_mz"));
1068 if (k == 0) {mrmFeature.
setMZ(chromatogram.getMetaValue(
"precursor_mz"));}
1071 f.
setRT(picked_chroms[chr_idx][peak_idx].getPos());
1076 f.
setMetaValue(MRMTransitionGroupPickerMeta::nativeID(), chromatogram.getNativeID());
1077 f.
setMetaValue(MRMTransitionGroupPickerMeta::peakApexInt(), peak_apex_int);
1079 if (use_precursors_ && transition_group.
getTransitions().empty())
1081 total_intensity += peak_integral;
1101 template <
typename SpectrumT>
1105 Size count_inside = 0;
1106 for (
Size k = 0; k < picked_chroms.size(); k++)
1108 for (
Size i = 0; i < picked_chroms[k].size(); i++)
1110 if (picked_chroms[k][i].getPos() >= best_left && picked_chroms[k][i].getPos() <= best_right)
1112 picked_chroms[k][i].setIntensity(0.0);
1118 Size count_overlap = 0;
1120 for (
Size k = 0; k < picked_chroms.size(); k++)
1122 for (
Size i = 0; i < picked_chroms[k].size(); i++)
1124 if (picked_chroms[k][i].getIntensity() <= 1e-11) {
continue; }
1126 double left = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][i];
1127 double right = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][i];
1128 if ((left > best_left && left < best_right)
1129 || (right > best_left && right < best_right))
1131 picked_chroms[k][i].setIntensity(0.0);
1136 OPENMS_LOG_DEBUG <<
" ** Removed " << count_inside <<
" peaks enclosed in and " <<
1137 count_overlap <<
" peaks overlapping with added feature." << std::endl;
1141 void findLargestPeak(
const std::vector<MSChromatogram >& picked_chroms,
int& chr_idx,
int& peak_idx);
1143 template <
typename SpectrumT>
1145 std::vector<int>& largest_peak_indices,
1147 int& peak_idx)
const
1150 "Cached largest peak indices must match picked chromatogram count.");
1151 double largest = 0.0;
1152 for (
Size k = 0; k < picked_chroms.size(); k++)
1154 int candidate_idx = largest_peak_indices[k];
1155 while (candidate_idx >= 0 && picked_chroms[k][candidate_idx].getIntensity() <= 0.0)
1159 largest_peak_indices[k] = candidate_idx;
1160 if (candidate_idx < 0)
1164 const double intensity = picked_chroms[k][candidate_idx].getIntensity();
1165 if (intensity > largest)
1167 largest = intensity;
1168 chr_idx =
static_cast<int>(k);
1169 peak_idx = candidate_idx;
1195 template <
typename SpectrumT,
typename TransitionT>
1208 throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"Did not find chromatogram for id '" + native_id +
"'.");
1228 template <
typename SpectrumT,
typename TransitionT>
1230 const std::vector<SpectrumT>& picked_chroms,
1231 const std::vector<const SpectrumT*>& picked_input_chromatograms,
1233 const double best_left,
1234 const double best_right,
1235 std::string& outlier)
1240 double resample_boundary = resample_boundary_;
1241 SpectrumT master_peak_container;
1242 const SpectrumT& ref_chromatogram = *picked_input_chromatograms[chr_idx];
1243 prepareMasterContainer_(ref_chromatogram, master_peak_container, best_left - resample_boundary, best_right + resample_boundary);
1246 auto &all_ints = pool.all_ints;
1248 for (
Size k = 0; k < picked_chroms.size(); k++)
1250 const SpectrumT& chromatogram = *picked_input_chromatograms[k];
1251 const SpectrumT used_chromatogram = resampleChromatogram_(chromatogram,
1252 master_peak_container, best_left - resample_boundary, best_right + resample_boundary);
1254 std::vector<double> int_here;
1255 for (
const auto& peak : used_chromatogram) int_here.push_back(peak.getIntensity());
1257 double tic = std::accumulate(int_here.begin(), int_here.end(), 0.0);
1258 if (tic > 1e-11) all_ints.push_back(int_here);
1262 auto &mean_shapes = pool.mean_shapes;
1263 auto &mean_coel = pool.mean_coel;
1264 mean_shapes.clear();
1266 for (
Size k = 0; k < all_ints.size(); k++)
1268 std::vector<double> shapes;
1269 std::vector<double> coel;
1270 for (
Size i = 0; i < all_ints.size(); i++)
1272 if (i == k) {
continue;}
1280 shapes.push_back(res_shape);
1281 coel.push_back(res_coelution);
1287 msc = std::for_each(shapes.begin(), shapes.end(), msc);
1288 double shapes_mean = msc.
mean();
1289 msc = std::for_each(coel.begin(), coel.end(), msc);
1290 double coel_mean = msc.
mean();
1294 mean_shapes.push_back(shapes_mean);
1295 mean_coel.push_back(coel_mean);
1301 int min_index_shape = std::distance(mean_shapes.begin(), std::min_element(mean_shapes.begin(), mean_shapes.end()));
1302 int max_index_coel = std::distance(mean_coel.begin(), std::max_element(mean_coel.begin(), mean_coel.end()));
1305 int missing_peaks = 0;
1306 int multiple_peaks = 0;
1309 auto &left_borders = pool.left_borders;
1310 auto &right_borders = pool.right_borders;
1311 left_borders.clear();
1312 right_borders.clear();
1313 for (
Size k = 0; k < picked_chroms.size(); k++)
1317 double max_int = -1;
1322 for (
Size i = 0; i < picked_chroms[k].size(); i++)
1324 if (picked_chroms[k][i].getPos() >= best_left && picked_chroms[k][i].getPos() <= best_right)
1327 if (picked_chroms[k][i].getIntensity() > max_int)
1329 max_int = picked_chroms[k][i].getIntensity() > max_int;
1330 l_tmp = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][i];
1331 r_tmp = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][i];
1336 if (l_tmp > 1e-11) left_borders.push_back(l_tmp);
1337 if (r_tmp > 1e-11) right_borders.push_back(r_tmp);
1339 if (pfound == 0) missing_peaks++;
1340 if (pfound > 1) multiple_peaks++;
1345 OPENMS_LOG_DEBUG <<
" Overall found missing : " << missing_peaks <<
" and multiple : " << multiple_peaks << std::endl;
1351 if (min_index_shape == max_index_coel)
1353 OPENMS_LOG_DEBUG <<
" Element " << min_index_shape <<
" is a candidate for removal ... " << std::endl;
1354 outlier =std::string(picked_chroms[min_index_shape].getNativeID());
1366 double shape_score = std::accumulate(mean_shapes.begin(), mean_shapes.end(), 0.0) / mean_shapes.size();
1367 double coel_score = std::accumulate(mean_coel.begin(), mean_coel.end(), 0.0) / mean_coel.size();
1368 coel_score = (coel_score - 1.0) / 2.0;
1370 double score = shape_score - coel_score - 1.0 * missing_peaks / picked_chroms.size();
1372 OPENMS_LOG_DEBUG <<
" Computed score " << score <<
" (from " << shape_score <<
1373 " - " << coel_score <<
" - " << 1.0 * missing_peaks / picked_chroms.size() <<
")" << std::endl;
1387 template <
typename SpectrumT>
1396 std::vector<double> left_borders;
1397 std::vector<double> right_borders;
1398 for (
Size k = 0; k < picked_chroms.size(); k++)
1400 double max_int = -1;
1403 for (
Size i = 0; i < picked_chroms[k].size(); i++)
1405 if (picked_chroms[k][i].getPos() >= best_left && picked_chroms[k][i].getPos() <= best_right)
1407 if (picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_ABUNDANCE][i] > max_int)
1409 max_int = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_ABUNDANCE][i];
1410 left = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_LEFTBORDER][i];
1411 right = picked_chroms[k].getFloatDataArrays()[PeakPickerChromatogram::IDX_RIGHTBORDER][i];
1417 left_borders.push_back(left);
1418 right_borders.push_back(right);
1419 OPENMS_LOG_DEBUG <<
" * peak " << k <<
" left boundary " << left_borders.back() <<
" with inty " << max_int << std::endl;
1420 OPENMS_LOG_DEBUG <<
" * peak " << k <<
" right boundary " << right_borders.back() <<
" with inty " << max_int << std::endl;
1425 if (right_borders.empty())
1443 mean = std::accumulate(right_borders.begin(), right_borders.end(), 0.0) / (double) right_borders.size();
1444 stdev = std::sqrt(std::inner_product(right_borders.begin(), right_borders.end(), right_borders.begin(), 0.0)
1445 / right_borders.size() - mean * mean);
1446 std::sort(right_borders.begin(), right_borders.end());
1448 OPENMS_LOG_DEBUG <<
" - Recalculating right peak boundaries " << mean <<
" mean / best "
1449 << best_right <<
" std " << stdev <<
" : " << std::fabs(best_right - mean) / stdev
1450 <<
" coefficient of variation" << std::endl;
1453 if (std::fabs(best_right - mean) / stdev > max_z)
1455 best_right = right_borders[right_borders.size() / 2];
1456 OPENMS_LOG_DEBUG <<
" - CV too large: correcting right boundary to " << best_right << std::endl;
1460 mean = std::accumulate(left_borders.begin(), left_borders.end(), 0.0) / (double) left_borders.size();
1461 stdev = std::sqrt(std::inner_product(left_borders.begin(), left_borders.end(), left_borders.begin(), 0.0)
1462 / left_borders.size() - mean * mean);
1463 std::sort(left_borders.begin(), left_borders.end());
1465 OPENMS_LOG_DEBUG <<
" - Recalculating left peak boundaries " << mean <<
" mean / best "
1466 << best_left <<
" std " << stdev <<
" : " << std::fabs(best_left - mean) / stdev
1467 <<
" coefficient of variation" << std::endl;
1470 if (std::fabs(best_left - mean) / stdev > max_z)
1472 best_left = left_borders[left_borders.size() / 2];
1473 OPENMS_LOG_DEBUG <<
" - CV too large: correcting left boundary to " << best_left << std::endl;
1495 template <
typename PeakContainerT>
1497 PeakContainerT& master_peak_container,
1498 double left_boundary,
1499 double right_boundary)
1506 auto begin = ref_chromatogram.begin();
1507 while (begin != ref_chromatogram.end() && begin->getPos() < left_boundary) {begin++; }
1508 if (begin != ref_chromatogram.begin()) { begin--; }
1511 while (end != ref_chromatogram.end() && end->getPos() < right_boundary) {end++; }
1512 if (end != ref_chromatogram.end()) { end++; }
1515 master_peak_container.resize(distance(begin, end));
1516 auto it = master_peak_container.begin();
1517 for (
auto chrom_it = begin; chrom_it != end; chrom_it++, it++)
1519 it->setPos(chrom_it->getPos());
1533 template <
typename PeakContainerT>
1535 const PeakContainerT& master_peak_container,
1536 double left_boundary,
1537 double right_boundary)
1542 auto begin = chromatogram.begin();
1543 while (begin != chromatogram.end() && begin->getPos() < left_boundary) {begin++;}
1544 if (begin != chromatogram.begin()) { begin--; }
1547 while (end != chromatogram.end() && end->getPos() < right_boundary) {end++;}
1548 if (end != chromatogram.end()) { end++; }
1550 auto resampled_peak_container = master_peak_container;
1553 lresampler.
raster(begin, end, resampled_peak_container.begin(), resampled_peak_container.end());
1555 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:1496
void findLargestPeakCached_(const std::vector< SpectrumT > &picked_chroms, std::vector< int > &largest_peak_indices, int &chr_idx, int &peak_idx) const
Definition MRMTransitionGroupPicker.h:1144
bool compute_total_mi_
Definition MRMTransitionGroupPicker.h:1568
std::string peak_integration_
Definition MRMTransitionGroupPicker.h:1561
bool compute_peak_quality_
Definition MRMTransitionGroupPicker.h:1566
bool use_precursors_
Definition MRMTransitionGroupPicker.h:1564
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:1534
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:704
std::string background_subtraction_
Definition MRMTransitionGroupPicker.h:1562
const SpectrumT & selectChromHelper_(const MRMTransitionGroup< SpectrumT, TransitionT > &transition_group, const std::string &native_id)
Select matching precursor or fragment ion chromatogram.
Definition MRMTransitionGroupPicker.h:1196
double min_peak_width_
Definition MRMTransitionGroupPicker.h:1573
void remove_overlapping_features(std::vector< SpectrumT > &picked_chroms, double best_left, double best_right)
Remove overlapping features.
Definition MRMTransitionGroupPicker.h:1102
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:1388
int stop_after_feature_
Definition MRMTransitionGroupPicker.h:1571
PeakPickerChromatogram picker_
Definition MRMTransitionGroupPicker.h:1584
double recalculate_peaks_max_z_
Definition MRMTransitionGroupPicker.h:1574
PeakIntegrator pi_
Definition MRMTransitionGroupPicker.h:1585
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:1569
double resample_boundary_
Definition MRMTransitionGroupPicker.h:1575
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:501
~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:745
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:562
void updateMembers_() override
Synchronize members with param class.
double stop_after_intensity_ratio_
Definition MRMTransitionGroupPicker.h:1572
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:1565
std::string boundary_selection_method_
Which method to use for selecting peaks' boundaries.
Definition MRMTransitionGroupPicker.h:1582
bool recalculate_peaks_
Definition MRMTransitionGroupPicker.h:1563
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:958
bool compute_peak_shape_metrics_
Definition MRMTransitionGroupPicker.h:1567
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:1229
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:253
const std::vector< TransitionType > & getTransitions() const
Definition MRMTransitionGroup.h:115
ChromatogramType & getPrecursorChromatogram(const std::string &key)
Definition MRMTransitionGroup.h:258
const TransitionType & getTransition(const std::string &key)
Definition MRMTransitionGroup.h:148
ChromatogramType & getChromatogram(const std::string &key)
Definition MRMTransitionGroup.h:204
bool isInternallyConsistent() const
Check whether internal state is consistent, e.g. same number of chromatograms and transitions are pre...
Definition MRMTransitionGroup.h:302
bool chromatogramIdsMatch() const
Ensure that chromatogram native ids match their keys in the map.
Definition MRMTransitionGroup.h:311
const std::string & getTransitionGroupID() const
Definition MRMTransitionGroup.h:103
void addFeature(const MRMFeature &feature)
Definition MRMTransitionGroup.h:286
std::vector< ChromatogramType > & getPrecursorChromatograms()
Definition MRMTransitionGroup.h:222
std::vector< ChromatogramType > & getChromatograms()
Definition MRMTransitionGroup.h:159
bool hasChromatogram(const std::string &key) const
Definition MRMTransitionGroup.h:199
bool hasTransition(const std::string &key) const
Definition MRMTransitionGroup.h:143
The representation of a chromatogram.
Definition MSChromatogram.h:34
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:179
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