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<std::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<std::string, MRMFeatureSelector::LambdaScore> score_weights;
109 };
110
121 virtual void optimize(
122 const std::vector<std::pair<double, std::string>>& time_to_name,
123 const std::map<std::string, std::vector<Feature>>& feature_name_map,
124 std::vector<std::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 std::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<std::string, LambdaScore>& score_weights) const;
175
188 LPWrapper& problem,
189 const std::vector<Int>& indices,
190 const std::vector<double>& values,
191 const std::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, std::string>>& time_to_name,
211 std::map<std::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
235 std::string removeSpaces_(std::string str) const;
236 };
237
251 class OPENMS_DLLAPI MRMFeatureSelectorQMIP : public MRMFeatureSelector
252 {
253public:
271 const std::vector<std::pair<double, std::string>>& time_to_name,
272 const std::map<std::string, std::vector<Feature>>& feature_name_map,
273 std::vector<std::string>& result,
274 const SelectorParameters& parameters
275 ) const override;
276 };
277
290 class OPENMS_DLLAPI MRMFeatureSelectorScore : public MRMFeatureSelector
291 {
292public:
310 const std::vector<std::pair<double, std::string>>& time_to_name,
311 const std::map<std::string, std::vector<Feature>>& feature_name_map,
312 std::vector<std::string>& result,
313 const SelectorParameters& parameters
314 ) const override;
315 };
316
318 {
319public:
321 ~MRMFeatureSelector_test() override = default;
322
324 const FeatureMap& features,
325 std::vector<std::pair<double, std::string>>& time_to_name,
326 std::map<std::string, std::vector<Feature>>& feature_name_map,
327 const bool select_transition_group
328 ) const
329 {
330 selector_.constructTargTransList_(features, time_to_name, feature_name_map, select_transition_group);
331 }
332
333 double weightScore_(const double score, const LambdaScore lambda_score) const
334 {
335 return selector_.weightScore_(score, lambda_score);
336 }
337
338 double computeScore_(const Feature& feature, const std::map<std::string, LambdaScore>& score_weights) const
339 {
340 return selector_.computeScore_(feature, score_weights);
341 }
342
343 std::string removeSpaces_(std::string str) const
344 {
345 return selector_.removeSpaces_(str);
346 }
347
349 };
350}
A container for features.
Definition FeatureMap.h:78
An LC-MS feature.
Definition Feature.h:46
A wrapper class for linear programming (LP) solvers.
Definition LPWrapper.h:71
Type
Enumeration for variable/constraint bound types.
Definition LPWrapper.h:119
MRMFeatureSelector implementation that selects MRM features via a quadratic-programming formulation o...
Definition MRMFeatureSelector.h:252
void optimize(const std::vector< std::pair< double, std::string > > &time_to_name, const std::map< std::string, std::vector< Feature > > &feature_name_map, std::vector< std::string > &result, const SelectorParameters &parameters) const override
Build the quadratic LP problem for time_to_name and write the names of selected features to result.
MRMFeatureSelector implementation that selects MRM features via a linear program with score-weighted ...
Definition MRMFeatureSelector.h:291
void optimize(const std::vector< std::pair< double, std::string > > &time_to_name, const std::map< std::string, std::vector< Feature > > &feature_name_map, std::vector< std::string > &result, const SelectorParameters &parameters) const override
Build the linear program for time_to_name and write the names of selected features to result.
Definition MRMFeatureSelector.h:318
MRMFeatureSelectorQMIP selector_
Definition MRMFeatureSelector.h:348
double weightScore_(const double score, const LambdaScore lambda_score) const
Definition MRMFeatureSelector.h:333
std::string removeSpaces_(std::string str) const
Definition MRMFeatureSelector.h:343
void constructTargTransList_(const FeatureMap &features, std::vector< std::pair< double, std::string > > &time_to_name, std::map< std::string, std::vector< Feature > > &feature_name_map, const bool select_transition_group) const
Definition MRMFeatureSelector.h:323
~MRMFeatureSelector_test() override=default
double computeScore_(const Feature &feature, const std::map< std::string, LambdaScore > &score_weights) const
Definition MRMFeatureSelector.h:338
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
std::string removeSpaces_(std::string str) const
Removes spaces from the given string, not-in-place.
void constructTargTransList_(const FeatureMap &features, std::vector< std::pair< double, std::string > > &time_to_name, std::map< std::string, std::vector< Feature > > &feature_name_map, const bool select_transition_group) const
virtual void optimize(const std::vector< std::pair< double, std::string > > &time_to_name, const std::map< std::string, std::vector< Feature > > &feature_name_map, std::vector< std::string > &result, const SelectorParameters &parameters) const =0
void addConstraint_(LPWrapper &problem, const std::vector< Int > &indices, const std::vector< double > &values, const std::string &name, const double lb, const double ub, const LPWrapper::Type param) const
Int addVariable_(LPWrapper &problem, const std::string &name, const bool bounded, const double obj, const VariableType variableType) const
VariableType
Definition MRMFeatureSelector.h:58
double computeScore_(const Feature &feature, const std::map< std::string, LambdaScore > &score_weights) const
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< std::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< std::string, MRMFeatureSelector::LambdaScore > &sw)
Definition MRMFeatureSelector.h:82