44 #include <unordered_set>
45 #include <unordered_map>
56 :
public std::vector<ScoreToTgtDecLabelPair>
58 typedef std::vector<ScoreToTgtDecLabelPair>
Base;
74 std::is_same<T, PeptideIdentification>::value || std::is_same<T, ProteinIdentification>::value;
80 static bool const value = std::is_same<T, PeptideHit>::value || std::is_same<T, ProteinHit>::value;
93 std::unordered_map<String, ScoreToTgtDecLabelPair>& picked_scores,
95 const String& decoy_string,
107 const std::unordered_map<String, ScoreToTgtDecLabelPair>& picked_scores,
109 const std::vector<ProteinIdentification::ProteinGroup>& grps,
110 const String& decoy_string,
130 const std::vector<ProteinIdentification::ProteinGroup> &grps,
131 const std::unordered_set<std::string> &decoy_accs);
138 scores_labels.reserve(scores_labels.size() +
id.getHits().size());
139 std::transform(
id.getHits().begin(),
id.getHits().end(),
140 std::back_inserter(scores_labels),
154 if (
id.getIdentifier() == identifier)
156 getScores_(scores_labels,
id, all_hits, charge);
165 if (
id.getIdentifier() == identifier)
175 if (
id.getIdentifier() == identifier)
181 template<typename IDType, typename std::enable_if<IsIDType<IDType>::value>::type * =
nullptr>
184 const IDType &
id,
const String &identifier)
186 if (
id.getIdentifier() == identifier)
192 template<
class ...Args>
203 getScores_(scores_labels, hit, std::forward<Args>(args)...);
211 getScores_(scores_labels, hit, std::forward<Args>(args)...);
238 template<typename HitType, typename std::enable_if<IsHitType<HitType>::value>::type * =
nullptr>
244 scores_labels.emplace_back(hit.getScore(),
getTDLabel_(hit));
247 template<typename IDType, typename std::enable_if<IsIDType<IDType>::value>::type * =
nullptr>
252 for (
const typename IDType::HitType &hit :
id.getHits())
258 template<
class ...Args>
261 const std::vector<PeptideIdentification> &ids,
264 for (
const auto &
id : ids)
266 getScores_(scores_labels,
id, std::forward<Args>(args)...);
277 template<
class ...Args>
280 const ConsensusMap &cmap,
bool include_unassigned_peptides, Args &&... args)
284 {
getScores_(scores_labels,
id, std::forward<Args>(args)...); };
295 return std::string(idOrHit.
getMetaValue(
"target_decoy"))[0] ==
't';
309 template<
typename IDType,
class ...Args>
310 static void setScores_(
const std::map<double, double> &scores_to_FDR,
311 std::vector<IDType> &ids,
312 const std::string &score_type,
318 setScores_(scores_to_FDR,
id, score_type, higher_better, std::forward<Args>(args)...);
322 template<
typename IDType>
326 String old_score_type =
id.getScoreType() +
"_score";
327 id.setScoreType(score_type);
328 id.setHigherScoreBetter(higher_better);
329 return old_score_type;
332 template<
typename IDType>
333 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
334 bool higher_better,
bool keep_decoy)
336 bool old_higher_better =
id.isHigherScoreBetter();
341 if (old_higher_better)
343 setScores_(scores_to_FDR,
id, old_score_type);
352 if (old_higher_better)
363 template<
typename IDType>
364 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
365 const String &old_score_type)
367 std::vector<typename IDType::HitType> &hits =
id.getHits();
368 for (
auto &hit : hits)
370 setScore_(scores_to_FDR, hit, old_score_type);
374 template<
typename IDType>
376 const String &old_score_type)
378 std::vector<typename IDType::HitType> &hits =
id.getHits();
379 for (
auto &hit : hits)
385 template<
typename IDType,
class ...Args>
387 const String &old_score_type, Args&& ... args)
389 std::vector<typename IDType::HitType> &hits =
id.getHits();
390 std::vector<typename IDType::HitType> new_hits;
391 new_hits.reserve(hits.size());
392 for (
auto &hit : hits)
399 template<
typename IDType,
class ...Args>
401 const String &old_score_type, Args&& ... args)
403 std::vector<typename IDType::HitType> &hits =
id.getHits();
404 std::vector<typename IDType::HitType> new_hits;
405 new_hits.reserve(hits.size());
406 for (
auto &hit : hits)
413 template<
typename HitType>
414 static void setScore_(
const std::map<double, double> &scores_to_FDR, HitType &hit,
const std::string &old_score_type)
416 hit.setMetaValue(old_score_type, hit.getScore());
417 hit.setScore(scores_to_FDR.lower_bound(hit.getScore())->second);
420 template<
typename HitType>
421 static void setScoreHigherWorse_(
const std::map<double, double> &scores_to_FDR, HitType &hit,
const std::string &old_score_type)
423 hit.setMetaValue(old_score_type, hit.getScore());
424 auto ub = scores_to_FDR.upper_bound(hit.getScore());
425 if (ub != scores_to_FDR.begin()) ub--;
426 hit.setScore(ub->second);
438 static void setScores_(
const std::map<double, double> &scores_to_FDR,
440 const std::string &score_type,
448 setScores_(scores_to_FDR,
id, old_score_type, higher_better, charge);
452 setScoresAndRemoveDecoys_<PeptideIdentification>(scores_to_FDR,
id, old_score_type, charge);
456 static void setScores_(
const std::map<double, double> &scores_to_FDR,
458 const std::string &score_type,
464 if (
id.getIdentifier() == identifier)
466 setScores_(scores_to_FDR,
id, score_type, higher_better, keep_decoy, charge);
470 template<
typename IDType>
471 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
472 bool higher_better,
bool keep_decoy,
const String &identifier)
474 if (
id.getIdentifier() == identifier)
476 setScores_(scores_to_FDR,
id, score_type, higher_better, keep_decoy);
480 static void setScores_(
const std::map<double, double> &scores_to_FDR,
482 const std::string &score_type,
487 if (
id.getIdentifier() == identifier)
489 setScores_(scores_to_FDR,
id, score_type, higher_better, charge);
493 template<
typename IDType>
494 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
495 bool higher_better,
const String &identifier)
497 if (
id.getIdentifier() == identifier)
499 setScores_(scores_to_FDR,
id, score_type, higher_better);
503 template<
typename IDType>
504 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
505 bool higher_better,
int charge)
507 for (
auto& hit :
id.getHits())
509 if (hit.getCharge() == charge)
513 setScore_(scores_to_FDR, hit, score_type);
525 const std::map<double, double> &scores_to_FDR,
526 std::vector<ProteinIdentification::ProteinGroup> &grps,
527 const std::string &score_type,
540 template<
typename HitType>
543 const std::string &old_score_type,
544 std::vector<HitType> &new_hits)
546 const String &target_decoy(hit.getMetaValue(
"target_decoy"));
547 if (target_decoy[0] ==
't')
549 hit.setMetaValue(old_score_type, hit.getScore());
550 hit.setScore(scores_to_FDR.lower_bound(hit.getScore())->second);
551 new_hits.push_back(std::move(hit));
555 template<
typename HitType>
558 const std::string &old_score_type,
559 std::vector<HitType> &new_hits)
561 const String &target_decoy(hit.getMetaValue(
"target_decoy"));
562 if (target_decoy[0] ==
't')
564 hit.setMetaValue(old_score_type, hit.getScore());
565 auto ub = scores_to_FDR.upper_bound(hit.getScore());
566 if (ub != scores_to_FDR.begin()) ub--;
567 hit.setScore(ub->second);
568 new_hits.push_back(std::move(hit));
583 const std::string &old_score_type,
584 std::vector<PeptideHit> &new_hits,
590 if (target_decoy[0] ==
't')
594 new_hits.push_back(std::move(hit));
599 new_hits.push_back(std::move(hit));
613 template<
class ...Args>
616 bool include_unassigned_peptides,
617 const std::string &score_type,
626 higher_better, keep_decoy, std::forward<Args>(args)...); };
641 OPENMS_PRETTY_FUNCTION,
642 "Meta value 'target_decoy' does not exist in all ProteinHits! Reindex the idXML file with 'PeptideIndexer'");
A container for consensus elements.
Definition: ConsensusMap.h:90
A class for extracting and reinserting IDScores from Peptide/ProteinIdentifications and from Consensu...
Definition: IDScoreGetterSetter.h:66
static std::pair< bool, String > removeDecoyStringIfPresent_(const String &acc, const String &decoy_string, bool decoy_prefix)
removes the decoy_string from acc if present. Returns if string was removed and the new string.
static void setScoreHigherWorseAndMoveIfTarget_(const std::map< double, double > &scores_to_FDR, HitType &hit, const std::string &old_score_type, std::vector< HitType > &new_hits)
Definition: IDScoreGetterSetter.h:556
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:541
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, Args &&... args)
Helper for applying set Scores on ConsensusMaps.
Definition: IDScoreGetterSetter.h:614
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:293
static void getPeptideScoresFromMap_(ScoreToTgtDecLabelPairs &scores_labels, const ConsensusMap &cmap, bool include_unassigned_peptides, Args &&... args)
Helper for getting scores in ConsensusMaps.
Definition: IDScoreGetterSetter.h:278
static void checkTDAnnotation_(const MetaInfoInterface &id_or_hit)
To check the metavalues before we do anything.
Definition: IDScoreGetterSetter.h:635
static void getPickedProteinGroupScores_(const std::unordered_map< String, ScoreToTgtDecLabelPair > &picked_scores, ScoreToTgtDecLabelPairs &scores_labels, const std::vector< ProteinIdentification::ProteinGroup > &grps, const String &decoy_string, bool decoy_prefix)
Fills the scores_labels vector from a vector of ProteinGroups grps for picked protein group FDR.
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:581
static void getPickedProteinScores_(std::unordered_map< String, ScoreToTgtDecLabelPair > &picked_scores, const ProteinIdentification &id, const String &decoy_string, bool decoy_prefix)
Fills the scores_labels vector from an ProteinIdentification id for picked protein FDR....
void applyFunctionOnPeptideIDs(T &&f, bool include_unassigned=true)
applies a function on all PeptideIDs or only assigned ones
Definition: MapUtilities.h:68
Representation of a peptide hit.
Definition: PeptideHit.h:57
double getScore() const
returns the PSM score
Int getCharge() const
returns the charge of the peptide
void setScore(double score)
sets the PSM score
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:65
Representation of a protein hit.
Definition: ProteinHit.h:60
double getScore() const
returns the score of the protein hit
Representation of a protein identification run.
Definition: ProteinIdentification.h:72
A more convenient string class.
Definition: String.h:60
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const IDType &id, const String &identifier)
Definition: IDScoreGetterSetter.h:182
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentification &id, int charge)
Definition: IDScoreGetterSetter.h:227
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentification &id, int charge, const String &identifier)
Definition: IDScoreGetterSetter.h:171
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const IDType &id)
Definition: IDScoreGetterSetter.h:248
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideHit &hit, int charge)
Definition: IDScoreGetterSetter.h:215
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const std::vector< PeptideIdentification > &ids, Args &&... args)
Definition: IDScoreGetterSetter.h:259
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const HitType &hit)
Definition: IDScoreGetterSetter.h:239
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentification &id, bool all_hits, const String &identifier)
Definition: IDScoreGetterSetter.h:161
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const std::vector< ProteinIdentification::ProteinGroup > &grps, const std::unordered_set< std::string > &decoy_accs)
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const ProteinIdentification &id)
Definition: IDScoreGetterSetter.h:133
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentification &id, bool all_hits, int charge, const String &identifier)
Definition: IDScoreGetterSetter.h:150
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentification &id, bool all_hits, Args &&... args)
Definition: IDScoreGetterSetter.h:193
static void setScoresHigherWorseAndRemoveDecoys_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type, Args &&... args)
Definition: IDScoreGetterSetter.h:400
static void setScores_(const std::map< double, double > &scores_to_FDR, std::vector< ProteinIdentification::ProteinGroup > &grps, const std::string &score_type, bool higher_better)
static String setScoreType_(IDType &id, const std::string &score_type, bool higher_better)
Definition: IDScoreGetterSetter.h:323
static void setScoreHigherWorse_(const std::map< double, double > &scores_to_FDR, HitType &hit, const std::string &old_score_type)
Definition: IDScoreGetterSetter.h:421
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:456
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:471
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:438
static void setScore_(const std::map< double, double > &scores_to_FDR, HitType &hit, const std::string &old_score_type)
Definition: IDScoreGetterSetter.h:414
static void setScoresHigherWorse_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type)
Definition: IDScoreGetterSetter.h:375
static void setScoresAndRemoveDecoys_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type, Args &&... args)
Definition: IDScoreGetterSetter.h:386
static void setScores_(const std::map< double, double > &scores_to_FDR, IDType &id, const std::string &score_type, bool higher_better, int charge)
Definition: IDScoreGetterSetter.h:504
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:333
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:310
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:480
static void setScores_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type)
Definition: IDScoreGetterSetter.h:364
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:494
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
std::pair< double, double > ScoreToTgtDecLabelPair
Definition: IDScoreGetterSetter.h:53
Definition: IDScoreGetterSetter.h:79
static bool const value
Definition: IDScoreGetterSetter.h:80
Definition: IDScoreGetterSetter.h:72
static bool const value
Definition: IDScoreGetterSetter.h:73
Definition: IDScoreGetterSetter.h:57
std::vector< ScoreToTgtDecLabelPair > Base
Definition: IDScoreGetterSetter.h:58