OpenMS
Loading...
Searching...
No Matches
ProSEAlgorithm.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: $
6// $Authors: Raphael Förster $
7// --------------------------------------------------------------------------
8
9#pragma once
10
13
21
22#include <algorithm> // std::min (used by inline computeModMatchTolerance_)
23#include <vector>
24
25namespace OpenMS
26{
27
28class TheoreticalSpectrumGenerator;
29
44class OPENMS_DLLAPI ProSEAlgorithm :
46 public ProgressLogger
47{
48 public:
50
52 enum class ExitCodes
53 {
54 EXECUTION_OK,
55 INPUT_FILE_EMPTY,
56 UNEXPECTED_RESULT,
57 UNKNOWN_ERROR,
58 ILLEGAL_PARAMETERS
59 };
60
70 {
71 ExitCodes exit_code = ExitCodes::EXECUTION_OK;
72 std::vector<ProteinIdentification> protein_ids;
75 bool is_open_search = false;
76 };
77
103 {
104 std::vector<SearchResult> per_file;
106
110 std::string decoy_string;
112 bool decoy_is_prefix = true;
114 bool have_decoys = false;
115 };
116
126 {
127 std::vector<FASTAFile::FASTAEntry> db;
129
139 bool release_fragment_index_after_scoring = false;
140
145 std::string decoy_string;
147 bool decoy_is_prefix = true;
150 bool have_decoys = false;
151 };
152
174 ExitCodes search(const std::string& in_spectra,
175 const std::string& in_db,
176 std::vector<ProteinIdentification>& prot_ids,
177 PeptideIdentificationList& pep_ids) const;
178
203 static void applyCompleteSetProteinFDR(std::vector<ProteinIdentification>& protein_ids,
204 PeptideIdentificationList& peptide_ids,
205 const std::string& decoy_string,
206 bool decoy_is_prefix,
207 double protein_fdr);
208
254 SearchResult searchWithModificationAnalysis(const std::string& in_spectra,
255 const std::string& in_db,
256 const std::string& output_base_name = "") const;
257
276 const std::vector<FASTAFile::FASTAEntry>& fasta_db,
277 std::vector<ProteinIdentification>& prot_ids,
278 PeptideIdentificationList& pep_ids) const;
279
298 SearchContext prepareContext(const std::vector<FASTAFile::FASTAEntry>& fasta_db) const;
299
321 SearchContext& ctx,
322 std::vector<ProteinIdentification>& prot_ids,
323 PeptideIdentificationList& pep_ids) const;
324
336 const std::vector<FASTAFile::FASTAEntry>& fasta_db,
337 const std::string& output_base_name = "") const;
338
366 const std::vector<std::string>& in_spectra_files,
367 const std::vector<FASTAFile::FASTAEntry>& fasta_db,
368 const std::vector<std::string>& output_base_names = {},
369 const std::string& aggregate_base_name = "") const;
370
382 const std::vector<std::string>& in_spectra_files,
383 const std::string& in_db,
384 const std::vector<std::string>& output_base_names = {},
385 const std::string& aggregate_base_name = "") const;
386
387 protected:
388 void updateMembers_() override;
389
392 {
394 /*
395 std::string_view sequence;
396 SignedSize peptide_mod_index; ///< enumeration index of the non-RNA peptide modification
397 */
398 // Layout: doubles first, then floats, then int, then uint16_t — minimizes padding (40 bytes excluding AASequence)
399 double score = 0;
400 double delta_mass = 0.0;
401 float prefix_fraction = 0;
402 float suffix_fraction = 0;
403 float mean_error = 0.0f;
404 int isotope_error = 0;
405 uint16_t applied_charge = 0;
406 uint16_t matched_prefix_ions = 0;
407 uint16_t matched_suffix_ions = 0;
408
409 static bool hasBetterScore(const AnnotatedHit_& a, const AnnotatedHit_& b)
410 {
411 if (a.score != b.score) return a.score > b.score;
412 return a.sequence < b.sequence;
413 }
414 };
415
417 static void preprocessSpectra_(PeakMap& exp, double fragment_mass_tolerance, bool fragment_mass_tolerance_unit_ppm, bool deisotope_requested, Size peaks_keep_n, Int peaks_window_top);
418
420 enum class DecoyMode_
421 {
422 AUTO,
423 GENERATE,
424 IGNORE
425 };
426
435 {
436 bool generate{false};
437 bool strip_existing{false};
438 bool have_decoys{false};
439 std::string decoy_string;
440 bool is_prefix{true};
441 std::string strip_string;
442 bool strip_is_prefix{true};
443 };
444
454 const std::vector<FASTAFile::FASTAEntry>& db) const;
455
466
474 std::vector<FASTAFile::FASTAEntry> buildDecoyAugmentedDB_(
475 const std::vector<FASTAFile::FASTAEntry>& fasta_db,
476 const DecoyStrategy_& strategy) const;
477
491 std::vector<FASTAFile::FASTAEntry> buildCalibrationSample_(
492 const std::vector<FASTAFile::FASTAEntry>& full_db) const;
493
508 PeakMap& spectra,
509 std::vector<FASTAFile::FASTAEntry>& full_db,
510 const DecoyStrategy_& strategy,
511 std::vector<ProteinIdentification>& protein_ids,
512 PeptideIdentificationList& peptide_ids) const;
513
523 const PeakMap& spectra,
524 FragmentIndex& fi,
525 const std::vector<FASTAFile::FASTAEntry>& db,
526 const TheoreticalSpectrumGenerator& spectrum_generator,
527 double effective_fragment_tol,
528 bool fragment_mass_tolerance_unit_ppm,
529 bool open_search_mode,
530 std::vector<std::vector<AnnotatedHit_>>& annotated_hits,
531 const std::string& progress_label) const;
532
557 void postProcessHits_(const PeakMap& exp,
558 std::vector<std::vector<ProSEAlgorithm::AnnotatedHit_> >& annotated_hits,
559 std::vector<ProteinIdentification>& protein_ids,
560 PeptideIdentificationList& peptide_ids,
561 Size top_hits,
562 const StringList& modifications_fixed,
563 const StringList& modifications_variable,
564 Int peptide_missed_cleavages,
565 double precursor_mass_tolerance,
566 double fragment_mass_tolerance,
567 const std::string& precursor_mass_tolerance_unit_ppm,
568 const std::string& fragment_mass_tolerance_unit_ppm,
569 const Int precursor_min_charge,
570 const Int precursor_max_charge,
571 const std::string& enzyme,
572 const std::string& database_name) const;
573
577 mutable double precursor_mass_tolerance_lower_{10.0};
578 mutable double precursor_mass_tolerance_upper_{10.0};
579 std::string precursor_mass_tolerance_unit_{"ppm"};
580
583
585
587
589
594 bool deisotope_requested_{true};
595 Size peaks_keep_n_{0};
596 Int peaks_window_top_{20};
597
599
601
603
604 std::string enzyme_;
605
606 DecoyMode_ decoy_mode_{DecoyMode_::AUTO};
607 std::string decoy_prefix_;
608
609 double fdr_psm_{0.0};
610 double fdr_protein_{0.0};
611
613
617 EnzymaticDigestion::Specificity peptide_enzyme_specificity_{EnzymaticDigestion::SPEC_FULL};
618
619 std::string peptide_motif_;
620
622
623 bool add_a_ions_{false};
624 bool add_b_ions_{true};
625 bool add_c_ions_{false};
626 bool add_x_ions_{false};
627 bool add_y_ions_{true};
628 bool add_z_ions_{false};
629
630 Size database_chunk_size_{0};
631
632 bool calibration_enabled_{false};
633 double calibration_subset_ratio_{0.1};
634 Size calibration_min_psms_{50};
635
644 {
645 double precursor_shift{0};
646 double precursor_spread{0};
647 double cal_lower{0};
648 double cal_upper{0};
649 double fragment_tolerance{0};
650 double fragment_shift{0};
651 bool extreme_bias{false};
652 bool success{false};
653 };
654
659
667 mutable double last_mod_match_tolerance_used_{-1.0};
668
680 {
681 if (precursor_mass_tolerance_lower_ <= 0.0) return precursor_mass_tolerance_upper_;
682 if (precursor_mass_tolerance_upper_ <= 0.0) return precursor_mass_tolerance_lower_;
683 return std::min(precursor_mass_tolerance_lower_, precursor_mass_tolerance_upper_);
684 }
685
699 FragmentIndex& fragment_index,
700 const std::vector<FASTAFile::FASTAEntry>& db) const;
701
704 const std::string& output_base_name) const;
705
707 void logSearchDiagnostics_(const PeakMap& spectra,
708 const std::vector<ProteinIdentification>& protein_ids,
709 const PeptideIdentificationList& peptide_ids) const;
710
712 bool isOpenSearchMode_() const
713 {
714 return FragmentIndex::isOpenSearchMode(precursor_mass_tolerance_lower_,
715 precursor_mass_tolerance_upper_,
716 precursor_mass_tolerance_unit_ == "ppm");
717 }
718};
719
720} // namespace
Representation of a peptide/protein sequence.
Definition AASequence.h:88
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
Specificity
when querying for valid digestion products, this determines if the specificity of the two peptide end...
Definition EnzymaticDigestion.h:42
Generates from a set of Fasta files a 2D-datastructure which stores all theoretical masses of all b a...
Definition FragmentIndex.h:35
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
Combined result of open search modification analysis.
Definition OpenSearchModificationAnalysis.h:104
Management and storage of parameters / INI files.
Definition Param.h:46
Container for peptide identifications from multiple spectra.
Definition PeptideIdentificationList.h:66
Fragment-index-based peptide database search algorithm (experimental).
Definition ProSEAlgorithm.h:47
ExitCodes search(PeakMap &spectra, const std::vector< FASTAFile::FASTAEntry > &fasta_db, std::vector< ProteinIdentification > &prot_ids, PeptideIdentificationList &pep_ids) const
In-memory search: search spectra against a protein database without file I/O.
std::string enzyme_
Definition ProSEAlgorithm.h:604
FragmentIndex fragment_index
Definition ProSEAlgorithm.h:128
void logSearchDiagnostics_(const PeakMap &spectra, const std::vector< ProteinIdentification > &protein_ids, const PeptideIdentificationList &peptide_ids) const
Helper: log search summary statistics and per-run tolerance estimation.
Size peptide_max_size_
Definition ProSEAlgorithm.h:615
SearchResult searchWithModificationAnalysis(const std::string &in_spectra, const std::string &in_db, const std::string &output_base_name="") const
Search with comprehensive results including modification analysis tables.
Size precursor_max_charge_
Definition ProSEAlgorithm.h:582
Size precursor_min_charge_
Definition ProSEAlgorithm.h:581
std::string decoy_prefix_
Definition ProSEAlgorithm.h:607
Size report_top_hits_
Definition ProSEAlgorithm.h:621
Size modifications_max_variable_mods_per_peptide_
Definition ProSEAlgorithm.h:602
SearchResult searchWithModificationAnalysis(PeakMap &spectra, const std::vector< FASTAFile::FASTAEntry > &fasta_db, const std::string &output_base_name="") const
In-memory search with modification analysis: no file I/O required.
std::string peptide_motif_
Definition ProSEAlgorithm.h:619
StringList modifications_fixed_
Definition ProSEAlgorithm.h:598
CalibrationResult_ runCalibrationPass_(PeakMap &spectra, FragmentIndex &fragment_index, const std::vector< FASTAFile::FASTAEntry > &db) const
Run a fast calibration pass on a subset of spectra to estimate mass accuracy.
Param fragmentIndexParameters_() const
ProSE parameters made safe to hand to a FragmentIndex.
void postProcessHits_(const PeakMap &exp, std::vector< std::vector< ProSEAlgorithm::AnnotatedHit_ > > &annotated_hits, std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids, Size top_hits, const StringList &modifications_fixed, const StringList &modifications_variable, Int peptide_missed_cleavages, double precursor_mass_tolerance, double fragment_mass_tolerance, const std::string &precursor_mass_tolerance_unit_ppm, const std::string &fragment_mass_tolerance_unit_ppm, const Int precursor_min_charge, const Int precursor_max_charge, const std::string &enzyme, const std::string &database_name) const
Filter and annotate search results.
std::vector< ProteinIdentification > protein_ids
Definition ProSEAlgorithm.h:72
Size peptide_min_size_
Definition ProSEAlgorithm.h:614
std::vector< FASTAFile::FASTAEntry > buildDecoyAugmentedDB_(const std::vector< FASTAFile::FASTAEntry > &fasta_db, const DecoyStrategy_ &strategy) const
Build the searched database according to strategy.
SearchResult aggregate
Definition ProSEAlgorithm.h:105
IntList precursor_isotopes_
Definition ProSEAlgorithm.h:584
MultiFileSearchResult searchWithModificationAnalysis(const std::vector< std::string > &in_spectra_files, const std::string &in_db, const std::vector< std::string > &output_base_names={}, const std::string &aggregate_base_name="") const
Multi-file search with modification analysis (FASTA file path).
std::string strip_string
marker of pre-existing decoys to strip
Definition ProSEAlgorithm.h:441
MultiFileSearchResult searchWithModificationAnalysis(const std::vector< std::string > &in_spectra_files, const std::vector< FASTAFile::FASTAEntry > &fasta_db, const std::vector< std::string > &output_base_names={}, const std::string &aggregate_base_name="") const
Multi-file search with modification analysis (in-memory FASTA).
std::string fragment_mass_tolerance_unit_
Definition ProSEAlgorithm.h:588
StringList annotate_psm_
Definition ProSEAlgorithm.h:612
static void applyCompleteSetProteinFDR(std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids, const std::string &decoy_string, bool decoy_is_prefix, double protein_fdr)
Finalize protein-level FDR on a COMPLETE protein set (a single input file, or a merged cross-file agg...
OpenSearchModificationAnalysis::OpenSearchAnalysisResult modification_analysis
Definition ProSEAlgorithm.h:74
ExitCodes search(const std::string &in_spectra, const std::string &in_db, std::vector< ProteinIdentification > &prot_ids, PeptideIdentificationList &pep_ids) const
Search spectra in a spectrum file (mzML or Bruker .d) against a protein database using an FI-backed w...
std::vector< FASTAFile::FASTAEntry > db
Definition ProSEAlgorithm.h:127
ExitCodes search(PeakMap &spectra, SearchContext &ctx, std::vector< ProteinIdentification > &prot_ids, PeptideIdentificationList &pep_ids) const
In-memory search using a pre-built SearchContext.
bool isOpenSearchMode_() const
Helper function to determine if open search should be used based on tolerance.
Definition ProSEAlgorithm.h:712
ExitCodes searchChunked_(PeakMap &spectra, std::vector< FASTAFile::FASTAEntry > &full_db, const DecoyStrategy_ &strategy, std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids) const
Chunked database search implementation.
std::string decoy_string
Definition ProSEAlgorithm.h:110
static void preprocessSpectra_(PeakMap &exp, double fragment_mass_tolerance, bool fragment_mass_tolerance_unit_ppm, bool deisotope_requested, Size peaks_keep_n, Int peaks_window_top)
filter, deisotope, decharge spectra
DecoyStrategy_ resolveDecoyStrategy_(const std::vector< FASTAFile::FASTAEntry > &db) const
Decide how to obtain/recognise decoys for db.
std::vector< FASTAFile::FASTAEntry > buildCalibrationSample_(const std::vector< FASTAFile::FASTAEntry > &full_db) const
Build a strided protein sample for chunked calibration.
PeptideIdentificationList peptide_ids
Definition ProSEAlgorithm.h:73
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
ExitCodes
Exit codes.
Definition ProSEAlgorithm.h:53
StringList modifications_variable_
Definition ProSEAlgorithm.h:600
std::vector< SearchResult > per_file
Definition ProSEAlgorithm.h:104
double fragment_mass_tolerance_
Definition ProSEAlgorithm.h:586
SearchContext prepareContext(const std::vector< FASTAFile::FASTAEntry > &fasta_db) const
Build a SearchContext (decoy-augmented database + FragmentIndex) for reuse.
void scoreSpectraAgainstIndex_(const PeakMap &spectra, FragmentIndex &fi, const std::vector< FASTAFile::FASTAEntry > &db, const TheoreticalSpectrumGenerator &spectrum_generator, double effective_fragment_tol, bool fragment_mass_tolerance_unit_ppm, bool open_search_mode, std::vector< std::vector< AnnotatedHit_ > > &annotated_hits, const std::string &progress_label) const
Score all spectra against one FragmentIndex.
Size peptide_missed_cleavages_
Definition ProSEAlgorithm.h:616
CalibrationResult_ last_calibration_result_
Definition ProSEAlgorithm.h:658
double computeModMatchTolerance_() const
Definition ProSEAlgorithm.h:679
void logModificationAnalysisSummary_(const SearchResult &result, const std::string &output_base_name) const
Helper: log the modification analysis summary (shared by in-memory and file-based paths)
DecoyMode_
How decoys are obtained/recognised for a search (parameter "decoys").
Definition ProSEAlgorithm.h:421
Result of a calibration pass.
Definition ProSEAlgorithm.h:644
Resolved decoy handling for one concrete input database.
Definition ProSEAlgorithm.h:435
Multi-file search result bundle.
Definition ProSEAlgorithm.h:103
Prepared per-database state shared across multiple spectrum files.
Definition ProSEAlgorithm.h:126
Comprehensive search result including modification analysis.
Definition ProSEAlgorithm.h:70
Base class for all classes that want to report their progress.
Definition ProgressLogger.h:27
Generates theoretical spectra for peptides with various options.
Definition TheoreticalSpectrumGenerator.h:45
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< Int > IntList
Vector of signed integers.
Definition ListUtils.h:29
std::vector< std::string > StringList
Vector of String.
Definition ListUtils.h:44
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Slimmer structure as storing all scored candidates in PeptideHit objects takes too much space.
Definition ProSEAlgorithm.h:392
static bool hasBetterScore(const AnnotatedHit_ &a, const AnnotatedHit_ &b)
Definition ProSEAlgorithm.h:409
double score
main score
Definition ProSEAlgorithm.h:399
AASequence sequence
Definition ProSEAlgorithm.h:393