This class is used to switch identification scores within identification or consensus feature maps. More...
#include <OpenMS/ANALYSIS/ID/IDScoreSwitcherAlgorithm.h>
Classes | |
struct | IDSwitchResult |
Structure holding score switching information for IDScoreSwitcherAlgorithm. More... | |
Public Types | |
enum class | ScoreType { RAW , RAW_EVAL , PP , PEP , FDR , QVAL } |
This is a rough hierarchy of possible score types in MS. More... | |
Public Member Functions | |
IDScoreSwitcherAlgorithm () | |
Default constructor. Initializes the parameter handler with default values. More... | |
bool | isScoreType (const String &score_name, const ScoreType &type) |
Checks if the given score name corresponds to a specific score type. More... | |
bool | isScoreTypeHigherBetter (ScoreType score_type) |
Determines whether a higher score type is better given a ScoreType enum. More... | |
std::vector< String > | getScoreNames () |
Gets a vector of all score names that are used in OpenMS. More... | |
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) |
Switches the score type of a ConsensusMap to a general score type. More... | |
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. More... | |
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. More... | |
void | switchScores (ConsensusMap &cmap, Size &counter, bool unassigned_peptides_too=true) |
Switches the scores of peptide identifications in a ConsensusMap. More... | |
void | switchScores (std::vector< PeptideIdentification > &pep_ids, Size &counter) |
Switches the scores of peptide identifications. More... | |
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... | |
![]() | |
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... | |
DefaultParamHandler & | operator= (const DefaultParamHandler &rhs) |
Assignment operator. More... | |
virtual bool | operator== (const DefaultParamHandler &rhs) const |
Equality operator. More... | |
void | setParameters (const Param ¶m) |
Sets the parameters. More... | |
const Param & | getParameters () const |
Non-mutable access to the parameters. More... | |
const Param & | getDefaults () const |
Non-mutable access to the default parameters. More... | |
const String & | getName () 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 | toScoreTypeEnum (String score_type) |
Converts a string representation of a score type to a ScoreType enum. More... | |
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. More... | |
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. More... | |
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. More... | |
static void | switchBackScoreType (std::vector< PeptideIdentification > &pep_ids, IDSwitchResult isr) |
Reverts the scoring type of peptide identifications to their original scores. More... | |
![]() | |
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 |
documented in base class 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 | |
![]() | |
void | defaultsToParam_ () |
Updates the parameters after the defaults have been set in the constructor. More... | |
![]() | |
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< String > | subsections_ |
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... | |
This class is used to switch identification scores within identification or consensus feature maps.
This class provides functionality to switch the main scoring type used in peptide or protein identification data. It supports switching between different score types, such as raw scores, E-values, posterior probabilities, posterior error probabilities, FDR, and q-values. The class also handles the direction of the score (whether a higher score is better) and can store the original scores as meta values to prevent data loss.
The score switching process is configurable through parameters that specify the score types, as well as the desired score direction and how old scores are annotated in the meta information.
The class can operate on individual identification objects or ConsensusMaps, updating the main scores of all hits based on the specified criteria.
struct OpenMS::IDScoreSwitcherAlgorithm::IDSwitchResult |
Structure holding score switching information for IDScoreSwitcherAlgorithm.
This structure contains both the original and requested score details, including score names, their orientation (whether higher scores are better), and score types before and after the switch. It also includes a flag to indicate if the main score has been switched. Used to switch back to the original score if needed.
Class Members | ||
---|---|---|
bool | original_score_higher_better | The name of the original score used before the switch. |
String | original_score_name | |
ScoreType | original_score_type | whether a higher original score is better |
bool | requested_score_higher_better | the type of the original score |
String | requested_score_name | the type of the requested score |
ScoreType | requested_score_type | whether a higher requested score is better |
bool | score_switched |
|
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.
Default constructor. Initializes the parameter handler with default values.
|
inline |
Determines the score type and orientation of the main score in a ConsensusMap.
This static method inspects a ConsensusMap to determine the overall score type and whether a higher score is considered better. It iterates through the ConsensusMap's features and uses the first PeptideIdentification found to determine the score type and orientation. If no assigned peptide identifications are found, it optionally considers unassigned peptide identifications.
cmap | The ConsensusMap to inspect. |
name | Output parameter to store the determined overall score type. |
higher_better | Output parameter to store whether a higher score is considered better. |
score_type | Output parameter to store the determined score type. |
include_unassigned | If true, unassigned peptide identifications are considered if no assigned ones are found. Default is true. |
References ConsensusMap::getUnassignedPeptideIdentifications().
|
inline |
Determines the score type and orientation of the main score for a set of peptide identifications.
This static method inspects a vector of PeptideIdentification objects to determine the overall score type and whether a higher score is considered better. It uses the first PeptideIdentification in the vector to make this determination, assuming that all identifications in the vector have the same score type and orientation.
pep_ids | The vector of PeptideIdentification objects to inspect. |
name | Output parameter to store the determined overall score type. |
higher_better | Output parameter to store whether a higher score is considered better. |
score_type | Output parameter to store the determined score type. |
References OPENMS_LOG_INFO.
Referenced by IDScoreSwitcherAlgorithm::switchToScoreType().
|
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.
IDType | The type of the identification object, which must support getScoreType(), getHits(), and meta value operations. |
[in] | id | The 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] | type | The ScoreType to search for, defined in IDScoreSwitcherAlgorithm . This type specifies the score of interest. |
id
for meta values. References OPENMS_LOG_INFO, and OPENMS_LOG_WARN.
Referenced by IDFilter::filterHitsByScore().
std::vector<String> getScoreNames | ( | ) |
Checks if the given score name corresponds to a specific score type.
This method determines if a given score name, typically derived from an identification object or meta value, matches a specified ScoreType. It performs a case-insensitive comparison and optionally removes the "_score" suffix if present.
score_name | The name of the score to check. |
type | The ScoreType to compare against. |
References String::chop(), and String::hasSuffix().
Referenced by IDFilter::filterHitsByScore().
|
inline |
Determines whether a higher score type is better given a ScoreType enum.
score_type | The score type to check. |
Referenced by IDFilter::filterHitsByScore(), and IDScoreSwitcherAlgorithm::switchToScoreType().
|
inlinestatic |
Reverts the score type of a ConsensusMap to its original type based on the provided IDSwitchResult.
This function checks if the scores have been switched and, if so, it switches them back to the original score type. It updates the ConsensusMap by switching the scores, optionally including unassigned PSMs.
cmap | The ConsensusMap object whose scores will be modified. |
isr | The IDSwitchResult containing information about the score switch. |
include_unassigned | A boolean flag indicating whether to include unassigned PSMs in the score switching process. Defaults to true. |
References DefaultParamHandler::getDefaults(), OPENMS_LOG_DEBUG, IDScoreSwitcherAlgorithm::IDSwitchResult::original_score_higher_better, IDScoreSwitcherAlgorithm::IDSwitchResult::original_score_name, IDScoreSwitcherAlgorithm::IDSwitchResult::score_switched, DefaultParamHandler::setParameters(), Param::setValue(), and IDScoreSwitcherAlgorithm::switchScores().
|
inlinestatic |
Reverts the scoring type of peptide identifications to their original scores.
This function checks if the scores have been switched. If so, it restores the original scoring parameters using the provided IDSwitchResult. It updates the peptide identifications accordingly and logs the number of PSMs (Peptide-Spectrum Matches) that were reverted.
pep_ids | A vector of PeptideIdentification objects to be updated. |
isr | An IDSwitchResult object containing information about the score switch state and original score details. |
References DefaultParamHandler::getDefaults(), OPENMS_LOG_DEBUG, IDScoreSwitcherAlgorithm::IDSwitchResult::original_score_higher_better, IDScoreSwitcherAlgorithm::IDSwitchResult::original_score_name, IDScoreSwitcherAlgorithm::IDSwitchResult::score_switched, DefaultParamHandler::setParameters(), Param::setValue(), and IDScoreSwitcherAlgorithm::switchScores().
|
inline |
Switches the scores of peptide identifications in a ConsensusMap.
This function iterates over all peptide identifications in the given ConsensusMap and switches their scores using the switchScores function. It also increments the provided counter for each peptide identification processed. Score names are taken from the algorithm's parameters. If the requested score is already set as the main score, the function returns without making any changes.
cmap | The ConsensusMap containing peptide identifications whose scores need to be switched. |
counter | A reference to a counter that will be incremented for each peptide identification processed. |
unassigned_peptides_too | A boolean flag indicating whether to include unassigned peptides in the score switching process. Default is true. |
References MapUtilities< MapType >::applyFunctionOnPeptideIDs().
|
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.
IDType | The type of the identification object, which must support getHits(), getScoreType(), setScoreType(), and setHigherScoreBetter() methods, along with the ability to handle meta values. |
[in,out] | id | An 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] | counter | A reference to a Size variable that counts the number of hits processed. |
Exception::MissingInformation | If a required meta value (specified as the new score) is not found in any of the hits, indicating incomplete or incorrect score setup. |
References DataValue::isEmpty().
Referenced by IDScoreSwitcherAlgorithm::switchBackScoreType().
|
inline |
Switches the scores of peptide identifications.
This function iterates over all peptide identifications and switches their scores using the switchScores function. It also increments the provided counter for each peptide identification processed. Score names are taken from the algorithm's parameters. If the requested score is already set as the main score, the function returns without making any changes.
pep_ids | The peptide identifications whose scores need to be switched. |
counter | A reference to a counter that will be incremented for each peptide identification processed. |
|
inline |
Switches the score type of a ConsensusMap to a general score type.
Looks at the first Hit of the given ConsensusMap and according to the given score type, deduces a fitting score and score direction to be switched to. Then tries to switch all hits.
cmap | The ConsensusMap containing peptide identifications whose scores need to be switched. |
type | The desired general score type to switch to. |
counter | A reference to a counter that will be incremented for each peptide identification processed. |
unassigned_peptides_too | A boolean flag indicating whether to include unassigned peptides in the score switching process. Default is true. |
Exception::MissingInformation | If the first encountered ID does not have the requested score type. |
References MapUtilities< MapType >::applyFunctionOnPeptideIDs(), String::chop(), String::hasSuffix(), and OPENMS_LOG_WARN.
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.
IDType | The type of the identification objects contained in the vector. Must have getScoreType() and other relevant methods for score manipulation. |
[in,out] | id | A vector of identification objects whose score types are to be switched. |
[in] | type | The 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] | counter | A 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. |
Exception::MissingInformation | If the first identification object in the vector does not have the requested score type, indicating that the operation cannot proceed. |
References String::chop(), String::hasSuffix(), and OPENMS_LOG_WARN.
Referenced by IDScoreSwitcherAlgorithm::switchToScoreType().
|
inlinestatic |
Switches the score type of a ConsensusMap to the requested score type.
This static method updates the scores within the provided ConsensusMap to the specified score type. It determines the original score properties, checks if a switch is necessary based on the requested score type, and performs the switch if required.
cmap | The ConsensusMap object whose score types are to be switched. |
requested_score_type_as_string | The desired score type as a string (e.g., "RAW", "PEP", "q-value"). |
include_unassigned | Optional flag indicating whether to include unassigned IDs in the score switch. Defaults to true. |
References IDScoreSwitcherAlgorithm::determineScoreNameOrientationAndType(), DefaultParamHandler::getDefaults(), IDScoreSwitcherAlgorithm::isScoreTypeHigherBetter(), OPENMS_LOG_DEBUG, IDScoreSwitcherAlgorithm::IDSwitchResult::original_score_higher_better, IDScoreSwitcherAlgorithm::IDSwitchResult::original_score_name, IDScoreSwitcherAlgorithm::IDSwitchResult::original_score_type, IDScoreSwitcherAlgorithm::IDSwitchResult::requested_score_higher_better, IDScoreSwitcherAlgorithm::IDSwitchResult::requested_score_name, IDScoreSwitcherAlgorithm::IDSwitchResult::requested_score_type, IDScoreSwitcherAlgorithm::IDSwitchResult::score_switched, DefaultParamHandler::setParameters(), Param::setValue(), IDScoreSwitcherAlgorithm::switchToGeneralScoreType(), and IDScoreSwitcherAlgorithm::toScoreTypeEnum().
|
inlinestatic |
Switches the score type of peptide identifications to the requested type.
This static function modifies the provided vector of PeptideIdentification objects by switching their main score to the specified type. If no score type is requested, the original main score is retained. The function determines the original score's name, orientation, and type, and updates these attributes based on the requested score type. If a different score type is requested, it performs the switch and updates the relevant score information.
pep_ids | A vector of PeptideIdentification objects to be processed. |
requested_score_type_as_string | The desired score type as a string (e.g., "RAW", "PEP", "q-value"). |
References IDScoreSwitcherAlgorithm::determineScoreNameOrientationAndType(), DefaultParamHandler::getDefaults(), IDScoreSwitcherAlgorithm::isScoreTypeHigherBetter(), OPENMS_LOG_DEBUG, IDScoreSwitcherAlgorithm::IDSwitchResult::original_score_higher_better, IDScoreSwitcherAlgorithm::IDSwitchResult::original_score_name, IDScoreSwitcherAlgorithm::IDSwitchResult::original_score_type, IDScoreSwitcherAlgorithm::IDSwitchResult::requested_score_higher_better, IDScoreSwitcherAlgorithm::IDSwitchResult::requested_score_name, IDScoreSwitcherAlgorithm::IDSwitchResult::requested_score_type, IDScoreSwitcherAlgorithm::IDSwitchResult::score_switched, DefaultParamHandler::setParameters(), Param::setValue(), IDScoreSwitcherAlgorithm::switchToGeneralScoreType(), and IDScoreSwitcherAlgorithm::toScoreTypeEnum().
Converts a string representation of a score type to a ScoreType enum.
This static method attempts to map a given string, representing a score type, to the corresponding ScoreType enum value. It handles various common representations of score types, including those with or without the "_score" suffix, and ignores case and special characters like '-', '_', and ' '.
score_type | The string representation of the score type. |
Exception::MissingInformation | If the provided score_type string does not match any known score type. |
References OpenMS::Constants::c, String::chop(), String::hasSuffix(), and String::toLower().
Referenced by IDScoreSwitcherAlgorithm::switchToScoreType().
|
overrideprivatevirtual |
documented in base class
Reimplemented from DefaultParamHandler.
|
private |
will be set according to the algorithm parameters
|
private |
will be set according to the algorithm parameters
|
private |
|
private |
|
private |
relative tolerance for score comparisons:
|
private |
a map from ScoreType to their ordering
a map from ScoreType to their names as used around OpenMS