77 String chopped = score_name;
80 chopped = chopped.
chop(6);
82 const std::set<String>& possible_types = type_to_str_.at(type);
83 return possible_types.find(chopped) != possible_types.end();
102 score_type = score_type.
chop(6);
105 score_type.erase(std::remove_if(score_type.begin(), score_type.end(),
106 [](
unsigned char c) { return c ==
'-' || c ==
'_' || c ==
' '; }),
109 const std::map<String, ScoreType> s_to_type =
111 {
"raw", ScoreType::RAW},
112 {
"rawevalue", ScoreType::RAW_EVAL},
113 {
"qvalue", ScoreType::QVAL},
114 {
"fdr", ScoreType::FDR},
115 {
"falsediscoveryrate", ScoreType::FDR},
116 {
"pep", ScoreType::PEP},
117 {
"posteriorerrorprobability", ScoreType::PEP},
118 {
"posteriorprobability", ScoreType::PP},
119 {
"pp", ScoreType::PP}
122 if (
auto it = s_to_type.find(score_type); it != s_to_type.end())
129 OPENMS_PRETTY_FUNCTION,
String(
"Unknown score type '") + score_type +
"'.");
141 return type_to_better_[score_type];
156 bool is_main_score_type =
false;
175 template <
typename IDType>
181 const String& main_score_type =
id.getScoreType();
189 else if (!
id.getHits().empty())
192 const auto& first_hit =
id.getHits()[0];
193 const std::set<String>& score_types = type_to_str_.at(score_type);
196 for (
const String& score_name : score_types)
198 if (first_hit.metaValueExists(score_name))
204 String score_name_with_suffix = score_name +
"_score";
205 if (first_hit.metaValueExists(score_name_with_suffix))
237 template <
typename IDType>
240 for (
auto hit_it =
id.getHits().begin();
241 hit_it !=
id.getHits().end(); ++hit_it, ++counter)
243 if (!hit_it->metaValueExists(new_score_))
245 std::stringstream msg;
246 msg <<
"Meta value '" << new_score_ <<
"' not found for " << *hit_it;
248 OPENMS_PRETTY_FUNCTION, msg.str());
251 const String& old_score_meta = (old_score_.empty() ?
id.getScoreType() :
253 const DataValue& dv = hit_it->getMetaValue(old_score_meta);
261 if (fabs((
double(dv) - hit_it->getScore()) * 2.0 /
262 (
double(dv) + hit_it->getScore())) > tolerance_)
264 hit_it->setMetaValue(old_score_meta +
"~", hit_it->getScore());
269 hit_it->setMetaValue(old_score_meta, hit_it->getScore());
271 hit_it->setScore(hit_it->getMetaValue(new_score_));
273 id.setScoreType(new_score_type_);
274 id.setHigherScoreBetter(higher_better_);
303 template<
class IDType>
306 if (
id.empty())
return;
308 auto sr = findScoreType(
id[0], type);
311 if (sr.is_main_score_type)
319 if (sr.score_name.empty())
321 String msg =
"First encountered ID does not have the requested score type.";
323 OPENMS_PRETTY_FUNCTION, msg);
330 new_score_type_ = t.
chop(6);
338 if (higher_better_ != type_to_better_[type])
340 OPENMS_LOG_WARN <<
"Requested score type does not match the expected score direction. Correcting!\n";
341 higher_better_ = type_to_better_[type];
345 switchScores(i, counter);
360 std::vector<PeptideIdentification>& vec = pep_ids.
getData();
361 switchToGeneralScoreType(vec, type, counter);
380 for (
const auto& f : cmap)
382 const auto& ids = f.getPeptideIdentifications();
385 auto sr = findScoreType(ids[0], type);
386 if (sr.is_main_score_type)
390 if (!sr.score_name.empty())
392 new_type = sr.score_name;
398 if (new_type.empty())
400 String msg =
"First encountered ID does not have the requested score type.";
402 OPENMS_PRETTY_FUNCTION, msg);
407 new_score_type_ = new_type.
chop(6);
411 new_score_type_ = new_type;
413 new_score_ = new_type;
415 if (higher_better_ != type_to_better_[type])
417 OPENMS_LOG_WARN <<
"Requested score type does not match the expected score direction. Correcting!\n";
418 higher_better_ = type_to_better_[type];
421 const auto switchScoresSingle = [&counter,
this](
PeptideIdentification& id){switchScores(
id,counter);};
445 if (!pep_ids.
empty())
447 name = pep_ids[0].getScoreType();
448 higher_better = pep_ids[0].isHigherScoreBetter();
451 for (
auto& [scoretype, names] : type_to_str_)
453 if (names.find(name) != names.end())
455 score_type = scoretype;
457 <<
static_cast<std::underlying_type<ScoreType>::type
>(scoretype) << std::endl;
482 bool include_unassigned =
true)
485 higher_better =
true;
488 for (
const auto& cf : cmap)
490 const auto& pep_ids = cf.getPeptideIdentifications();
491 if (!pep_ids.empty())
493 name = pep_ids[0].getScoreType();
494 higher_better = pep_ids[0].isHigherScoreBetter();
497 for (
auto& [scoretype, names] : type_to_str_)
499 if (names.find(name) != names.end())
501 score_type = scoretype;
508 if (name.empty() && include_unassigned)
512 name =
id.getScoreType();
513 higher_better =
id.isHigherScoreBetter();
516 for (
auto& [scoretype, names] : type_to_str_)
518 if (names.find(name) != names.end())
520 score_type = scoretype;
544 for (
const auto& f : cmap)
546 const auto& ids = f.getPeptideIdentifications();
549 if (new_score_ == ids[0].getScoreType())
559 const auto switchScoresSingle = [&counter,
this](
PeptideIdentification& id){switchScores(
id,counter);};
577 if (pep_ids.
empty())
return;
579 if (new_score_ == pep_ids[0].getScoreType())
584 for (
auto&
id : pep_ids)
586 switchScores(
id, counter);
603 bool original_score_higher_better =
true;
606 bool requested_score_higher_better = original_score_higher_better;
610 bool score_switched =
false;
642 if (requested_score_type_as_string.empty())
644 OPENMS_LOG_DEBUG <<
"No score type specified. Using main score." << std::endl;
657 param.setValue(
"proteins",
"false");
658 param.setValue(
"old_score",
"");
663 OPENMS_LOG_DEBUG <<
"Switched scores for " << counter <<
" IDs." << std::endl;
707 if (requested_score_type_as_string.empty())
709 OPENMS_LOG_DEBUG <<
"No score type specified. Using main score." << std::endl;
722 param.setValue(
"proteins",
"false");
723 param.setValue(
"old_score",
"");
727 OPENMS_LOG_DEBUG <<
"Switched scores for " << counter <<
" IDs." << std::endl;
761 param.setValue(
"proteins",
"false");
762 param.setValue(
"old_score",
"");
766 OPENMS_LOG_DEBUG <<
"Switched scores back for " << counter <<
" PSMs." << std::endl;
789 param.setValue(
"proteins",
"false");
790 param.setValue(
"old_score",
"");
794 OPENMS_LOG_DEBUG <<
"Switched scores back for " << counter <<
" PSMs." << std::endl;
803 const double tolerance_ = 1e-6;
812 std::map<ScoreType, std::set<String>> type_to_str_ =
815 {ScoreType::RAW, {
"svm",
"MS:1001492",
"XTandem",
"OMSSA",
"SEQUEST:xcorr",
"Mascot",
"mvh",
"hyperscore",
"ln(hyperscore)"}},
821 {ScoreType::RAW_EVAL, {
"expect",
"SpecEValue",
"E-Value",
"evalue",
"MS:1002053",
"MS:1002257"}},
822 {ScoreType::PP, {
"Posterior Probability"}},
823 {ScoreType::PEP, {
"Posterior Error Probability",
"pep",
"PEP",
"posterior_error_probability",
"MS:1001493"}},
824 {ScoreType::FDR, {
"FDR",
"fdr",
"false discovery rate"}},
825 {ScoreType::QVAL, {
"q-value",
"qvalue",
"MS:1001491",
"q-Value",
"qval"}}
829 std::map<ScoreType, bool> type_to_better_ =
831 {ScoreType::RAW,
true},
832 {ScoreType::RAW_EVAL,
false},
833 {ScoreType::PP,
true},
834 {ScoreType::PEP,
false},
835 {ScoreType::FDR,
false},
836 {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:68
const PeptideIdentificationList & 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.
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.
bool empty() const noexcept
Definition: ExposedVector.h:140
const VecMember & getData() const
read-only access to the underlying data
Definition: ExposedVector.h:328
This class is used to switch identification scores within identification or consensus feature maps.
Definition: IDScoreSwitcherAlgorithm.h:42
void switchScores(PeptideIdentificationList &pep_ids, Size &counter)
Switches the scores of peptide identifications.
Definition: IDScoreSwitcherAlgorithm.h:575
bool score_switched
Definition: IDScoreSwitcherAlgorithm.h:610
bool requested_score_higher_better
the type of the original score
Definition: IDScoreSwitcherAlgorithm.h:606
IDScoreSwitcherAlgorithm::ScoreType original_score_type
whether a higher original score is better
Definition: IDScoreSwitcherAlgorithm.h:604
bool isScoreTypeHigherBetter(ScoreType score_type)
Determines whether a higher score type is better given a ScoreType enum.
Definition: IDScoreSwitcherAlgorithm.h:139
String score_name
Name of score to use (main score name if is_main_score_type=true, meta value name if found in meta va...
Definition: IDScoreSwitcherAlgorithm.h:157
void switchToGeneralScoreType(PeptideIdentificationList &pep_ids, ScoreType type, Size &counter)
Switches the score type of a PeptideIdentificationList to a general score type.
Definition: IDScoreSwitcherAlgorithm.h:358
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:478
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:377
IDScoreSwitcherAlgorithm::ScoreType requested_score_type
whether a higher requested score is better
Definition: IDScoreSwitcherAlgorithm.h:607
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:238
static ScoreType toScoreTypeEnum(String score_type)
Converts a string representation of a score type to a ScoreType enum.
Definition: IDScoreSwitcherAlgorithm.h:98
bool is_main_score_type
True if the main score is already of the requested score type.
Definition: IDScoreSwitcherAlgorithm.h:156
std::vector< String > getScoreNames()
Gets a vector of all score names that are used in OpenMS.
bool isScoreType(const String &score_name, const ScoreType &type) const
Checks if the given score name corresponds to a specific score type.
Definition: IDScoreSwitcherAlgorithm.h:75
void switchScores(ConsensusMap &cmap, Size &counter, bool unassigned_peptides_too=true)
Switches the scores of peptide identifications in a ConsensusMap.
Definition: IDScoreSwitcherAlgorithm.h:542
String requested_score_name
the type of the requested score
Definition: IDScoreSwitcherAlgorithm.h:608
ScoreType
This is a rough hierarchy of possible score types in MS.
Definition: IDScoreSwitcherAlgorithm.h:55
@ 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:304
void determineScoreNameOrientationAndType(const PeptideIdentificationList &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:438
bool original_score_higher_better
The name of the original score used before the switch.
Definition: IDScoreSwitcherAlgorithm.h:603
void updateMembers_() override
documented in base class
String original_score_name
Definition: IDScoreSwitcherAlgorithm.h:602
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:752
ScoreSearchResult findScoreType(const IDType &id, ScoreType score_type) const
Searches for a general score type (e.g. PEP, QVAL) in an identification data structure.
Definition: IDScoreSwitcherAlgorithm.h:176
String new_score_
will be set according to the algorithm parameters
Definition: IDScoreSwitcherAlgorithm.h:806
static void switchBackScoreType(PeptideIdentificationList &pep_ids, IDSwitchResult isr)
Reverts the scoring type of peptide identifications to their original scores.
Definition: IDScoreSwitcherAlgorithm.h:780
static IDSwitchResult switchToScoreType(PeptideIdentificationList &pep_ids, String requested_score_type_as_string)
Switches the score type of peptide identifications to the requested type.
Definition: IDScoreSwitcherAlgorithm.h:691
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:626
bool higher_better_
will be set according to the algorithm parameters
Definition: IDScoreSwitcherAlgorithm.h:809
Structure holding score switching information for IDScoreSwitcherAlgorithm.
Definition: IDScoreSwitcherAlgorithm.h:600
Structure to hold score detection results for any ScoreType.
Definition: IDScoreSwitcherAlgorithm.h:155
void applyFunctionOnPeptideIDs(T &&f, bool include_unassigned=true)
applies a function on all PeptideIDs or only assigned ones
Definition: MapUtilities.h:43
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.
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
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