OpenMS  2.7.0
MRMFeatureSelector.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2021.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Douglas McCloskey, Pasquale Domenico Colaianni, Svetlana Kutuzova $
32 // $Authors: Douglas McCloskey, Pasquale Domenico Colaianni, Svetlana Kutuzova $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/config.h> // OPENMS_DLLAPI
41 
42 namespace OpenMS
43 {
44 
50  class OPENMS_DLLAPI MRMFeatureSelector
51  {
52 public:
53  MRMFeatureSelector() = default;
54  virtual ~MRMFeatureSelector() = default;
55 
56  enum class VariableType
57  {
58  INTEGER = 1,
59  CONTINUOUS
60  };
61 
62  enum class LambdaScore
63  {
64  LINEAR = 1,
65  INVERSE,
66  LOG,
67  INVERSE_LOG,
68  INVERSE_LOG10
69  };
70 
73 
78  {
79  SelectorParameters() = default;
80 
82  Int nn,
83  bool lw,
84  bool stg,
85  Int swl,
86  Int ssl,
88  double ot,
89  std::map<String, MRMFeatureSelector::LambdaScore>& sw
90  ) :
91  nn_threshold(nn),
92  locality_weight(lw),
93  select_transition_group(stg),
94  segment_window_length(swl),
95  segment_step_length(ssl),
96  variable_type(vt),
97  optimal_threshold(ot),
98  score_weights(sw) {}
99 
100  Int nn_threshold = 4;
101  bool locality_weight = false;
102  bool select_transition_group = true;
103  Int segment_window_length = 8;
104  Int segment_step_length = 4;
106  double optimal_threshold = 0.5;
107  std::map<String, MRMFeatureSelector::LambdaScore> score_weights;
108  };
109 
120  virtual void optimize(
121  const std::vector<std::pair<double, String>>& time_to_name,
122  const std::map<String, std::vector<Feature>>& feature_name_map,
123  std::vector<String>& result,
124  const SelectorParameters& parameters
125  ) const = 0;
126 
138  const FeatureMap& features,
139  FeatureMap& selected_filtered,
140  const SelectorParameters& parameters
141  ) const;
142 
143 protected:
156  LPWrapper& problem,
157  const String& name,
158  const bool bounded,
159  const double obj,
160  const VariableType variableType
161  ) const;
162 
173  double computeScore_(const Feature& feature, const std::map<String, LambdaScore>& score_weights) const;
174 
187  LPWrapper& problem,
188  std::vector<Int> indices,
189  std::vector<double> values,
190  const String& name,
191  const double lb,
192  const double ub,
193  const LPWrapper::Type param
194  ) const;
195 
196 private:
208  const FeatureMap& features,
209  std::vector<std::pair<double, String>>& time_to_name,
210  std::map<String, std::vector<Feature>>& feature_name_map,
211  const bool select_transition_group
212  ) const;
213 
231  double weightScore_(const double score, const LambdaScore lambda_score) const;
232 
235  };
236 
242  class OPENMS_DLLAPI MRMFeatureSelectorQMIP : public MRMFeatureSelector
243  {
244 public:
253  void optimize(
254  const std::vector<std::pair<double, String>>& time_to_name,
255  const std::map<String, std::vector<Feature>>& feature_name_map,
256  std::vector<String>& result,
257  const SelectorParameters& parameters
258  ) const override;
259  };
260 
266  class OPENMS_DLLAPI MRMFeatureSelectorScore : public MRMFeatureSelector
267  {
268 public:
277  void optimize(
278  const std::vector<std::pair<double, String>>& time_to_name,
279  const std::map<String, std::vector<Feature>>& feature_name_map,
280  std::vector<String>& result,
281  const SelectorParameters& parameters
282  ) const override;
283  };
284 
286  {
287 public:
290 
292  const FeatureMap& features,
293  std::vector<std::pair<double, String>>& time_to_name,
294  std::map<String, std::vector<Feature>>& feature_name_map,
295  const bool select_transition_group
296  ) const
297  {
298  selector_.constructTargTransList_(features, time_to_name, feature_name_map, select_transition_group);
299  }
300 
301  double weightScore_(const double score, const LambdaScore lambda_score) const
302  {
303  return selector_.weightScore_(score, lambda_score);
304  }
305 
306  double computeScore_(const Feature& feature, const std::map<String, LambdaScore>& score_weights) const
307  {
308  return selector_.computeScore_(feature, score_weights);
309  }
310 
312  {
313  return selector_.removeSpaces_(str);
314  }
315 
317  };
318 }
A container for features.
Definition: FeatureMap.h:105
An LC-MS feature.
Definition: Feature.h:72
Definition: LPWrapper.h:68
Type
Definition: LPWrapper.h:102
Definition: MRMFeatureSelector.h:243
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:267
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:286
MRMFeatureSelectorQMIP selector_
Definition: MRMFeatureSelector.h:316
double weightScore_(const double score, const LambdaScore lambda_score) const
Definition: MRMFeatureSelector.h:301
String removeSpaces_(String str) const
Definition: MRMFeatureSelector.h:311
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:291
double computeScore_(const Feature &feature, const std::map< String, LambdaScore > &score_weights) const
Definition: MRMFeatureSelector.h:306
Definition: MRMFeatureSelector.h:51
virtual ~MRMFeatureSelector()=default
void addConstraint_(LPWrapper &problem, std::vector< Int > indices, std::vector< double > values, const String &name, const double lb, const double ub, const LPWrapper::Type param) 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
LambdaScore
Definition: MRMFeatureSelector.h:63
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:57
double computeScore_(const Feature &feature, const std::map< String, LambdaScore > &score_weights) const
A more convenient string class.
Definition: String.h:61
int Int
Signed integer type.
Definition: Types.h:102
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Definition: MRMFeatureSelector.h:78
std::map< String, MRMFeatureSelector::LambdaScore > score_weights
Weights for the scores.
Definition: MRMFeatureSelector.h:107
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:81