67 return Scores::isScoreType(score_name, type);
84 return Scores::parseIDType(score_type);
95 return Scores::isHigherBetter(score_type);
110 bool is_main_score_type =
false;
129 template <
typename IdentificationType>
135 const String& main_score_type =
id.getScoreType();
143 else if (!
id.getHits().empty())
146 const auto& first_hit =
id.getHits()[0];
147 const std::set<String>& score_types = Scores::getIDNamesForType(score_type);
150 for (
const String& score_name : score_types)
152 if (first_hit.metaValueExists(score_name))
158 String score_name_with_suffix = score_name +
"_score";
159 if (first_hit.metaValueExists(score_name_with_suffix))
191 template <
typename IdentificationType>
194 for (
auto hit_it =
id.getHits().begin();
195 hit_it !=
id.getHits().end(); ++hit_it, ++counter)
197 if (!hit_it->metaValueExists(new_score_))
199 std::stringstream msg;
200 msg <<
"Meta value '" << new_score_ <<
"' not found for " << *hit_it;
202 OPENMS_PRETTY_FUNCTION, msg.str());
205 const String& old_score_meta = (old_score_.empty() ?
id.getScoreType() :
207 const DataValue& dv = hit_it->getMetaValue(old_score_meta);
215 if (fabs((
double(dv) - hit_it->getScore()) * 2.0 /
216 (
double(dv) + hit_it->getScore())) > tolerance_)
218 hit_it->setMetaValue(old_score_meta +
"~", hit_it->getScore());
223 hit_it->setMetaValue(old_score_meta, hit_it->getScore());
225 hit_it->setScore(hit_it->getMetaValue(new_score_));
227 id.setScoreType(new_score_type_);
228 id.setHigherScoreBetter(higher_better_);
257 template<
class IdentificationType>
260 if (
id.empty())
return;
262 auto sr = findScoreType(
id[0], type);
265 if (sr.is_main_score_type)
273 if (sr.score_name.empty())
275 String msg =
"First encountered ID does not have the requested score type.";
277 OPENMS_PRETTY_FUNCTION, msg);
284 new_score_type_ = t.
chop(6);
292 if (higher_better_ != Scores::isHigherBetter(type))
294 OPENMS_LOG_WARN <<
"Requested score type does not match the expected score direction. Correcting!\n";
295 higher_better_ = Scores::isHigherBetter(type);
299 switchScores(i, counter);
314 std::vector<PeptideIdentification>& vec = pep_ids.
getData();
315 switchToGeneralScoreType(vec, type, counter);
334 for (
const auto& f : cmap)
336 const auto& ids = f.getPeptideIdentifications();
339 auto sr = findScoreType(ids[0], type);
340 if (sr.is_main_score_type)
344 if (!sr.score_name.empty())
346 new_type = sr.score_name;
352 if (new_type.empty())
354 String msg =
"First encountered ID does not have the requested score type.";
356 OPENMS_PRETTY_FUNCTION, msg);
361 new_score_type_ = new_type.
chop(6);
365 new_score_type_ = new_type;
367 new_score_ = new_type;
369 if (higher_better_ != Scores::isHigherBetter(type))
371 OPENMS_LOG_WARN <<
"Requested score type does not match the expected score direction. Correcting!\n";
372 higher_better_ = Scores::isHigherBetter(type);
375 const auto switchScoresSingle = [&counter,
this](
PeptideIdentification& id){switchScores(
id,counter);};
399 if (!pep_ids.
empty())
401 name = pep_ids[0].getScoreType();
402 higher_better = pep_ids[0].isHigherScoreBetter();
405 if (Scores::findIDTypeByName(name, score_type))
408 <<
static_cast<std::underlying_type<ScoreType>::type
>(score_type) << std::endl;
431 bool include_unassigned =
true)
434 higher_better =
true;
437 for (
const auto& cf : cmap)
439 const auto& pep_ids = cf.getPeptideIdentifications();
440 if (!pep_ids.empty())
442 name = pep_ids[0].getScoreType();
443 higher_better = pep_ids[0].isHigherScoreBetter();
446 if (Scores::findIDTypeByName(name, score_type))
453 if (name.empty() && include_unassigned)
457 name =
id.getScoreType();
458 higher_better =
id.isHigherScoreBetter();
461 if (Scores::findIDTypeByName(name, score_type))
485 for (
const auto& f : cmap)
487 const auto& ids = f.getPeptideIdentifications();
490 if (new_score_ == ids[0].getScoreType())
500 const auto switchScoresSingle = [&counter,
this](
PeptideIdentification& id){switchScores(
id,counter);};
518 if (pep_ids.
empty())
return;
520 if (new_score_ == pep_ids[0].getScoreType())
525 for (
auto&
id : pep_ids)
527 switchScores(
id, counter);
544 bool original_score_higher_better =
true;
547 bool requested_score_higher_better = original_score_higher_better;
551 bool score_switched =
false;
583 if (requested_score_type_as_string.empty())
585 OPENMS_LOG_DEBUG <<
"No score type specified. Using main score." << std::endl;
590 result.
requested_score_type = IDScoreSwitcherAlgorithm::toScoreTypeEnum(requested_score_type_as_string);
598 param.setValue(
"proteins",
"false");
599 param.setValue(
"old_score",
"");
604 OPENMS_LOG_DEBUG <<
"Switched scores for " << counter <<
" IDs." << std::endl;
648 if (requested_score_type_as_string.empty())
650 OPENMS_LOG_DEBUG <<
"No score type specified. Using main score." << std::endl;
655 result.
requested_score_type = IDScoreSwitcherAlgorithm::toScoreTypeEnum(requested_score_type_as_string);
663 param.setValue(
"proteins",
"false");
664 param.setValue(
"old_score",
"");
668 OPENMS_LOG_DEBUG <<
"Switched scores for " << counter <<
" IDs." << std::endl;
702 param.setValue(
"proteins",
"false");
703 param.setValue(
"old_score",
"");
707 OPENMS_LOG_DEBUG <<
"Switched scores back for " << counter <<
" PSMs." << std::endl;
730 param.setValue(
"proteins",
"false");
731 param.setValue(
"old_score",
"");
735 OPENMS_LOG_DEBUG <<
"Switched scores back for " << counter <<
" PSMs." << std::endl;
744 const double tolerance_ = 1e-6;
#define OPENMS_LOG_DEBUG
Macro for debug information - includes file and line info.
Definition LogStream.h:558
#define OPENMS_LOG_WARN
Macro for warnings.
Definition LogStream.h:550
#define OPENMS_LOG_INFO
Macro for information/status messages.
Definition LogStream.h:554
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:34
bool isEmpty() const
Test if the value is empty.
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
const Param & getDefaults() const
Non-mutable access to the default parameters.
void setParameters(const Param ¶m)
Sets the parameters.
const VecMember & getData() const
read-only access to the underlying data
Definition ExposedVector.h:328
bool empty() const noexcept
Definition ExposedVector.h:140
This class is used to switch identification scores within identification or consensus feature maps.
Definition IDScoreSwitcherAlgorithm.h:43
void switchScores(PeptideIdentificationList &pep_ids, Size &counter)
Switches the scores of peptide identifications.
Definition IDScoreSwitcherAlgorithm.h:516
bool score_switched
Definition IDScoreSwitcherAlgorithm.h:551
bool requested_score_higher_better
the type of the original score
Definition IDScoreSwitcherAlgorithm.h:547
std::vector< String > getScoreNames()
Gets a vector of all score names that are used in OpenMS.
IDScoreSwitcherAlgorithm::ScoreType original_score_type
whether a higher original score is better
Definition IDScoreSwitcherAlgorithm.h:545
bool isScoreTypeHigherBetter(ScoreType score_type)
Determines whether a higher score type is better given a ScoreType enum.
Definition IDScoreSwitcherAlgorithm.h:93
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:111
void switchToGeneralScoreType(PeptideIdentificationList &pep_ids, ScoreType type, Size &counter)
Switches the score type of a PeptideIdentificationList to a general score type.
Definition IDScoreSwitcherAlgorithm.h:312
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:427
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:331
IDScoreSwitcherAlgorithm::ScoreType requested_score_type
whether a higher requested score is better
Definition IDScoreSwitcherAlgorithm.h:548
bool is_main_score_type
True if the main score is already of the requested score type.
Definition IDScoreSwitcherAlgorithm.h:110
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:65
void switchScores(ConsensusMap &cmap, Size &counter, bool unassigned_peptides_too=true)
Switches the scores of peptide identifications in a ConsensusMap.
Definition IDScoreSwitcherAlgorithm.h:483
String requested_score_name
the type of the requested score
Definition IDScoreSwitcherAlgorithm.h:549
ScoreSearchResult findScoreType(const IdentificationType &id, ScoreType score_type) const
Searches for a general score type (e.g. PEP, QVAL) in an identification data structure.
Definition IDScoreSwitcherAlgorithm.h:130
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:392
bool original_score_higher_better
The name of the original score used before the switch.
Definition IDScoreSwitcherAlgorithm.h:544
void updateMembers_() override
documented in base class
String original_score_name
Definition IDScoreSwitcherAlgorithm.h:543
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:693
String new_score_
will be set according to the algorithm parameters
Definition IDScoreSwitcherAlgorithm.h:747
static void switchBackScoreType(PeptideIdentificationList &pep_ids, IDSwitchResult isr)
Reverts the scoring type of peptide identifications to their original scores.
Definition IDScoreSwitcherAlgorithm.h:721
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:632
void switchScores(IdentificationType &id, Size &counter)
Switches the main scores of all hits in an identification object based on the new scoring settings.
Definition IDScoreSwitcherAlgorithm.h:192
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:567
static ScoreType toScoreTypeEnum(const String &score_type)
Converts a string representation of a score type to a ScoreType enum.
Definition IDScoreSwitcherAlgorithm.h:82
bool higher_better_
will be set according to the algorithm parameters
Definition IDScoreSwitcherAlgorithm.h:750
void switchToGeneralScoreType(std::vector< IdentificationType > &id, ScoreType type, Size &counter)
Switches the scoring type of identification objects to a general score type.
Definition IDScoreSwitcherAlgorithm.h:258
Structure holding score switching information for IDScoreSwitcherAlgorithm.
Definition IDScoreSwitcherAlgorithm.h:541
Structure to hold score detection results for any ScoreType.
Definition IDScoreSwitcherAlgorithm.h:109
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:66
IDType
Hierarchy of possible score types in MS identification.
Definition Scores.h:51
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.
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
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19