18 #include <unordered_set>
19 #include <unordered_map>
30 :
public std::vector<ScoreToTgtDecLabelPair>
32 typedef std::vector<ScoreToTgtDecLabelPair>
Base;
48 std::is_same<T, PeptideIdentification>::value || std::is_same<T, ProteinIdentification>::value;
54 static bool const value = std::is_same<T, PeptideHit>::value || std::is_same<T, ProteinHit>::value;
67 std::unordered_map<String, ScoreToTgtDecLabelPair>& picked_scores,
69 const String& decoy_string,
81 const std::unordered_map<String, ScoreToTgtDecLabelPair>& picked_scores,
83 const std::vector<ProteinIdentification::ProteinGroup>& grps,
84 const String& decoy_string,
91 std::unordered_map<String, ScoreToTgtDecLabelPair>& seq_to_score_labels,
92 std::vector<PeptideIdentification>
const& ids);
95 std::unordered_map<String, ScoreToTgtDecLabelPair>& seq_to_score_labels,
97 bool include_unassigned);
114 const std::vector<ProteinIdentification::ProteinGroup> &grps,
115 const std::unordered_set<std::string> &decoy_accs);
118 template<
class ...Args>
121 const std::vector<PeptideIdentification> &ids,
126 getScores_(scores_labels,
id, std::forward<Args>(args)...);
134 scores_labels.reserve(scores_labels.size() +
id.getHits().size());
135 std::transform(
id.getHits().begin(),
id.getHits().end(),
136 std::back_inserter(scores_labels),
145 template<
class ...Args>
157 getScores_(scores_labels, hit, std::forward<Args>(args)...);
165 getScores_(scores_labels, hit, std::forward<Args>(args)...);
169 template<
typename IDPredicate,
class ...Args>
184 getScores_(scores_labels, hit, std::forward<Args>(args)...);
192 getScores_(scores_labels, hit, std::forward<Args>(args)...);
197 template<
typename HitPredicate>
209 template<typename HitType, typename std::enable_if<IsHitType<HitType>::value>::type * =
nullptr>
215 scores_labels.emplace_back(hit.getScore(),
getTDLabel_(hit));
225 template<
class ...Args>
228 const ConsensusMap &cmap,
bool include_unassigned_peptides,
Args &&... args)
232 {
getScores_(scores_labels,
id, std::forward<Args>(args)...); };
243 return std::string(idOrHit.
getMetaValue(
"target_decoy"))[0] ==
't';
257 template<
typename IDType,
class ...Args>
258 static void setScores_(
const std::map<double, double> &scores_to_FDR,
259 std::vector<IDType> &ids,
260 const std::string &score_type,
266 setScores_(scores_to_FDR,
id, score_type, higher_better, std::forward<Args>(args)...);
270 template<
typename IDType>
274 String old_score_type =
id.getScoreType() +
"_score";
275 id.setScoreType(score_type);
276 id.setHigherScoreBetter(higher_better);
277 return old_score_type;
280 template<
typename IDType>
281 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
282 bool higher_better,
bool keep_decoy)
284 bool old_higher_better =
id.isHigherScoreBetter();
289 if (old_higher_better)
291 setScores_(scores_to_FDR,
id, old_score_type);
300 if (old_higher_better)
311 template<
typename IDType>
312 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
313 const String &old_score_type)
315 std::vector<typename IDType::HitType> &hits =
id.getHits();
316 for (
auto &hit : hits)
318 setScore_(scores_to_FDR, hit, old_score_type);
322 template<
typename IDType>
324 const String &old_score_type)
326 std::vector<typename IDType::HitType> &hits =
id.getHits();
327 for (
auto &hit : hits)
333 template<
typename IDType,
class ...Args>
335 const String &old_score_type,
Args&& ... args)
337 std::vector<typename IDType::HitType> &hits =
id.getHits();
338 std::vector<typename IDType::HitType> new_hits;
339 new_hits.reserve(hits.size());
340 for (
auto &hit : hits)
347 template<
typename IDType,
class ...Args>
349 const String &old_score_type,
Args&& ... args)
351 std::vector<typename IDType::HitType> &hits =
id.getHits();
352 std::vector<typename IDType::HitType> new_hits;
353 new_hits.reserve(hits.size());
354 for (
auto &hit : hits)
361 template<
typename HitType>
362 static void setScore_(
const std::map<double, double> &scores_to_FDR, HitType &hit,
const std::string &old_score_type)
364 hit.setMetaValue(old_score_type, hit.getScore());
365 hit.setScore(scores_to_FDR.lower_bound(hit.getScore())->second);
368 template<
typename HitType>
369 static void setScoreHigherWorse_(
const std::map<double, double> &scores_to_FDR, HitType &hit,
const std::string &old_score_type)
371 hit.setMetaValue(old_score_type, hit.getScore());
372 auto ub = scores_to_FDR.upper_bound(hit.getScore());
373 if (ub != scores_to_FDR.begin()) ub--;
374 hit.setScore(ub->second);
386 static void setScores_(
const std::map<double, double> &scores_to_FDR,
388 const std::string &score_type,
396 setScores_(scores_to_FDR,
id, old_score_type, higher_better, charge);
400 setScoresAndRemoveDecoys_<PeptideIdentification>(scores_to_FDR,
id, old_score_type, charge);
404 static void setScores_(
const std::map<double, double> &scores_to_FDR,
406 const std::string &score_type,
412 if (
id.getIdentifier() == identifier)
414 setScores_(scores_to_FDR,
id, score_type, higher_better, keep_decoy, charge);
418 template<
typename IDType>
419 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
420 bool higher_better,
bool keep_decoy,
const String &identifier)
422 if (
id.getIdentifier() == identifier)
424 setScores_(scores_to_FDR,
id, score_type, higher_better, keep_decoy);
428 static void setScores_(
const std::map<double, double> &scores_to_FDR,
430 const std::string &score_type,
435 if (
id.getIdentifier() == identifier)
437 setScores_(scores_to_FDR,
id, score_type, higher_better, charge);
441 template<
typename IDType>
442 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
443 bool higher_better,
const String &identifier)
445 if (
id.getIdentifier() == identifier)
447 setScores_(scores_to_FDR,
id, score_type, higher_better);
451 template<
typename IDType>
452 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
453 bool higher_better,
int charge)
455 for (
auto& hit :
id.getHits())
457 if (hit.getCharge() == charge)
461 setScore_(scores_to_FDR, hit, score_type);
473 const std::map<double, double> &scores_to_FDR,
474 std::vector<ProteinIdentification::ProteinGroup> &grps,
475 const std::string &score_type,
488 template<
typename HitType>
491 const std::string &old_score_type,
492 std::vector<HitType> &new_hits)
494 const String &target_decoy(hit.getMetaValue(
"target_decoy"));
495 if (target_decoy[0] ==
't')
497 hit.setMetaValue(old_score_type, hit.getScore());
498 hit.setScore(scores_to_FDR.lower_bound(hit.getScore())->second);
499 new_hits.push_back(std::move(hit));
503 template<
typename HitType>
506 const std::string &old_score_type,
507 std::vector<HitType> &new_hits)
509 const String &target_decoy(hit.getMetaValue(
"target_decoy"));
510 if (target_decoy[0] ==
't')
512 hit.setMetaValue(old_score_type, hit.getScore());
513 auto ub = scores_to_FDR.upper_bound(hit.getScore());
514 if (ub != scores_to_FDR.begin()) ub--;
515 hit.setScore(ub->second);
516 new_hits.push_back(std::move(hit));
531 const std::string &old_score_type,
532 std::vector<PeptideHit> &new_hits,
538 if (target_decoy[0] ==
't')
542 new_hits.push_back(std::move(hit));
547 new_hits.push_back(std::move(hit));
561 template<
class ...Args>
564 bool include_unassigned_peptides,
565 const std::string &score_type,
574 higher_better, keep_decoy, std::forward<Args>(args)...); };
589 OPENMS_PRETTY_FUNCTION,
590 "Meta value 'target_decoy' does not exist in all ProteinHits! Reindex the idXML file with 'PeptideIndexer'");
595 std::vector<PeptideIdentification>& ids,
596 std::string
const& score_type,
601 std::string
const& score_type,
603 bool include_unassigned);
A container for consensus elements.
Definition: ConsensusMap.h:66
A class for extracting and reinserting IDScores from Peptide/ProteinIdentifications and from Consensu...
Definition: IDScoreGetterSetter.h:40
static void fillPeptideScoreMap_(std::unordered_map< String, ScoreToTgtDecLabelPair > &seq_to_score_labels, ConsensusMap const &map, bool include_unassigned)
static void setPeptideScoresFromMap_(std::unordered_map< String, ScoreToTgtDecLabelPair > const &seq_to_fdr, std::vector< PeptideIdentification > &ids, std::string const &score_type, bool keep_decoys)
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:504
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:489
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:562
static void fillPeptideScoreMap_(std::unordered_map< String, ScoreToTgtDecLabelPair > &seq_to_score_labels, std::vector< PeptideIdentification > const &ids)
static void setPeptideScoresFromMap_(std::unordered_map< String, ScoreToTgtDecLabelPair > const &seq_to_fdr, ConsensusMap &map, std::string const &score_type, bool keep_decoys, bool include_unassigned)
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:241
static void getPeptideScoresFromMap_(ScoreToTgtDecLabelPairs &scores_labels, const ConsensusMap &cmap, bool include_unassigned_peptides, Args &&... args)
Helper for getting scores in ConsensusMaps.
Definition: IDScoreGetterSetter.h:226
static void checkTDAnnotation_(const MetaInfoInterface &id_or_hit)
To check the metavalues before we do anything.
Definition: IDScoreGetterSetter.h:583
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:529
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:42
Representation of a peptide hit.
Definition: PeptideHit.h:31
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:39
Representation of a protein hit.
Definition: ProteinHit.h:34
double getScore() const
returns the score of the protein hit
Representation of a protein identification run.
Definition: ProteinIdentification.h:50
A more convenient string class.
Definition: String.h:34
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentification &id, IDPredicate &&fun, bool all_hits, Args &&... args)
Definition: IDScoreGetterSetter.h:170
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideHit &hit, HitPredicate &&fun)
Definition: IDScoreGetterSetter.h:198
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const std::vector< PeptideIdentification > &ids, Args &&... args)
Definition: IDScoreGetterSetter.h:119
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const HitType &hit)
Definition: IDScoreGetterSetter.h:210
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:130
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentification &id, bool all_hits, Args &&... args)
Definition: IDScoreGetterSetter.h:146
static void setScoresHigherWorseAndRemoveDecoys_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type, Args &&... args)
Definition: IDScoreGetterSetter.h:348
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:271
static void setScoreHigherWorse_(const std::map< double, double > &scores_to_FDR, HitType &hit, const std::string &old_score_type)
Definition: IDScoreGetterSetter.h:369
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:404
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:419
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:386
static void setScore_(const std::map< double, double > &scores_to_FDR, HitType &hit, const std::string &old_score_type)
Definition: IDScoreGetterSetter.h:362
static void setScoresHigherWorse_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type)
Definition: IDScoreGetterSetter.h:323
static void setScoresAndRemoveDecoys_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type, Args &&... args)
Definition: IDScoreGetterSetter.h:334
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:452
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:281
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:258
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:428
static void setScores_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type)
Definition: IDScoreGetterSetter.h:312
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:442
custom arguments to allow for looping calls
Definition: WizardHelper.h:47
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
std::pair< double, double > ScoreToTgtDecLabelPair
Definition: IDScoreGetterSetter.h:27
Definition: IDScoreGetterSetter.h:53
static bool const value
Definition: IDScoreGetterSetter.h:54
Definition: IDScoreGetterSetter.h:46
static bool const value
Definition: IDScoreGetterSetter.h:47
Definition: IDScoreGetterSetter.h:31
std::vector< ScoreToTgtDecLabelPair > Base
Definition: IDScoreGetterSetter.h:32