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
22
23#include <algorithm> // std::min (used by inline computeModMatchTolerance_)
24#include <functional> // std::hash (ProteinMapping_), std::function (FileResultConsumer, loadSpectra)
25#include <iosfwd> // std::ostream (renderRunSummary / renderModificationSummary)
26#include <limits>
27#include <map>
28#include <memory> // std::shared_ptr (released_hits_)
29#include <string> // std::string (renderRunSummaryJson return / manifest)
30#include <string_view>
31#include <unordered_map>
32#include <unordered_set>
33#include <utility> // std::pair (renderRunSummaryJson manifest)
34#include <vector>
35
36namespace OpenMS
37{
38
39class Percolator;
40class TheoreticalSpectrumGenerator;
41
56class OPENMS_DLLAPI ProSEAlgorithm :
58 public ProgressLogger
59{
60 public:
62
65 static constexpr const char* CHIMERIC_RANK = "chimeric_rank";
66
69 static constexpr double MIN_DECOYS_PER_TARGET = 0.5;
71 static constexpr double MAX_DECOYS_PER_TARGET = 2.0;
72
74 enum class ExitCodes
75 {
76 EXECUTION_OK,
77 INPUT_FILE_EMPTY,
78 UNEXPECTED_RESULT,
79 UNKNOWN_ERROR,
80 ILLEGAL_PARAMETERS
81 };
82
93 {
94 std::string input_file;
95 Size ms2_spectra = 0;
96 Size profile_spectra = 0;
97 Size charge_out_of_range_spectra = 0;
98 Size matched_spectra = 0;
99 Size target_psms = 0;
100 Size decoy_psms = 0;
101 bool fdr_applied = false;
102 double achieved_psm_fdr = -1.0;
103 Size unique_peptides = 0;
104 Size unique_proteins = 0;
105 std::map<Int, Size> charge_histogram;
106 std::map<Size, Size> missed_cleavage_histogram;
107 bool score_stats_valid = false;
108 double hyperscore_min = 0.0;
109 double hyperscore_median = 0.0;
110 double hyperscore_max = 0.0;
115 bool prec_tol_valid = false;
116 double prec_err_median = 0.0, prec_err_mad = 0.0, prec_err_recommended = 0.0;
119 bool frag_tol_valid = false;
120 double frag_err_median = 0.0, frag_err_mad = 0.0, frag_err_recommended = 0.0;
121 double seconds_search = 0.0;
122 double seconds_calibration = 0.0;
123 double seconds_fdr = 0.0;
126 std::vector<std::pair<std::string, DataValue>> recalibration;
127 };
128
138 {
139 std::string database_file;
140 std::string enzyme;
141 double precursor_tol_lower = 0.0, precursor_tol_upper = 0.0;
143 double fragment_tol = 0.0;
144 std::string fragment_tol_unit;
145 Int min_charge = 0, max_charge = 0;
146 Size missed_cleavages = 0;
147 std::vector<std::string> fixed_mods, variable_mods, ion_series;
148 bool open_search = false;
149 bool calibration_enabled = false;
150 std::string recalibrate;
151 bool peptide_mass_mode = false;
152 bool chunked = false;
153 std::string decoy_mode;
154 double psm_fdr_threshold = 0.0, protein_fdr_threshold = 0.0;
155 Size db_target_proteins = 0;
156 Size db_decoy_proteins = 0;
157 Size indexed_peptides = 0;
158 Size indexed_fragments = 0;
159 double seconds_index_build = 0.0;
160 double seconds_total = 0.0;
161 double seconds_output = 0.0;
162 double seconds_qpx_extended = 0.0;
163 };
164
171 {
173 bool applied = false;
175 std::string skipped_reason;
178 std::string warning;
181 std::string model;
182 };
183
189 {
190 int subset_max_train = 0;
191 std::string subset_mode = "out_of_fold";
192 int curve_start = 100000;
193 double curve_min_gain = 0.002;
194 int iterations = 10;
195 double tron_epsilon = 1e-7;
196 bool warm_start = false;
197 bool single_cneg = false;
198 std::string solver = "newton";
199 std::string use_pi0 = "true";
200 bool calc_mass_feature = false;
201 bool fixed_enzyme_termini = false;
202 bool peptide_level = true;
203 };
204
212 static void stratumQValues(PeptideIdentificationList& peptide_ids);
213
222 static bool reuseTrainingDraw(UInt64 seed, Size file, Size spectrum, double fraction);
223
227 static bool reuseCalibrationDraw(UInt64 seed, Size file, Size spectrum, double fraction);
228
256
299 {
300 std::vector<SearchResult> per_file;
302
306 std::string decoy_string;
308 bool decoy_is_prefix = true;
310 bool have_decoys = false;
311
315 };
316
319 {
320 std::vector<ProteinIdentification> protein_ids;
324 bool protein_fdr_applied = false;
325 };
326
336 {
337 std::vector<FASTAFile::FASTAEntry> db;
339
349 bool release_fragment_index_after_scoring = false;
350
355 std::string decoy_string;
357 bool decoy_is_prefix = true;
360 bool have_decoys = false;
365 bool electron_ions = false;
366 };
367
389 ExitCodes search(const std::string& in_spectra,
390 const std::string& in_db,
391 std::vector<ProteinIdentification>& prot_ids,
392 PeptideIdentificationList& pep_ids) const;
393
444 static bool applyCompleteSetProteinFDR(std::vector<ProteinIdentification>& protein_ids,
445 PeptideIdentificationList& peptide_ids,
446 const std::string& decoy_string,
447 bool decoy_is_prefix,
448 double protein_fdr,
449 bool remove_decoys,
450 const PeptideIdentificationList& inference_only_psms);
451
470 static std::string inferProteins(std::vector<ProteinIdentification>& protein_ids,
471 const PeptideIdentificationList& peptide_ids,
472 const PeptideIdentificationList& inference_only_psms = PeptideIdentificationList());
473
483 static void removeUnreportedProteins(std::vector<ProteinIdentification>& protein_ids,
484 const PeptideIdentificationList& peptide_ids,
485 const PeptideIdentificationList& also_referencing = PeptideIdentificationList());
486
500 static Size removeDuplicateProteins(std::vector<FASTAFile::FASTAEntry>& db, const std::string& source);
501
514
551 static PercolatorRescoring rescoreWithPercolator(std::vector<ProteinIdentification>& protein_ids,
552 PeptideIdentificationList& peptide_ids,
553 int threads,
554 Size max_train_psms = 0);
555
564 static std::string pinEnzymeName(const std::string& enzyme);
565
572 static std::string pinFeatureEnzyme(const std::string& enzyme, bool fixed_enzyme_termini);
573
589 static PeakMap loadSpectra(const std::string& filename, const std::function<bool(const MSSpectrum&)>& keep = {});
590
618 bool applyDeferredPsmFDR(const std::vector<ProteinIdentification>& protein_ids,
619 PeptideIdentificationList& peptide_ids,
620 bool rescored,
621 double psm_fdr,
622 PeptideIdentificationList* inference_only_psms = nullptr) const;
623
670 SearchResult searchWithModificationAnalysis(const std::string& in_spectra,
671 const std::string& in_db,
672 const std::string& output_base_name = "") const;
673
694 const std::vector<FASTAFile::FASTAEntry>& fasta_db,
695 std::vector<ProteinIdentification>& prot_ids,
696 PeptideIdentificationList& pep_ids) const;
697
718 SearchContext prepareContext(const std::vector<FASTAFile::FASTAEntry>& fasta_db) const;
719
733 SearchContext prepareContext(const std::vector<FASTAFile::FASTAEntry>& fasta_db, bool electron_ions) const;
734
757 SearchContext& ctx,
758 std::vector<ProteinIdentification>& prot_ids,
759 PeptideIdentificationList& pep_ids) const;
760
772 const std::vector<FASTAFile::FASTAEntry>& fasta_db,
773 const std::string& output_base_name = "") const;
774
826 const std::vector<std::string>& in_spectra_files,
827 const std::vector<FASTAFile::FASTAEntry>& fasta_db,
828 const std::vector<std::string>& output_base_names = {},
829 const std::string& aggregate_base_name = "",
830 bool build_pooled_aggregate = true) const;
831
846 const std::vector<std::string>& in_spectra_files,
847 const std::string& in_db,
848 const std::vector<std::string>& output_base_names = {},
849 const std::string& aggregate_base_name = "",
850 bool build_pooled_aggregate = true) const;
851
905 bool remove_decoys = true) const;
906
929
933 void setParameterNamePrefix(const std::string& prefix) { parameter_name_prefix_ = prefix; }
934
938 void setKeepPreFdrPsms(bool keep)
939 {
940 keep_pre_fdr_psms_ = keep;
941 if (!keep) { pre_fdr_peptide_ids_ = PeptideIdentificationList(); }
942 }
943
945 using FileResultConsumer = std::function<void(Size, const SearchResult&)>;
946
965 {
966 file_result_consumer_ = std::move(consumer);
967 }
968
969 protected:
970 void updateMembers_() override;
971
974 {
976 /*
977 std::string_view sequence;
978 SignedSize peptide_mod_index; ///< enumeration index of the non-RNA peptide modification
979 */
980 // Layout: doubles first, then floats, then int, then uint16_t — minimizes padding (40 bytes excluding AASequence)
981 double score = 0;
982 double delta_mass = 0.0;
983 float prefix_fraction = 0;
984 float suffix_fraction = 0;
985 float mean_error = 0.0f;
986 int isotope_error = 0;
987 uint16_t applied_charge = 0;
988 uint16_t matched_prefix_ions = 0;
989 uint16_t matched_suffix_ions = 0;
990 UInt32 index_peptide = 0;
991
992 static bool hasBetterScore(const AnnotatedHit_& a, const AnnotatedHit_& b)
993 {
994 if (a.score != b.score) return a.score > b.score;
995 return a.sequence < b.sequence;
996 }
997 };
998
1019 {
1020 double sum = 0.0;
1021 double sumsq = 0.0;
1022 double best = 0.0;
1023 double second_best = 0.0;
1024 Size count = 0;
1027 std::unordered_set<std::string> seen_candidates;
1029 int scoring_thread = 0;
1030
1032 void add(double score)
1033 {
1034 if (score > best) { second_best = best; best = score; }
1035 else if (score > second_best) { second_best = score; }
1036 sum += score;
1037 sumsq += score * score;
1038 ++count;
1039 }
1040
1042 double deltaScore() const { return best - second_best; }
1043
1065 double zScore() const;
1066 };
1067
1077 {
1078 unsigned int min_peaks{3};
1079 bool charge_cap_precursor{false};
1080 bool sum_intensity{false};
1081 };
1082
1097 static void preprocessSpectra_(PeakMap& exp,
1098 double fragment_mass_tolerance,
1099 bool fragment_mass_tolerance_unit_ppm,
1100 bool deisotope_requested,
1101 Size peaks_keep_n,
1102 Int peaks_window_top,
1103 const std::string& window_type,
1104 const DeisotopingSettings_& deisotoping,
1105 FragmentIonLikelihoodModel::PeakLists* ion_evidence = nullptr,
1106 bool ion_evidence_scored_peaks = false,
1107 PeakMap* evidence_spectra = nullptr,
1108 PeakMap* query_spectra = nullptr);
1109
1111 static void preprocessSpectra_(PeakMap& exp,
1112 double fragment_mass_tolerance,
1113 bool fragment_mass_tolerance_unit_ppm,
1114 bool deisotope_requested,
1115 Size peaks_keep_n,
1116 Int peaks_window_top,
1117 const std::string& window_type = "auto");
1118
1145 void annotateIonPriors_(const PeakMap& spectra,
1147 std::vector<ProteinIdentification>& protein_ids,
1148 PeptideIdentificationList& peptide_ids) const;
1149
1152
1154 static void filterLocalPeaks_(MSSpectrum& spectrum, Size peaks_per_window);
1155
1157 enum class DecoyMode_
1158 {
1159 AUTO,
1160 GENERATE,
1161 IGNORE
1162 };
1163
1172 {
1173 bool generate{false};
1174 bool strip_existing{false};
1175 bool have_decoys{false};
1176 std::string decoy_string;
1177 bool is_prefix{true};
1178 std::string strip_string;
1179 bool strip_is_prefix{true};
1180 };
1181
1191 const std::vector<FASTAFile::FASTAEntry>& db) const;
1192
1205 Param fragmentIndexParameters_(bool electron_ions = false) const;
1206
1209 struct SpectrumGenerators_;
1210
1212 struct MzRecalibration_;
1213
1215 SpectrumGenerators_ spectrumGenerators_() const;
1216
1219 {
1220 double chance_match_surprise = 0.0;
1221 double mass_competition_evidence = 0.0;
1222 };
1223
1225 static std::vector<double> localPeakDensities_(const MSSpectrum& spectrum);
1226
1246 const MSSpectrum& theoretical,
1247 const std::vector<double>& densities,
1248 double tolerance, bool ppm);
1249
1253 const MSSpectrum& theoretical,
1254 int max_charge,
1255 const std::vector<double>& densities,
1256 double tolerance, bool ppm,
1257 std::vector<double>& alternatives);
1258
1261 const MSSpectrum& theoretical,
1262 const std::vector<Int>& charges,
1263 int max_charge,
1264 const std::vector<double>& densities,
1265 double tolerance, bool ppm,
1266 std::vector<double>& alternatives);
1267
1269 static bool isElectronActivated_(const MSSpectrum& spectrum);
1270
1272 Size countElectronActivated_(const PeakMap& spectra) const;
1273
1281 std::vector<FASTAFile::FASTAEntry> buildDecoyAugmentedDB_(
1282 const std::vector<FASTAFile::FASTAEntry>& fasta_db,
1283 const DecoyStrategy_& strategy) const;
1284
1286 std::vector<FASTAFile::FASTAEntry> buildDecoyAugmentedDB_(
1287 std::vector<FASTAFile::FASTAEntry>&& fasta_db,
1288 const DecoyStrategy_& strategy) const;
1289
1294 const std::vector<std::string>& in_spectra_files,
1295 const std::vector<FASTAFile::FASTAEntry>& fasta_db_given,
1296 const std::string* in_db,
1297 const std::vector<std::string>& output_base_names,
1298 const std::string& aggregate_base_name,
1299 bool build_pooled_aggregate) const;
1300
1305 void reportDecoyParity_(const SearchContext& ctx) const;
1306 SearchContext prepareContext_(std::vector<FASTAFile::FASTAEntry>&& fasta_db, bool electron_ions,
1307 const std::function<const PeakMap*(Size)>& searched_spectra = {}) const;
1308
1313 bool restrictIndexToSpectra_() const { return !chimeric_enabled_ && !(calibration_enabled_ && calibration_recalibrate_ == "linear"); }
1314
1317 void buildFragmentIndex_(SearchContext& ctx, const Param& params, const std::function<const PeakMap*(Size)>& searched_spectra) const;
1318
1320 static double calibrationPassWindow_(double configured, bool ppm);
1321
1323 static double measuredError_(double offset, double sigma);
1324
1327 static double measuredCoverage_(const std::vector<double>& errors, bool fragment);
1328
1331 bool chimericSearch_() const { return chimeric_enabled_ && database_chunk_size_ == 0; }
1332
1335 {
1336 Size parent = 0;
1338 std::vector<UInt32> removed;
1339 };
1340
1365 void searchCoIsolated_(const PeakMap& spectra,
1366 const std::vector<std::vector<AnnotatedHit_>>& annotated_hits,
1367 FragmentIndex& fi,
1368 const std::vector<FASTAFile::FASTAEntry>& db,
1369 const SpectrumGenerators_& generators,
1370 double fragment_tol,
1371 bool fragment_tol_ppm,
1372 bool open_search_mode,
1373 std::vector<CoIsolatedPSM_>& psms,
1374 std::vector<std::vector<AnnotatedHit_>>& hits,
1375 std::vector<CandidatePoolStats_>& pool_stats) const;
1376
1379 static MSSpectrum residualSpectrum_(const MSSpectrum& spectrum, const std::vector<UInt32>& removed, const Precursor& precursor);
1380
1394 std::vector<FASTAFile::FASTAEntry> buildCalibrationSample_(
1395 const std::vector<FASTAFile::FASTAEntry>& full_db) const;
1396
1411 PeakMap& spectra,
1412 std::vector<FASTAFile::FASTAEntry>& full_db,
1413 const DecoyStrategy_& strategy,
1414 std::vector<ProteinIdentification>& protein_ids,
1415 PeptideIdentificationList& peptide_ids) const;
1416
1442 const PeakMap& spectra,
1443 FragmentIndex& fi,
1444 const std::vector<FASTAFile::FASTAEntry>& db,
1445 const SpectrumGenerators_& generators,
1446 double effective_fragment_tol,
1447 bool fragment_mass_tolerance_unit_ppm,
1448 bool open_search_mode,
1449 std::vector<std::vector<AnnotatedHit_>>& annotated_hits,
1450 std::vector<CandidatePoolStats_>& pool_stats,
1451 const std::string& progress_label,
1452 const PeakMap* query_spectra = nullptr) const;
1453
1459 static std::vector<SignedSize> scoringOrder_(const PeakMap& spectra, const PeakMap* query_spectra);
1460
1498 void postProcessHits_(const PeakMap& exp,
1499 std::vector<std::vector<ProSEAlgorithm::AnnotatedHit_> >& annotated_hits,
1500 const std::vector<CandidatePoolStats_>& pool_stats,
1501 std::vector<ProteinIdentification>& protein_ids,
1502 PeptideIdentificationList& peptide_ids,
1503 Size top_hits,
1504 const StringList& modifications_fixed,
1505 const StringList& modifications_variable,
1506 Int peptide_missed_cleavages,
1507 double precursor_mass_tolerance,
1508 double fragment_mass_tolerance,
1509 const std::string& precursor_mass_tolerance_unit_ppm,
1510 const std::string& fragment_mass_tolerance_unit_ppm,
1511 const Int precursor_min_charge,
1512 const Int precursor_max_charge,
1513 const std::string& enzyme,
1514 const std::string& database_name,
1515 const PeakMap* evidence_spectra = nullptr,
1516 const std::vector<Size>* evidence_parent = nullptr,
1517 bool defer_peak_annotations = false,
1518 const MzRecalibration_* fragment_recalibration = nullptr) const;
1519
1526 double fragment_mass_tolerance, const std::string& fragment_mass_tolerance_unit_ppm,
1527 const MzRecalibration_* fragment_recalibration = nullptr) const;
1528
1537 std::vector<ProteinIdentification>& protein_ids,
1538 PeptideIdentificationList& peptide_ids) const;
1539
1540 bool peptdeep_enable_{false};
1543 std::string peptdeep_instrument_{"QE"};
1544 double peptdeep_nce_{-1.0};
1545 std::string peptdeep_rt_model_type_{"b_spline"};
1546 int peptdeep_batch_size_{500};
1547
1551 mutable double precursor_mass_tolerance_lower_{10.0};
1552 mutable double precursor_mass_tolerance_upper_{10.0};
1553 std::string precursor_mass_tolerance_unit_{"ppm"};
1554
1557
1559
1561
1566 bool deisotope_requested_{true};
1567 bool scoring_multiple_charges_{false};
1568 int scoring_max_charge_{2};
1569 bool mass_accuracy_score_{false};
1570 double mass_error_sd_ppm_{7.0};
1571
1573 int scoringMaxCharge_(int precursor_charge) const
1574 {
1575 return scoring_multiple_charges_ ? std::max(1, std::min(precursor_charge - 1, scoring_max_charge_)) : 1;
1576 }
1577 Size peaks_keep_n_{0};
1578 Int peaks_window_top_{20};
1579 std::string peaks_window_type_ {"auto"};
1581 bool query_raw_spectrum_{false};
1582
1584
1586
1588
1589 std::string enzyme_;
1590
1591 DecoyMode_ decoy_mode_{DecoyMode_::AUTO};
1592 std::string decoy_prefix_;
1593 bool decoy_keep_termini_ = false;
1594 bool decoy_parity_report_ = false;
1595 // The effective values of the current search: buildDecoyAugmentedDB_() (a const step) re-derives them from the
1596 // parameters at every database build and switches both off when the reused decoys rarely start with M (the
1597 // Met-share check of that function); nterm_options_disabled_ records that for the output's search parameters.
1598 mutable bool terminal_features_ = false;
1599 mutable bool stratum_q_values_ = false;
1600 mutable bool nterm_options_disabled_ = false;
1601
1602 bool rescore_{true};
1605 mutable std::string reset_run_name_;
1606 std::string reuse_mode_{"per_file"};
1607 Size reuse_max_train_{250000};
1608 Size reuse_static_files_{1};
1609 double reuse_max_shift_{0.5};
1610 Size max_train_psms_{500000};
1611 double fdr_psm_{0.0};
1612 bool fdr_psm_by_scored_charges_{true};
1613 double fdr_protein_{0.0};
1614 double fdr_protein_inference_psm_{0.1};
1615
1617
1618 bool self_trained_ion_priors_{false};
1619 FragmentIonLikelihoodModel::ContextSet ion_prior_model_{FragmentIonLikelihoodModel::ContextSet::RICH};
1620 bool ion_prior_scored_peaks_{false};
1621 int ion_prior_max_fragment_charge_{2};
1622 double ion_prior_train_fdr_{0.01};
1623 Size ion_prior_min_psms_{100};
1624 bool ion_prior_feature_llr_{true};
1625 bool ion_prior_feature_explained_{true};
1626 bool ion_prior_feature_topk_{false};
1627
1631 EnzymaticDigestion::Specificity peptide_enzyme_specificity_{EnzymaticDigestion::SPEC_FULL};
1632
1633
1636 Size rescore_top_hits_{0};
1639 {
1640 return rescore_top_hits_ > 0 ? rescore_top_hits_ : report_top_hits_;
1641 }
1646 {
1647 if (!rescore_ || decoy_mode_ == DecoyMode_::IGNORE) return report_top_hits_;
1648 return keep_pre_fdr_psms_ ? std::max(report_top_hits_, rescoreTopHits_()) : rescoreTopHits_();
1649 }
1652 bool isotope_error_observed_minus_theoretical_{true};
1653
1654 bool add_a_ions_{false};
1655 bool add_b_ions_{true};
1656 bool add_c_ions_{false};
1657 bool add_x_ions_{false};
1658 bool add_y_ions_{true};
1659 bool add_z_ions_{false};
1660 bool add_zp1_ions_{false};
1661 bool ions_by_activation_{true};
1662 bool protein_mapping_from_index_{true};
1663
1664 Size database_chunk_size_{0};
1665
1666 bool calibration_enabled_{false};
1667 double calibration_subset_ratio_{0.1};
1668 bool chimeric_enabled_{false};
1669 Size calibration_min_psms_{50};
1670 double calibration_sigma_factor_{4.0};
1671 double calibration_precursor_sigma_factor_{0.0};
1672 double calibration_min_precursor_tol_{0.0};
1673 double calibration_min_fragment_tol_{0.0};
1674 std::string calibration_recalibrate_{"none"};
1675 Size calibration_recalibrate_rt_chunks_{1};
1676
1679 static constexpr const char* OBSERVED_PRECURSOR_MZ = "observed_precursor_mz";
1682 static constexpr const char* OBSERVED_COISOLATED_MZ = "observed_coisolated_mz";
1683
1692 struct OPENMS_DLLAPI MzRecalibration_ // exported: the class test calls its functions (MSVC links nothing of a nested struct without it)
1693 {
1694 struct Chunk { double rt; double intercept; double slope; Size points; };
1695 std::vector<Chunk> chunks;
1696 bool ppm{true};
1697 bool active() const { return !chunks.empty(); }
1698 double error(double mz, double rt) const;
1699 double correct(double mz, double rt) const;
1700 double uncorrect(double corrected, double rt) const;
1705 struct OPENMS_DLLAPI AtRT // (exported like its parent: MSVC links nothing of a nested struct without it)
1706 {
1707 const Chunk* lo{nullptr};
1708 const Chunk* hi{nullptr};
1709 double w{0.0};
1710 bool ppm{true};
1711 double error(double mz) const
1712 {
1713 if (lo == nullptr) return 0.0;
1714 const double e_lo = lo->intercept + lo->slope * mz;
1715 if (hi == nullptr) return e_lo;
1716 return (1.0 - w) * e_lo + w * (hi->intercept + hi->slope * mz);
1717 }
1718 double correct(double mz) const
1719 {
1720 const double e = error(mz);
1721 return ppm ? mz - e * 1e-6 * mz : mz - e;
1722 }
1723 };
1724 AtRT at(double rt) const;
1725 std::string toString() const;
1732 static MzRecalibration_ fit(const std::vector<double>& errors, const std::vector<double>& mzs,
1733 const std::vector<double>& rts, Size n_chunks, Size min_points, bool linear, bool ppm);
1734 };
1735
1746 {
1747 double precursor_shift{0};
1748 double precursor_sigma{0};
1749 double precursor_raw_shift{0};
1750 double precursor_raw_sigma{0};
1751 double fragment_raw_shift{0};
1752 double fragment_raw_sigma{0};
1755 bool recalibrated() const { return precursor_recalibration.active() || fragment_recalibration.active(); }
1757 const MzRecalibration_* appliedFragmentRecalibration() const { return success && fragment_recalibration.active() ? &fragment_recalibration : nullptr; }
1758 double precursor_spread{0};
1759 double cal_lower{0};
1760 double cal_upper{0};
1761 double fragment_tolerance{0};
1762 double fragment_shift{0};
1763 double fragment_sigma{0};
1764 double precursor_coverage{0};
1765 double fragment_coverage{0};
1766 Size psms{0};
1768 double precursor_measured_coverage{0};
1770 double fragment_measured_coverage{0};
1772 bool precursor_measurement_trusted{false};
1774 bool fragment_measurement_trusted{false};
1775 Size fragment_peaks{0};
1776 bool extreme_bias{false};
1777 bool success{false};
1778 };
1779
1784
1791
1795 bool keep_pre_fdr_psms_ = false;
1799 std::string paramName_(const std::string& name) const { return parameter_name_prefix_ + name; }
1802 mutable bool pool_rescoring_ = false;
1804 bool keepPreRescoringPsms_() const { return keep_pre_fdr_psms_ || pool_rescoring_; }
1807 mutable Size pool_files_ = 0;
1818 static std::vector<Size> transferSample_(const PeptideIdentificationList& ids, Size max_psms, Size hits_per_spectrum);
1825 mutable std::shared_ptr<void> released_hits_;
1826
1828 struct ReuseScoring_;
1830 struct ReuseModel_;
1833 {
1835 const std::vector<ProteinIdentification>* protein_ids;
1837 };
1838
1843 static PercolatorRescoring rescoreWithPercolator_(std::vector<ProteinIdentification>& protein_ids,
1844 PeptideIdentificationList& peptide_ids,
1845 int threads,
1846 std::vector<std::vector<PeptideHit>>* dropped,
1847 const PercolatorTraining& training,
1848 const Param& extra,
1849 const ReuseScoring_* reuse = nullptr);
1850
1853 std::shared_ptr<const ReuseModel_> trainReuseModel_(const std::vector<ReuseRun_>& runs, int threads) const;
1854
1858 PercolatorRescoring rescoreWithReuseModel_(std::vector<ProteinIdentification>& protein_ids,
1859 PeptideIdentificationList& peptide_ids,
1860 Size file_index,
1861 const ReuseModel_& model,
1862 bool check_shift,
1863 int threads,
1864 std::vector<std::vector<PeptideHit>>* dropped) const;
1865
1870 void applyRescoredPsmFDR_(std::vector<ProteinIdentification>& protein_ids,
1871 PeptideIdentificationList& peptide_ids,
1872 bool has_decoys,
1873 RunStatistics& stats,
1874 bool rescored,
1875 PeptideIdentificationList* inference_only_psms) const;
1876
1879 void finishDeferredRescoring_(MultiFileSearchResult& mfres, const std::vector<Size>& deferred) const;
1880
1882 mutable std::shared_ptr<const ReuseModel_> reuse_model_;
1884 mutable bool reuse_defer_ = false;
1886 mutable Size reuse_file_index_ = 0;
1890
1898 mutable double last_mod_match_tolerance_used_{-1.0};
1899
1911 {
1912 if (precursor_mass_tolerance_lower_ <= 0.0) return precursor_mass_tolerance_upper_;
1913 if (precursor_mass_tolerance_upper_ <= 0.0) return precursor_mass_tolerance_lower_;
1914 return std::min(precursor_mass_tolerance_lower_, precursor_mass_tolerance_upper_);
1915 }
1916
1931 FragmentIndex& fragment_index,
1932 const std::vector<FASTAFile::FASTAEntry>& db,
1933 const PeakMap* query_spectra = nullptr) const;
1934
1945 void applyRecalibration_(const CalibrationResult_& cal, PeakMap& spectra, PeakMap* query_spectra,
1946 PeakMap* evidence_spectra) const;
1947
1950 void recordRecalibration_(const CalibrationResult_& cal, std::vector<ProteinIdentification>& protein_ids) const;
1951
1970 {
1972 static constexpr Size SHARDS = 64;
1974 std::vector<std::string_view> sequences;
1976 std::vector<std::vector<std::pair<UInt32, UInt32>>> occurrences;
1978 std::vector<std::unordered_map<std::string_view, Size>> entries;
1980 std::string fallback_reason;
1981
1983 Size find(std::string_view sequence) const
1984 {
1985 if (entries.empty()) return sequences.size();
1986 const auto& table = entries[std::hash<std::string_view>{}(sequence) % SHARDS];
1987 const auto entry = table.find(sequence);
1988 return entry == table.end() ? sequences.size() : entry->second;
1989 }
1990 };
1991
2002 const std::vector<FASTAFile::FASTAEntry>& db,
2003 std::vector<UInt32> candidates,
2004 const Param& indexer_parameters);
2005
2014 static bool applyProteinMapping_(const ProteinMapping_& mapping,
2015 const std::vector<FASTAFile::FASTAEntry>& db,
2016 const Param& indexer_parameters,
2017 std::vector<ProteinIdentification>& protein_ids,
2018 PeptideIdentificationList& peptide_ids,
2019 std::string& fallback_reason);
2020
2023 static bool accessionHasDecoyMarker_(const std::string& accession,
2024 const std::string& marker, bool is_prefix);
2025
2029 static void removeProteinsReferencedByNeither_(std::vector<ProteinIdentification>& protein_ids,
2030 const PeptideIdentificationList& peptide_ids,
2031 const PeptideIdentificationList& also_referencing);
2032
2035 static constexpr const char* SEARCH_ENGINE_SCORE = "ln(hyperscore)";
2036
2042
2044 static Size countDecoyEntries_(const std::vector<FASTAFile::FASTAEntry>& db, const std::string& marker, bool is_prefix);
2045
2053 static void poolSearchedFiles_(std::vector<SearchResult>& per_file, bool move_psms, const StringList& in_spectra_files,
2054 std::vector<ProteinIdentification>& protein_ids, PeptideIdentificationList& peptide_ids);
2055
2057 static bool searched_(const SearchResult& pf);
2058
2061 static int searchedFileOf_(const PeptideIdentification& id, const std::vector<SearchResult>& per_file);
2062
2066 static void returnPooledPsms_(PeptideIdentificationList& pooled, std::vector<SearchResult>& per_file);
2067
2074 static void capturePreFdrStats_(const PeptideIdentificationList& peptide_ids,
2075 RunStatistics& stats);
2076
2080 static double maxRetainedScore_(const PeptideIdentificationList& peptide_ids);
2081
2084 static void keepTopHits_(PeptideIdentificationList& peptide_ids, Size n);
2085
2097 PercolatorRescoring applyPsmFDR_(std::vector<ProteinIdentification>& protein_ids,
2098 PeptideIdentificationList& peptide_ids,
2099 bool has_decoys,
2100 RunStatistics& stats,
2101 PeptideIdentificationList* pre_fdr_psms = nullptr,
2102 PeptideIdentificationList* inference_only_psms = nullptr) const;
2103
2107 static void markRescoredByPercolator_(std::vector<ProteinIdentification>& protein_ids, const Param& pp,
2108 const PercolatorTraining& training, const Percolator* perc = nullptr,
2109 const ReuseScoring_* reuse = nullptr);
2110
2112 static bool hasPSMs_(const PeptideIdentificationList& ids);
2113
2118 static void tdcQValues_(PeptideIdentificationList& peptide_ids, bool plus_one = false);
2119
2120
2139 void rescoreFilesTogether_(MultiFileSearchResult& mfres, const std::vector<std::string>& in_spectra_files) const;
2140
2143 void collectInferenceOnlyPsms_(const PeptideIdentificationList& peptide_ids, double psm_fdr,
2144 PeptideIdentificationList& inference_only_psms) const;
2145
2151 void collectRunStatistics_(const PeakMap& spectra,
2152 const std::vector<ProteinIdentification>& protein_ids,
2153 const PeptideIdentificationList& peptide_ids,
2154 RunStatistics& stats) const;
2155
2159 {
2160 Size ms2 = 0;
2161 Size profile = 0;
2162 Size charge_out_of_range = 0;
2163 };
2164
2166 SpectraCounts_ countSpectra_(const PeakMap& spectra) const;
2167
2172 void preprocessSearchedSpectra_(PeakMap& spectra, const std::string& input,
2174 PeakMap* evidence_spectra, PeakMap* query_spectra) const;
2175
2176 public:
2187 const PeptideIdentificationList& peptide_ids,
2188 const std::string& enzyme,
2189 bool fdr_applied);
2190
2193 static void releaseInParallel(SearchResult& result);
2194
2201 static std::string renderTotalTime(const SharedSearchStats& sh);
2202
2207 static void renderRunSummary(const RunStatistics& stats,
2208 const SharedSearchStats& shared,
2210 bool is_open_search,
2211 std::ostream& os);
2212
2216 std::ostream& os);
2217
2224 static std::string renderRunSummaryYaml(
2225 const MultiFileSearchResult& mfres,
2226 const std::vector<std::pair<std::string, std::vector<std::string>>>& manifest,
2227 Size files_failed,
2228 Size files_total);
2229
2230 private:
2231
2234 {
2235 return FragmentIndex::isOpenSearchMode(precursor_mass_tolerance_lower_,
2236 precursor_mass_tolerance_upper_,
2237 precursor_mass_tolerance_unit_ == "ppm");
2238 }
2239};
2240
2241} // namespace
Definition AASequence.h:96
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:43
Generates from a set of Fasta files a 2D-datastructure which stores all theoretical masses of all b a...
Definition FragmentIndex.h:36
Compact peak lists of the spectra of one run: per peak only its m/z and its intensity-rank bin.
Definition FragmentIonLikelihoodModel.h:92
ContextSet
Ion contexts and outcomes the model distinguishes.
Definition FragmentIonLikelihoodModel.h:68
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
The representation of a 1D spectrum.
Definition MSSpectrum.h:44
Combined result of open search modification analysis.
Definition OpenSearchModificationAnalysis.h:106
Management and storage of parameters / INI files.
Definition Param.h:46
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
In-process Percolator: semi-supervised target/decoy rescoring with q-values + PEPs.
Definition Percolator.h:81
Precursor meta information.
Definition Precursor.h:37
Fragment-index-based peptide database search algorithm (experimental).
Definition ProSEAlgorithm.h:59
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.
static LocalFragmentEvidence_ localFragmentEvidence_(const MSSpectrum &spectrum, const MSSpectrum &theoretical, const std::vector< double > &densities, double tolerance, bool ppm)
Compute local fragment-match evidence on the spectrum before window/top-N peak filtering.
static Size countDecoyEntries_(const std::vector< FASTAFile::FASTAEntry > &db, const std::string &marker, bool is_prefix)
Helper: the entries of db whose accession carries the decoy marker (accessionHasDecoyMarker_())
std::string enzyme_
Definition ProSEAlgorithm.h:1589
static std::string renderRunSummaryYaml(const MultiFileSearchResult &mfres, const std::vector< std::pair< std::string, std::vector< std::string > > > &manifest, Size files_failed, Size files_total)
static MSSpectrum residualSpectrum_(const MSSpectrum &spectrum, const std::vector< UInt32 > &removed, const Precursor &precursor)
Size searchTopHits_() const
Definition ProSEAlgorithm.h:1645
static std::string pinFeatureEnzyme(const std::string &enzyme, bool fixed_enzyme_termini)
The enzyme argument of PercolatorInfile (store(), the in-process rescoring) for the enzN/enzC/enzInt ...
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, const std::string &window_type, const DeisotopingSettings_ &deisotoping, FragmentIonLikelihoodModel::PeakLists *ion_evidence=nullptr, bool ion_evidence_scored_peaks=false, PeakMap *evidence_spectra=nullptr, PeakMap *query_spectra=nullptr)
filter, deisotope, decharge spectra
PercolatorRescoring last_percolator_
Definition ProSEAlgorithm.h:1794
static std::string inferProteins(std::vector< ProteinIdentification > &protein_ids, const PeptideIdentificationList &peptide_ids, const PeptideIdentificationList &inference_only_psms=PeptideIdentificationList())
The protein inference of the protein FDR (applyCompleteSetProteinFDR()) and of mergeFileResults().
const std::vector< ProteinIdentification > * protein_ids
Definition ProSEAlgorithm.h:1835
FragmentIndex fragment_index
Definition ProSEAlgorithm.h:338
std::string fragment_tol_unit
Definition ProSEAlgorithm.h:144
Size peptide_max_size_
Definition ProSEAlgorithm.h:1629
static void updateFinalStats(RunStatistics &stats, const PeptideIdentificationList &peptide_ids, const std::string &enzyme, bool fdr_applied)
static double measuredError_(double offset, double sigma)
The measured mass error |offset| + 4 sigma: the range that holds practically all correct matches.
PercolatorRescoring percolator
Outcome of the Percolator rescoring of this run (parameter 'rescore')
Definition ProSEAlgorithm.h:247
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, const std::string &window_type="auto")
preprocessSpectra_() with the DeisotopingSettings_ defaults (the behaviour before its parameters exis...
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.
std::vector< std::pair< std::string, DataValue > > recalibration
Definition ProSEAlgorithm.h:126
Size precursor_max_charge_
Definition ProSEAlgorithm.h:1556
bool applyDeferredPsmFDR(const std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids, bool rescored, double psm_fdr, PeptideIdentificationList *inference_only_psms=nullptr) const
Apply the PSM-level FDR to PSMs that were rescored separately, e.g. with rescoreWithPercolator() on t...
PeptideIdentificationList * peptide_ids
Definition ProSEAlgorithm.h:1836
Size precursor_min_charge_
Definition ProSEAlgorithm.h:1555
std::string decoy_prefix_
Definition ProSEAlgorithm.h:1592
static void markRescoredByPercolator_(std::vector< ProteinIdentification > &protein_ids, const Param &pp, const PercolatorTraining &training, const Percolator *perc=nullptr, const ReuseScoring_ *reuse=nullptr)
RunStatistics stats
Definition ProSEAlgorithm.h:245
PercolatorRescoring applyPsmFDR_(std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids, bool has_decoys, RunStatistics &stats, PeptideIdentificationList *pre_fdr_psms=nullptr, PeptideIdentificationList *inference_only_psms=nullptr) const
void setParameterNamePrefix(const std::string &prefix)
Definition ProSEAlgorithm.h:933
Size report_top_hits_
Definition ProSEAlgorithm.h:1634
Size modifications_max_variable_mods_per_peptide_
Definition ProSEAlgorithm.h:1587
static PercolatorRescoring rescoreWithPercolator(std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids, int threads, Size max_train_psms=0)
Rescore the PSMs of one search run in-process with Percolator, as the parameter 'rescore' does in eve...
static void renderModificationSummary(const OpenSearchModificationAnalysis::OpenSearchAnalysisResult &mod_analysis, std::ostream &os)
std::string warning
Definition ProSEAlgorithm.h:178
static std::vector< Size > transferSample_(const PeptideIdentificationList &ids, Size max_psms, Size hits_per_spectrum)
The spectra (positions in ids) of a seeded random sample of whole spectra with at most max_psms PSMs,...
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.
void setKeepPreFdrPsms(bool keep)
Definition ProSEAlgorithm.h:938
std::string model
Definition ProSEAlgorithm.h:181
Precursor precursor
the co-isolated precursor: that of the spectrum with its m/z and charge
Definition ProSEAlgorithm.h:1337
std::string recalibrate
calibration:recalibrate ("none", or empty, when the spectra are not corrected)
Definition ProSEAlgorithm.h:150
void searchCoIsolated_(const PeakMap &spectra, const std::vector< std::vector< AnnotatedHit_ > > &annotated_hits, FragmentIndex &fi, const std::vector< FASTAFile::FASTAEntry > &db, const SpectrumGenerators_ &generators, double fragment_tol, bool fragment_tol_ppm, bool open_search_mode, std::vector< CoIsolatedPSM_ > &psms, std::vector< std::vector< AnnotatedHit_ > > &hits, std::vector< CandidatePoolStats_ > &pool_stats) const
Search the precursors co-isolated with the selected one in what the spectrum's other PSMs leave of it...
std::string input_file
spectrum file this run searched (basename or path)
Definition ProSEAlgorithm.h:94
SearchContext prepareContext_(std::vector< FASTAFile::FASTAEntry > &&fasta_db, bool electron_ions, const std::function< const PeakMap *(Size)> &searched_spectra={}) const
PeptideIdentificationList pre_fdr_peptide_ids
Definition ProSEAlgorithm.h:248
PercolatorRescoring rescoreWithReuseModel_(std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids, Size file_index, const ReuseModel_ &model, bool check_shift, int threads, std::vector< std::vector< PeptideHit > > *dropped) const
std::map< Int, Size > charge_histogram
precursor charge -> PSM count
Definition ProSEAlgorithm.h:105
static void releaseInParallel(SearchResult &result)
SpectrumGenerators_ spectrumGenerators_() const
Generators for scoring, annotation and calibration, configured from the ions:* parameters.
StringList modifications_fixed_
Definition ProSEAlgorithm.h:1583
void setFileResultConsumer(FileResultConsumer consumer)
Lets the multi-file searchWithModificationAnalysis() overloads hand each file's result to consumer as...
Definition ProSEAlgorithm.h:964
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="", bool build_pooled_aggregate=true) const
Multi-file search with modification analysis (in-memory FASTA).
std::string parameter_name_prefix_
Definition ProSEAlgorithm.h:1797
Param percolator_extra_
rescore_method 'reset': Percolator's RESET parameters (empty: Percolator)
Definition ProSEAlgorithm.h:1604
static void stratumQValues(PeptideIdentificationList &peptide_ids)
rescoring:stratum_q_values: grouped target-decoy competition on the best hit of every spectrum that h...
static void splitMergedPsms(MergedResult &merged, MultiFileSearchResult &result)
Makes the PSMs of each file of a multi-file search its part of the pooled result (mergeFileResults())...
static void capturePreFdrStats_(const PeptideIdentificationList &peptide_ids, RunStatistics &stats)
void annotateIonPriors_(const PeakMap &spectra, const FragmentIonLikelihoodModel::PeakLists &evidence, std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids) const
Learn per-run fragment ion likelihoods from confident PSMs and annotate every hit with them.
PercolatorTraining percolator_training_
rescoring:...: options of Percolator's training
Definition ProSEAlgorithm.h:1603
void annotatePsmQValues(PeptideIdentificationList &peptide_ids) const
Annotate PSM q-values by target-decoy competition of the best hit of each spectrum,...
static bool hasPSMs_(const PeptideIdentificationList &ids)
Helper: whether a PSM of ids has a hit.
Size transferQuota_() const
std::vector< UInt32 > removed
the peaks of the spectrum that its residual spectrum leaves out (ascending)
Definition ProSEAlgorithm.h:1338
static int searchedFileOf_(const PeptideIdentification &id, const std::vector< SearchResult > &per_file)
std::vector< ProteinIdentification > protein_ids
Definition ProSEAlgorithm.h:241
bool restrictIndexToSpectra_() const
Definition ProSEAlgorithm.h:1313
bool chimericSearch_() const
Definition ProSEAlgorithm.h:1331
Size peptide_min_size_
Definition ProSEAlgorithm.h:1628
SpectraCounts_ countSpectra_(const PeakMap &spectra) const
Helper: the SpectraCounts_ of spectra.
std::vector< FASTAFile::FASTAEntry > buildDecoyAugmentedDB_(const std::vector< FASTAFile::FASTAEntry > &fasta_db, const DecoyStrategy_ &strategy) const
Build the searched database according to strategy.
static bool applyCompleteSetProteinFDR(std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids, const std::string &decoy_string, bool decoy_is_prefix, double protein_fdr, bool remove_decoys, const PeptideIdentificationList &inference_only_psms)
Finalize protein-level FDR on a COMPLETE protein set (a single input file, or a merged cross-file agg...
MergedResult mergeFileResults(MultiFileSearchResult &result, const StringList &in_spectra_files, bool remove_decoys=true) const
Pools result (moving its PSMs out), infers proteins across files, applies FDR:protein of this instanc...
SearchResult aggregate
Definition ProSEAlgorithm.h:301
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="", bool build_pooled_aggregate=true) const
Multi-file search with modification analysis (FASTA file path).
void annotatePeptDeepFeatures_(const PeakMap &spectra, std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids) const
Adds PeptDeep-prediction-derived rescoring features to the PSMs.
std::string reset_run_name_
spectra file of the run being rescored (names its RESET stem table)
Definition ProSEAlgorithm.h:1605
std::string database_file
FASTA path (empty for in-memory db)
Definition ProSEAlgorithm.h:139
static AASequence reversedNoiseSequence_(const AASequence &sequence)
Reversed sequence keeping the C-terminal residue and every residue's modification: the noise hypothes...
CalibrationResult_ runCalibrationPass_(PeakMap &spectra, FragmentIndex &fragment_index, const std::vector< FASTAFile::FASTAEntry > &db, const PeakMap *query_spectra=nullptr) const
Run a fast calibration pass on a subset of spectra to estimate mass accuracy.
std::vector< FASTAFile::FASTAEntry > buildDecoyAugmentedDB_(std::vector< FASTAFile::FASTAEntry > &&fasta_db, const DecoyStrategy_ &strategy) const
As above, but takes the entries of fasta_db over instead of copying them.
std::string strip_string
marker of pre-existing decoys to strip
Definition ProSEAlgorithm.h:1178
std::map< Size, Size > missed_cleavage_histogram
missed cleavages -> PSM count
Definition ProSEAlgorithm.h:106
static ProteinMapping_ buildProteinMapping_(const FragmentIndex &index, const std::vector< FASTAFile::FASTAEntry > &db, std::vector< UInt32 > candidates, const Param &indexer_parameters)
Collects the protein occurrences of the sequences of the index peptides candidates.
RunStatistics last_run_stats_
Definition ProSEAlgorithm.h:1790
std::string fragment_mass_tolerance_unit_
Definition ProSEAlgorithm.h:1560
static bool applyProteinMapping_(const ProteinMapping_ &mapping, const std::vector< FASTAFile::FASTAEntry > &db, const Param &indexer_parameters, std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids, std::string &fallback_reason)
Writes what PeptideIndexing::run(db, protein_ids, peptide_ids) with indexer_parameters writes: the ev...
StringList annotate_psm_
Definition ProSEAlgorithm.h:1616
static void removeUnreportedProteins(std::vector< ProteinIdentification > &protein_ids, const PeptideIdentificationList &peptide_ids, const PeptideIdentificationList &also_referencing=PeptideIdentificationList())
Removes the proteins that no PSM references, and them from the protein groups.
static void filterLocalPeaks_(MSSpectrum &spectrum, Size peaks_per_window)
Keep the strongest peaks in each non-overlapping 100 Da window, including a short final window.
void applyRescoredPsmFDR_(std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids, bool has_decoys, RunStatistics &stats, bool rescored, PeptideIdentificationList *inference_only_psms) const
Param fragmentIndexParameters_(bool electron_ions=false) const
ProSE parameters made safe to hand to a FragmentIndex.
static PeakMap loadSpectra(const std::string &filename, const std::function< bool(const MSSpectrum &)> &keep={})
The MS2 spectra of a spectrum file as the searches of this class read them.
OpenSearchModificationAnalysis::OpenSearchAnalysisResult modification_analysis
Definition ProSEAlgorithm.h:243
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:337
static std::string renderTotalTime(const SharedSearchStats &sh)
The total time of a run, by part: "total <s>s | search of the file(s) <s>s | outputs <s>s (of ...
static bool accessionHasDecoyMarker_(const std::string &accession, const std::string &marker, bool is_prefix)
void applyRecalibration_(const CalibrationResult_ &cal, PeakMap &spectra, PeakMap *query_spectra, PeakMap *evidence_spectra) const
calibration:recalibrate: subtract the error models of cal from the MS2 spectra, in place.
void finishDeferredRescoring_(MultiFileSearchResult &mfres, const std::vector< Size > &deferred) const
static void renderRunSummary(const RunStatistics &stats, const SharedSearchStats &shared, const OpenSearchModificationAnalysis::OpenSearchAnalysisResult &mod_analysis, bool is_open_search, std::ostream &os)
ExitCodes search(PeakMap &spectra, SearchContext &ctx, std::vector< ProteinIdentification > &prot_ids, PeptideIdentificationList &pep_ids) const
In-memory search using a pre-built SearchContext.
MultiFileSearchResult searchWithModificationAnalysis_(const std::vector< std::string > &in_spectra_files, const std::vector< FASTAFile::FASTAEntry > &fasta_db_given, const std::string *in_db, const std::vector< std::string > &output_base_names, const std::string &aggregate_base_name, bool build_pooled_aggregate) const
std::shared_ptr< void > released_hits_
Definition ProSEAlgorithm.h:1825
SharedSearchStats shared
Definition ProSEAlgorithm.h:314
bool isOpenSearchMode_() const
Helper function to determine if open search should be used based on tolerance.
Definition ProSEAlgorithm.h:2233
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.
void annotateFragmentPeaks_(const PeakMap &exp, PeptideIdentificationList &peptide_ids, double fragment_mass_tolerance, const std::string &fragment_mass_tolerance_unit_ppm, const MzRecalibration_ *fragment_recalibration=nullptr) const
The fragment annotations that postProcessHits_() leaves out with defer_peak_annotations,...
static double calibrationPassWindow_(double configured, bool ppm)
The window the calibration pass searches with, from the configured one (ppm or Da)
Size rescoreTopHits_() const
The hits per spectrum that Percolator rescores: rescoring:top_hits, or report:top_hits if that is 0.
Definition ProSEAlgorithm.h:1638
void postProcessHits_(const PeakMap &exp, std::vector< std::vector< ProSEAlgorithm::AnnotatedHit_ > > &annotated_hits, const std::vector< CandidatePoolStats_ > &pool_stats, 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 PeakMap *evidence_spectra=nullptr, const std::vector< Size > *evidence_parent=nullptr, bool defer_peak_annotations=false, const MzRecalibration_ *fragment_recalibration=nullptr) const
Filter and annotate search results.
PeptideIdentificationList inference_only_peptide_ids
Definition ProSEAlgorithm.h:254
void collectInferenceOnlyPsms_(const PeptideIdentificationList &peptide_ids, double psm_fdr, PeptideIdentificationList &inference_only_psms) const
std::string decoy_string
Definition ProSEAlgorithm.h:306
DecoyStrategy_ resolveDecoyStrategy_(const std::vector< FASTAFile::FASTAEntry > &db) const
Decide how to obtain/recognise decoys for db.
Size countElectronActivated_(const PeakMap &spectra) const
Number of spectra that ions:by_activation also scores with c and z+1 ions (0 if it is off)
DeisotopingSettings_ deisotoping_
MS2 deisotoping rule (fragment:deisotope_*)
Definition ProSEAlgorithm.h:1580
std::vector< FASTAFile::FASTAEntry > buildCalibrationSample_(const std::vector< FASTAFile::FASTAEntry > &full_db) const
Build a strided protein sample for chunked calibration.
static std::vector< double > localPeakDensities_(const MSSpectrum &spectrum)
Peak counts per Da in a fixed +/-50 m/z window around each peak of a sorted spectrum.
void scoreSpectraAgainstIndex_(const PeakMap &spectra, FragmentIndex &fi, const std::vector< FASTAFile::FASTAEntry > &db, const SpectrumGenerators_ &generators, double effective_fragment_tol, bool fragment_mass_tolerance_unit_ppm, bool open_search_mode, std::vector< std::vector< AnnotatedHit_ > > &annotated_hits, std::vector< CandidatePoolStats_ > &pool_stats, const std::string &progress_label, const PeakMap *query_spectra=nullptr) const
Score all spectra against one FragmentIndex.
static void returnPooledPsms_(PeptideIdentificationList &pooled, std::vector< SearchResult > &per_file)
static bool isElectronActivated_(const MSSpectrum &spectrum)
True if the precursor of spectrum was activated by electrons (ETD, ECD, EThcD or ETciD)
bool keepPreRescoringPsms_() const
Whether a search keeps the PSMs of each file before the rescoring (SearchResult::pre_fdr_peptide_ids)
Definition ProSEAlgorithm.h:1804
std::string paramName_(const std::string &name) const
Helper: name as the user sets the parameter (setParameterNamePrefix()), for messages.
Definition ProSEAlgorithm.h:1799
std::string decoy_mode
"generated" | "external" | "none (target-only)"
Definition ProSEAlgorithm.h:153
std::function< void(Size, const SearchResult &)> FileResultConsumer
The consumer of the files' results (setFileResultConsumer()): file index, result. Must only read the ...
Definition ProSEAlgorithm.h:945
Size file_index
Definition ProSEAlgorithm.h:1834
PeptideIdentificationList peptide_ids
Definition ProSEAlgorithm.h:242
std::string enzyme
Definition ProSEAlgorithm.h:140
static LocalFragmentEvidence_ localFragmentEvidence_(const MSSpectrum &spectrum, const MSSpectrum &theoretical, int max_charge, const std::vector< double > &densities, double tolerance, bool ppm, std::vector< double > &alternatives)
static bool reuseCalibrationDraw(UInt64 seed, Size file, Size spectrum, double fraction)
static std::string pinEnzymeName(const std::string &enzyme)
The name of enzyme as PercolatorInfile computes the enzN/enzC/enzInt features of a ....
std::string skipped_reason
Why the PSMs were not rescored, as a sentence to show to the user (empty if applied or not attempted)
Definition ProSEAlgorithm.h:175
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
static void tdcQValues_(PeptideIdentificationList &peptide_ids, bool plus_one=false)
ExitCodes
Exit codes.
Definition ProSEAlgorithm.h:75
std::shared_ptr< const ReuseModel_ > reuse_model_
rescore_reuse: the models of a multi-file search ('static': trained on its first files; null otherwis...
Definition ProSEAlgorithm.h:1882
void rescoreFilesTogether_(MultiFileSearchResult &mfres, const std::vector< std::string > &in_spectra_files) const
The end of a multi-file search with 'rescore' (with pool_rescoring_), for the files with PSMs that Pe...
StringList modifications_variable_
Definition ProSEAlgorithm.h:1585
static double maxRetainedScore_(const PeptideIdentificationList &peptide_ids)
PeptideIdentificationList pre_fdr_peptide_ids_
Definition ProSEAlgorithm.h:1821
std::vector< SearchResult > per_file
Definition ProSEAlgorithm.h:300
double fragment_mass_tolerance_
Definition ProSEAlgorithm.h:1558
std::shared_ptr< const ReuseModel_ > trainReuseModel_(const std::vector< ReuseRun_ > &runs, int threads) const
PeptideIdentificationList inference_only_peptide_ids_
Definition ProSEAlgorithm.h:1889
SearchContext prepareContext(const std::vector< FASTAFile::FASTAEntry > &fasta_db) const
Build a SearchContext (decoy-augmented database + FragmentIndex) for reuse.
static std::vector< SignedSize > scoringOrder_(const PeakMap &spectra, const PeakMap *query_spectra)
The order in which scoreSpectraAgainstIndex_() scores the spectra: the scan indices sorted by the neu...
static Size removeDuplicateProteins(std::vector< FASTAFile::FASTAEntry > &db, const std::string &source)
Removes the repeated entries of a protein database, which searching would report twice (e....
int scoringMaxCharge_(int precursor_charge) const
Fragment charges that score a candidate of the given precursor charge; also used by the calibration p...
Definition ProSEAlgorithm.h:1573
static void removeProteinsReferencedByNeither_(std::vector< ProteinIdentification > &protein_ids, const PeptideIdentificationList &peptide_ids, const PeptideIdentificationList &also_referencing)
SearchContext prepareContext(const std::vector< FASTAFile::FASTAEntry > &fasta_db, bool electron_ions) const
Build a SearchContext whose FragmentIndex also holds c and z+1 ions.
void reportDecoyParity_(const SearchContext &ctx) const
static PercolatorRescoring rescoreWithPercolator_(std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids, int threads, std::vector< std::vector< PeptideHit > > *dropped, const PercolatorTraining &training, const Param &extra, const ReuseScoring_ *reuse=nullptr)
Size peptide_missed_cleavages_
Definition ProSEAlgorithm.h:1630
CalibrationResult_ last_calibration_result_
Definition ProSEAlgorithm.h:1783
double computeModMatchTolerance_() const
Definition ProSEAlgorithm.h:1910
static LocalFragmentEvidence_ localFragmentEvidence_(const MSSpectrum &spectrum, const MSSpectrum &theoretical, const std::vector< Int > &charges, int max_charge, const std::vector< double > &densities, double tolerance, bool ppm, std::vector< double > &alternatives)
localFragmentEvidence_() with the charges of the peaks of theoretical given (charges,...
static void poolSearchedFiles_(std::vector< SearchResult > &per_file, bool move_psms, const StringList &in_spectra_files, std::vector< ProteinIdentification > &protein_ids, PeptideIdentificationList &peptide_ids)
FileResultConsumer file_result_consumer_
see setFileResultConsumer()
Definition ProSEAlgorithm.h:1796
void collectRunStatistics_(const PeakMap &spectra, const std::vector< ProteinIdentification > &protein_ids, const PeptideIdentificationList &peptide_ids, RunStatistics &stats) const
std::vector< std::string > fixed_mods
Definition ProSEAlgorithm.h:147
void buildFragmentIndex_(SearchContext &ctx, const Param &params, const std::function< const PeakMap *(Size)> &searched_spectra) const
static bool useSearchEngineScore_(PeptideIdentificationList &ids)
static bool reuseTrainingDraw(UInt64 seed, Size file, Size spectrum, double fraction)
rescore_reuse: whether spectrum spectrum (its index in the run) of file file is drawn for the trainin...
void recordRecalibration_(const CalibrationResult_ &cal, std::vector< ProteinIdentification > &protein_ids) const
std::string peptdeep_ms2_model_
Definition ProSEAlgorithm.h:1541
static void keepTopHits_(PeptideIdentificationList &peptide_ids, Size n)
static bool searched_(const SearchResult &pf)
Helper: whether the file of pf was searched (exit code EXECUTION_OK, with a run)
std::string precursor_tol_unit
Definition ProSEAlgorithm.h:142
DecoyMode_
How decoys are obtained/recognised for a search (parameter "decoys").
Definition ProSEAlgorithm.h:1158
std::string peptdeep_rt_model_
Definition ProSEAlgorithm.h:1542
static double measuredCoverage_(const std::vector< double > &errors, bool fragment)
void preprocessSearchedSpectra_(PeakMap &spectra, const std::string &input, FragmentIonLikelihoodModel::PeakLists &ion_evidence, PeakMap *evidence_spectra, PeakMap *query_spectra) const
The PSM of a precursor co-isolated with the selected one (chimeric:enabled), until its residual spect...
Definition ProSEAlgorithm.h:1335
Resolved decoy handling for one concrete input database.
Definition ProSEAlgorithm.h:1172
MS2 deisotoping rule of preprocessSpectra_().
Definition ProSEAlgorithm.h:1077
Local fragment evidence of one candidate (annotate:local_fragment_evidence).
Definition ProSEAlgorithm.h:1219
The pooled evaluation of a multi-file search (the ProSE tool's -out_merged).
Definition ProSEAlgorithm.h:319
Multi-file search result bundle.
Definition ProSEAlgorithm.h:299
Outcome of the Percolator rescoring of one search run (see rescoreWithPercolator() and the parameter ...
Definition ProSEAlgorithm.h:171
Options of Percolator's training for the rescoring (the parameters 'rescoring:...'; the defaults are ...
Definition ProSEAlgorithm.h:189
rescore_reuse: a run that trains models: its index in the search (the random halves depend on it) and...
Definition ProSEAlgorithm.h:1833
Per-run identification statistics for the end-of-search report.
Definition ProSEAlgorithm.h:93
Prepared per-database state shared across multiple spectrum files.
Definition ProSEAlgorithm.h:336
Comprehensive search result including modification analysis.
Definition ProSEAlgorithm.h:239
Configuration, database and fragment-index facts shared across all input files of one ProSE invocatio...
Definition ProSEAlgorithm.h:138
Definition ProSEAlgorithm.h:2159
Base class for all classes that want to report their progress.
Definition ProgressLogger.h:28
int Int
Signed integer type.
Definition Types.h:72
uint32_t UInt32
Unsigned integer type (32bit)
Definition Types.h:33
uint64_t UInt64
Unsigned integer type (64bit)
Definition Types.h:47
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
std::vector< std::string > StringList
Vector of String.
Definition TypeAliases.h:39
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:974
static bool hasBetterScore(const AnnotatedHit_ &a, const AnnotatedHit_ &b)
Definition ProSEAlgorithm.h:992
double score
main score
Definition ProSEAlgorithm.h:981
AASequence sequence
Definition ProSEAlgorithm.h:975
Result of a calibration pass.
Definition ProSEAlgorithm.h:1746
bool recalibrated() const
Definition ProSEAlgorithm.h:1755
MzRecalibration_ precursor_recalibration
the models subtracted from the spectra (calibration:recalibrate; inactive otherwise)
Definition ProSEAlgorithm.h:1753
const MzRecalibration_ * appliedFragmentRecalibration() const
the fragment model applyRecalibration_() subtracts from the peaks (nullptr: the peaks are not correct...
Definition ProSEAlgorithm.h:1757
MzRecalibration_ fragment_recalibration
Definition ProSEAlgorithm.h:1754
Running summary of the complete candidate pool of one spectrum.
Definition ProSEAlgorithm.h:1019
std::unordered_set< std::string > seen_candidates
Definition ProSEAlgorithm.h:1027
void add(double score)
Fold one freshly scored candidate into the summary.
Definition ProSEAlgorithm.h:1032
double deltaScore() const
Best minus runner-up over the full pool.
Definition ProSEAlgorithm.h:1042
double zScore() const
How much of an outlier the best score is within its own candidate pool.
Definition ProSEAlgorithm.h:1706
double correct(double mz) const
Definition ProSEAlgorithm.h:1718
double error(double mz) const
Definition ProSEAlgorithm.h:1711
An m/z error model of a run (calibration:recalibrate), fitted to the calibration PSMs and subtracted ...
Definition ProSEAlgorithm.h:1693
std::vector< Chunk > chunks
in RT order; empty: no correction
Definition ProSEAlgorithm.h:1695
double correct(double mz, double rt) const
mz without the modelled error
std::string toString() const
"ppm; rt <s>: <intercept> + <slope> mz (<points>) | ..." (empty: inactive)
double uncorrect(double corrected, double rt) const
the inverse of correct(): the m/z it maps to corrected
static MzRecalibration_ fit(const std::vector< double > &errors, const std::vector< double > &mzs, const std::vector< double > &rts, Size n_chunks, Size min_points, bool linear, bool ppm)
AtRT at(double rt) const
the model at rt (the chunks must not change while the result is used)
double intercept
Definition ProSEAlgorithm.h:1694
bool active() const
Definition ProSEAlgorithm.h:1697
double error(double mz, double rt) const
the modelled error at (mz, rt)
Definition ProSEAlgorithm.h:1694
The protein occurrences of the sequences of a search's hits (peptide:protein_mapping = index).
Definition ProSEAlgorithm.h:1970
std::vector< std::string_view > sequences
The unmodified hit sequences (views into the database), one entry each.
Definition ProSEAlgorithm.h:1974
std::string fallback_reason
Why PeptideIndexing has to run instead; empty if the mapping applies.
Definition ProSEAlgorithm.h:1980
Size find(std::string_view sequence) const
The entry of sequence, or sequences.size() if there is none.
Definition ProSEAlgorithm.h:1983
std::vector< std::vector< std::pair< UInt32, UInt32 > > > occurrences
Per entry: its occurrences {protein index, position}, ascending (PeptideIndexing's evidence order)
Definition ProSEAlgorithm.h:1976
std::vector< std::unordered_map< std::string_view, Size > > entries
Sequence -> entry, in SHARDS hash tables.
Definition ProSEAlgorithm.h:1978