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;
68 std::unordered_map<String, ScoreToTgtDecLabelPair>& picked_scores,
70 const String& decoy_string,
83 const std::unordered_map<String, ScoreToTgtDecLabelPair>& picked_scores,
85 const std::vector<ProteinIdentification::ProteinGroup>& grps,
86 const String& decoy_string,
93 std::unordered_map<String, ScoreToTgtDecLabelPair>& seq_to_score_labels,
94 std::vector<PeptideIdentification>
const& ids);
97 std::unordered_map<String, ScoreToTgtDecLabelPair>& seq_to_score_labels,
99 bool include_unassigned);
116 const std::vector<ProteinIdentification::ProteinGroup> &grps,
117 const std::unordered_set<std::string> &decoy_accs);
120 template<
class ...Args>
123 const std::vector<PeptideIdentification> &ids,
128 getScores_(scores_labels,
id, std::forward<Args>(args)...);
136 scores_labels.reserve(scores_labels.size() +
id.getHits().size());
137 std::transform(
id.getHits().begin(),
id.getHits().end(),
138 std::back_inserter(scores_labels),
147 template<
class ...Args>
159 getScores_(scores_labels, hit, std::forward<Args>(args)...);
167 getScores_(scores_labels, hit, std::forward<Args>(args)...);
171 template<
typename IDPredicate,
class ...Args>
186 getScores_(scores_labels, hit, std::forward<Args>(args)...);
194 getScores_(scores_labels, hit, std::forward<Args>(args)...);
199 template<
typename HitPredicate>
211 template<typename HitType, typename std::enable_if<IsHitType<HitType>::value>::type * =
nullptr>
217 scores_labels.emplace_back(hit.getScore(),
getTDLabel_(hit));
227 template<
class ...Args>
230 const ConsensusMap &cmap,
bool include_unassigned_peptides,
Args &&... args)
234 {
getScores_(scores_labels,
id, std::forward<Args>(args)...); };
245 return std::string(idOrHit.
getMetaValue(
"target_decoy"))[0] ==
't';
259 template<
typename IDType,
class ...Args>
260 static void setScores_(
const std::map<double, double> &scores_to_FDR,
261 std::vector<IDType> &ids,
262 const std::string &score_type,
268 setScores_(scores_to_FDR,
id, score_type, higher_better, std::forward<Args>(args)...);
272 template<
typename IDType>
276 String old_score_type =
id.getScoreType() +
"_score";
277 id.setScoreType(score_type);
278 id.setHigherScoreBetter(higher_better);
279 return old_score_type;
282 template<
typename IDType>
283 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
284 bool higher_better,
bool keep_decoy)
286 bool old_higher_better =
id.isHigherScoreBetter();
291 if (old_higher_better)
293 setScores_(scores_to_FDR,
id, old_score_type);
302 if (old_higher_better)
313 template<
typename IDType>
314 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
315 const String &old_score_type)
317 std::vector<typename IDType::HitType> &hits =
id.getHits();
318 for (
auto &hit : hits)
320 setScore_(scores_to_FDR, hit, old_score_type);
324 template<
typename IDType>
326 const String &old_score_type)
328 std::vector<typename IDType::HitType> &hits =
id.getHits();
329 for (
auto &hit : hits)
335 template<
typename IDType,
class ...Args>
337 const String &old_score_type,
Args&& ... args)
339 std::vector<typename IDType::HitType> &hits =
id.getHits();
340 std::vector<typename IDType::HitType> new_hits;
341 new_hits.reserve(hits.size());
342 for (
auto &hit : hits)
349 template<
typename IDType,
class ...Args>
351 const String &old_score_type,
Args&& ... args)
353 std::vector<typename IDType::HitType> &hits =
id.getHits();
354 std::vector<typename IDType::HitType> new_hits;
355 new_hits.reserve(hits.size());
356 for (
auto &hit : hits)
363 template<
typename HitType>
364 static void setScore_(
const std::map<double, double> &scores_to_FDR, HitType &hit,
const std::string &old_score_type)
366 hit.setMetaValue(old_score_type, hit.getScore());
367 hit.setScore(scores_to_FDR.lower_bound(hit.getScore())->second);
370 template<
typename HitType>
371 static void setScoreHigherWorse_(
const std::map<double, double> &scores_to_FDR, HitType &hit,
const std::string &old_score_type)
373 hit.setMetaValue(old_score_type, hit.getScore());
374 auto ub = scores_to_FDR.upper_bound(hit.getScore());
375 if (ub != scores_to_FDR.begin()) ub--;
376 hit.setScore(ub->second);
388 static void setScores_(
const std::map<double, double> &scores_to_FDR,
390 const std::string &score_type,
398 setScores_(scores_to_FDR,
id, old_score_type, higher_better, charge);
402 setScoresAndRemoveDecoys_<PeptideIdentification>(scores_to_FDR,
id, old_score_type, charge);
406 static void setScores_(
const std::map<double, double> &scores_to_FDR,
408 const std::string &score_type,
414 if (
id.getIdentifier() == identifier)
416 setScores_(scores_to_FDR,
id, score_type, higher_better, keep_decoy, charge);
420 template<
typename IDType>
421 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
422 bool higher_better,
bool keep_decoy,
const String &identifier)
424 if (
id.getIdentifier() == identifier)
426 setScores_(scores_to_FDR,
id, score_type, higher_better, keep_decoy);
430 static void setScores_(
const std::map<double, double> &scores_to_FDR,
432 const std::string &score_type,
437 if (
id.getIdentifier() == identifier)
439 setScores_(scores_to_FDR,
id, score_type, higher_better, charge);
443 template<
typename IDType>
444 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
445 bool higher_better,
const String &identifier)
447 if (
id.getIdentifier() == identifier)
449 setScores_(scores_to_FDR,
id, score_type, higher_better);
453 template<
typename IDType>
454 static void setScores_(
const std::map<double, double> &scores_to_FDR, IDType &
id,
const std::string &score_type,
455 bool higher_better,
int charge)
457 for (
auto& hit :
id.getHits())
459 if (hit.getCharge() == charge)
463 setScore_(scores_to_FDR, hit, score_type);
475 const std::map<double, double> &scores_to_FDR,
476 std::vector<ProteinIdentification::ProteinGroup> &grps,
477 const std::string &score_type,
490 template<
typename HitType>
493 const std::string &old_score_type,
494 std::vector<HitType> &new_hits)
496 const String &target_decoy(hit.getMetaValue(
"target_decoy"));
497 if (target_decoy[0] ==
't')
499 hit.setMetaValue(old_score_type, hit.getScore());
500 hit.setScore(scores_to_FDR.lower_bound(hit.getScore())->second);
501 new_hits.push_back(std::move(hit));
505 template<
typename HitType>
508 const std::string &old_score_type,
509 std::vector<HitType> &new_hits)
511 const String &target_decoy(hit.getMetaValue(
"target_decoy"));
512 if (target_decoy[0] ==
't')
514 hit.setMetaValue(old_score_type, hit.getScore());
515 auto ub = scores_to_FDR.upper_bound(hit.getScore());
516 if (ub != scores_to_FDR.begin()) ub--;
517 hit.setScore(ub->second);
518 new_hits.push_back(std::move(hit));
533 const std::string &old_score_type,
534 std::vector<PeptideHit> &new_hits,
540 if (target_decoy[0] ==
't')
544 new_hits.push_back(std::move(hit));
549 new_hits.push_back(std::move(hit));
564 template<
class ...Args>
567 bool include_unassigned_peptides,
568 const std::string& score_type,
577 higher_better, keep_decoy, std::forward<Args>(args)...); };
592 OPENMS_PRETTY_FUNCTION,
593 "Meta value 'target_decoy' does not exist in all ProteinHits! Reindex the idXML file with 'PeptideIndexer'");
598 std::vector<PeptideIdentification>& ids,
599 std::string
const& score_type,
604 std::string
const& score_type,
606 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:506
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:491
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:565
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:243
static void getPeptideScoresFromMap_(ScoreToTgtDecLabelPairs &scores_labels, const ConsensusMap &cmap, bool include_unassigned_peptides, Args &&... args)
Helper for getting scores in ConsensusMaps.
Definition: IDScoreGetterSetter.h:228
static void checkTDAnnotation_(const MetaInfoInterface &id_or_hit)
To check the metavalues before we do anything.
Definition: IDScoreGetterSetter.h:586
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:531
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:172
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideHit &hit, HitPredicate &&fun)
Definition: IDScoreGetterSetter.h:200
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const std::vector< PeptideIdentification > &ids, Args &&... args)
Definition: IDScoreGetterSetter.h:121
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const HitType &hit)
Definition: IDScoreGetterSetter.h:212
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:132
static void getScores_(ScoreToTgtDecLabelPairs &scores_labels, const PeptideIdentification &id, bool all_hits, Args &&... args)
Definition: IDScoreGetterSetter.h:148
static void setScoresHigherWorseAndRemoveDecoys_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type, Args &&... args)
Definition: IDScoreGetterSetter.h:350
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:273
static void setScoreHigherWorse_(const std::map< double, double > &scores_to_FDR, HitType &hit, const std::string &old_score_type)
Definition: IDScoreGetterSetter.h:371
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:406
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: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)
Definition: IDScoreGetterSetter.h:388
static void setScore_(const std::map< double, double > &scores_to_FDR, HitType &hit, const std::string &old_score_type)
Definition: IDScoreGetterSetter.h:364
static void setScoresHigherWorse_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type)
Definition: IDScoreGetterSetter.h:325
static void setScoresAndRemoveDecoys_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type, Args &&... args)
Definition: IDScoreGetterSetter.h:336
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:454
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:283
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:260
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:430
static void setScores_(const std::map< double, double > &scores_to_FDR, IDType &id, const String &old_score_type)
Definition: IDScoreGetterSetter.h:314
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:444
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: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