OpenMS  2.6.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-2020.
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 
137  void selectMRMFeature(
138  const FeatureMap& features,
139  FeatureMap& selected_filtered,
140  const SelectorParameters& parameters
141  ) const;
142 
143 protected:
155  Int addVariable_(
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 
186  void addConstraint_(
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:
207  void constructTargTransList_(
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 
234  String removeSpaces_(String str) const;
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:
288  MRMFeatureSelector_test() = default;
289  ~MRMFeatureSelector_test() = default;
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 }
OpenMS::MRMFeatureSelectorQMIP
Definition: MRMFeatureSelector.h:242
OpenMS::MRMFeatureSelector_test::selector_
MRMFeatureSelectorQMIP selector_
Definition: MRMFeatureSelector.h:316
OpenMS::MRMFeatureSelectorScore
Definition: MRMFeatureSelector.h:266
OpenMS::LPWrapper::Type
Type
Definition: LPWrapper.h:101
OpenMS::MRMFeatureSelector_test::constructTargTransList_
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
OpenMS::MRMFeatureSelector_test::computeScore_
double computeScore_(const Feature &feature, const std::map< String, LambdaScore > &score_weights) const
Definition: MRMFeatureSelector.h:306
OpenMS::MRMFeatureSelector::weightScore_
double weightScore_(const double score, const LambdaScore lambda_score) const
OpenMS::String
A more convenient string class.
Definition: String.h:59
OpenMS::MRMFeatureSelector_test::MRMFeatureSelector_test
MRMFeatureSelector_test()=default
OpenMS::MRMFeatureSelector
Definition: MRMFeatureSelector.h:50
OpenMS::LPWrapper
Definition: LPWrapper.h:67
OpenMS::MRMFeatureSelector::computeScore_
double computeScore_(const Feature &feature, const std::map< String, LambdaScore > &score_weights) const
OpenMS::MRMFeatureSelector::SelectorParameters::SelectorParameters
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
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::MRMFeatureSelector_test::removeSpaces_
String removeSpaces_(String str) const
Definition: MRMFeatureSelector.h:311
OpenMS::MRMFeatureSelector::LambdaScore
LambdaScore
Definition: MRMFeatureSelector.h:62
int
OpenMS::MRMFeatureSelector::removeSpaces_
String removeSpaces_(String str) const
Removes spaces from the given string, not-in-place.
FeatureMap.h
OpenMS::MRMFeatureSelector_test::~MRMFeatureSelector_test
~MRMFeatureSelector_test()=default
OpenMS::MRMFeatureSelector::SelectorParameters::score_weights
std::map< String, MRMFeatureSelector::LambdaScore > score_weights
Weights for the scores.
Definition: MRMFeatureSelector.h:107
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:97
OpenMS::Feature
An LC-MS feature.
Definition: Feature.h:70
LPWrapper.h
OpenMS::MRMFeatureSelector::VariableType::CONTINUOUS
String.h
OpenMS::MRMFeatureSelector_test
Definition: MRMFeatureSelector.h:285
OpenMS::MRMFeatureSelector::VariableType
VariableType
Definition: MRMFeatureSelector.h:56
OpenMS::MRMFeatureSelector::SelectorParameters
Definition: MRMFeatureSelector.h:77
OpenMS::MRMFeatureSelector::constructTargTransList_
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
OpenMS::MRMFeatureSelector_test::weightScore_
double weightScore_(const double score, const LambdaScore lambda_score) const
Definition: MRMFeatureSelector.h:301