OpenMS
IDScoreSwitcherAlgorithm Class Reference

#include <OpenMS/ANALYSIS/ID/IDScoreSwitcherAlgorithm.h>

Inheritance diagram for IDScoreSwitcherAlgorithm:
[legend]
Collaboration diagram for IDScoreSwitcherAlgorithm:
[legend]

Public Types

enum class  ScoreType {
  RAW , RAW_EVAL , PP , PEP ,
  FDR , QVAL
}
 

Public Member Functions

 IDScoreSwitcherAlgorithm ()
 
bool isScoreType (const String &score_name, const ScoreType &type)
 Checks if the given score_name is of ScoreType type. More...
 
bool isScoreTypeHigherBetter (ScoreType score_type)
 Determines whether a higher score type is better given a ScoreType enum. More...
 
std::vector< StringgetScoreTypeNames ()
 
template<typename IDType >
void switchScores (IDType &id, Size &counter)
 Switches the main scores of all hits in an identification object based on the new scoring settings. More...
 
template<class IDType >
void switchToGeneralScoreType (std::vector< IDType > &id, ScoreType type, Size &counter)
 Switches the scoring type of identification objects to a general score type. More...
 
void switchToGeneralScoreType (ConsensusMap &cmap, ScoreType type, Size &counter, bool unassigned_peptides_too=true)
 
template<typename IDType >
String findScoreType (IDType &id, IDScoreSwitcherAlgorithm::ScoreType type)
 Searches for a specified score type within an identification object and its meta values. More...
 
- Public Member Functions inherited from DefaultParamHandler
 DefaultParamHandler (const String &name)
 Constructor with name that is displayed in error messages. More...
 
 DefaultParamHandler (const DefaultParamHandler &rhs)
 Copy constructor. More...
 
virtual ~DefaultParamHandler ()
 Destructor. More...
 
DefaultParamHandleroperator= (const DefaultParamHandler &rhs)
 Assignment operator. More...
 
virtual bool operator== (const DefaultParamHandler &rhs) const
 Equality operator. More...
 
void setParameters (const Param &param)
 Sets the parameters. More...
 
const ParamgetParameters () const
 Non-mutable access to the parameters. More...
 
const ParamgetDefaults () const
 Non-mutable access to the default parameters. More...
 
const StringgetName () const
 Non-mutable access to the name. More...
 
void setName (const String &name)
 Mutable access to the name. More...
 
const std::vector< String > & getSubsections () const
 Non-mutable access to the registered subsections. More...
 

Static Public Member Functions

static ScoreType getScoreType (String score_type)
 Gets a ScoreType enum from a given score name score_name. More...
 
- Static Public Member Functions inherited from DefaultParamHandler
static void writeParametersToMetaValues (const Param &write_this, MetaInfoInterface &write_here, const String &key_prefix="")
 Writes all parameters to meta values. More...
 

Private Member Functions

void updateMembers_ () override
 This method is used to update extra member variables at the end of the setParameters() method. More...
 

Private Attributes

const double tolerance_ = 1e-6
 relative tolerance for score comparisons: More...
 
String new_score_
 will be set according to the algorithm parameters More...
 
String new_score_type_
 
String old_score_
 
bool higher_better_
 will be set according to the algorithm parameters More...
 
std::map< ScoreType, std::set< String > > type_to_str_
 a map from ScoreType to their names as used around OpenMS More...
 
std::map< ScoreType, bool > type_to_better_
 a map from ScoreType to their ordering More...
 

Additional Inherited Members

- Protected Member Functions inherited from DefaultParamHandler
void defaultsToParam_ ()
 Updates the parameters after the defaults have been set in the constructor. More...
 
- Protected Attributes inherited from DefaultParamHandler
Param param_
 Container for current parameters. More...
 
Param defaults_
 Container for default parameters. This member should be filled in the constructor of derived classes! More...
 
std::vector< Stringsubsections_
 Container for registered subsections. This member should be filled in the constructor of derived classes! More...
 
String error_name_
 Name that is displayed in error messages during the parameter checking. More...
 
bool check_defaults_
 If this member is set to false no checking if parameters in done;. More...
 
bool warn_empty_defaults_
 If this member is set to false no warning is emitted when defaults are empty;. More...
 

Member Enumeration Documentation

◆ ScoreType

enum ScoreType
strong

This is a rough hierarchy of possible score types in MS In an ideal case this should be reimplemented to follow ontology hierarchies as soon as e.g. MS-OBO is complete and we switched the Metavalues to CV terms.

Enumerator
RAW 
RAW_EVAL 
PP 
PEP 
FDR 
QVAL 

Constructor & Destructor Documentation

◆ IDScoreSwitcherAlgorithm()

Member Function Documentation

◆ findScoreType()

String findScoreType ( IDType &  id,
IDScoreSwitcherAlgorithm::ScoreType  type 
)
inline

Searches for a specified score type within an identification object and its meta values.

This method attempts to find a given score type in the main score type of an identification object (id) or within its hits' meta values. It first checks if the current main score type of id matches any of the possible score types for the specified type. If not found, it iterates through the meta values of the first hit in id looking for a match. If the score type or a related meta value is found, it is returned as a String. Otherwise, an empty String is returned, indicating the score type is not present.

Template Parameters
IDTypeThe type of the identification object, which must support getScoreType(), getHits(), and meta value operations.
Parameters
[in]idThe identification object to search for the score type. It is expected to have a main score type and possibly additional scores stored as meta values in its hits.
[in]typeThe ScoreType to search for, defined in IDScoreSwitcherAlgorithm. This type specifies the score of interest.
Returns
A String representing the found score type. If the score type is not found, an empty String is returned.
Note
This method logs an informational message if the requested score type is already set as the main score, a warning if the identification entry is empty, and another warning if the score type is not found in the UserParams of the checked ID object. It only checks the first hit of the id for meta values.

