OpenMS
Loading...
Searching...
No Matches
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
19
20#include <vector>
21#include <fstream>
22#include <map>
23
24namespace OpenMS {
73{
74public:
77
90 void run(
92 const std::vector<ProteinIdentification>& proteins,
93 FeatureMap& features,
94 const FeatureMap& seeds = FeatureMap(),
95 const std::string& spectra_file = ""
96 );
97
99 void runOnCandidates(FeatureMap& features);
100
110 const PeakMap& getMSData() const;
111
116 void setMSData(const PeakMap& ms_data); // for pyOpenMS
121 void setMSData(PeakMap&& ms_data); // moves peak data and saves the copy. Note that getMSData() will give back a processed/modified version.
122
132 const PeakMap& getChromatograms() const;
133
144
156
157protected:
158
161
163 typedef std::multimap<double, PeptideIdentification*> RTMap;
165 typedef std::map<Int, RTMap> ChargeMap;
167 typedef std::map<AASequence, ChargeMap> PeptideMap;
169 typedef std::map<std::string, RTMap> PeptideRefRTMap;
170
172
173 Size n_peptides_ = 0;
174
176 double rt_window_;
177 double mz_window_;
179
181
184
188
189 std::string elution_model_;
190
191 // output file (before filtering)
192 std::string candidates_out_;
193
195 FeatureMap* candidates_sink_ = nullptr;
196
198
199 void updateMembers_() override;
200
202 void storeCandidates_(const FeatureMap& candidates) const;
203
205 struct RTRegion
206 {
207 double start, end;
209 };
210
222 struct IMStats
223 {
224 double median = -1.0;
225 double min = -1.0;
226 double max = -1.0;
227 };
228
231 {
232 bool operator()(const Feature& feature)
233 {
234 return feature.getOverallQuality() == 0.0;
235 }
236 } feature_filter_quality_;
237
240 {
241 bool operator()(const Feature& feature)
242 {
243 return feature.getPeptideIdentifications().empty();
244 }
245 } feature_filter_peptides_;
246
249 {
251 const PeptideIdentification& p2)
252 {
253 const std::string& seq1 = p1.getHits()[0].getSequence().toString();
254 const std::string& seq2 = p2.getHits()[0].getSequence().toString();
255 if (seq1 == seq2)
256 {
257 Int charge1 = p1.getHits()[0].getCharge();
258 Int charge2 = p2.getHits()[0].getCharge();
259 if (charge1 == charge2)
260 {
261 return p1.getRT() < p2.getRT();
262 }
263 return charge1 < charge2;
264 }
265 return seq1 < seq2;
266 }
267 } peptide_compare_;
268
271 {
272 bool operator()(const Feature& f1, const Feature& f2)
273 {
274 const std::string ref1 = StringUtils::toStr(f1.getMetaValue("PeptideRef"));
275 const std::string ref2 = StringUtils::toStr(f2.getMetaValue("PeptideRef"));
276 if (ref1 == ref2)
277 {
278 return f1.getRT() < f2.getRT();
279 }
280 return ref1 < ref2;
281 }
282 } feature_compare_;
283
288
290 double add_mass_offset_peptides_{0.0};
291 double seed_apex_rt_tolerance_{5.0};
295
296 const double seed_rt_window_ = 60.0;
297
298 std::map<std::string, double> isotope_probs_;
306 std::map<std::string, IMStats> im_stats_;
307
316
318
320
322 void generateTransitions_(const std::string& peptide_id, double mz, Int charge,
323 const IsotopeDistribution& iso_dist);
324
325 void addPeptideRT_(TargetedExperiment::Peptide& peptide, double rt) const;
326
328 void getRTRegions_(ChargeMap& peptide_data, std::vector<RTRegion>& rt_regions, bool clear_IDs = true) const;
329
353
367
369 FeatureMap& features,
370 std::map<Size, std::vector<PeptideIdentification*> >& feat_ids,
371 RTMap& rt_internal);
372
374 void annotateFeatures_(FeatureMap& features, PeptideRefRTMap& ref_rt_map);
375
376 void ensureConvexHulls_(Feature& feature) const;
377
379 void postProcess_(FeatureMap& features, bool store_candidates = true);
380
383 double calculateRTWindow_() const;
385
387 static bool isSeedPseudoHit_(const PeptideHit& hit);
389 static bool isPseudoID_(const PeptideIdentification& pid);
390
393
395 std::pair<double, double> calculateRTBounds_(double rt_min, double rt_max) const;
396
398 void statistics_(const FeatureMap& features) const;
399
403 void createAssayLibrary_(const PeptideMap::iterator& begin, const PeptideMap::iterator& end, PeptideRefRTMap& ref_rt_map, bool clear_IDs = true);
404
409 PeptideMap& peptide_map);
410
412
417 const std::vector<ProteinIdentification>& proteins,
418 FeatureMap& features,
419 const FeatureMap& seeds,
420 const std::string& spectra_file);
421
422 // seeds for untargeted extraction
424
425 // quant. decoys
427
430 template <typename It>
431 std::vector<std::pair<It,It>>
432 chunk_(It range_from, It range_to, const std::ptrdiff_t batch_size)
433 {
434 /* Aliases, to make the rest of the code more readable. */
435 using std::vector;
436 using std::pair;
437 using std::make_pair;
438 using std::distance;
439 using diff_t = std::ptrdiff_t;
440
441 /* Total item number and batch_size size. */
442 const diff_t total {distance(range_from, range_to)};
443 const diff_t num {total / batch_size};
444
445 vector<pair<It,It>> chunks(num);
446
447 It batch_end {range_from};
448
449 /* Use the 'generate' algorithm to create batches. */
450 std::generate(begin(chunks), end(chunks), [&batch_end, batch_size]()
451 {
452 It batch_start {batch_end };
453
454 std::advance(batch_end, batch_size);
455 return make_pair(batch_start, batch_end);
456 });
457
458 /* The last batch_size's end must always be 'range_to'. */
459 if (chunks.empty())
460 {
461 chunks.emplace_back(range_from, range_to);
462 }
463 else
464 {
465 chunks.back().second = range_to;
466 }
467
468 return chunks;
469 }
470}; // namespace OpenMS
471} // namespace OpenMS
472
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
ID-guided MS1 feature finder; the algorithm behind FeatureFinderIdentification.
Definition FeatureFinderIdentificationAlgorithm.h:73
const TargetedExperiment & getLibrary() const
Read-only access to the assay library used / produced by the last run.
FeatureFinderAlgorithmPickedHelperStructs::MassTraces MassTraces
Definition FeatureFinderIdentificationAlgorithm.h:160
std::map< std::string, RTMap > PeptideRefRTMap
mapping: peptide ref. -> (RT -> pointer to peptide)
Definition FeatureFinderIdentificationAlgorithm.h:169
double rt_window_
RT window width.
Definition FeatureFinderIdentificationAlgorithm.h:176
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
std::map< std::string, double > isotope_probs_
isotope probabilities of transitions
Definition FeatureFinderIdentificationAlgorithm.h:298
void runOnCandidates(FeatureMap &features)
Filter an existing candidate FeatureMap in place and (optionally) fit elution models (entry point use...
std::map< AASequence, ChargeMap > PeptideMap
mapping: sequence -> charge -> ID information
Definition FeatureFinderIdentificationAlgorithm.h:167
void createAssayLibrary_(const PeptideMap::iterator &begin, const PeptideMap::iterator &end, PeptideRefRTMap &ref_rt_map, bool clear_IDs=true)
static bool isSeedPseudoHit_(const PeptideHit &hit)
Helper function to check if a peptide hit is a seed pseudo-ID.
IMStats global_im_stats_
Global ion mobility statistics from all peptide identifications.
Definition FeatureFinderIdentificationAlgorithm.h:315
PeptideMap peptide_map_
Definition FeatureFinderIdentificationAlgorithm.h:171
std::string candidates_out_
Definition FeatureFinderIdentificationAlgorithm.h:192
double end
Definition FeatureFinderIdentificationAlgorithm.h:207
MRMFeatureFinderScoring feat_finder_
OpenSWATH feature finder.
Definition FeatureFinderIdentificationAlgorithm.h:317
FeatureFinderIdentificationAlgorithm()
Default constructor; installs the FFid parameters (see class docs)
void initializeFeatureFinder_()
Helper functions for run()
void generateTransitions_(const std::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:
double signal_to_noise_
Definition FeatureFinderIdentificationAlgorithm.h:187
std::map< Int, RTMap > ChargeMap
mapping: charge -> (RT -> pointer to peptide)
Definition FeatureFinderIdentificationAlgorithm.h:165
static bool isEmptyPseudoID_(const PeptideIdentification &pid)
Is pid a pseudo ID (of a seed or offset peptide) without hits (or empty)?
bool quantify_decoys_
Definition FeatureFinderIdentificationAlgorithm.h:289
void run(PeptideIdentificationList peptides, const std::vector< ProteinIdentification > &proteins, FeatureMap &features, const FeatureMap &seeds=FeatureMap(), const std::string &spectra_file="")
Run the FFid pipeline; for FAIMS data this dispatches one run per CV group and merges results.
TargetedExperiment library_
assays for peptides (cleared per chunk during processing)
Definition FeatureFinderIdentificationAlgorithm.h:286
void annotateFeaturesFinalizeAssay_(FeatureMap &features, std::map< Size, std::vector< PeptideIdentification * > > &feat_ids, RTMap &rt_internal)
double min_peak_width_
Definition FeatureFinderIdentificationAlgorithm.h:186
const PeakMap & getMSData() const
Read-only access to the cached MS1 data.
ProgressLogger & getProgressLogger()
Mutable access to the progress logger used by the algorithm.
const ProgressLogger & getProgressLogger() const
Read-only access to the progress logger.
void setMSData(const PeakMap &ms_data)
Copy the MS data into the algorithm instance; useful from pyOpenMS where moving is awkward.
Size addSeeds_(PeptideIdentificationList &peptides, const FeatureMap &seeds)
ProgressLogger prog_log_
Definition FeatureFinderIdentificationAlgorithm.h:319
PeakMap ms_data_
input LC-MS data
Definition FeatureFinderIdentificationAlgorithm.h:284
void statistics_(const FeatureMap &features) const
some statistics on detected features
void setMSData(PeakMap &&ms_data)
Move the MS data into the algorithm instance (no copy).
std::vector< std::pair< It, It > > chunk_(It range_from, It range_to, const std::ptrdiff_t batch_size)
Definition FeatureFinderIdentificationAlgorithm.h:432
const PeakMap & getChromatograms() const
Read-only access to the accumulated extracted chromatograms.
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:175
void runSingleGroup_(PeptideIdentificationList peptides, const std::vector< ProteinIdentification > &proteins, FeatureMap &features, const FeatureMap &seeds, const std::string &spectra_file)
double mz_window_
m/z window width
Definition FeatureFinderIdentificationAlgorithm.h:177
double peak_width_
Definition FeatureFinderIdentificationAlgorithm.h:185
void storeCandidates_(const FeatureMap &candidates) const
Write candidates to candidates_out_ (featureXML or featureparquet)
FeatureFinderAlgorithmPickedHelperStructs::MassTrace MassTrace
Definition FeatureFinderIdentificationAlgorithm.h:159
PeakMap & getMSData()
Mutable access to the cached MS1 data.
Size n_isotopes_
number of isotopes for peptide assay
Definition FeatureFinderIdentificationAlgorithm.h:183
double mapping_tolerance_
RT tolerance for mapping IDs to features.
Definition FeatureFinderIdentificationAlgorithm.h:180
std::string elution_model_
Definition FeatureFinderIdentificationAlgorithm.h:189
Size debug_level_
Definition FeatureFinderIdentificationAlgorithm.h:197
ChargeMap ids
peptide IDs (per charge) in this region
Definition FeatureFinderIdentificationAlgorithm.h:208
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:178
void filterFeatures_(FeatureMap &features)
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
TargetedExperiment & getLibrary()
Mutable access to the assay library used / produced by the last run.
void postProcess_(FeatureMap &features, bool store_candidates=true)
Store the candidates (if requested and store_candidates), filter them and fit elution models.
TargetedExperiment output_library_
accumulated assays for output (populated from library_ before clearing)
Definition FeatureFinderIdentificationAlgorithm.h:287
bool use_psm_cutoff_
Definition FeatureFinderIdentificationAlgorithm.h:292
std::map< std::string, IMStats > im_stats_
Ion mobility statistics per peptide reference (peptide sequence/charge:region)
Definition FeatureFinderIdentificationAlgorithm.h:306
IMStats getRTRegionIMStats_(const RTRegion &r)
Calculate ion mobility statistics for peptide identifications in an RT region.
static bool isPseudoID_(const PeptideIdentification &pid)
Is pid a pseudo ID (of a seed or offset peptide)?
void addPeptideRT_(TargetedExperiment::Peptide &peptide, double rt) const
PeakMap chrom_data_
accumulated chromatograms (XICs)
Definition FeatureFinderIdentificationAlgorithm.h:285
void ensureConvexHulls_(Feature &feature) const
std::multimap< double, PeptideIdentification * > RTMap
mapping: RT (not necessarily unique) -> pointer to peptide
Definition FeatureFinderIdentificationAlgorithm.h:163
PeptideIdentificationList unassignedIDs_
Definition FeatureFinderIdentificationAlgorithm.h:294
double psm_score_cutoff_
Definition FeatureFinderIdentificationAlgorithm.h:293
void annotateFeatures_(FeatureMap &features, PeptideRefRTMap &ref_rt_map)
annotate identified features with m/z, isotope probabilities, etc.
PeakMap & getChromatograms()
Mutable access to the accumulated extracted chromatograms (XICs) from the last run.
double isotope_pmin_
min. isotope probability for peptide assay
Definition FeatureFinderIdentificationAlgorithm.h:182
void addPeptideToMap_(PeptideIdentification &peptide, PeptideMap &peptide_map)
Ion mobility statistics for a peptide in a specific RT region and charge state.
Definition FeatureFinderIdentificationAlgorithm.h:223
region in RT in which a peptide elutes:
Definition FeatureFinderIdentificationAlgorithm.h:206
A container for features.
Definition FeatureMap.h:78
An LC-MS feature.
Definition Feature.h:46
QualityType getOverallQuality() const
Non-mutable access to the overall quality.
Definition IsotopeDistribution.h:40
The MRMFeatureFinder finds and scores peaks of transitions that co-elute.
Definition MRMFeatureFinderScoring.h:69
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
const DataValue & getMetaValue(const std::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:185
Represents a single spectrum match (candidate) for a specific tandem mass spectrum (MS/MS).
Definition PeptideHit.h:52
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:66
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:28
Represents a peptide (amino acid sequence)
Definition TargetedExperimentHelper.h:334
A description of a targeted experiment containing precursor and production ions.
Definition TargetedExperiment.h:40
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
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:271
bool operator()(const Feature &f1, const Feature &f2)
Definition FeatureFinderIdentificationAlgorithm.h:272
predicate for filtering features by assigned peptides:
Definition FeatureFinderIdentificationAlgorithm.h:240
bool operator()(const Feature &feature)
Definition FeatureFinderIdentificationAlgorithm.h:241
predicate for filtering features by overall quality:
Definition FeatureFinderIdentificationAlgorithm.h:231
bool operator()(const Feature &feature)
Definition FeatureFinderIdentificationAlgorithm.h:232
comparison functor for (unassigned) peptide IDs
Definition FeatureFinderIdentificationAlgorithm.h:249
bool operator()(const PeptideIdentification &p1, const PeptideIdentification &p2)
Definition FeatureFinderIdentificationAlgorithm.h:250