OpenMS
Loading...
Searching...
No Matches
MRMFeatureSelector.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Douglas McCloskey, Pasquale Domenico Colaianni, Svetlana Kutuzova $
6// $Authors: Douglas McCloskey, Pasquale Domenico Colaianni, Svetlana Kutuzova $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <OpenMS/config.h> // OPENMS_DLLAPI
15
16namespace OpenMS
17{
18
51 class OPENMS_DLLAPI MRMFeatureSelector
52 {
53public:
54 MRMFeatureSelector() = default;
55 virtual ~MRMFeatureSelector() = default;
56
57 enum class VariableType
58 {
59 INTEGER = 1,
60 CONTINUOUS
61 };
62
63 enum class LambdaScore
64 {
65 LINEAR = 1,
66 INVERSE,
67 LOG,
68 INVERSE_LOG,
69 INVERSE_LOG10
70 };
71
74
79 {
80 SelectorParameters() = default;
81
83 Int nn,
84 bool lw,
85 bool stg,
86 Int swl,
87 Int ssl,
89 double ot,
90 std::map<String, MRMFeatureSelector::LambdaScore>& sw
91 ) :
92 nn_threshold(nn),
93 locality_weight(lw),
94 select_transition_group(stg),
95 segment_window_length(swl),
96 segment_step_length(ssl),
97 variable_type(vt),
98 optimal_threshold(ot),
99 score_weights(sw) {}
100
101 Int nn_threshold = 4;
102 bool locality_weight = false;
103 bool select_transition_group = true;
104 Int segment_window_length = 8;
105 Int segment_step_length = 4;
106 MRMFeatureSelector::VariableType variable_type = MRMFeatureSelector::VariableType::CONTINUOUS;
107 double optimal_threshold = 0.5;
108 std::map<String, MRMFeatureSelector::LambdaScore> score_weights;
109 };
110
121 virtual void optimize(
122 const std::vector<std::pair<double, String>>& time_to_name,
123 const std::map<String, std::vector<Feature>>& feature_name_map,
124 std::vector<String>& result,
125 const SelectorParameters& parameters
126 ) const = 0;
127
139 const FeatureMap& features,
140 FeatureMap& selected_filtered,
141 const SelectorParameters& parameters
142 ) const;
143
144protected:
157 LPWrapper& problem,
158 const String& name,
159 const bool bounded,
160 const double obj,
161 const VariableType variableType
162 ) const;
163
174 double computeScore_(const Feature& feature, const std::map<String, LambdaScore>& score_weights) const;
175
188 LPWrapper& problem,
189 const std::vector<Int>& indices,
190 const std::vector<double>& values,
191 const String& name,
192 const double lb,
193 const double ub,
194 const LPWrapper::Type param
195 ) const;
196
197private:
209 const FeatureMap& features,
210 std::vector<std::pair<double, String>>& time_to_name,
211 std::map<String, std::vector<Feature>>& feature_name_map,
212 const bool select_transition_group
213 ) const;
214
232 double weightScore_(const double score, const LambdaScore lambda_score) const;
233
236 };
237
243 class OPENMS_DLLAPI MRMFeatureSelectorQMIP : public MRMFeatureSelector
244 {
245public:
255 const std::vector<std::pair<double, String>>& time_to_name,
256 const std::map<String, std::vector<Feature>>& feature_name_map,
257 std::vector<String>& result,
258 const SelectorParameters& parameters
259 ) const override;
260 };
261
267 class OPENMS_DLLAPI MRMFeatureSelectorScore : public MRMFeatureSelector
268 {
269public:
279 const std::vector<std::pair<double, String>>& time_to_name,
280 const std::map<String, std::vector<Feature>>& feature_name_map,
281 std::vector<String>& result,
282 const SelectorParameters& parameters
283 ) const override;
284 };
285
287 {
288public:
290 ~MRMFeatureSelector_test() override = default;
291
293 const FeatureMap& features,
294 std::vector<std::pair<double, String>>& time_to_name,
295 std::map<String, std::vector<Feature>>& feature_name_map,
296 const bool select_transition_group
297 ) const
298 {
299 selector_.constructTargTransList_(features, time_to_name, feature_name_map, select_transition_group);
300 }
301
302 double weightScore_(const double score, const LambdaScore lambda_score) const
303 {
304 return selector_.weightScore_(score, lambda_score);
305 }
306
307 double computeScore_(const Feature& feature, const std::map<String, LambdaScore>& score_weights) const
308 {
309 return selector_.computeScore_(feature, score_weights);
310 }
311
313 {
314 return selector_.removeSpaces_(str);
315 }
316
318 };
319}
A container for features.
Definition FeatureMap.h:82
An LC-MS feature.
Definition Feature.h:46
A wrapper class for linear programming (LP) solvers.
Definition LPWrapper.h:66
Type
Enumeration for variable/constraint bound types.
Definition LPWrapper.h:114
Definition MRMFeatureSelector.h:244
void optimize(const std::vector< std::pair< double, String > > &time_to_name, const std::map< String, std::vector< Feature > > &feature_name_map, std::vector< String > &result, const SelectorParameters &parameters) const override
Definition MRMFeatureSelector.h:268
void optimize(const std::vector< std::pair< double, String > > &time_to_name, const std::map< String, std::vector< Feature > > &feature_name_map, std::vector< String > &result, const SelectorParameters &parameters) const override
Definition MRMFeatureSelector.h:287
MRMFeatureSelectorQMIP selector_
Definition MRMFeatureSelector.h:317
double weightScore_(const double score, const LambdaScore lambda_score) const
Definition MRMFeatureSelector.h:302
void constructTargTransList_(const FeatureMap &features, std::vector< std::pair< double, String > > &time_to_name, std::map< String, std::vector< Feature > > &feature_name_map, const bool select_transition_group) const
Definition MRMFeatureSelector.h:292
~MRMFeatureSelector_test() override=default
String removeSpaces_(String str) const
Definition MRMFeatureSelector.h:312
double computeScore_(const Feature &feature, const std::map< String, LambdaScore > &score_weights) const
Definition MRMFeatureSelector.h:307
A base class for selection of MRM Features through Linear Programming optimization.
Definition MRMFeatureSelector.h:52
virtual ~MRMFeatureSelector()=default
LambdaScore
Definition MRMFeatureSelector.h:64
void selectMRMFeature(const FeatureMap &features, FeatureMap &selected_filtered, const SelectorParameters &parameters) const
double weightScore_(const double score, const LambdaScore lambda_score) const
void constructTargTransList_(const FeatureMap &features, std::vector< std::pair< double, String > > &time_to_name, std::map< String, std::vector< Feature > > &feature_name_map, const bool select_transition_group) const
String removeSpaces_(String str) const
Removes spaces from the given string, not-in-place.
Int addVariable_(LPWrapper &problem, const String &name, const bool bounded, const double obj, const VariableType variableType) const
VariableType
Definition MRMFeatureSelector.h:58
void addConstraint_(LPWrapper &problem, const std::vector< Int > &indices, const std::vector< double > &values, const String &name, const double lb, const double ub, const LPWrapper::Type param) const
double computeScore_(const Feature &feature, const std::map< String, LambdaScore > &score_weights) const
virtual void optimize(const std::vector< std::pair< double, String > > &time_to_name, const std::map< String, std::vector< Feature > > &feature_name_map, std::vector< String > &result, const SelectorParameters &parameters) const =0
A more convenient string class.
Definition String.h:34
int Int
Signed integer type.
Definition Types.h:72
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Definition MRMFeatureSelector.h:79
std::map< String, MRMFeatureSelector::LambdaScore > score_weights
Weights for the scores.
Definition MRMFeatureSelector.h:108
SelectorParameters(Int nn, bool lw, bool stg, Int swl, Int ssl, MRMFeatureSelector::VariableType vt, double ot, std::map< String, MRMFeatureSelector::LambdaScore > &sw)
Definition MRMFeatureSelector.h:82