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,
117 std::unordered_map<String, ScoreToTgtDecLabelPair>& seq_to_score_labels,
118 std::vector<PeptideIdentification>
const& ids);
121 std::unordered_map<String, ScoreToTgtDecLabelPair>& seq_to_score_labels,
123 bool include_unassigned);
140 const std::vector<ProteinIdentification::ProteinGroup> &grps,
141 const std::unordered_set<std::string> &decoy_accs);
144 template<
class ...Args>
147 const std::vector<PeptideIdentification> &ids,
152 getScores_(scores_labels,
id, std::forward<Args>(args)...);
160 scores_labels.reserve(scores_labels.size() +
id.getHits().size());
161 std::transform(
id.getHits().begin(),
id.getHits().end(),
162 std::back_inserter(scores_labels),
171 template<
class ...Args>
183 getScores_(scores_labels, hit, std::forward<Args>(args)...);
191 getScores_(scores_labels, hit, std::forward<Args>(args)...);
195 template<
typename IDPredicate,
class ...Args>
210 getScores_(scores_labels, hit, std::forward<Args>(args)...);
218 getScores_(scores_labels, hit, std::forward<Args>(args)...);
223 template<
typename HitPredicate>
235 template<typename HitType, typename std::enable_if<IsHitType<HitType>::value>::type * =
nullptr>
241 scores_labels.emplace_back(hit.getScore(),
getTDLabel_(hit));
251 template<
class ...Args>
254 const ConsensusMap &cmap,
bool include_unassigned_peptides,
Args &&... args)
258 {
getScores_(scores_labels,
id, std::forward<Args>(args)...); };
269 return std::string(idOrHit.
getMetaValue(
"target_decoy"))[0] ==
't';
283 template<
typename IDType,
class ...Args>
284 static void setScores_(
const std::map<double, double> &scores_to_FDR,
285 std::vector<IDType> &ids,
286 const std::string &score_type,
292 setScores_(scores_to_FDR,
id, score_type, higher_better, std::forward<Args>(args)...);
296 template<
typename IDType>
300 String old_score_type =
id.getScoreType() +
"_score";
301 id.setScoreType(score_type);
302 id.setHigherScoreBetter(higher_better);
303 return old_score_type;
306 template<
typename IDType>
307 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
308 bool higher_better,
bool keep_decoy)
310 bool old_higher_better =
id.isHigherScoreBetter();
315 if (old_higher_better)
317 setScores_(scores_to_FDR,
id, old_score_type);
326 if (old_higher_better)
337 template<
typename IDType>
338 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
339 const String &old_score_type)
341 std::vector<typename IDType::HitType> &hits =
id.getHits();
342 for (
auto &hit : hits)
344 setScore_(scores_to_FDR, hit, old_score_type);
348 template<
typename IDType>
350 const String &old_score_type)
352 std::vector<typename IDType::HitType> &hits =
id.getHits();
353 for (
auto &hit : hits)
359 template<
typename IDType,
class ...Args>
361 const String &old_score_type,
Args&& ... args)
363 std::vector<typename IDType::HitType> &hits =
id.getHits();
364 std::vector<typename IDType::HitType> new_hits;
365 new_hits.reserve(hits.size());
366 for (
auto &hit : hits)
373 template<
typename IDType,
class ...Args>
375 const String &old_score_type,
Args&& ... args)
377 std::vector<typename IDType::HitType> &hits =
id.getHits();
378 std::vector<typename IDType::HitType> new_hits;
379 new_hits.reserve(hits.size());
380 for (
auto &hit : hits)
387 template<
typename HitType>
388 static void setScore_(
const std::map<double, double> &scores_to_FDR, HitType &hit,
const std::string &old_score_type)
390 hit.setMetaValue(old_score_type, hit.getScore());
391 hit.setScore(scores_to_FDR.lower_bound(hit.getScore())->second);
394 template<
typename HitType>
395 static void setScoreHigherWorse_(
const std::map<double, double> &scores_to_FDR, HitType &hit,
const std::string &old_score_type)
397 hit.setMetaValue(old_score_type, hit.getScore());
398 auto ub = scores_to_FDR.upper_bound(hit.getScore());
399 if (ub != scores_to_FDR.begin()) ub--;
400 hit.setScore(ub->second);
412 static void setScores_(
const std::map<double, double> &scores_to_FDR,
414 const std::string &score_type,
422 setScores_(scores_to_FDR,
id, old_score_type, higher_better, charge);
426 setScoresAndRemoveDecoys_<PeptideIdentification>(scores_to_FDR,
id, old_score_type, charge);
430 static void setScores_(
const std::map<double, double> &scores_to_FDR,
432 const std::string &score_type,
438 if (
id.getIdentifier() == identifier)
440 setScores_(scores_to_FDR,
id, score_type, higher_better, keep_decoy, 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,
bool keep_decoy,
const String &identifier)
448 if (
id.getIdentifier() == identifier)
450 setScores_(scores_to_FDR,
id, score_type, higher_better, keep_decoy);
454 static void setScores_(
const std::map<double, double> &scores_to_FDR,
456 const std::string &score_type,
461 if (
id.getIdentifier() == identifier)
463 setScores_(scores_to_FDR,
id, score_type, higher_better, charge);
467 template<
typename IDType>
468 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
469 bool higher_better,
const String &identifier)
471 if (
id.getIdentifier() == identifier)
473 setScores_(scores_to_FDR,
id, score_type, higher_better);
477 template<
typename IDType>
478 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
479 bool higher_better,
int charge)
481 for (
auto& hit :
id.getHits())
483 if (hit.getCharge() == charge)
487 setScore_(scores_to_FDR, hit, score_type);
499 const std::map<double, double> &scores_to_FDR,
500 std::vector<ProteinIdentification::ProteinGroup> &grps,
501 const std::string &score_type,
514 template<
typename HitType>
517 const std::string &old_score_type,
518 std::vector<HitType> &new_hits)
520 const String &target_decoy(hit.getMetaValue(
"target_decoy"));
521 if (target_decoy[0] ==
't')
523 hit.setMetaValue(old_score_type, hit.getScore());
524 hit.setScore(scores_to_FDR.lower_bound(hit.getScore())->second);
525 new_hits.push_back(std::move(hit));
529 template<
typename HitType>
532 const std::string &old_score_type,
533 std::vector<HitType> &new_hits)
535 const String &target_decoy(hit.getMetaValue(
"target_decoy"));
536 if (target_decoy[0] ==
't')
538 hit.setMetaValue(old_score_type, hit.getScore());
539 auto ub = scores_to_FDR.upper_bound(hit.getScore());
540 if (ub != scores_to_FDR.begin()) ub--;
541 hit.setScore(ub->second);
542 new_hits.push_back(std::move(hit));
557 const std::string &old_score_type,
558 std::vector<PeptideHit> &new_hits,
564 if (target_decoy[0] ==
't')
568 new_hits.push_back(std::move(hit));
573 new_hits.push_back(std::move(hit));
587 template<
class ...Args>
590 bool include_unassigned_peptides,
591 const std::string &score_type,
600 higher_better, keep_decoy, std::forward<Args>(args)...); };
615 OPENMS_PRETTY_FUNCTION,
616 "Meta value 'target_decoy' does not exist in all ProteinHits! Reindex the idXML file with 'PeptideIndexer'");
621 std::vector<PeptideIdentification>& ids,
622 std::string
const& score_type,
627 std::string
const& score_type,
629 bool include_unassigned);
A container for consensus elements.
Definition: ConsensusMap.h:92
A class for extracting and reinserting IDScores from Peptide/ProteinIdentifications and from Consensu...
Definition: IDScoreGetterSetter.h:66
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:530
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:515
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:588
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:267
static void getPeptideScoresFromMap_(ScoreToTgtDecLabelPairs &scores_labels, const ConsensusMap &cmap, bool include_unassigned_peptides, Args &&... args)
Helper for getting scores in ConsensusMaps.
Definition: IDScoreGetterSetter.h:252
static void checkTDAnnotation_(const MetaInfoInterface &id_or_hit)
To check the metavalues before we do anything.
Definition: IDScoreGetterSetter.h:609
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:555
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:76
A more convenient string class.
Definition: String.h:60
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentification &id, IDPredicate &&fun, bool all_hits, Args &&... args)
Definition: IDScoreGetterSetter.h:196
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideHit &hit, HitPredicate &&fun)
Definition: IDScoreGetterSetter.h:224
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const std::vector< PeptideIdentification > &ids, Args &&... args)
Definition: IDScoreGetterSetter.h:145
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const HitType &hit)
Definition: IDScoreGetterSetter.h:236
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:156
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentification &id, bool all_hits, Args &&... args)
Definition: IDScoreGetterSetter.h:172
static void setScoresHigherWorseAndRemoveDecoys_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type, Args &&... args)
Definition: IDScoreGetterSetter.h:374
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:297
static void setScoreHigherWorse_(const std::map< double, double > &scores_to_FDR, HitType &hit, const std::string &old_score_type)
Definition: IDScoreGetterSetter.h:395
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:430
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:445
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:412
static void setScore_(const std::map< double, double > &scores_to_FDR, HitType &hit, const std::string &old_score_type)
Definition: IDScoreGetterSetter.h:388
static void setScoresHigherWorse_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type)
Definition: IDScoreGetterSetter.h:349
static void setScoresAndRemoveDecoys_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type, Args &&... args)
Definition: IDScoreGetterSetter.h:360
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:478
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:307
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:284
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:454
static void setScores_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type)
Definition: IDScoreGetterSetter.h:338
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:468
custom arguments to allow for looping calls
Definition: WizardHelper.h:73
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
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