71 const std::set<String>& possible_types = type_to_str_[type];
72 return possible_types.find(score_name) != possible_types.end();
80 template <
typename IDType>
83 for (
auto hit_it =
id.getHits().begin();
84 hit_it !=
id.getHits().end(); ++hit_it, ++counter)
86 if (!hit_it->metaValueExists(new_score_))
88 std::stringstream msg;
89 msg <<
"Meta value '" << new_score_ <<
"' not found for " << *hit_it;
91 OPENMS_PRETTY_FUNCTION, msg.str());
94 const String& old_score_meta = (old_score_.empty() ?
id.getScoreType() :
96 const DataValue& dv = hit_it->getMetaValue(old_score_meta);
101 if (fabs((
double(dv) - hit_it->getScore()) * 2.0 /
102 (
double(dv) + hit_it->getScore())) > tolerance_)
104 hit_it->setMetaValue(old_score_meta +
"~", hit_it->getScore());
109 hit_it->setMetaValue(old_score_meta, hit_it->getScore());
111 hit_it->setScore(hit_it->getMetaValue(new_score_));
113 id.setScoreType(new_score_type_);
114 id.setHigherScoreBetter(higher_better_);
122 if (
id.empty())
return;
123 String t = findScoreType(
id[0], type);
126 String msg =
"First encountered ID does not have the requested score type.";
128 OPENMS_PRETTY_FUNCTION, msg);
130 else if (t ==
id[0].getScoreType())
139 new_score_type_ = t.
chop(6);
147 if (type != ScoreType::RAW && higher_better_ != type_to_better_[type])
149 OPENMS_LOG_WARN <<
"Requested non-raw score type does not match the expected score direction. Correcting!\n";
150 higher_better_ = type_to_better_[type];
154 switchScores(i, counter);
164 for (
const auto& f : cmap)
166 const auto& ids = f.getPeptideIdentifications();
169 new_type = findScoreType(ids[0], type);
170 if (new_type == ids[0].getScoreType())
181 if (new_type.empty())
183 String msg =
"First encountered ID does not have the requested score type.";
185 OPENMS_PRETTY_FUNCTION, msg);
190 new_score_type_ = new_type.
chop(6);
194 new_score_type_ = new_type;
196 new_score_ = new_type;
198 if (type != ScoreType::RAW && higher_better_ != type_to_better_[type])
200 OPENMS_LOG_WARN <<
"Requested non-raw score type does not match the expected score direction. Correcting!\n";
201 higher_better_ = type_to_better_[type];
204 const auto switchScoresSingle = [&counter,
this](
PeptideIdentification& id){switchScores(
id,counter);};
210 template <
typename IDType>
213 const String& curr_score_type =
id.getScoreType();
214 const std::set<String>& possible_types = type_to_str_[type];
215 if (possible_types.find(curr_score_type) != possible_types.end())
217 OPENMS_LOG_INFO <<
"Requested score type already set as main score: " + curr_score_type +
"\n";
218 return curr_score_type;
222 if (
id.getHits().empty())
224 OPENMS_LOG_WARN <<
"Identification entry used to check for alternative score was empty.\n";
227 const auto& hit =
id.getHits()[0];
228 for (
const auto& poss_str : possible_types)
230 if (hit.metaValueExists(poss_str))
return poss_str;
231 else if (hit.metaValueExists(poss_str +
"_score"))
return poss_str +
"_score";
233 OPENMS_LOG_WARN <<
"Score of requested type not found in the UserParams of the checked ID object.\n";
242 const double tolerance_ = 1e-6;
250 std::map<ScoreType, std::set<String>> type_to_str_ =
252 {ScoreType::RAW, {
"XTandem",
"OMSSA",
"SEQUEST:xcorr",
"Mascot",
"mvh"}},
258 {ScoreType::RAW_EVAL, {
"expect",
"SpecEValue",
"E-Value",
"evalue",
"MS:1002053",
"MS:1002257"}},
259 {ScoreType::PP, {
"Posterior Probability"}},
260 {ScoreType::PEP, {
"Posterior Error Probability",
"pep",
"MS:1001493"}},
261 {ScoreType::FDR, {
"FDR",
"fdr",
"false discovery rate"}},
262 {ScoreType::QVAL, {
"q-value",
"qvalue",
"MS:1001491",
"q-Value",
"qval"}}
266 std::map<ScoreType, bool> type_to_better_ =
268 {ScoreType::RAW,
true},
269 {ScoreType::RAW_EVAL,
false},
270 {ScoreType::PP,
true},
271 {ScoreType::PEP,
false},
272 {ScoreType::FDR,
false},
273 {ScoreType::QVAL,
false}
#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:470
#define OPENMS_LOG_INFO
Macro if a information, e.g. a status should be reported.
Definition: LogStream.h:475
A container for consensus elements.
Definition: ConsensusMap.h:92
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:59
bool isEmpty() const
Test if the value is empty.
Definition: DataValue.h:388
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
Definition: IDScoreSwitcherAlgorithm.h:50
String findScoreType(IDType &id, IDScoreSwitcherAlgorithm::ScoreType type)
finds a certain score type in an ID and its metavalues if present, otherwise returns empty string
Definition: IDScoreSwitcherAlgorithm.h:211
void switchToGeneralScoreType(ConsensusMap &cmap, ScoreType type, Size &counter, bool unassigned_peptides_too=true)
Definition: IDScoreSwitcherAlgorithm.h:161
void switchScores(IDType &id, Size &counter)
Definition: IDScoreSwitcherAlgorithm.h:81
ScoreType
Definition: IDScoreSwitcherAlgorithm.h:59
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
IDScoreSwitcherAlgorithm()
String new_score_
will be set according to the algorithm parameters
Definition: IDScoreSwitcherAlgorithm.h:245
void switchToGeneralScoreType(std::vector< PeptideIdentification > &id, ScoreType type, Size &counter)
Definition: IDScoreSwitcherAlgorithm.h:120
bool higher_better_
will be set according to the algorithm parameters
Definition: IDScoreSwitcherAlgorithm.h:247
bool isScoreType(const String &score_name, const ScoreType &type)
Checks if the given score_name is of ScoreType type.
Definition: IDScoreSwitcherAlgorithm.h:69
void applyFunctionOnPeptideIDs(T &&f, bool include_unassigned=true)
applies a function on all PeptideIDs or only assigned ones
Definition: MapUtilities.h:68
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:65
A more convenient string class.
Definition: String.h:60
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:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48