43 #include <boost/unordered_map.hpp> 46 #include <unordered_set> 54 :
public std::vector<std::pair<double, bool>>
56 typedef std::vector<std::pair<double, bool>>
Base;
71 static bool const value =
72 std::is_same<T, PeptideIdentification>::value || std::is_same<T, ProteinIdentification>::value;
78 static bool const value = std::is_same<T, PeptideHit>::value || std::is_same<T, ProteinHit>::value;
96 static void getScores_(
98 const std::vector<ProteinIdentification::ProteinGroup> &grps,
99 const std::unordered_set<std::string> &decoy_accs);
106 scores_labels.reserve(scores_labels.size() +
id.getHits().size());
107 std::transform(
id.getHits().begin(),
id.getHits().end(),
108 std::back_inserter(scores_labels),
111 checkTDAnnotation_(hit);
112 return std::make_pair<double, bool>(hit.
getScore(), getTDLabel_(hit));
122 if (
id.getIdentifier() == identifier)
124 getScores_(scores_labels,
id, all_hits, charge);
133 if (
id.getIdentifier() == identifier)
135 getScores_(scores_labels,
id, all_hits);
143 if (
id.getIdentifier() == identifier)
145 getScores_(scores_labels,
id, charge);
149 template<typename IDType, typename std::enable_if<IsIDType<IDType>::value>::type * =
nullptr>
152 const IDType &
id,
const String &identifier)
154 if (
id.getIdentifier() == identifier)
156 getScores_(scores_labels,
id);
160 template<
class ...Args>
171 getScores_(scores_labels, hit, std::forward<Args>(args)...);
179 getScores_(scores_labels, hit, std::forward<Args>(args)...);
190 checkTDAnnotation_(hit);
191 scores_labels.emplace_back(hit.
getScore(), getTDLabel_(hit));
202 getScores_(scores_labels, hit, charge);
206 template<typename HitType, typename std::enable_if<IsHitType<HitType>::value>::type * =
nullptr>
211 checkTDAnnotation_(hit);
212 scores_labels.emplace_back(hit.getScore(), getTDLabel_(hit));
215 template<typename IDType, typename std::enable_if<IsIDType<IDType>::value>::type * =
nullptr>
220 for (
const typename IDType::HitType &hit :
id.getHits())
222 getScores_(scores_labels, hit);
226 template<
class ...Args>
229 const std::vector<PeptideIdentification> &ids,
232 for (
const auto &
id : ids)
234 getScores_(scores_labels,
id, std::forward<Args>(args)...);
247 const ConsensusMap &cmap,
bool include_unassigned_peptides)
249 std::function<void(const PeptideIdentification &)> f =
251 { getScores_(scores_labels,
id); };
256 const ConsensusMap &cmap,
bool include_unassigned_peptides,
int charge)
258 std::function<void(const PeptideIdentification &)> f =
260 { getScores_(scores_labels,
id, charge); };
267 std::function<void(const PeptideIdentification &)> f =
269 { getScores_(scores_labels,
id, identifier); };
274 const ConsensusMap &cmap,
bool include_unassigned_peptides,
int charge,
const String &identifier)
276 std::function<void(const PeptideIdentification &)> f =
278 { getScores_(scores_labels,
id, charge, identifier); };
283 const ConsensusMap &cmap,
bool include_unassigned_peptides,
bool all_hits)
285 std::function<void(const PeptideIdentification &)> f =
287 { getScores_(scores_labels,
id, all_hits); };
292 const ConsensusMap &cmap,
bool include_unassigned_peptides,
bool all_hits,
int charge)
294 std::function<void(const PeptideIdentification &)> f =
296 { getScores_(scores_labels,
id, all_hits, charge); };
301 const ConsensusMap &cmap,
bool include_unassigned_peptides,
bool all_hits,
const String &identifier)
303 std::function<void(const PeptideIdentification &)> f =
305 { getScores_(scores_labels,
id, all_hits, identifier); };
310 const ConsensusMap &cmap,
bool include_unassigned_peptides,
bool all_hits,
int charge,
const String &identifier)
312 std::function<void(const PeptideIdentification &)> f =
314 { getScores_(scores_labels,
id, all_hits, charge, identifier); };
325 return std::string(idOrHit.
getMetaValue(
"target_decoy"))[0] ==
't';
339 template<
typename IDType,
class ...Args>
340 static void setScores_(
const std::map<double, double> &scores_to_FDR,
341 std::vector<IDType> &ids,
342 const std::string &score_type,
348 setScores_(scores_to_FDR,
id, score_type, higher_better, &args...);
352 template<
typename IDType>
356 String old_score_type =
id.getScoreType() +
"_score";
357 id.setScoreType(score_type);
358 id.setHigherScoreBetter(higher_better);
359 return old_score_type;
362 template<
typename IDType>
363 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
364 bool higher_better,
bool keep_decoy)
366 String old_score_type = setScoreType_(
id, score_type, higher_better);
370 setScores_(scores_to_FDR,
id, old_score_type);
374 setScoresAndRemoveDecoys_(scores_to_FDR,
id, old_score_type);
378 template<
typename IDType>
379 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
380 const String &old_score_type)
382 std::vector<typename IDType::HitType> &hits =
id.getHits();
383 for (
auto &hit : hits)
385 setScore_(scores_to_FDR, hit, old_score_type);
389 template<
typename IDType,
class ...Args>
391 const String &old_score_type, Args ... args)
393 std::vector<typename IDType::HitType> &hits =
id.getHits();
394 std::vector<typename IDType::HitType> new_hits;
395 new_hits.reserve(hits.size());
396 for (
auto &hit : hits)
398 setScoreAndMoveIfTarget_(scores_to_FDR, hit, old_score_type, new_hits, args...);
403 template<
typename HitType>
404 static void setScore_(
const std::map<double, double> &scores_to_FDR, HitType &hit,
const std::string &old_score_type)
406 hit.setMetaValue(old_score_type, hit.getScore());
407 hit.setScore(scores_to_FDR.lower_bound(hit.getScore())->second);
410 template<
typename IDType>
411 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
414 String old_score_type = setScoreType_(
id, score_type, higher_better);
415 setScores_(scores_to_FDR,
id, old_score_type);
418 static void setScores_(
const std::map<double, double> &scores_to_FDR,
420 const std::string &score_type,
425 String old_score_type = setScoreType_(
id, score_type, higher_better);
428 setScores_(scores_to_FDR,
id, old_score_type, charge);
432 setScoresAndRemoveDecoys_<PeptideIdentification>(scores_to_FDR, id, old_score_type, charge);
436 static void setScores_(
const std::map<double, double> &scores_to_FDR,
438 const std::string &score_type,
444 if (
id.getIdentifier() == identifier)
446 setScores_(scores_to_FDR,
id, score_type, higher_better, keep_decoy, charge);
450 template<
typename IDType>
451 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
452 bool higher_better,
bool keep_decoy,
const String &identifier)
454 if (
id.getIdentifier() == identifier)
456 setScores_(scores_to_FDR,
id, score_type, higher_better, keep_decoy);
460 static void setScores_(
const std::map<double, double> &scores_to_FDR,
462 const std::string &score_type,
467 if (
id.getIdentifier() == identifier)
469 setScores_(scores_to_FDR,
id, score_type, higher_better, charge);
473 template<
typename IDType>
474 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
475 bool higher_better,
const String &identifier)
477 if (
id.getIdentifier() == identifier)
479 setScores_(scores_to_FDR,
id, score_type, higher_better);
484 static void setScores_(
485 const std::map<double, double> &scores_to_FDR,
486 std::vector<ProteinIdentification::ProteinGroup> &grps,
487 const std::string &score_type,
500 template<
typename HitType>
503 const std::string &old_score_type,
504 std::vector<HitType> &new_hits)
506 const String &target_decoy(hit.getMetaValue(
"target_decoy"));
507 if (target_decoy[0] ==
't')
509 hit.setMetaValue(old_score_type, hit.getScore());
510 hit.setScore(scores_to_FDR.lower_bound(hit.getScore())->second);
511 new_hits.push_back(std::move(hit));
525 const std::string &old_score_type,
526 std::vector<PeptideHit> &new_hits,
532 if (target_decoy[0] ==
't')
536 new_hits.push_back(std::move(hit));
541 new_hits.push_back(std::move(hit));
559 bool include_unassigned_peptides,
560 const std::string &score_type,
565 std::function<void(PeptideIdentification &)> f =
567 { setScores_(scores_to_FDR,
id, score_type,
568 higher_better, keep_decoy); };
573 bool include_unassigned_peptides,
574 const std::string &score_type,
580 std::function<void(PeptideIdentification &)> f =
582 { setScores_(scores_to_FDR,
id, score_type,
583 higher_better, keep_decoy, charge); };
588 bool include_unassigned_peptides,
589 const std::string &score_type,
592 const String& run_identifier)
595 std::function<void(PeptideIdentification &)> f =
597 { setScores_(scores_to_FDR,
id, score_type,
598 higher_better, keep_decoy, run_identifier); };
603 bool include_unassigned_peptides,
604 const std::string &score_type,
608 const String& run_identifier)
611 std::function<void(PeptideIdentification &)> f =
613 { setScores_(scores_to_FDR,
id, score_type,
614 higher_better, keep_decoy, charge, run_identifier); };
629 OPENMS_PRETTY_FUNCTION,
630 "Meta value 'target_decoy' does not exist in all ProteinHits! Reindex the idXML file with 'PeptideIndexer'");
static void setPeptideScoresForMap_(const std::map< double, double > &scores_to_FDR, ConsensusMap &cmap, bool include_unassigned_peptides, const std::string &score_type, bool higher_better, bool keep_decoy, int charge, const String &run_identifier)
Definition: IDScoreGetterSetter.h:601
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentification &id, bool all_hits, const String &identifier)
Definition: IDScoreGetterSetter.h:129
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideHit &hit, int charge)
Definition: IDScoreGetterSetter.h:183
void setMetaValue(const String &name, const DataValue &value)
Sets the DataValue corresponding to a name.
void setScore(double score)
sets the PSM score
Int getCharge() const
returns the charge of the peptide
Definition: IDScoreGetterSetter.h:53
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const IDType &id)
Definition: IDScoreGetterSetter.h:216
static void getPeptideScoresFromMap_(ScoreToTgtDecLabelPairs &scores_labels, const ConsensusMap &cmap, bool include_unassigned_peptides, bool all_hits, int charge, const String &identifier)
Definition: IDScoreGetterSetter.h:308
static bool getTDLabel_(const MetaInfoInterface &idOrHit)
For peptide hits, a hit is considered target also if it maps to both a target and a decoy protein (i...
Definition: IDScoreGetterSetter.h:323
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentification &id, int charge)
Definition: IDScoreGetterSetter.h:195
static void setPeptideScoresForMap_(const std::map< double, double > &scores_to_FDR, ConsensusMap &cmap, bool include_unassigned_peptides, const std::string &score_type, bool higher_better, bool keep_decoy, const String &run_identifier)
Definition: IDScoreGetterSetter.h:586
static void checkTDAnnotation_(const MetaInfoInterface &id_or_hit)
To check the metavalues before we do anything.
Definition: IDScoreGetterSetter.h:623
static void getPeptideScoresFromMap_(ScoreToTgtDecLabelPairs &scores_labels, const ConsensusMap &cmap, bool include_unassigned_peptides, bool all_hits, int charge)
Definition: IDScoreGetterSetter.h:290
static void setScore_(const std::map< double, double > &scores_to_FDR, HitType &hit, const std::string &old_score_type)
Definition: IDScoreGetterSetter.h:404
static void setScores_(const std::map< double, double > &scores_to_FDR, IDType &id, const std::string &score_type, bool higher_better, const String &identifier)
Definition: IDScoreGetterSetter.h:474
static void setScores_(const std::map< double, double > &scores_to_FDR, std::vector< IDType > &ids, const std::string &score_type, bool higher_better, Args &... args)
Definition: IDScoreGetterSetter.h:340
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentification &id, bool all_hits, Args &&... args)
Definition: IDScoreGetterSetter.h:161
bool metaValueExists(const String &name) const
Returns whether an entry with the given name exists.
static void getPeptideScoresFromMap_(ScoreToTgtDecLabelPairs &scores_labels, const ConsensusMap &cmap, bool include_unassigned_peptides, bool all_hits, const String &identifier)
Definition: IDScoreGetterSetter.h:299
double getScore() const
returns the PSM score
A class for extracting and reinserting IDScores from Peptide/ProteinIdentifications and from Consensu...
Definition: IDScoreGetterSetter.h:63
static void setPeptideScoresForMap_(const std::map< double, double > &scores_to_FDR, ConsensusMap &cmap, bool include_unassigned_peptides, const std::string &score_type, bool higher_better, bool keep_decoy)
Helper for applying set Scores on ConsensusMaps.
Definition: IDScoreGetterSetter.h:557
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentification &id, int charge, const String &identifier)
Definition: IDScoreGetterSetter.h:139
double getScore() const
returns the score of the protein hit
static String setScoreType_(IDType &id, const std::string &score_type, bool higher_better)
Definition: IDScoreGetterSetter.h:353
static void setScores_(const std::map< double, double > &scores_to_FDR, PeptideIdentification &id, const std::string &score_type, bool higher_better, bool keep_decoy, int charge)
Definition: IDScoreGetterSetter.h:418
Representation of a protein hit.
Definition: ProteinHit.h:57
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:62
static void getPeptideScoresFromMap_(ScoreToTgtDecLabelPairs &scores_labels, const ConsensusMap &cmap, bool include_unassigned_peptides, const String &identifier)
Definition: IDScoreGetterSetter.h:263
void applyFunctionOnPeptideIDs(std::function< void(PeptideIdentification &)> &f, bool include_unassigned=true)
applies a function on all PeptideIDs or only assigned ones
Representation of a protein identification run.
Definition: ProteinIdentification.h:71
static void setScores_(const std::map< double, double > &scores_to_FDR, IDType &id, const std::string &score_type, bool higher_better, bool keep_decoy)
Definition: IDScoreGetterSetter.h:363
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const IDType &id, const String &identifier)
Definition: IDScoreGetterSetter.h:150
Definition: IDScoreGetterSetter.h:76
const DataValue & getMetaValue(const String &name, const DataValue &default_value=DataValue::EMPTY) const
Returns the value corresponding to a string, or a default value (default: DataValue::EMPTY) if not fo...
static void setPeptideScoresForMap_(const std::map< double, double > &scores_to_FDR, ConsensusMap &cmap, bool include_unassigned_peptides, const std::string &score_type, bool higher_better, bool keep_decoy, int charge)
Definition: IDScoreGetterSetter.h:571
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:60
static void getPeptideScoresFromMap_(ScoreToTgtDecLabelPairs &scores_labels, const ConsensusMap &cmap, bool include_unassigned_peptides)
Helper for getting scores in ConsensusMaps.
Definition: IDScoreGetterSetter.h:245
Definition: IDScoreGetterSetter.h:69
Representation of a peptide hit.
Definition: PeptideHit.h:54
Not all required information provided.
Definition: Exception.h:195
static void getPeptideScoresFromMap_(ScoreToTgtDecLabelPairs &scores_labels, const ConsensusMap &cmap, bool include_unassigned_peptides, int charge, const String &identifier)
Definition: IDScoreGetterSetter.h:272
static void setScores_(const std::map< double, double > &scores_to_FDR, PeptideIdentification &id, const std::string &score_type, bool higher_better, bool keep_decoy, int charge, const String &identifier)
Definition: IDScoreGetterSetter.h:436
A more convenient string class.
Definition: String.h:58
A container for consensus elements.
Definition: ConsensusMap.h:79
static void setScores_(const std::map< double, double > &scores_to_FDR, IDType &id, const std::string &score_type, bool higher_better, bool keep_decoy, const String &identifier)
Definition: IDScoreGetterSetter.h:451
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const std::vector< PeptideIdentification > &ids, Args &&... args)
Definition: IDScoreGetterSetter.h:227
static void setScores_(const std::map< double, double > &scores_to_FDR, IDType &id, const std::string &score_type, bool higher_better)
Definition: IDScoreGetterSetter.h:411
static void setScoreAndMoveIfTarget_(const std::map< double, double > &scores_to_FDR, HitType &hit, const std::string &old_score_type, std::vector< HitType > &new_hits)
Used when keep_decoy_peptides or proteins is false.
Definition: IDScoreGetterSetter.h:501
std::vector< std::pair< double, bool > > Base
Definition: IDScoreGetterSetter.h:56
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const HitType &hit)
Definition: IDScoreGetterSetter.h:207
static void setScores_(const std::map< double, double > &scores_to_FDR, PeptideIdentification &id, const std::string &score_type, bool higher_better, int charge, const String &identifier)
Definition: IDScoreGetterSetter.h:460
static void setScoreAndMoveIfTarget_(const std::map< double, double > &scores_to_FDR, PeptideHit &hit, const std::string &old_score_type, std::vector< PeptideHit > &new_hits, int charge)
Used when keep_decoy_peptides is false and charge states are considered.
Definition: IDScoreGetterSetter.h:523
static void setScores_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type)
Definition: IDScoreGetterSetter.h:379
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentification &id, bool all_hits, int charge, const String &identifier)
Definition: IDScoreGetterSetter.h:118
static void getPeptideScoresFromMap_(ScoreToTgtDecLabelPairs &scores_labels, const ConsensusMap &cmap, bool include_unassigned_peptides, int charge)
Definition: IDScoreGetterSetter.h:254
static void setScoresAndRemoveDecoys_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type, Args ... args)
Definition: IDScoreGetterSetter.h:390
static void getPeptideScoresFromMap_(ScoreToTgtDecLabelPairs &scores_labels, const ConsensusMap &cmap, bool include_unassigned_peptides, bool all_hits)
Definition: IDScoreGetterSetter.h:281
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const ProteinIdentification &id)
Definition: IDScoreGetterSetter.h:101