All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
45  void run(
47  const std::vector<ProteinIdentification>& proteins,
48  PeptideIdentificationList peptides_ext,
49  std::vector<ProteinIdentification> proteins_ext,
50  FeatureMap& features,
51  const FeatureMap& seeds = FeatureMap(),
52  const String& spectra_file = ""
53  );
54 
55  void runOnCandidates(FeatureMap& features);
56 
58  const PeakMap& getMSData() const;
59 
61  void setMSData(const PeakMap& ms_data); // for pyOpenMS
62  void setMSData(PeakMap&& ms_data); // moves peak data and saves the copy. Note that getMSData() will give back a processed/modified version.
63 
65  const PeakMap& getChromatograms() const;
66 
69 
72 
73 protected:
74 
77 
79  typedef std::multimap<double, PeptideIdentification*> RTMap;
81  typedef std::map<Int, std::pair<RTMap, RTMap> > ChargeMap;
83  typedef std::map<AASequence, ChargeMap> PeptideMap;
85  typedef std::map<String, std::pair<RTMap, RTMap> > PeptideRefRTMap;
86 
88 
91 
93  double rt_window_;
94  double mz_window_;
96 
98 
99  double isotope_pmin_;
101 
102  double rt_quantile_;
103 
104  double peak_width_;
107 
109 
110  // SVM related parameters
117 
118  // output file (before filtering)
120 
122 
123  void updateMembers_() override;
124 
126  struct RTRegion
127  {
128  double start, end;
130  };
131 
134  {
135  bool operator()(const Feature& feature)
136  {
137  return feature.getOverallQuality() == 0.0;
138  }
139  } feature_filter_quality_;
140 
143  {
144  bool operator()(const Feature& feature)
145  {
146  return feature.getPeptideIdentifications().empty();
147  }
148  } feature_filter_peptides_;
149 
152  {
154  const PeptideIdentification& p2)
155  {
156  const String& seq1 = p1.getHits()[0].getSequence().toString();
157  const String& seq2 = p2.getHits()[0].getSequence().toString();
158  if (seq1 == seq2)
159  {
160  Int charge1 = p1.getHits()[0].getCharge();
161  Int charge2 = p2.getHits()[0].getCharge();
162  if (charge1 == charge2)
163  {
164  return p1.getRT() < p2.getRT();
165  }
166  return charge1 < charge2;
167  }
168  return seq1 < seq2;
169  }
170  } peptide_compare_;
171 
174  {
175  bool operator()(const Feature& f1, const Feature& f2)
176  {
177  const String& ref1 = f1.getMetaValue("PeptideRef");
178  const String& ref2 = f2.getMetaValue("PeptideRef");
179  if (ref1 == ref2)
180  {
181  return f1.getRT() < f2.getRT();
182  }
183  return ref1 < ref2;
184  }
185  } feature_compare_;
186 
190 
192  double add_mass_offset_peptides_{0.0};
196 
197  const double seed_rt_window_ = 60.0;
198 
200  std::map<double, std::pair<Size, Size> > svm_probs_internal_;
202  std::multiset<double> svm_probs_external_;
206  std::map<String, double> isotope_probs_;
209 
211 
213  void generateTransitions_(const String& peptide_id, double mz, Int charge,
214  const IsotopeDistribution& iso_dist);
215 
216  void addPeptideRT_(TargetedExperiment::Peptide& peptide, double rt) const;
217 
219  void getRTRegions_(ChargeMap& peptide_data, std::vector<RTRegion>& rt_regions, bool clear_IDs = true) const;
220 
222  FeatureMap& features,
223  std::map<Size, std::vector<PeptideIdentification*> >& feat_ids,
224  RTMap& rt_internal);
225 
227  void annotateFeatures_(FeatureMap& features, PeptideRefRTMap& ref_rt_map);
228 
229  void ensureConvexHulls_(Feature& feature) const;
230 
231  void postProcess_(FeatureMap& features, bool with_external_ids);
232 
234  void statistics_(const FeatureMap& features) const;
235 
239  void createAssayLibrary_(const PeptideMap::iterator& begin, const PeptideMap::iterator& end, PeptideRefRTMap& ref_rt_map, bool clear_IDs = true);
240 
245  PeptideMap& peptide_map,
246  bool external = false);
247 
248  void filterFeatures_(FeatureMap& features, bool classified);
249 
250  // seeds for untargeted extraction
252 
253  // quant. decoys
255 
258  template <typename It>
259  std::vector<std::pair<It,It>>
260  chunk_(It range_from, It range_to, const std::ptrdiff_t batch_size)
261  {
262  /* Aliases, to make the rest of the code more readable. */
263  using std::vector;
264  using std::pair;
265  using std::make_pair;
266  using std::distance;
267  using diff_t = std::ptrdiff_t;
268 
269  /* Total item number and batch_size size. */
270  const diff_t total {distance(range_from, range_to)};
271  const diff_t num {total / batch_size};
272 
273  vector<pair<It,It>> chunks(num);
274 
275  It batch_end {range_from};
276 
277  /* Use the 'generate' algorithm to create batches. */
278  std::generate(begin(chunks), end(chunks), [&batch_end, batch_size]()
279  {
280  It batch_start {batch_end };
281 
282  std::advance(batch_end, batch_size);
283  return make_pair(batch_start, batch_end);
284  });
285 
286  /* The last batch_size's end must always be 'range_to'. */
287  if (chunks.empty())
288  {
289  chunks.emplace_back(range_from, range_to);
290  }
291  else
292  {
293  chunks.back().second = range_to;
294  }
295 
296  return chunks;
297  }
298 }; // namespace OpenMS
299 } // namespace OpenMS
300 
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:76
void postProcess_(FeatureMap &features, bool with_external_ids)
double rt_window_
RT window width.
Definition: FeatureFinderIdentificationAlgorithm.h:93
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:83
const TargetedExperiment & getLibrary() const
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:113
String elution_model_
Definition: FeatureFinderIdentificationAlgorithm.h:108
PeptideMap peptide_map_
Definition: FeatureFinderIdentificationAlgorithm.h:87
double end
Definition: FeatureFinderIdentificationAlgorithm.h:128
Internal::FFIDAlgoExternalIDHandler external_id_handler_
Handler for external peptide IDs.
Definition: FeatureFinderIdentificationAlgorithm.h:208
MRMFeatureFinderScoring feat_finder_
OpenSWATH feature finder.
Definition: FeatureFinderIdentificationAlgorithm.h:207
FeatureFinderIdentificationAlgorithm()
default constructor
void filterFeatures_(FeatureMap &features, bool classified)
Size n_external_peps_
number of external peptides
Definition: FeatureFinderIdentificationAlgorithm.h:90
double signal_to_noise_
Definition: FeatureFinderIdentificationAlgorithm.h:106
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:191
TargetedExperiment library_
accumulated assays for peptides
Definition: FeatureFinderIdentificationAlgorithm.h:189
void annotateFeaturesFinalizeAssay_(FeatureMap &features, std::map< Size, std::vector< PeptideIdentification * > > &feat_ids, RTMap &rt_internal)
double min_peak_width_
Definition: FeatureFinderIdentificationAlgorithm.h:105
StringList svm_predictor_names_
Definition: FeatureFinderIdentificationAlgorithm.h:112
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:81
Size svm_n_parts_
number of partitions for SVM cross-validation
Definition: FeatureFinderIdentificationAlgorithm.h:115
Size svm_n_samples_
number of samples for SVM training
Definition: FeatureFinderIdentificationAlgorithm.h:116
Size n_internal_peps_
number of internal peptide
Definition: FeatureFinderIdentificationAlgorithm.h:89
Size addSeeds_(PeptideIdentificationList &peptides, const FeatureMap &seeds)
Size n_internal_features_
internal feature counter (for FDR calculation)
Definition: FeatureFinderIdentificationAlgorithm.h:203
ProgressLogger prog_log_
Definition: FeatureFinderIdentificationAlgorithm.h:210
PeakMap ms_data_
input LC-MS data
Definition: FeatureFinderIdentificationAlgorithm.h:187
void statistics_(const FeatureMap &features) const
some statistics on detected features
Size batch_size_
nr of peptides to use at the same time during chromatogram extraction
Definition: FeatureFinderIdentificationAlgorithm.h:92
double mz_window_
m/z window width
Definition: FeatureFinderIdentificationAlgorithm.h:94
double svm_min_prob_
Definition: FeatureFinderIdentificationAlgorithm.h:111
std::map< String, double > isotope_probs_
TransformationDescription trafo_; // RT transformation (to range 0-1)
Definition: FeatureFinderIdentificationAlgorithm.h:206
double peak_width_
Definition: FeatureFinderIdentificationAlgorithm.h:104
Size n_external_features_
Definition: FeatureFinderIdentificationAlgorithm.h:204
FeatureFinderAlgorithmPickedHelperStructs::MassTrace MassTrace
Definition: FeatureFinderIdentificationAlgorithm.h:75
Size n_isotopes_
number of isotopes for peptide assay
Definition: FeatureFinderIdentificationAlgorithm.h:100
double mapping_tolerance_
RT tolerance for mapping IDs to features.
Definition: FeatureFinderIdentificationAlgorithm.h:97
std::map< String, std::pair< RTMap, RTMap > > PeptideRefRTMap
mapping: peptide ref. -> int./ext.: (RT -> pointer to peptide)
Definition: FeatureFinderIdentificationAlgorithm.h:85
Size debug_level_
Definition: FeatureFinderIdentificationAlgorithm.h:121
double rt_quantile_
Definition: FeatureFinderIdentificationAlgorithm.h:102
std::vector< std::pair< It, It > > chunk_(It range_from, It range_to, const std::ptrdiff_t batch_size)
Definition: FeatureFinderIdentificationAlgorithm.h:260
std::multiset< double > svm_probs_external_
SVM probabilities for "external" features (for FDR calculation):
Definition: FeatureFinderIdentificationAlgorithm.h:202
ChargeMap ids
internal/external peptide IDs (per charge) in this region
Definition: FeatureFinderIdentificationAlgorithm.h:129
Size addOffsetPeptides_(PeptideIdentificationList &peptides, double offset)
bool mz_window_ppm_
m/z window width is given in PPM (not Da)?
Definition: FeatureFinderIdentificationAlgorithm.h:95
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
bool use_psm_cutoff_
Definition: FeatureFinderIdentificationAlgorithm.h:193
void addPeptideRT_(TargetedExperiment::Peptide &peptide, double rt) const
PeakMap chrom_data_
accumulated chromatograms (XICs)
Definition: FeatureFinderIdentificationAlgorithm.h:188
void ensureConvexHulls_(Feature &feature) const
std::multimap< double, PeptideIdentification * > RTMap
mapping: RT (not necessarily unique) -> pointer to peptide
Definition: FeatureFinderIdentificationAlgorithm.h:79
PeptideIdentificationList unassignedIDs_
Definition: FeatureFinderIdentificationAlgorithm.h:195
void addPeptideToMap_(PeptideIdentification &peptide, PeptideMap &peptide_map, bool external=false)
double psm_score_cutoff_
Definition: FeatureFinderIdentificationAlgorithm.h:194
void annotateFeatures_(FeatureMap &features, PeptideRefRTMap &ref_rt_map)
annotate identified features with m/z, isotope probabilities, etc.
String candidates_out_
Definition: FeatureFinderIdentificationAlgorithm.h:119
double isotope_pmin_
min. isotope probability for peptide assay
Definition: FeatureFinderIdentificationAlgorithm.h:99
double svm_quality_cutoff
Definition: FeatureFinderIdentificationAlgorithm.h:114
std::map< double, std::pair< Size, Size > > svm_probs_internal_
SVM probability -> number of pos./neg. features (for FDR calculation):
Definition: FeatureFinderIdentificationAlgorithm.h:200
region in RT in which a peptide elutes:
Definition: FeatureFinderIdentificationAlgorithm.h:127
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
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
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:174
bool operator()(const Feature &f1, const Feature &f2)
Definition: FeatureFinderIdentificationAlgorithm.h:175
predicate for filtering features by assigned peptides:
Definition: FeatureFinderIdentificationAlgorithm.h:143
bool operator()(const Feature &feature)
Definition: FeatureFinderIdentificationAlgorithm.h:144
predicate for filtering features by overall quality:
Definition: FeatureFinderIdentificationAlgorithm.h:134
bool operator()(const Feature &feature)
Definition: FeatureFinderIdentificationAlgorithm.h:135
comparison functor for (unassigned) peptide IDs
Definition: FeatureFinderIdentificationAlgorithm.h:152
bool operator()(const PeptideIdentification &p1, const PeptideIdentification &p2)
Definition: FeatureFinderIdentificationAlgorithm.h:153