OpenMS
FeatureFinderIdentificationAlgorithm.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: Hendrik Weisser $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
20 
21 #include <vector>
22 #include <fstream>
23 #include <map>
24 
25 namespace OpenMS {
27  public DefaultParamHandler
28 {
29 public:
32 
52  void run(
54  const std::vector<ProteinIdentification>& proteins,
55  PeptideIdentificationList peptides_ext,
56  std::vector<ProteinIdentification> proteins_ext,
57  FeatureMap& features,
58  const FeatureMap& seeds = FeatureMap(),
59  const String& spectra_file = ""
60  );
61 
62  void runOnCandidates(FeatureMap& features);
63 
65  const PeakMap& getMSData() const;
66 
68  void setMSData(const PeakMap& ms_data); // for pyOpenMS
69  void setMSData(PeakMap&& ms_data); // moves peak data and saves the copy. Note that getMSData() will give back a processed/modified version.
70 
72  const PeakMap& getChromatograms() const;
73 
76 
79 
80 protected:
81 
84 
86  typedef std::multimap<double, PeptideIdentification*> RTMap;
88  typedef std::map<Int, std::pair<RTMap, RTMap> > ChargeMap;
90  typedef std::map<AASequence, ChargeMap> PeptideMap;
92  typedef std::map<String, std::pair<RTMap, RTMap> > PeptideRefRTMap;
93 
95 
98 
100  double rt_window_;
101  double mz_window_;
103 
105 
106  double isotope_pmin_;
108 
109  double rt_quantile_;
110 
111  double peak_width_;
114 
116 
117  // SVM related parameters
124 
125  // output file (before filtering)
127 
129 
130  void updateMembers_() override;
131 
133  struct RTRegion
134  {
135  double start, end;
137  };
138 
150  struct IMStats
151  {
152  double median = -1.0;
153  double min = -1.0;
154  double max = -1.0;
155  };
156 
159  {
160  bool operator()(const Feature& feature)
161  {
162  return feature.getOverallQuality() == 0.0;
163  }
164  } feature_filter_quality_;
165 
168  {
169  bool operator()(const Feature& feature)
170  {
171  return feature.getPeptideIdentifications().empty();
172  }
173  } feature_filter_peptides_;
174 
177  {
179  const PeptideIdentification& p2)
180  {
181  const String& seq1 = p1.getHits()[0].getSequence().toString();
182  const String& seq2 = p2.getHits()[0].getSequence().toString();
183  if (seq1 == seq2)
184  {
185  Int charge1 = p1.getHits()[0].getCharge();
186  Int charge2 = p2.getHits()[0].getCharge();
187  if (charge1 == charge2)
188  {
189  return p1.getRT() < p2.getRT();
190  }
191  return charge1 < charge2;
192  }
193  return seq1 < seq2;
194  }
195  } peptide_compare_;
196 
199  {
200  bool operator()(const Feature& f1, const Feature& f2)
201  {
202  const String& ref1 = f1.getMetaValue("PeptideRef");
203  const String& ref2 = f2.getMetaValue("PeptideRef");
204  if (ref1 == ref2)
205  {
206  return f1.getRT() < f2.getRT();
207  }
208  return ref1 < ref2;
209  }
210  } feature_compare_;
211 
216 
218  double add_mass_offset_peptides_{0.0};
222 
223  const double seed_rt_window_ = 60.0;
224 
226  std::map<double, std::pair<Size, Size> > svm_probs_internal_;
228  std::multiset<double> svm_probs_external_;
232  std::map<String, double> isotope_probs_;
240  std::map<String, IMStats> im_stats_;
241 
250 
253 
255 
257  void generateTransitions_(const String& peptide_id, double mz, Int charge,
258  const IsotopeDistribution& iso_dist);
259 
260  void addPeptideRT_(TargetedExperiment::Peptide& peptide, double rt) const;
261 
263  void getRTRegions_(ChargeMap& peptide_data, std::vector<RTRegion>& rt_regions, bool clear_IDs = true) const;
264 
288 
302 
304  FeatureMap& features,
305  std::map<Size, std::vector<PeptideIdentification*> >& feat_ids,
306  RTMap& rt_internal);
307 
309  void annotateFeatures_(FeatureMap& features, PeptideRefRTMap& ref_rt_map);
310 
311  void ensureConvexHulls_(Feature& feature) const;
312 
313  void postProcess_(FeatureMap& features, bool with_external_ids);
314 
318  double calculateRTWindow_(double rt_uncertainty) const;
320 
322  static bool isSeedPseudoHit_(const PeptideHit& hit);
323 
325  std::pair<double, double> calculateRTBounds_(double rt_min, double rt_max) const;
326 
328  void statistics_(const FeatureMap& features) const;
329 
333  void createAssayLibrary_(const PeptideMap::iterator& begin, const PeptideMap::iterator& end, PeptideRefRTMap& ref_rt_map, bool clear_IDs = true);
334 
339  PeptideMap& peptide_map,
340  bool external = false);
341 
342  void filterFeatures_(FeatureMap& features, bool classified);
343 
347  PeptideIdentificationList peptides,
348  const std::vector<ProteinIdentification>& proteins,
349  PeptideIdentificationList peptides_ext,
350  std::vector<ProteinIdentification> proteins_ext,
351  FeatureMap& features,
352  const FeatureMap& seeds,
353  const String& spectra_file);
354 
355  // seeds for untargeted extraction
357 
358  // quant. decoys
360 
363  template <typename It>
364  std::vector<std::pair<It,It>>
365  chunk_(It range_from, It range_to, const std::ptrdiff_t batch_size)
366  {
367  /* Aliases, to make the rest of the code more readable. */
368  using std::vector;
369  using std::pair;
370  using std::make_pair;
371  using std::distance;
372  using diff_t = std::ptrdiff_t;
373 
374  /* Total item number and batch_size size. */
375  const diff_t total {distance(range_from, range_to)};
376  const diff_t num {total / batch_size};
377 
378  vector<pair<It,It>> chunks(num);
379 
380  It batch_end {range_from};
381 
382  /* Use the 'generate' algorithm to create batches. */
383  std::generate(begin(chunks), end(chunks), [&batch_end, batch_size]()
384  {
385  It batch_start {batch_end };
386 
387  std::advance(batch_end, batch_size);
388  return make_pair(batch_start, batch_end);
389  });
390 
391  /* The last batch_size's end must always be 'range_to'. */
392  if (chunks.empty())
393  {
394  chunks.emplace_back(range_from, range_to);
395  }
396  else
397  {
398  chunks.back().second = range_to;
399  }
400 
401  return chunks;
402  }
403 }; // namespace OpenMS
404 } // namespace OpenMS
405 
const PeptideIdentificationList & getPeptideIdentifications() const
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
bool empty() const noexcept
Definition: ExposedVector.h:140
Definition: FeatureFinderIdentificationAlgorithm.h:28
FeatureFinderAlgorithmPickedHelperStructs::MassTraces MassTraces
Definition: FeatureFinderIdentificationAlgorithm.h:83
void postProcess_(FeatureMap &features, bool with_external_ids)
double rt_window_
RT window width.
Definition: FeatureFinderIdentificationAlgorithm.h:100
void getRTRegions_(ChargeMap &peptide_data, std::vector< RTRegion > &rt_regions, bool clear_IDs=true) const
get regions in which peptide eludes (ideally only one) by clustering RT elution times
void runOnCandidates(FeatureMap &features)
std::map< AASequence, ChargeMap > PeptideMap
mapping: sequence -> charge -> internal/external ID information
Definition: FeatureFinderIdentificationAlgorithm.h:90
const TargetedExperiment & getLibrary() const
void validateSVMParameters_() const
Helper functions for run()
void createAssayLibrary_(const PeptideMap::iterator &begin, const PeptideMap::iterator &end, PeptideRefRTMap &ref_rt_map, bool clear_IDs=true)
String svm_xval_out_
Definition: FeatureFinderIdentificationAlgorithm.h:120
static bool isSeedPseudoHit_(const PeptideHit &hit)
Helper function to check if a peptide hit is a seed pseudo-ID.
std::map< String, IMStats > im_stats_
Ion mobility statistics per peptide reference (peptide sequence/charge:region)
Definition: FeatureFinderIdentificationAlgorithm.h:240
IMStats global_im_stats_
Global ion mobility statistics from all peptide identifications.
Definition: FeatureFinderIdentificationAlgorithm.h:249
String elution_model_
Definition: FeatureFinderIdentificationAlgorithm.h:115
PeptideMap peptide_map_
Definition: FeatureFinderIdentificationAlgorithm.h:94
double end
Definition: FeatureFinderIdentificationAlgorithm.h:135
Internal::FFIDAlgoExternalIDHandler external_id_handler_
Handler for external peptide IDs.
Definition: FeatureFinderIdentificationAlgorithm.h:252
MRMFeatureFinderScoring feat_finder_
OpenSWATH feature finder.
Definition: FeatureFinderIdentificationAlgorithm.h:251
FeatureFinderIdentificationAlgorithm()
default constructor
void filterFeatures_(FeatureMap &features, bool classified)
Size n_external_peps_
number of external peptides
Definition: FeatureFinderIdentificationAlgorithm.h:97
double signal_to_noise_
Definition: FeatureFinderIdentificationAlgorithm.h:113
void run(PeptideIdentificationList peptides, const std::vector< ProteinIdentification > &proteins, PeptideIdentificationList peptides_ext, std::vector< ProteinIdentification > proteins_ext, FeatureMap &features, const FeatureMap &seeds=FeatureMap(), const String &spectra_file="")
void generateTransitions_(const String &peptide_id, double mz, Int charge, const IsotopeDistribution &iso_dist)
generate transitions (isotopic traces) for a peptide ion and add them to the library:
const ProgressLogger & getProgressLogger() const
bool quantify_decoys_
Definition: FeatureFinderIdentificationAlgorithm.h:217
TargetedExperiment library_
assays for peptides (cleared per chunk during processing)
Definition: FeatureFinderIdentificationAlgorithm.h:214
void annotateFeaturesFinalizeAssay_(FeatureMap &features, std::map< Size, std::vector< PeptideIdentification * > > &feat_ids, RTMap &rt_internal)
double min_peak_width_
Definition: FeatureFinderIdentificationAlgorithm.h:112
StringList svm_predictor_names_
Definition: FeatureFinderIdentificationAlgorithm.h:119
void setMSData(const PeakMap &ms_data)
set the MS data used for feature detection
std::map< Int, std::pair< RTMap, RTMap > > ChargeMap
mapping: charge -> internal/external: (RT -> pointer to peptide)
Definition: FeatureFinderIdentificationAlgorithm.h:88
Size svm_n_parts_
number of partitions for SVM cross-validation
Definition: FeatureFinderIdentificationAlgorithm.h:122
Size svm_n_samples_
number of samples for SVM training
Definition: FeatureFinderIdentificationAlgorithm.h:123
Size n_internal_peps_
number of internal peptide
Definition: FeatureFinderIdentificationAlgorithm.h:96
Size addSeeds_(PeptideIdentificationList &peptides, const FeatureMap &seeds)
Size n_internal_features_
internal feature counter (for FDR calculation)
Definition: FeatureFinderIdentificationAlgorithm.h:229
ProgressLogger prog_log_
Definition: FeatureFinderIdentificationAlgorithm.h:254
PeakMap ms_data_
input LC-MS data
Definition: FeatureFinderIdentificationAlgorithm.h:212
void statistics_(const FeatureMap &features) const
some statistics on detected features
void calculateGlobalIMStats_()
Calculate global IM statistics from MS data and peptide identifications.
Size batch_size_
nr of peptides to use at the same time during chromatogram extraction
Definition: FeatureFinderIdentificationAlgorithm.h:99
double mz_window_
m/z window width
Definition: FeatureFinderIdentificationAlgorithm.h:101
double svm_min_prob_
Definition: FeatureFinderIdentificationAlgorithm.h:118
std::map< String, double > isotope_probs_
TransformationDescription trafo_; // RT transformation (to range 0-1)
Definition: FeatureFinderIdentificationAlgorithm.h:232
double peak_width_
Definition: FeatureFinderIdentificationAlgorithm.h:111
Size n_external_features_
Definition: FeatureFinderIdentificationAlgorithm.h:230
double calculateRTWindow_(double rt_uncertainty) const
FeatureFinderAlgorithmPickedHelperStructs::MassTrace MassTrace
Definition: FeatureFinderIdentificationAlgorithm.h:82
Size n_isotopes_
number of isotopes for peptide assay
Definition: FeatureFinderIdentificationAlgorithm.h:107
double mapping_tolerance_
RT tolerance for mapping IDs to features.
Definition: FeatureFinderIdentificationAlgorithm.h:104
std::map< String, std::pair< RTMap, RTMap > > PeptideRefRTMap
mapping: peptide ref. -> int./ext.: (RT -> pointer to peptide)
Definition: FeatureFinderIdentificationAlgorithm.h:92
Size debug_level_
Definition: FeatureFinderIdentificationAlgorithm.h:128
double rt_quantile_
Definition: FeatureFinderIdentificationAlgorithm.h:109
std::vector< std::pair< It, It > > chunk_(It range_from, It range_to, const std::ptrdiff_t batch_size)
Definition: FeatureFinderIdentificationAlgorithm.h:365
std::multiset< double > svm_probs_external_
SVM probabilities for "external" features (for FDR calculation):
Definition: FeatureFinderIdentificationAlgorithm.h:228
ChargeMap ids
internal/external peptide IDs (per charge) in this region
Definition: FeatureFinderIdentificationAlgorithm.h:136
std::pair< double, double > calculateRTBounds_(double rt_min, double rt_max) const
Calculate RT bounds with optional tolerance expansion.
void removeSeedPseudoIDs_(FeatureMap &features)
Size addOffsetPeptides_(PeptideIdentificationList &peptides, double offset)
bool mz_window_ppm_
m/z window width is given in PPM (not Da)?
Definition: FeatureFinderIdentificationAlgorithm.h:102
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
TargetedExperiment output_library_
accumulated assays for output (populated from library_ before clearing)
Definition: FeatureFinderIdentificationAlgorithm.h:215
bool use_psm_cutoff_
Definition: FeatureFinderIdentificationAlgorithm.h:219
IMStats getRTRegionIMStats_(const RTRegion &r)
Calculate ion mobility statistics for peptide identifications in an RT region.
void addPeptideRT_(TargetedExperiment::Peptide &peptide, double rt) const
PeakMap chrom_data_
accumulated chromatograms (XICs)
Definition: FeatureFinderIdentificationAlgorithm.h:213
void ensureConvexHulls_(Feature &feature) const
std::multimap< double, PeptideIdentification * > RTMap
mapping: RT (not necessarily unique) -> pointer to peptide
Definition: FeatureFinderIdentificationAlgorithm.h:86
PeptideIdentificationList unassignedIDs_
Definition: FeatureFinderIdentificationAlgorithm.h:221
void addPeptideToMap_(PeptideIdentification &peptide, PeptideMap &peptide_map, bool external=false)
double psm_score_cutoff_
Definition: FeatureFinderIdentificationAlgorithm.h:220
void runSingleGroup_(PeptideIdentificationList peptides, const std::vector< ProteinIdentification > &proteins, PeptideIdentificationList peptides_ext, std::vector< ProteinIdentification > proteins_ext, FeatureMap &features, const FeatureMap &seeds, const String &spectra_file)
void annotateFeatures_(FeatureMap &features, PeptideRefRTMap &ref_rt_map)
annotate identified features with m/z, isotope probabilities, etc.
String candidates_out_
Definition: FeatureFinderIdentificationAlgorithm.h:126
double isotope_pmin_
min. isotope probability for peptide assay
Definition: FeatureFinderIdentificationAlgorithm.h:106
double svm_quality_cutoff
Definition: FeatureFinderIdentificationAlgorithm.h:121
std::map< double, std::pair< Size, Size > > svm_probs_internal_
SVM probability -> number of pos./neg. features (for FDR calculation):
Definition: FeatureFinderIdentificationAlgorithm.h:226
Ion mobility statistics for a peptide in a specific RT region and charge state.
Definition: FeatureFinderIdentificationAlgorithm.h:151
region in RT in which a peptide elutes:
Definition: FeatureFinderIdentificationAlgorithm.h:134
A container for features.
Definition: FeatureMap.h:82
An LC-MS feature.
Definition: Feature.h:46
QualityType getOverallQuality() const
Non-mutable access to the overall quality.
Class for handling external peptide identifications in feature finding.
Definition: FFIDAlgoExternalIDHandler.h:38
Definition: IsotopeDistribution.h:39
The MRMFeatureFinder finds and scores peaks of transitions that co-elute.
Definition: MRMFeatureFinderScoring.h:65
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:49
const DataValue & getMetaValue(const String &name) const
Returns the value corresponding to a string, or DataValue::EMPTY if not found.
CoordinateType getRT() const
Returns the RT coordinate (index 0)
Definition: Peak2D.h:184
Represents a single spectrum match (candidate) for a specific tandem mass spectrum (MS/MS).
Definition: PeptideHit.h:50
Container for peptide identifications from multiple spectra.
Definition: PeptideIdentificationList.h:66
Represents the set of candidates (SpectrumMatches) identified for a single precursor spectrum.
Definition: PeptideIdentification.h:63
double getRT() const
returns the RT of the MS2 spectrum where the identification occurred
const std::vector< PeptideHit > & getHits() const
returns the peptide hits as const
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:27
A more convenient string class.
Definition: String.h:34
Represents a peptide (amino acid sequence)
Definition: TargetedExperimentHelper.h:333
A description of a targeted experiment containing precursor and production ions.
Definition: TargetedExperiment.h:39
int Int
Signed integer type.
Definition: Types.h:72
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:44
static double median(IteratorType begin, IteratorType end, bool sorted=false)
Calculates the median of a range of values.
Definition: StatisticFunctions.h:134
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Helper struct for mass traces used in FeatureFinderAlgorithmPicked.
Definition: FeatureFinderAlgorithmPickedHelperStructs.h:54
Helper struct for a collection of mass traces used in FeatureFinderAlgorithmPicked.
Definition: FeatureFinderAlgorithmPickedHelperStructs.h:85
comparison functor for features
Definition: FeatureFinderIdentificationAlgorithm.h:199
bool operator()(const Feature &f1, const Feature &f2)
Definition: FeatureFinderIdentificationAlgorithm.h:200
predicate for filtering features by assigned peptides:
Definition: FeatureFinderIdentificationAlgorithm.h:168
bool operator()(const Feature &feature)
Definition: FeatureFinderIdentificationAlgorithm.h:169
predicate for filtering features by overall quality:
Definition: FeatureFinderIdentificationAlgorithm.h:159
bool operator()(const Feature &feature)
Definition: FeatureFinderIdentificationAlgorithm.h:160
comparison functor for (unassigned) peptide IDs
Definition: FeatureFinderIdentificationAlgorithm.h:177
bool operator()(const PeptideIdentification &p1, const PeptideIdentification &p2)
Definition: FeatureFinderIdentificationAlgorithm.h:178