76 String chopped = score_name;
79 chopped = chopped.
chop(6);
81 const std::set<String>& possible_types = type_to_str_[type];
82 return possible_types.find(chopped) != possible_types.end();
101 score_type = score_type.
chop(6);
104 score_type.erase(std::remove_if(score_type.begin(), score_type.end(),
105 [](
unsigned char c) { return c ==
'-' || c ==
'_' || c ==
' '; }),
108 const std::map<String, ScoreType> s_to_type =
110 {
"raw", ScoreType::RAW},
111 {
"rawevalue", ScoreType::RAW_EVAL},
112 {
"qvalue", ScoreType::QVAL},
113 {
"fdr", ScoreType::FDR},
114 {
"falsediscoveryrate", ScoreType::FDR},
115 {
"pep", ScoreType::PEP},
116 {
"posteriorerrorprobability", ScoreType::PEP},
117 {
"posteriorprobabilty", ScoreType::PP},
118 {
"pp", ScoreType::PP}
121 if (
auto it = s_to_type.find(score_type); it != s_to_type.end())
128 OPENMS_PRETTY_FUNCTION,
String(
"Unknown score type '") + score_type +
"'.");
140 return type_to_better_[score_type];
170 template <
typename IDType>
173 for (
auto hit_it =
id.getHits().begin();
174 hit_it !=
id.getHits().end(); ++hit_it, ++counter)
176 if (!hit_it->metaValueExists(new_score_))
178 std::stringstream msg;
179 msg <<
"Meta value '" << new_score_ <<
"' not found for " << *hit_it;
181 OPENMS_PRETTY_FUNCTION, msg.str());
184 const String& old_score_meta = (old_score_.empty() ?
id.getScoreType() :
186 const DataValue& dv = hit_it->getMetaValue(old_score_meta);
194 if (fabs((
double(dv) - hit_it->getScore()) * 2.0 /
195 (
double(dv) + hit_it->getScore())) > tolerance_)
197 hit_it->setMetaValue(old_score_meta +
"~", hit_it->getScore());
202 hit_it->setMetaValue(old_score_meta, hit_it->getScore());
204 hit_it->setScore(hit_it->getMetaValue(new_score_));
206 id.setScoreType(new_score_type_);
207 id.setHigherScoreBetter(higher_better_);
236 template<
class IDType>
239 if (
id.empty())
return;
240 String t = findScoreType(
id[0], type);
243 String msg =
"First encountered ID does not have the requested score type.";
245 OPENMS_PRETTY_FUNCTION, msg);
247 else if (t ==
id[0].getScoreType())
256 new_score_type_ = t.
chop(6);
264 if (higher_better_ != type_to_better_[type])
266 OPENMS_LOG_WARN <<
"Requested score type does not match the expected score direction. Correcting!\n";
267 higher_better_ = type_to_better_[type];
271 switchScores(i, counter);
286 std::vector<PeptideIdentification>& vec = pep_ids.
getData();
287 switchToGeneralScoreType(vec, type, counter);
306 for (
const auto& f : cmap)
308 const auto& ids = f.getPeptideIdentifications();
311 new_type = findScoreType(ids[0], type);
312 if (new_type == ids[0].getScoreType())
323 if (new_type.empty())
325 String msg =
"First encountered ID does not have the requested score type.";
327 OPENMS_PRETTY_FUNCTION, msg);
332 new_score_type_ = new_type.
chop(6);
336 new_score_type_ = new_type;
338 new_score_ = new_type;
340 if (higher_better_ != type_to_better_[type])
342 OPENMS_LOG_WARN <<
"Requested score type does not match the expected score direction. Correcting!\n";
343 higher_better_ = type_to_better_[type];
346 const auto switchScoresSingle = [&counter,
this](
PeptideIdentification& id){switchScores(
id,counter);};
370 if (!pep_ids.
empty())
372 name = pep_ids[0].getScoreType();
373 higher_better = pep_ids[0].isHigherScoreBetter();
376 for (
auto& [scoretype, names] : type_to_str_)
378 if (names.find(name) != names.end())
380 score_type = scoretype;
382 <<
static_cast<std::underlying_type<ScoreType>::type
>(scoretype) << std::endl;
407 bool include_unassigned =
true)
410 higher_better =
true;
413 for (
const auto& cf : cmap)
415 const auto& pep_ids = cf.getPeptideIdentifications();
416 if (!pep_ids.empty())
418 name = pep_ids[0].getScoreType();
419 higher_better = pep_ids[0].isHigherScoreBetter();
422 for (
auto& [scoretype, names] : type_to_str_)
424 if (names.find(name) != names.end())
426 score_type = scoretype;
433 if (name.empty() && include_unassigned)
437 name =
id.getScoreType();
438 higher_better =
id.isHigherScoreBetter();
441 for (
auto& [scoretype, names] : type_to_str_)
443 if (names.find(name) != names.end())
445 score_type = scoretype;
469 for (
const auto& f : cmap)
471 const auto& ids = f.getPeptideIdentifications();
474 if (new_score_ == ids[0].getScoreType())
484 const auto switchScoresSingle = [&counter,
this](
PeptideIdentification& id){switchScores(
id,counter);};
502 if (pep_ids.
empty())
return;
504 if (new_score_ == pep_ids[0].getScoreType())
509 for (
auto&
id : pep_ids)
511 switchScores(
id, counter);
539 template <
typename IDType>
542 const String& curr_score_type =
id.getScoreType();
543 const std::set<String>& possible_types = type_to_str_[type];
544 if (possible_types.find(curr_score_type) != possible_types.end())
546 OPENMS_LOG_INFO <<
"Requested score type already set as main score: " + curr_score_type +
"\n";
547 return curr_score_type;
551 if (
id.getHits().empty())
553 OPENMS_LOG_WARN <<
"Identification entry used to check for alternative score was empty.\n";
556 const auto& hit =
id.getHits()[0];
557 for (
const auto& poss_str : possible_types)
559 if (hit.metaValueExists(poss_str))
563 else if (hit.metaValueExists(poss_str +
"_score"))
565 return poss_str +
"_score";
568 OPENMS_LOG_WARN <<
"Score of requested type not found in the UserParams of the checked ID object.\n";
585 bool original_score_higher_better =
true;
588 bool requested_score_higher_better = original_score_higher_better;
592 bool score_switched =
false;
624 if (requested_score_type_as_string.empty())
626 OPENMS_LOG_DEBUG <<
"No score type specified. Using main score." << std::endl;
639 param.setValue(
"proteins",
"false");
640 param.setValue(
"old_score",
"");
645 OPENMS_LOG_DEBUG <<
"Switched scores for " << counter <<
" IDs." << std::endl;
689 if (requested_score_type_as_string.empty())
691 OPENMS_LOG_DEBUG <<
"No score type specified. Using main score." << std::endl;
704 param.setValue(
"proteins",
"false");
705 param.setValue(
"old_score",
"");
709 OPENMS_LOG_DEBUG <<
"Switched scores for " << counter <<
" IDs." << std::endl;
743 param.setValue(
"proteins",
"false");
744 param.setValue(
"old_score",
"");
748 OPENMS_LOG_DEBUG <<
"Switched scores back for " << counter <<
" PSMs." << std::endl;
771 param.setValue(
"proteins",
"false");
772 param.setValue(
"old_score",
"");
776 OPENMS_LOG_DEBUG <<
"Switched scores back for " << counter <<
" PSMs." << std::endl;
785 const double tolerance_ = 1e-6;
794 std::map<ScoreType, std::set<String>> type_to_str_ =
797 {ScoreType::RAW, {
"svm",
"MS:1001492",
"XTandem",
"OMSSA",
"SEQUEST:xcorr",
"Mascot",
"mvh",
"hyperscore",
"ln(hyperscore)"}},
803 {ScoreType::RAW_EVAL, {
"expect",
"SpecEValue",
"E-Value",
"evalue",
"MS:1002053",
"MS:1002257"}},
804 {ScoreType::PP, {
"Posterior Probability"}},
805 {ScoreType::PEP, {
"Posterior Error Probability",
"pep",
"MS:1001493"}},
806 {ScoreType::FDR, {
"FDR",
"fdr",
"false discovery rate"}},
807 {ScoreType::QVAL, {
"q-value",
"qvalue",
"MS:1001491",
"q-Value",
"qval"}}
811 std::map<ScoreType, bool> type_to_better_ =
813 {ScoreType::RAW,
true},
814 {ScoreType::RAW_EVAL,
false},
815 {ScoreType::PP,
true},
816 {ScoreType::PEP,
false},
817 {ScoreType::FDR,
false},
818 {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.
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.
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:41
void switchScores(PeptideIdentificationList &pep_ids, Size &counter)
Switches the scores of peptide identifications.
Definition: IDScoreSwitcherAlgorithm.h:500
bool score_switched
Definition: IDScoreSwitcherAlgorithm.h:592
bool requested_score_higher_better
the type of the original score
Definition: IDScoreSwitcherAlgorithm.h:588
String findScoreType(IDType &id, IDScoreSwitcherAlgorithm::ScoreType type)
Searches for a specified score type within an identification object and its meta values.
Definition: IDScoreSwitcherAlgorithm.h:540
IDScoreSwitcherAlgorithm::ScoreType original_score_type
whether a higher original score is better
Definition: IDScoreSwitcherAlgorithm.h:586
bool isScoreTypeHigherBetter(ScoreType score_type)
Determines whether a higher score type is better given a ScoreType enum.
Definition: IDScoreSwitcherAlgorithm.h:138
void switchToGeneralScoreType(PeptideIdentificationList &pep_ids, ScoreType type, Size &counter)
Switches the score type of a PeptideIdentificationList to a general score type.
Definition: IDScoreSwitcherAlgorithm.h:284
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:403
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:303
IDScoreSwitcherAlgorithm::ScoreType requested_score_type
whether a higher requested score is better
Definition: IDScoreSwitcherAlgorithm.h:589
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:171
static ScoreType toScoreTypeEnum(String score_type)
Converts a string representation of a score type to a ScoreType enum.
Definition: IDScoreSwitcherAlgorithm.h:97
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:467
String requested_score_name
the type of the requested score
Definition: IDScoreSwitcherAlgorithm.h:590
ScoreType
This is a rough hierarchy of possible score types in MS.
Definition: IDScoreSwitcherAlgorithm.h:54
@ 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:237
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:363
bool original_score_higher_better
The name of the original score used before the switch.
Definition: IDScoreSwitcherAlgorithm.h:585
void updateMembers_() override
documented in base class
String original_score_name
Definition: IDScoreSwitcherAlgorithm.h:584
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:734
String new_score_
will be set according to the algorithm parameters
Definition: IDScoreSwitcherAlgorithm.h:788
static void switchBackScoreType(PeptideIdentificationList &pep_ids, IDSwitchResult isr)
Reverts the scoring type of peptide identifications to their original scores.
Definition: IDScoreSwitcherAlgorithm.h:762
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:673
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:608
bool higher_better_
will be set according to the algorithm parameters
Definition: IDScoreSwitcherAlgorithm.h:791
bool isScoreType(const String &score_name, const ScoreType &type)
Checks if the given score name corresponds to a specific score type.
Definition: IDScoreSwitcherAlgorithm.h:74
Structure holding score switching information for IDScoreSwitcherAlgorithm.
Definition: IDScoreSwitcherAlgorithm.h:582
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