OpenMS
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 
16 namespace OpenMS
17 {
18 
24  class OPENMS_DLLAPI MRMFeatureSelector
25  {
26 public:
27  MRMFeatureSelector() = default;
28  virtual ~MRMFeatureSelector() = default;
29 
30  enum class VariableType
31  {
32  INTEGER = 1,
33  CONTINUOUS
34  };
35 
36  enum class LambdaScore
37  {
38  LINEAR = 1,
39  INVERSE,
40  LOG,
41  INVERSE_LOG,
42  INVERSE_LOG10
43  };
44 
47 
52  {
53  SelectorParameters() = default;
54 
56  Int nn,
57  bool lw,
58  bool stg,
59  Int swl,
60  Int ssl,
62  double ot,
63  std::map<String, MRMFeatureSelector::LambdaScore>& sw
64  ) :
65  nn_threshold(nn),
66  locality_weight(lw),
67  select_transition_group(stg),
68  segment_window_length(swl),
69  segment_step_length(ssl),
70  variable_type(vt),
71  optimal_threshold(ot),
72  score_weights(sw) {}
73 
74  Int nn_threshold = 4;
75  bool locality_weight = false;
76  bool select_transition_group = true;
77  Int segment_window_length = 8;
78  Int segment_step_length = 4;
80  double optimal_threshold = 0.5;
81  std::map<String, MRMFeatureSelector::LambdaScore> score_weights;
82  };
83 
94  virtual void optimize(
95  const std::vector<std::pair<double, String>>& time_to_name,
96  const std::map<String, std::vector<Feature>>& feature_name_map,
97  std::vector<String>& result,
98  const SelectorParameters& parameters
99  ) const = 0;
100 
112  const FeatureMap& features,
113  FeatureMap& selected_filtered,
114  const SelectorParameters& parameters
115  ) const;
116 
117 protected:
130  LPWrapper& problem,
131  const String& name,
132  const bool bounded,
133  const double obj,
134  const VariableType variableType
135  ) const;
136 
147  double computeScore_(const Feature& feature, const std::map<String, LambdaScore>& score_weights) const;
148 
161  LPWrapper& problem,
162  const std::vector<Int>& indices,
163  const std::vector<double>& values,
164  const String& name,
165  const double lb,
166  const double ub,
167  const LPWrapper::Type param
168  ) const;
169 
170 private:
182  const FeatureMap& features,
183  std::vector<std::pair<double, String>>& time_to_name,
184  std::map<String, std::vector<Feature>>& feature_name_map,
185  const bool select_transition_group
186  ) const;
187 
205  double weightScore_(const double score, const LambdaScore lambda_score) const;
206 
209  };
210 
216  class OPENMS_DLLAPI MRMFeatureSelectorQMIP : public MRMFeatureSelector
217  {
218 public:
227  void optimize(
228  const std::vector<std::pair<double, String>>& time_to_name,
229  const std::map<String, std::vector<Feature>>& feature_name_map,
230  std::vector<String>& result,
231  const SelectorParameters& parameters
232  ) const override;
233  };
234 
240  class OPENMS_DLLAPI MRMFeatureSelectorScore : public MRMFeatureSelector
241  {
242 public:
251  void optimize(
252  const std::vector<std::pair<double, String>>& time_to_name,
253  const std::map<String, std::vector<Feature>>& feature_name_map,
254  std::vector<String>& result,
255  const SelectorParameters& parameters
256  ) const override;
257  };
258 
260  {
261 public:
263  ~MRMFeatureSelector_test() override = default;
264 
266  const FeatureMap& features,
267  std::vector<std::pair<double, String>>& time_to_name,
268  std::map<String, std::vector<Feature>>& feature_name_map,
269  const bool select_transition_group
270  ) const
271  {
272  selector_.constructTargTransList_(features, time_to_name, feature_name_map, select_transition_group);
273  }
274 
275  double weightScore_(const double score, const LambdaScore lambda_score) const
276  {
277  return selector_.weightScore_(score, lambda_score);
278  }
279 
280  double computeScore_(const Feature& feature, const std::map<String, LambdaScore>& score_weights) const
281  {
282  return selector_.computeScore_(feature, score_weights);
283  }
284 
286  {
287  return selector_.removeSpaces_(str);
288  }
289 
291  };
292 }
A container for features.
Definition: FeatureMap.h:80
An LC-MS feature.
Definition: Feature.h:46
Definition: LPWrapper.h:45
Type
Definition: LPWrapper.h:79
Definition: MRMFeatureSelector.h:217
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:241
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:260
MRMFeatureSelectorQMIP selector_
Definition: MRMFeatureSelector.h:290
double weightScore_(const double score, const LambdaScore lambda_score) const
Definition: MRMFeatureSelector.h:275
~MRMFeatureSelector_test() override=default
String removeSpaces_(String str) const
Definition: MRMFeatureSelector.h:285
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:265
double computeScore_(const Feature &feature, const std::map< String, LambdaScore > &score_weights) const
Definition: MRMFeatureSelector.h:280
Definition: MRMFeatureSelector.h:25
virtual ~MRMFeatureSelector()=default
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
LambdaScore
Definition: MRMFeatureSelector.h:37
void selectMRMFeature(const FeatureMap &features, FeatureMap &selected_filtered, const SelectorParameters &parameters) const
double weightScore_(const double score, const LambdaScore lambda_score) 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
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
VariableType
Definition: MRMFeatureSelector.h:31
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
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:52
std::map< String, MRMFeatureSelector::LambdaScore > score_weights
Weights for the scores.
Definition: MRMFeatureSelector.h:81
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:55