19 #include <unordered_set>
20 #include <unordered_map>
31 :
public std::vector<ScoreToTgtDecLabelPair>
33 typedef std::vector<ScoreToTgtDecLabelPair>
Base;
49 std::is_same<T, PeptideIdentification>::value || std::is_same<T, ProteinIdentification>::value;
55 static bool const value = std::is_same<T, PeptideHit>::value || std::is_same<T, ProteinHit>::value;
69 std::unordered_map<String, ScoreToTgtDecLabelPair>& picked_scores,
71 const String& decoy_string,
84 const std::unordered_map<String, ScoreToTgtDecLabelPair>& picked_scores,
86 const std::vector<ProteinIdentification::ProteinGroup>& grps,
87 const String& decoy_string,
94 std::unordered_map<String, ScoreToTgtDecLabelPair>& seq_to_score_labels,
98 std::unordered_map<String, ScoreToTgtDecLabelPair>& seq_to_score_labels,
100 bool include_unassigned);
117 const std::vector<ProteinIdentification::ProteinGroup> &grps,
118 const std::unordered_set<std::string> &decoy_accs);
121 template<
class ...Args>
129 getScores_(scores_labels,
id, std::forward<Args>(args)...);
137 scores_labels.reserve(scores_labels.size() +
id.getHits().size());
138 std::transform(
id.getHits().begin(),
id.getHits().end(),
139 std::back_inserter(scores_labels),
148 template<
class ...Args>
160 getScores_(scores_labels, hit, std::forward<Args>(args)...);
168 getScores_(scores_labels, hit, std::forward<Args>(args)...);
172 template<
typename IDPredicate,
class ...Args>
187 getScores_(scores_labels, hit, std::forward<Args>(args)...);
195 getScores_(scores_labels, hit, std::forward<Args>(args)...);
200 template<
typename HitPredicate>
212 template<typename HitType, typename std::enable_if<IsHitType<HitType>::value>::type * =
nullptr>
218 scores_labels.emplace_back(hit.getScore(),
getTDLabel_(hit));
228 template<
class ...Args>
231 const ConsensusMap &cmap,
bool include_unassigned_peptides,
Args &&... args)
235 {
getScores_(scores_labels,
id, std::forward<Args>(args)...); };
246 return std::string(idOrHit.
getMetaValue(
"target_decoy"))[0] ==
't';
260 template<
typename IDType,
class ...Args>
261 static void setScores_(
const std::map<double, double> &scores_to_FDR,
262 std::vector<IDType> &ids,
263 const std::string &score_type,
269 setScores_(scores_to_FDR,
id, score_type, higher_better, std::forward<Args>(args)...);
273 template<
typename IDType>
277 String old_score_type =
id.getScoreType() +
"_score";
278 id.setScoreType(score_type);
279 id.setHigherScoreBetter(higher_better);
280 return old_score_type;
283 template<
typename IDType>
284 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
285 bool higher_better,
bool keep_decoy)
287 bool old_higher_better =
id.isHigherScoreBetter();
292 if (old_higher_better)
294 setScores_(scores_to_FDR,
id, old_score_type);
303 if (old_higher_better)
314 template<
typename IDType>
315 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
316 const String &old_score_type)
318 std::vector<typename IDType::HitType> &hits =
id.getHits();
319 for (
auto &hit : hits)
321 setScore_(scores_to_FDR, hit, old_score_type);
325 template<
typename IDType>
327 const String &old_score_type)
329 std::vector<typename IDType::HitType> &hits =
id.getHits();
330 for (
auto &hit : hits)
336 template<
typename IDType,
class ...Args>
338 const String &old_score_type,
Args&& ... args)
340 std::vector<typename IDType::HitType> &hits =
id.getHits();
341 std::vector<typename IDType::HitType> new_hits;
342 new_hits.reserve(hits.size());
343 for (
auto &hit : hits)
350 template<
typename IDType,
class ...Args>
352 const String &old_score_type,
Args&& ... args)
354 std::vector<typename IDType::HitType> &hits =
id.getHits();
355 std::vector<typename IDType::HitType> new_hits;
356 new_hits.reserve(hits.size());
357 for (
auto &hit : hits)
364 template<
typename HitType>
365 static void setScore_(
const std::map<double, double> &scores_to_FDR, HitType &hit,
const std::string &old_score_type)
367 hit.setMetaValue(old_score_type, hit.getScore());
368 hit.setScore(scores_to_FDR.lower_bound(hit.getScore())->second);
371 template<
typename HitType>
372 static void setScoreHigherWorse_(
const std::map<double, double> &scores_to_FDR, HitType &hit,
const std::string &old_score_type)
374 hit.setMetaValue(old_score_type, hit.getScore());
375 auto ub = scores_to_FDR.upper_bound(hit.getScore());
376 if (ub != scores_to_FDR.begin()) ub--;
377 hit.setScore(ub->second);
389 static void setScores_(
const std::map<double, double> &scores_to_FDR,
391 const std::string &score_type,
399 setScores_(scores_to_FDR,
id, old_score_type, higher_better, charge);
403 setScoresAndRemoveDecoys_<PeptideIdentification>(scores_to_FDR,
id, old_score_type, charge);
407 static void setScores_(
const std::map<double, double> &scores_to_FDR,
409 const std::string &score_type,
415 if (
id.getIdentifier() == identifier)
417 setScores_(scores_to_FDR,
id, score_type, higher_better, keep_decoy, charge);
421 template<
typename IDType>
422 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
423 bool higher_better,
bool keep_decoy,
const String &identifier)
425 if (
id.getIdentifier() == identifier)
427 setScores_(scores_to_FDR,
id, score_type, higher_better, keep_decoy);
431 static void setScores_(
const std::map<double, double> &scores_to_FDR,
433 const std::string &score_type,
438 if (
id.getIdentifier() == identifier)
440 setScores_(scores_to_FDR,
id, score_type, higher_better, charge);
444 template<
typename IDType>
445 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
446 bool higher_better,
const String &identifier)
448 if (
id.getIdentifier() == identifier)
450 setScores_(scores_to_FDR,
id, score_type, higher_better);
454 template<
typename IDType>
455 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
456 bool higher_better,
int charge)
458 for (
auto& hit :
id.getHits())
460 if (hit.getCharge() == charge)
464 setScore_(scores_to_FDR, hit, score_type);
476 const std::map<double, double> &scores_to_FDR,
477 std::vector<ProteinIdentification::ProteinGroup> &grps,
478 const std::string &score_type,
491 template<
typename HitType>
494 const std::string &old_score_type,
495 std::vector<HitType> &new_hits)
497 const String &target_decoy(hit.getMetaValue(
"target_decoy"));
498 if (target_decoy[0] ==
't')
500 hit.setMetaValue(old_score_type, hit.getScore());
501 hit.setScore(scores_to_FDR.lower_bound(hit.getScore())->second);
502 new_hits.push_back(std::move(hit));
506 template<
typename HitType>
509 const std::string &old_score_type,
510 std::vector<HitType> &new_hits)
512 const String &target_decoy(hit.getMetaValue(
"target_decoy"));
513 if (target_decoy[0] ==
't')
515 hit.setMetaValue(old_score_type, hit.getScore());
516 auto ub = scores_to_FDR.upper_bound(hit.getScore());
517 if (ub != scores_to_FDR.begin()) ub--;
518 hit.setScore(ub->second);
519 new_hits.push_back(std::move(hit));
534 const std::string &old_score_type,
535 std::vector<PeptideHit> &new_hits,
541 if (target_decoy[0] ==
't')
545 new_hits.push_back(std::move(hit));
550 new_hits.push_back(std::move(hit));
565 template<
class ...Args>
568 bool include_unassigned_peptides,
569 const std::string& score_type,
578 higher_better, keep_decoy, std::forward<Args>(args)...); };
593 OPENMS_PRETTY_FUNCTION,
594 "Meta value 'target_decoy' does not exist in all ProteinHits! Reindex the idXML file with 'PeptideIndexer'");
600 std::string
const& score_type,
605 std::string
const& score_type,
607 bool include_unassigned);
A container for consensus elements.
Definition: ConsensusMap.h:68
A class for extracting and reinserting IDScores from Peptide/ProteinIdentifications and from Consensu...
Definition: IDScoreGetterSetter.h:41
static void fillPeptideScoreMap_(std::unordered_map< String, ScoreToTgtDecLabelPair > &seq_to_score_labels, ConsensusMap const &map, bool include_unassigned)
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:507
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:492
static void setPeptideScoresFromMap_(std::unordered_map< String, ScoreToTgtDecLabelPair > const &seq_to_fdr, PeptideIdentificationList &ids, std::string const &score_type, bool keep_decoys)
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:566
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:244
static void getPeptideScoresFromMap_(ScoreToTgtDecLabelPairs &scores_labels, const ConsensusMap &cmap, bool include_unassigned_peptides, Args &&... args)
Helper for getting scores in ConsensusMaps.
Definition: IDScoreGetterSetter.h:229
static void checkTDAnnotation_(const MetaInfoInterface &id_or_hit)
To check the metavalues before we do anything.
Definition: IDScoreGetterSetter.h:587
static void fillPeptideScoreMap_(std::unordered_map< String, ScoreToTgtDecLabelPair > &seq_to_score_labels, PeptideIdentificationList const &ids)
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:532
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:43
Represents a single spectrum match (candidate) for a specific tandem mass spectrum (MS/MS).
Definition: PeptideHit.h:50
double getScore() const
returns the PSM score
Int getCharge() const
returns the charge of the peptide
void setScore(double score)
sets the PSM score
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:63
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:51
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:173
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideHit &hit, HitPredicate &&fun)
Definition: IDScoreGetterSetter.h:201
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const HitType &hit)
Definition: IDScoreGetterSetter.h:213
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, Args &&... args)
Definition: IDScoreGetterSetter.h:149
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentificationList &ids, Args &&... args)
Definition: IDScoreGetterSetter.h:122
static void setScoresHigherWorseAndRemoveDecoys_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type, Args &&... args)
Definition: IDScoreGetterSetter.h:351
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:274
static void setScoreHigherWorse_(const std::map< double, double > &scores_to_FDR, HitType &hit, const std::string &old_score_type)
Definition: IDScoreGetterSetter.h:372
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:407
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:422
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:389
static void setScore_(const std::map< double, double > &scores_to_FDR, HitType &hit, const std::string &old_score_type)
Definition: IDScoreGetterSetter.h:365
static void setScoresHigherWorse_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type)
Definition: IDScoreGetterSetter.h:326
static void setScoresAndRemoveDecoys_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type, Args &&... args)
Definition: IDScoreGetterSetter.h:337
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:455
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:284
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:261
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:431
static void setScores_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type)
Definition: IDScoreGetterSetter.h:315
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:445
custom arguments to allow for looping calls
Definition: WizardHelper.h:47
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::pair< double, double > ScoreToTgtDecLabelPair
Definition: IDScoreGetterSetter.h:28
Definition: IDScoreGetterSetter.h:54
static bool const value
Definition: IDScoreGetterSetter.h:55
Definition: IDScoreGetterSetter.h:47
static bool const value
Definition: IDScoreGetterSetter.h:48
Definition: IDScoreGetterSetter.h:32
std::vector< ScoreToTgtDecLabelPair > Base
Definition: IDScoreGetterSetter.h:33