OpenMS
Loading...
Searching...
No Matches
Biosaur2Algorithm.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Timo Sachsenberg $
7// --------------------------------------------------------------------------
8
9#pragma once
10
14
15#include <map>
16#include <vector>
17
18namespace OpenMS
19{
20
50class OPENMS_DLLAPI Biosaur2Algorithm :
52{
53public:
62 struct Hill
63 {
64 std::vector<Size> scan_indices;
65 std::vector<Size> peak_indices;
66 std::vector<double> mz_values;
67 std::vector<double> intensities;
68 std::vector<double> rt_values;
69 std::vector<double> drift_times;
70 std::vector<double> ion_mobilities;
71 double mz_weighted_mean = 0.0;
72 double rt_start = 0.0;
73 double rt_end = 0.0;
74 double rt_apex = 0.0;
75 double intensity_apex = 0.0;
76 double intensity_sum = 0.0;
77 double drift_time_median = -1.0;
78 double ion_mobility_median = -1.0;
79 Size length = 0;
80 Size hill_idx = 0;
81 };
82
91 {
92 Size hill_idx = 0;
93 Size isotope_number = 0;
94 double mass_diff_ppm = 0.0;
95 double cos_corr = 0.0;
96 };
97
107 {
108 double mz = 0.0;
109 double rt_start = 0.0;
110 double rt_end = 0.0;
111 double rt_apex = 0.0;
112 double intensity_apex = 0.0;
113 double intensity_sum = 0.0;
114 int charge = 0;
115 Size n_isotopes = 0;
116 Size n_scans = 0;
117 double mass_calib = 0.0;
118 double drift_time = -1.0;
119 double ion_mobility = -1.0;
120 std::vector<IsotopeCandidate> isotopes;
121 Size mono_hill_idx = 0;
122 };
123
130
136 void setMSData(const MSExperiment& ms_data);
137
143 void setMSData(MSExperiment&& ms_data);
144
151
157 const MSExperiment& getMSData() const;
158
169 void run(FeatureMap& feature_map);
170
196 void run(FeatureMap& feature_map,
197 std::vector<Hill>& hills,
198 std::vector<PeptideFeature>& peptide_features);
199
209 void writeTSV(const std::vector<PeptideFeature>& features, const std::string& filename) const;
210
220 void writeHills(const std::vector<Hill>& hills, const std::string& filename) const;
221
222protected:
224 void updateMembers_() override;
225
226private:
228
229
237 {
238 Size hill_index = 0;
239 Size first_scan = 0;
240 Size last_scan = 0;
241 };
242
250 {
251 Size mono_index = 0;
252 double mono_mz = 0.0;
253 int charge = 0;
254 double cos_cor_isotopes = 0.0;
255 std::vector<IsotopeCandidate> isotopes;
256 Size n_scans = 0;
257 };
258
260
262
263
271 double calculatePPM_(double mz1, double mz2) const;
272
279 double calculateMedian_(const std::vector<double>& values) const;
280
286 double cosineCorrelation1D_(const std::vector<double>& v1,
287 const std::vector<double>& v2) const;
288
296 std::pair<double, Size> checkingCosCorrelationForCarbon_(const std::vector<double>& theor_full,
297 const std::vector<double>& exp_full,
298 double thresh) const;
299
308 std::pair<std::vector<double>, Size> computeAveragine_(double neutral_mass,
309 double apex_intensity) const;
310
320 std::vector<double> meanFilter_(const std::vector<double>& data, Size window) const;
321
331 std::pair<double, double> calibrateMass_(const std::vector<double>& mass_errors, double bin_width = 0.05) const;
332
341 double htol_ppm,
342 double min_intensity,
343 double min_mz,
344 double max_mz) const;
345
354 void processTOF_(MSExperiment& exp) const;
355
362
373 void centroidPASEFData_(MSExperiment& exp, double mz_step, double pasef_tolerance) const;
374
392 std::vector<Hill> detectHills_(const MSExperiment& exp, double htol_ppm, double min_intensity, double min_mz, double max_mz, bool use_im, Size min_length, std::vector<double>* hill_mass_diffs = nullptr) const;
393
395 struct ScanPrep
396 {
397 std::vector<int> ids;
398 std::vector<int> bins;
399 std::vector<std::pair<int, int>> by_bin;
400 int bin_lo = 0;
401 std::vector<int> bin_start;
402 std::vector<int> im_bin_per_peak;
403 bool use_im = false;
404 };
405
407 struct PeakRef { Size hill; Size scan; Size peak; };
408
409 ScanPrep prepareScan_(const MSSpectrum& spectrum, double min_intensity, double min_mz, double max_mz,
410 double mz_step, bool use_im_global) const;
411
420 void linkScanToHills_(const MSSpectrum& spectrum,
421 Size scan_idx,
422 double htol_ppm,
423 const ScanPrep& cur,
424 const ScanPrep* prev,
425 std::vector<PeakRef>& refs,
426 Size& hill_idx_counter,
427 std::vector<Size>& prev_peak_to_hill,
428 const MSSpectrum*& prev_spectrum_ptr,
429 std::vector<double>* hill_mass_diffs) const;
430
438 std::vector<Hill> processHills_(std::vector<Hill> hills, Size min_length) const;
439
451 std::vector<Hill> splitHills_(std::vector<Hill> hills, double hvf, Size min_length) const;
452
464 Size checkIsotopeValleySplit_(const std::vector<IsotopeCandidate>& isotopes, const std::vector<Hill>& hills, double ivf) const;
465
478 double buildFastMzLookup_(const std::vector<Hill>& hills,
479 bool use_im,
480 std::map<int, std::vector<FastHillEntry>>& hills_mz_fast,
481 std::vector<int>& hill_im_bins) const;
482
502 std::vector<PatternCandidate> generateIsotopeCandidates_(const std::vector<Hill>& hills,
503 double itol_ppm,
504 int min_charge,
505 int max_charge,
506 double ivf,
507 double mz_step,
508 const std::map<int, std::vector<FastHillEntry>>& hills_mz_fast,
509 const std::vector<Size>& hill_idx_to_index,
510 const std::vector<int>& hill_im_bins,
511 bool use_im) const;
512
524 std::vector<PatternCandidate> applyRtFiltering_(const std::vector<PatternCandidate>& candidates,
525 const std::vector<Hill>& hills,
526 const std::vector<Size>& hill_idx_to_index) const;
527
539 std::map<int, std::pair<double, double>> refineIsotopeCalibration_(const std::vector<PatternCandidate>& candidates,
540 double itol_ppm,
541 bool enable_isotope_calib) const;
542
556 std::vector<PatternCandidate> filterByCalibration_(const std::vector<PatternCandidate>& candidates,
557 const std::vector<Hill>& hills,
558 const std::vector<Size>& hill_idx_to_index,
559 const std::map<int, std::pair<double, double>>& isotope_calib_map_ready,
560 bool enable_isotope_calib) const;
561
576 std::vector<PeptideFeature> selectNonOverlappingPatterns_(const std::vector<PatternCandidate>& filtered_ready,
577 const std::vector<Hill>& hills,
578 bool negative_mode,
579 int iuse,
580 double itol_ppm) const;
581
600 std::vector<PeptideFeature> detectIsotopePatterns_(std::vector<Hill>& hills, double itol_ppm, int min_charge, int max_charge, bool negative_mode, double ivf, int iuse, bool enable_isotope_calib, bool use_im) const;
601
614 FeatureMap convertToFeatureMap_(const std::vector<PeptideFeature>& features,
615 const std::vector<Hill>& hills) const;
616
633 void debugCheckIsotopeConsistency_(const char* stage_label,
634 double mono_mz_center,
635 double mono_rt_apex,
636 Size mono_hill_idx,
637 int charge,
638 double itol_ppm,
639 const Hill& iso_hill,
640 Size isotope_number) const;
641
654 double cosineCorrelation_(const std::vector<double>& intensities1, const std::vector<Size>& scans1,
655 const std::vector<double>& intensities2, const std::vector<Size>& scans2) const;
656
666 bool shouldThrowForMissingIM_(const MSSpectrum& spectrum) const;
667
680 void processFAIMSGroup_(double faims_cv,
681 MSExperiment& group_exp,
682 double original_paseftol,
683 std::vector<Hill>& hills_out,
684 std::vector<PeptideFeature>& features_out);
686
688
690
691 // Algorithm parameters (cached from Param for performance)
692 double mini_;
693 double minmz_;
694 double maxmz_;
695 double htol_;
696 double itol_;
697 double hvf_;
698 double ivf_;
700 int cmin_;
701 int cmax_;
702 double pasefmini_;
704 int iuse_;
710 double paseftol_;
711 double hrttol_;
712 std::string convex_hull_mode_;
715};
716
717} // namespace OpenMS
Implementation of the Biosaur2 feature detection workflow for LC-MS1 data.
Definition Biosaur2Algorithm.h:52
int cmin_
Minimum charge state to consider.
Definition Biosaur2Algorithm.h:700
double pasefmini_
Minimum intensity for PASEF/TIMS clusters after centroiding.
Definition Biosaur2Algorithm.h:702
std::vector< double > drift_times
Drift time values (TIMS data), empty if not available.
Definition Biosaur2Algorithm.h:69
void centroidProfileSpectra_(MSExperiment &exp) const
Centroid profile spectra using PeakPickerHiRes.
void writeHills(const std::vector< Hill > &hills, const std::string &filename) const
Export the detected hills as TSV for diagnostic purposes.
double buildFastMzLookup_(const std::vector< Hill > &hills, bool use_im, std::map< int, std::vector< FastHillEntry > > &hills_mz_fast, std::vector< int > &hill_im_bins) const
Build fast m/z and optional ion-mobility lookup structures for hills.
void writeTSV(const std::vector< PeptideFeature > &features, const std::string &filename) const
Export detected peptide features to a Biosaur2-compatible TSV file.
std::vector< int > im_bin_per_peak
IM bin per peak index (empty without per-peak IM)
Definition Biosaur2Algorithm.h:402
double minmz_
Minimum m/z value.
Definition Biosaur2Algorithm.h:693
std::vector< Hill > splitHills_(std::vector< Hill > hills, double hvf, Size min_length) const
Split hills at valley positions to separate co-eluting species.
double mini_
Minimum intensity threshold.
Definition Biosaur2Algorithm.h:692
std::string convex_hull_mode_
Representation of feature convex hulls ("mass_traces" vs. "bounding_box")
Definition Biosaur2Algorithm.h:712
void processFAIMSGroup_(double faims_cv, MSExperiment &group_exp, double original_paseftol, std::vector< Hill > &hills_out, std::vector< PeptideFeature > &features_out)
Process a single FAIMS compensation voltage group.
std::vector< double > mz_values
m/z values of peaks in this hill
Definition Biosaur2Algorithm.h:66
std::vector< PatternCandidate > filterByCalibration_(const std::vector< PatternCandidate > &candidates, const std::vector< Hill > &hills, const std::vector< Size > &hill_idx_to_index, const std::map< int, std::pair< double, double > > &isotope_calib_map_ready, bool enable_isotope_calib) const
Filter isotope pattern candidates using refined calibration and cosine checks.
std::vector< double > rt_values
Retention time values corresponding to each peak.
Definition Biosaur2Algorithm.h:68
Size checkIsotopeValleySplit_(const std::vector< IsotopeCandidate > &isotopes, const std::vector< Hill > &hills, double ivf) const
Evaluate whether isotope pattern should be truncated at valley positions.
void run(FeatureMap &feature_map, std::vector< Hill > &hills, std::vector< PeptideFeature > &peptide_features)
Execute the Biosaur2 workflow on the stored MS1 experiment.
Size hill
Definition Biosaur2Algorithm.h:407
bool faims_merge_features_
Whether to merge features at different FAIMS CV values representing the same analyte.
Definition Biosaur2Algorithm.h:713
bool profile_mode_
Whether to centroid profile data using PeakPickerHiRes.
Definition Biosaur2Algorithm.h:707
std::vector< double > meanFilter_(const std::vector< double > &data, Size window) const
Apply a mean filter (moving average) to smooth data.
std::vector< int > bin_start
bin b's entries: by_bin[bin_start[b - bin_lo] .. bin_start[b - bin_lo + 1])
Definition Biosaur2Algorithm.h:401
double htol_
Mass tolerance in ppm for hill detection.
Definition Biosaur2Algorithm.h:695
bool shouldThrowForMissingIM_(const MSSpectrum &spectrum) const
Check if missing ion mobility data should be treated as an error.
double hrttol_
Maximum RT difference between monoisotopic and isotope apex (0=disable)
Definition Biosaur2Algorithm.h:711
const MSExperiment & getMSData() const
Get const reference to MS data.
Size minlh_
Minimum number of scans required for a hill.
Definition Biosaur2Algorithm.h:699
std::vector< PeptideFeature > detectIsotopePatterns_(std::vector< Hill > &hills, double itol_ppm, int min_charge, int max_charge, bool negative_mode, double ivf, int iuse, bool enable_isotope_calib, bool use_im) const
Detect isotope patterns and assemble peptide features.
std::vector< double > ion_mobilities
Ion mobility values, empty if not available.
Definition Biosaur2Algorithm.h:70
std::map< int, std::pair< double, double > > refineIsotopeCalibration_(const std::vector< PatternCandidate > &candidates, double itol_ppm, bool enable_isotope_calib) const
Refine isotope mass calibration based on initial pattern candidates.
std::vector< Hill > detectHills_(const MSExperiment &exp, double htol_ppm, double min_intensity, double min_mz, double max_mz, bool use_im, Size min_length, std::vector< double > *hill_mass_diffs=nullptr) const
Detect hills (continuous m/z traces) in the MS experiment.
std::pair< double, Size > checkingCosCorrelationForCarbon_(const std::vector< double > &theor_full, const std::vector< double > &exp_full, double thresh) const
Check cosine correlation for averagine-based isotope intensities.
Biosaur2Algorithm()
Default constructor.
bool ignore_iso_calib_
Whether to disable automatic isotope mass calibration.
Definition Biosaur2Algorithm.h:709
std::pair< std::vector< double >, Size > computeAveragine_(double neutral_mass, double apex_intensity) const
Compute averagine-based theoretical isotope intensities.
double itol_
Mass tolerance in ppm for isotope pattern detection.
Definition Biosaur2Algorithm.h:696
std::vector< int > ids
valid peak indices, by descending intensity
Definition Biosaur2Algorithm.h:397
std::vector< Hill > processHills_(std::vector< Hill > hills, Size min_length) const
Filter and process hills by applying length constraints and computing summary statistics.
std::vector< Size > scan_indices
Indices of spectra containing peaks of this hill.
Definition Biosaur2Algorithm.h:64
bool tof_mode_
Whether to enable TOF-specific intensity filtering.
Definition Biosaur2Algorithm.h:706
void setMSData(const MSExperiment &ms_data)
Set the MS data used for feature detection (copy version)
void run(FeatureMap &feature_map)
Execute the Biosaur2 workflow on the stored MS1 experiment (simplified interface)
int cmax_
Maximum charge state to consider.
Definition Biosaur2Algorithm.h:701
int iuse_
Number of isotopes for intensity calculation (0=mono, -1=all, N=mono+N)
Definition Biosaur2Algorithm.h:704
std::vector< double > intensities
Intensity values of peaks in this hill.
Definition Biosaur2Algorithm.h:67
std::vector< PatternCandidate > applyRtFiltering_(const std::vector< PatternCandidate > &candidates, const std::vector< Hill > &hills, const std::vector< Size > &hill_idx_to_index) const
Apply RT-apex based filtering to isotope pattern candidates.
FeatureMap convertToFeatureMap_(const std::vector< PeptideFeature > &features, const std::vector< Hill > &hills) const
Convert peptide features to OpenMS FeatureMap format.
double maxmz_
Maximum m/z value.
Definition Biosaur2Algorithm.h:694
void linkScanToHills_(const MSSpectrum &spectrum, Size scan_idx, double htol_ppm, const ScanPrep &cur, const ScanPrep *prev, std::vector< PeakRef > &refs, Size &hill_idx_counter, std::vector< Size > &prev_peak_to_hill, const MSSpectrum *&prev_spectrum_ptr, std::vector< double > *hill_mass_diffs) const
Link the peaks of one scan to the hills of the previous scan, or start new hills.
std::pair< double, double > calibrateMass_(const std::vector< double > &mass_errors, double bin_width=0.05) const
Estimate mass calibration parameters from a distribution of mass errors.
double paseftol_
Ion mobility tolerance for PASEF/TIMS data (0=disable)
Definition Biosaur2Algorithm.h:710
bool use_hill_calib_
Whether to use automatic hill mass tolerance calibration.
Definition Biosaur2Algorithm.h:708
void debugCheckIsotopeConsistency_(const char *stage_label, double mono_mz_center, double mono_rt_apex, Size mono_hill_idx, int charge, double itol_ppm, const Hill &iso_hill, Size isotope_number) const
Debug helper to log obviously inconsistent isotope assignments.
std::vector< Size > peak_indices
Indices of peaks within each spectrum.
Definition Biosaur2Algorithm.h:65
Size pasefminlh_
Minimum number of points per PASEF/TIMS cluster.
Definition Biosaur2Algorithm.h:703
ScanPrep prepareScan_(const MSSpectrum &spectrum, double min_intensity, double min_mz, double max_mz, double mz_step, bool use_im_global) const
double ivf_
Isotope valley factor for splitting isotope patterns.
Definition Biosaur2Algorithm.h:698
double cosineCorrelation1D_(const std::vector< double > &v1, const std::vector< double > &v2) const
Compute a cosine correlation between two 1D intensity vectors.
void updateMembers_() override
Update internal member variables from parameters (called automatically when parameters change)
bool negative_mode_
Whether to use negative ion mode.
Definition Biosaur2Algorithm.h:705
MSExperiment & getMSData()
Get non-const reference to MS data.
double calculatePPM_(double mz1, double mz2) const
Calculate the mass accuracy (ppm) between two m/z values.
MSExperiment ms_data_
Input LC-MS data.
Definition Biosaur2Algorithm.h:689
void centroidPASEFData_(MSExperiment &exp, double mz_step, double pasef_tolerance) const
Centroid PASEF/TIMS spectra in joint m/z-ion mobility space.
double calculateMedian_(const std::vector< double > &values) const
Calculate the median of a vector of values.
double cosineCorrelation_(const std::vector< double > &intensities1, const std::vector< Size > &scans1, const std::vector< double > &intensities2, const std::vector< Size > &scans2) const
Compute cosine correlation between two intensity traces.
void setMSData(MSExperiment &&ms_data)
Set the MS data used for feature detection (move version)
double computeHillMzStep_(const MSExperiment &exp, double htol_ppm, double min_intensity, double min_mz, double max_mz) const
Determine m/z binning step for hill detection.
void processTOF_(MSExperiment &exp) const
Apply TOF-specific intensity filtering.
std::vector< std::pair< int, int > > by_bin
(m/z bin, position in ids), sorted: the scan's bin lookup
Definition Biosaur2Algorithm.h:399
std::vector< IsotopeCandidate > isotopes
List of associated isotope peaks.
Definition Biosaur2Algorithm.h:120
std::vector< PeptideFeature > selectNonOverlappingPatterns_(const std::vector< PatternCandidate > &filtered_ready, const std::vector< Hill > &hills, bool negative_mode, int iuse, double itol_ppm) const
Greedily select non-overlapping isotope patterns and assemble peptide features.
std::vector< int > bins
their m/z bins (parallel to ids)
Definition Biosaur2Algorithm.h:398
std::vector< PatternCandidate > generateIsotopeCandidates_(const std::vector< Hill > &hills, double itol_ppm, int min_charge, int max_charge, double ivf, double mz_step, const std::map< int, std::vector< FastHillEntry > > &hills_mz_fast, const std::vector< Size > &hill_idx_to_index, const std::vector< int > &hill_im_bins, bool use_im) const
Generate initial isotope pattern candidates for all monoisotopic hills.
double hvf_
Hill valley factor for splitting hills at valleys.
Definition Biosaur2Algorithm.h:697
Lightweight index entry for fast m/z-based hill lookup.
Definition Biosaur2Algorithm.h:237
Representation of a single hill (continuous m/z trace across adjacent scans).
Definition Biosaur2Algorithm.h:63
Candidate isotope peak that can be associated with a monoisotopic hill.
Definition Biosaur2Algorithm.h:91
Internal representation of a candidate isotope pattern.
Definition Biosaur2Algorithm.h:250
one peak's hill assignment, recorded by linkScanToHills_ (the hills are built from these afterwards)
Definition Biosaur2Algorithm.h:407
Aggregated properties of a detected peptide feature.
Definition Biosaur2Algorithm.h:107
the part of linking one scan that depends on that scan alone (filter, intensity order,...
Definition Biosaur2Algorithm.h:396
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
A container for features.
Definition FeatureMap.h:78
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
The representation of a 1D spectrum.
Definition MSSpectrum.h:45
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19