References OPENMS_LOG_INFO, and OPENMS_LOG_WARN.

Referenced by IDFilter::filterHitsByScore().

◆ getScoreType()

static ScoreType getScoreType ( String  score_type)
inlinestatic

Gets a ScoreType enum from a given score name score_name.

References OpenMS::Constants::c, String::chop(), String::hasSuffix(), and String::toLower().

◆ getScoreTypeNames()

std::vector<String> getScoreTypeNames ( )

◆ isScoreType()

bool isScoreType ( const String score_name,
const ScoreType type 
)
inline

Checks if the given score_name is of ScoreType type.

References String::chop(), and String::hasSuffix().

Referenced by IDFilter::filterHitsByScore().

◆ isScoreTypeHigherBetter()

bool isScoreTypeHigherBetter ( ScoreType  score_type)
inline

Determines whether a higher score type is better given a ScoreType enum.

Parameters
score_typeThe score type to check.
Returns
True if a higher score type is better, false otherwise.

Referenced by IDFilter::filterHitsByScore().

◆ switchScores()

void switchScores ( IDType &  id,
Size counter 
)
inline

Switches the main scores of all hits in an identification object based on the new scoring settings.

This method iterates through all hits in the provided identification object and updates their main scores according to the new scoring settings defined in the switcher class's parameter object. If the old and new score types share the same name (e.g., "q-value"), the method safeguards the original scores by storing them as meta values with a "~" appended to the old score type. This prevents overwriting the meta value of the new score.

Template Parameters
IDTypeThe type of the identification object, which must support getHits(), getScoreType(), setScoreType(), and setHigherScoreBetter() methods, along with the ability to handle meta values.
Parameters
[in,out]idAn identification object containing hits whose scores are to be switched. The object will be modified in place, with updated scores and score type.
[in,out]counterA reference to a Size variable that counts the number of hits processed.
Exceptions
Exception::MissingInformationIf a required meta value (specified as the new score) is not found in any of the hits, indicating incomplete or incorrect score setup.
Note
The method assumes that the identification object's hits are properly initialized with all necessary meta values. It also relies on the tolerance_ value to determine significant differences between scores.

References DataValue::isEmpty().

◆ switchToGeneralScoreType() [1/2]

void switchToGeneralScoreType ( ConsensusMap cmap,
ScoreType  type,
Size counter,
bool  unassigned_peptides_too = true 
)
inline

Looks at the first Hit of the given id and according to the given type , deduces a fitting score and score direction to be switched to. Then tries to switch all hits.

References MapUtilities< MapType >::applyFunctionOnPeptideIDs(), String::chop(), String::hasSuffix(), and OPENMS_LOG_WARN.

◆ switchToGeneralScoreType() [2/2]

void switchToGeneralScoreType ( std::vector< IDType > &  id,
ScoreType  type,
Size counter 
)
inline

Switches the scoring type of identification objects to a general score type.

This method iterates over a vector of identification objects and changes their scoring type to a specified general score type. It first checks the score type of the first identification object in the vector to determine the necessary conversion. If the first ID does not have the requested score type, an exception is thrown. The method also adjusts the score direction (higher_better_) based on the specified score type if it's different from the raw score.

Template Parameters
IDTypeThe type of the identification objects contained in the vector. Must have getScoreType() and other relevant methods for score manipulation.
Parameters
[in,out]idA vector of identification objects whose score types are to be switched.
[in]typeThe desired general score type to switch to. This could be an enum or similar representing different scoring systems (e.g., RAW, LOG, etc.).
[in,out]counterA reference to a Size variable that may be used to count certain operations or changes made by this method. The exact usage depends on the implementation details and needs.
Exceptions
Exception::MissingInformationIf the first identification object in the vector does not have the requested score type, indicating that the operation cannot proceed.
Note
The method assumes that if the first identification object has the correct score type, all subsequent objects in the vector also have the correct score type. This assumption might need validation depending on the use case.

References String::chop(), String::hasSuffix(), and OPENMS_LOG_WARN.

◆ updateMembers_()

void updateMembers_ ( )
overrideprivatevirtual

This method is used to update extra member variables at the end of the setParameters() method.

Also call it at the end of the derived classes' copy constructor and assignment operator.

The default implementation is empty.

Reimplemented from DefaultParamHandler.

Member Data Documentation

◆ higher_better_

bool higher_better_
private

will be set according to the algorithm parameters

◆ new_score_

String new_score_
private

will be set according to the algorithm parameters

◆ new_score_type_

String new_score_type_
private

◆ old_score_

String old_score_
private

◆ tolerance_

const double tolerance_ = 1e-6
private

relative tolerance for score comparisons:

◆ type_to_better_

◆ type_to_str_

std::map<ScoreType, std::set<String> > type_to_str_
private
Initial value:
=
{
{ScoreType::RAW, {"svm", "MS:1001492", "XTandem", "OMSSA", "SEQUEST:xcorr", "Mascot", "mvh", "hyperscore", "ln(hyperscore)"}},
{ScoreType::RAW_EVAL, {"expect", "SpecEValue", "E-Value", "evalue", "MS:1002053", "MS:1002257"}},
{ScoreType::PP, {"Posterior Probability"}},
{ScoreType::PEP, {"Posterior Error Probability", "pep", "MS:1001493"}},
{ScoreType::FDR, {"FDR", "fdr", "false discovery rate"}},
{ScoreType::QVAL, {"q-value", "qvalue", "MS:1001491", "q-Value", "qval"}}
}

a map from ScoreType to their names as used around OpenMS