75 String chopped = score_name;
78 chopped = chopped.
chop(6);
80 const std::set<String>& possible_types = type_to_str_[type];
81 return possible_types.find(chopped) != possible_types.end();
100 score_type = score_type.
chop(6);
103 score_type.erase(std::remove_if(score_type.begin(), score_type.end(),
104 [](
unsigned char c) { return c ==
'-' || c ==
'_' || c ==
' '; }),
107 const std::map<String, ScoreType> s_to_type =
109 {
"raw", ScoreType::RAW},
110 {
"rawevalue", ScoreType::RAW_EVAL},
111 {
"qvalue", ScoreType::QVAL},
112 {
"fdr", ScoreType::FDR},
113 {
"falsediscoveryrate", ScoreType::FDR},
114 {
"pep", ScoreType::PEP},
115 {
"posteriorerrorprobability", ScoreType::PEP},
116 {
"posteriorprobabilty", ScoreType::PP},
117 {
"pp", ScoreType::PP}
120 if (
auto it = s_to_type.find(score_type); it != s_to_type.end())
127 OPENMS_PRETTY_FUNCTION,
String(
"Unknown score type '") + score_type +
"'.");
139 return type_to_better_[score_type];
169 template <
typename IDType>
172 for (
auto hit_it =
id.getHits().begin();
173 hit_it !=
id.getHits().end(); ++hit_it, ++counter)
175 if (!hit_it->metaValueExists(new_score_))
177 std::stringstream msg;
178 msg <<
"Meta value '" << new_score_ <<
"' not found for " << *hit_it;
180 OPENMS_PRETTY_FUNCTION, msg.str());
183 const String& old_score_meta = (old_score_.empty() ?
id.getScoreType() :
185 const DataValue& dv = hit_it->getMetaValue(old_score_meta);
193 if (fabs((
double(dv) - hit_it->getScore()) * 2.0 /
194 (
double(dv) + hit_it->getScore())) > tolerance_)
196 hit_it->setMetaValue(old_score_meta +
"~", hit_it->getScore());
201 hit_it->setMetaValue(old_score_meta, hit_it->getScore());
203 hit_it->setScore(hit_it->getMetaValue(new_score_));
205 id.setScoreType(new_score_type_);
206 id.setHigherScoreBetter(higher_better_);
235 template<
class IDType>
238 if (
id.empty())
return;
239 String t = findScoreType(
id[0], type);
242 String msg =
"First encountered ID does not have the requested score type.";
244 OPENMS_PRETTY_FUNCTION, msg);
246 else if (t ==
id[0].getScoreType())
255 new_score_type_ = t.
chop(6);
263 if (higher_better_ != type_to_better_[type])
265 OPENMS_LOG_WARN <<
"Requested score type does not match the expected score direction. Correcting!\n";
266 higher_better_ = type_to_better_[type];
270 switchScores(i, counter);
290 for (
const auto& f : cmap)
292 const auto& ids = f.getPeptideIdentifications();
295 new_type = findScoreType(ids[0], type);
296 if (new_type == ids[0].getScoreType())
307 if (new_type.empty())
309 String msg =
"First encountered ID does not have the requested score type.";
311 OPENMS_PRETTY_FUNCTION, msg);
316 new_score_type_ = new_type.
chop(6);
320 new_score_type_ = new_type;
322 new_score_ = new_type;
324 if (higher_better_ != type_to_better_[type])
326 OPENMS_LOG_WARN <<
"Requested score type does not match the expected score direction. Correcting!\n";
327 higher_better_ = type_to_better_[type];
330 const auto switchScoresSingle = [&counter,
this](
PeptideIdentification& id){switchScores(
id,counter);};
348 const std::vector<PeptideIdentification>& pep_ids,
354 if (!pep_ids.empty())
356 name = pep_ids[0].getScoreType();
357 higher_better = pep_ids[0].isHigherScoreBetter();
360 for (
auto& [scoretype, names] : type_to_str_)
362 if (names.find(name) != names.end())
364 score_type = scoretype;
366 <<
static_cast<std::underlying_type<ScoreType>::type
>(scoretype) << std::endl;
391 bool include_unassigned =
true)
394 higher_better =
true;
397 for (
const auto& cf : cmap)
399 const auto& pep_ids = cf.getPeptideIdentifications();
400 if (!pep_ids.empty())
402 name = pep_ids[0].getScoreType();
403 higher_better = pep_ids[0].isHigherScoreBetter();
406 for (
auto& [scoretype, names] : type_to_str_)
408 if (names.find(name) != names.end())
410 score_type = scoretype;
417 if (name.empty() && include_unassigned)
421 name =
id.getScoreType();
422 higher_better =
id.isHigherScoreBetter();
425 for (
auto& [scoretype, names] : type_to_str_)
427 if (names.find(name) != names.end())
429 score_type = scoretype;
453 for (
const auto& f : cmap)
455 const auto& ids = f.getPeptideIdentifications();
458 if (new_score_ == ids[0].getScoreType())
468 const auto switchScoresSingle = [&counter,
this](
PeptideIdentification& id){switchScores(
id,counter);};
486 if (pep_ids.empty())
return;
488 if (new_score_ == pep_ids[0].getScoreType())
493 for (
auto&
id : pep_ids)
495 switchScores(
id, counter);
523 template <
typename IDType>
526 const String& curr_score_type =
id.getScoreType();
527 const std::set<String>& possible_types = type_to_str_[type];
528 if (possible_types.find(curr_score_type) != possible_types.end())
530 OPENMS_LOG_INFO <<
"Requested score type already set as main score: " + curr_score_type +
"\n";
531 return curr_score_type;
535 if (
id.getHits().empty())
537 OPENMS_LOG_WARN <<
"Identification entry used to check for alternative score was empty.\n";
540 const auto& hit =
id.getHits()[0];
541 for (
const auto& poss_str : possible_types)
543 if (hit.metaValueExists(poss_str))
547 else if (hit.metaValueExists(poss_str +
"_score"))
549 return poss_str +
"_score";
552 OPENMS_LOG_WARN <<
"Score of requested type not found in the UserParams of the checked ID object.\n";
569 bool original_score_higher_better =
true;
572 bool requested_score_higher_better = original_score_higher_better;
576 bool score_switched =
false;
608 if (requested_score_type_as_string.empty())
610 OPENMS_LOG_DEBUG <<
"No score type specified. Using main score." << std::endl;
623 param.setValue(
"proteins",
"false");
624 param.setValue(
"old_score",
"");
629 OPENMS_LOG_DEBUG <<
"Switched scores for " << counter <<
" IDs." << std::endl;
673 if (requested_score_type_as_string.empty())
675 OPENMS_LOG_DEBUG <<
"No score type specified. Using main score." << std::endl;
688 param.setValue(
"proteins",
"false");
689 param.setValue(
"old_score",
"");
693 OPENMS_LOG_DEBUG <<
"Switched scores for " << counter <<
" IDs." << std::endl;
727 param.setValue(
"proteins",
"false");
728 param.setValue(
"old_score",
"");
732 OPENMS_LOG_DEBUG <<
"Switched scores back for " << counter <<
" PSMs." << std::endl;
755 param.setValue(
"proteins",
"false");
756 param.setValue(
"old_score",
"");
760 OPENMS_LOG_DEBUG <<
"Switched scores back for " << counter <<
" PSMs." << std::endl;
769 const double tolerance_ = 1e-6;
778 std::map<ScoreType, std::set<String>> type_to_str_ =
781 {ScoreType::RAW, {
"svm",
"MS:1001492",
"XTandem",
"OMSSA",
"SEQUEST:xcorr",
"Mascot",
"mvh",
"hyperscore",
"ln(hyperscore)"}},
787 {ScoreType::RAW_EVAL, {
"expect",
"SpecEValue",
"E-Value",
"evalue",
"MS:1002053",
"MS:1002257"}},
788 {ScoreType::PP, {
"Posterior Probability"}},
789 {ScoreType::PEP, {
"Posterior Error Probability",
"pep",
"MS:1001493"}},
790 {ScoreType::FDR, {
"FDR",
"fdr",
"false discovery rate"}},
791 {ScoreType::QVAL, {
"q-value",
"qvalue",
"MS:1001491",
"q-Value",
"qval"}}
795 std::map<ScoreType, bool> type_to_better_ =
797 {ScoreType::RAW,
true},
798 {ScoreType::RAW_EVAL,
false},
799 {ScoreType::PP,
true},
800 {ScoreType::PEP,
false},
801 {ScoreType::FDR,
false},
802 {ScoreType::QVAL,
false}
#define OPENMS_LOG_DEBUG
Macro for general debugging information.
Definition: LogStream.h:454
#define OPENMS_LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged.
Definition: LogStream.h:444
#define OPENMS_LOG_INFO
Macro if a information, e.g. a status should be reported.
Definition: LogStream.h:449
A container for consensus elements.
Definition: ConsensusMap.h:66
const std::vector< PeptideIdentification > & getUnassignedPeptideIdentifications() const
non-mutable access to the unassigned peptide identifications
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:33
bool isEmpty() const
Test if the value is empty.
Definition: DataValue.h:362
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
void setParameters(const Param ¶m)
Sets the parameters.
const Param & getDefaults() const
Non-mutable access to the default parameters.
This class is used to switch identification scores within identification or consensus feature maps.
Definition: IDScoreSwitcherAlgorithm.h:40
bool score_switched
Definition: IDScoreSwitcherAlgorithm.h:576
bool requested_score_higher_better
the type of the original score
Definition: IDScoreSwitcherAlgorithm.h:572
static void switchBackScoreType(std::vector< PeptideIdentification > &pep_ids, IDSwitchResult isr)
Reverts the scoring type of peptide identifications to their original scores.
Definition: IDScoreSwitcherAlgorithm.h:746
String findScoreType(IDType &id, IDScoreSwitcherAlgorithm::ScoreType type)
Searches for a specified score type within an identification object and its meta values.
Definition: IDScoreSwitcherAlgorithm.h:524
IDScoreSwitcherAlgorithm::ScoreType original_score_type
whether a higher original score is better
Definition: IDScoreSwitcherAlgorithm.h:570
bool isScoreTypeHigherBetter(ScoreType score_type)
Determines whether a higher score type is better given a ScoreType enum.
Definition: IDScoreSwitcherAlgorithm.h:137
void determineScoreNameOrientationAndType(const ConsensusMap &cmap, String &name, bool &higher_better, ScoreType &score_type, bool include_unassigned=true)
Determines the score type and orientation of the main score in a ConsensusMap.
Definition: IDScoreSwitcherAlgorithm.h:387
void determineScoreNameOrientationAndType(const std::vector< PeptideIdentification > &pep_ids, String &name, bool &higher_better, ScoreType &score_type)
Determines the score type and orientation of the main score for a set of peptide identifications.
Definition: IDScoreSwitcherAlgorithm.h:347
void switchToGeneralScoreType(ConsensusMap &cmap, ScoreType type, Size &counter, bool unassigned_peptides_too=true)
Switches the score type of a ConsensusMap to a general score type.
Definition: IDScoreSwitcherAlgorithm.h:287
IDScoreSwitcherAlgorithm::ScoreType requested_score_type
whether a higher requested score is better
Definition: IDScoreSwitcherAlgorithm.h:573
void switchScores(IDType &id, Size &counter)
Switches the main scores of all hits in an identification object based on the new scoring settings.
Definition: IDScoreSwitcherAlgorithm.h:170
static ScoreType toScoreTypeEnum(String score_type)
Converts a string representation of a score type to a ScoreType enum.
Definition: IDScoreSwitcherAlgorithm.h:96
std::vector< String > getScoreNames()
Gets a vector of all score names that are used in OpenMS.
void switchScores(ConsensusMap &cmap, Size &counter, bool unassigned_peptides_too=true)
Switches the scores of peptide identifications in a ConsensusMap.
Definition: IDScoreSwitcherAlgorithm.h:451
String requested_score_name
the type of the requested score
Definition: IDScoreSwitcherAlgorithm.h:574
ScoreType
This is a rough hierarchy of possible score types in MS.
Definition: IDScoreSwitcherAlgorithm.h:53
@ RAW
Raw score, e.g., search engine specific scores like hyperscore.
void switchToGeneralScoreType(std::vector< IDType > &id, ScoreType type, Size &counter)
Switches the scoring type of identification objects to a general score type.
Definition: IDScoreSwitcherAlgorithm.h:236
bool original_score_higher_better
The name of the original score used before the switch.
Definition: IDScoreSwitcherAlgorithm.h:569
static IDSwitchResult switchToScoreType(std::vector< PeptideIdentification > &pep_ids, String requested_score_type_as_string)
Switches the score type of peptide identifications to the requested type.
Definition: IDScoreSwitcherAlgorithm.h:657
void updateMembers_() override
documented in base class
void switchScores(std::vector< PeptideIdentification > &pep_ids, Size &counter)
Switches the scores of peptide identifications.
Definition: IDScoreSwitcherAlgorithm.h:484
String original_score_name
Definition: IDScoreSwitcherAlgorithm.h:568
IDScoreSwitcherAlgorithm()
Default constructor. Initializes the parameter handler with default values.
static void switchBackScoreType(ConsensusMap &cmap, IDSwitchResult isr, bool include_unassigned=true)
Reverts the score type of a ConsensusMap to its original type based on the provided IDSwitchResult.
Definition: IDScoreSwitcherAlgorithm.h:718
String new_score_
will be set according to the algorithm parameters
Definition: IDScoreSwitcherAlgorithm.h:772
static IDSwitchResult switchToScoreType(ConsensusMap &cmap, String requested_score_type_as_string, bool include_unassigned=true)
Switches the score type of a ConsensusMap to the requested score type.
Definition: IDScoreSwitcherAlgorithm.h:592
bool higher_better_
will be set according to the algorithm parameters
Definition: IDScoreSwitcherAlgorithm.h:775
bool isScoreType(const String &score_name, const ScoreType &type)
Checks if the given score name corresponds to a specific score type.
Definition: IDScoreSwitcherAlgorithm.h:73
Structure holding score switching information for IDScoreSwitcherAlgorithm.
Definition: IDScoreSwitcherAlgorithm.h:566
void applyFunctionOnPeptideIDs(T &&f, bool include_unassigned=true)
applies a function on all PeptideIDs or only assigned ones
Definition: MapUtilities.h:42
void setValue(const std::string &key, const ParamValue &value, const std::string &description="", const std::vector< std::string > &tags=std::vector< std::string >())
Sets a value.
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:39
A more convenient string class.
Definition: String.h:34
String chop(Size n) const
Returns a substring where n characters were removed from the end of the string.
String & toLower()
Converts the string to lowercase.
bool hasSuffix(const String &string) const
true if String ends with string, false otherwise
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
const double c
Definition: Constants.h:188
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19