OpenMS  2.6.0
PSLPFormulation.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: Timo Sachsenberg $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
40 
43 
44 //#define DEBUG_OPS
45 namespace OpenMS
46 {
47  class PrecursorIonSelectionPreprocessing;
48  class PSProteinInference;
49 
55  class OPENMS_DLLAPI PSLPFormulation :
56  public DefaultParamHandler
57  {
58 
59 
60 
61 public:
62 
64 
65  ~PSLPFormulation() override;
66 
70  struct IndexTriple
71  {
76  double signal_weight;
78  };
79 
80 
92  void createAndSolveILPForKnownLCMSMapFeatureBased(const FeatureMap& features,
93  const PeakMap& experiment,
94  std::vector<IndexTriple>& variable_indices,
95  std::vector<std::vector<std::pair<Size, Size> > >& mass_ranges,
96  std::set<Int>& charges_set, UInt ms2_spectra_per_rt_bin,
97  std::vector<int>& solution_indices);
98 
103  void createAndSolveILPForInclusionListCreation(PrecursorIonSelectionPreprocessing& preprocessing,
104  UInt ms2_spectra_per_rt_bin, UInt max_list_size,
105  FeatureMap& precursors,
106  bool solve_ILP = true);
107 
108  void createAndSolveCombinedLPForKnownLCMSMapFeatureBased(const FeatureMap& features,
109  const PeakMap& experiment,
110  std::vector<IndexTriple>& variable_indices,
111  std::vector<int>& solution_indices,
112  std::vector<std::vector<std::pair<Size, Size> > >& mass_ranges,
113  std::set<Int>& charges_set, UInt ms2_spectra_per_rt_bin,
114  Size step_size = 0, bool sequential_order = false);
115 
116  void updateStepSizeConstraint(Size iteration, UInt step_size);
117  void updateFeatureILPVariables(FeatureMap& new_features, std::vector<IndexTriple>& variable_indices, std::map<Size, std::vector<String> >& feature_constraints_map);
118  void updateRTConstraintsForSequentialILP(Size& rt_index, UInt ms2_spectra_per_rt_bin, Size max_rt_index);
119  void updateCombinedILP(FeatureMap& features, PrecursorIonSelectionPreprocessing& preprocessed_db, std::vector<IndexTriple>& variable_indices,
120  std::vector<String>& new_protein_accs, std::vector<String>& protein_accs, PSProteinInference& prot_inference, Size& variable_counter,
121  std::map<String, std::vector<Size> >& protein_feature_map, Feature& new_feature, std::map<String, Size>& protein_variable_index_map,
122  std::map<String, std::set<String> >& prot_id_counter);
123 
124 
128  void solveILP(std::vector<int>& solution_indices);
129 
131  {
132  solver_ = solver;
133  }
134 
136  {
137  return solver_;
138  }
139 
140  struct IndexLess :
141  std::binary_function<IndexTriple, IndexTriple, bool>
142  {
143  inline bool operator()(IndexTriple const& left,
144  IndexTriple const& right) const
145  {
146  return left.feature < right.feature;
147  }
148 
149  };
150 
151 
152  struct ScanLess :
153  std::binary_function<IndexTriple, IndexTriple, bool>
154  {
155  inline bool operator()(IndexTriple const& left,
156  IndexTriple const& right) const
157  {
158  return left.scan < right.scan;
159  }
160 
161  };
162 
164  std::binary_function<IndexTriple, IndexTriple, bool>
165  {
166  inline bool operator()(IndexTriple const& left,
167  IndexTriple const& right) const
168  {
169  return left.variable < right.variable;
170  }
171 
172  };
173 
174 protected:
175 
176  void getXIC_(const std::vector<std::pair<Size, Size> >& end_points,
177  std::vector<double>& weights,
178  const PeakMap& experiment,
179  const bool normalize);
180 
184  void calculateXICs_(std::vector<std::vector<double> >& xics,
185  const FeatureMap& features,
186  const PeakMap& experiment,
187  const std::vector<std::vector<std::pair<Size, Size> > >& mass_ranges,
188  const bool normalize);
189 
193  void createAndSolveILP_(const FeatureMap& features, std::vector<std::vector<double> >& intensity_weights,
194  std::set<Int>& charges_set, std::vector<std::vector<std::pair<Size, Size> > >& mass_ranges,
195  std::vector<IndexTriple>& variable_indices, std::vector<int>& solution_indices,
196  UInt ms2_spectra_per_rt_bin, Size number_of_scans);
197 
198  void createAndSolveCombinedLPFeatureBased_(const FeatureMap& features, std::vector<std::vector<double> >& intensity_weights,
199  std::set<Int>& charges_set, std::vector<std::vector<std::pair<Size, Size> > >& mass_ranges,
200  std::vector<IndexTriple>& variable_indices, std::vector<Int>& solution_indices,
201  UInt ms2_spectra_per_rt_bin, Size number_of_scans, Size step_size = 0, bool sequential_order = false);
202 
203  void addProteinToILP_(PrecursorIonSelectionPreprocessing& preprocessing,
204  std::map<String, std::vector<double> >::const_iterator map_iter,
205  Size& counter, Size& pep_counter, Size& feature_counter,
206  std::vector<IndexTriple>& variable_indices,
207  std::map<String, Size>& protein_penalty_index_map, FeatureMap& precursors);
208 
209  void addPrecursorAcquisitionNumberConstraint_(std::vector<IndexTriple>& variable_indices, Size number_of_features, UInt number_of_msms_per_precursor);
210 
211  void addMaxInclusionListSizeConstraints_(std::vector<IndexTriple>& variable_indices, /*Size number_of_features,*/ UInt max_list_size);
212 
213  void addRTBinCapacityConstraint_(std::vector<IndexTriple>& variable_indices,
214  Size max_rt_index, UInt ms2_spectra_per_rt_bin, bool sequential_order = false);
215 
216  void addProteinCoverageConstraint_(std::vector<IndexTriple>& variable_indices,
217  PrecursorIonSelectionPreprocessing& preprocessing,
218  std::map<String, Size> protein_variable_index_map);
219 
220  void addStepSizeConstraint_(std::vector<IndexTriple>& variable_indices, UInt step_size);
221 
222 
223  void assembleInclusionListForProteinBasedLP_(std::vector<IndexTriple>& variable_indices, FeatureMap& precursors, std::vector<int>& solution_indices, PrecursorIonSelectionPreprocessing& preprocessing);
224 
225  void updateObjFunction_(String acc, FeatureMap& features, PrecursorIonSelectionPreprocessing& preprocessed_db, std::vector<IndexTriple>& variable_indices);
226 
227 
228  Int getNumberOfPrecsInSpectrum_(Int constr_idx);
229 
232  };
233 
234  inline OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const PSLPFormulation::IndexTriple& triple)
235  {
236  os << "feature: " << triple.feature << " scan: " << triple.scan << " variable: " << triple.variable << " prot_acc: " << triple.prot_acc;
237  return os;
238  }
239 
240 } // namespace
241 
DefaultParamHandler.h
OpenMS::PSLPFormulation::IndexLess
Definition: PSLPFormulation.h:140
OpenMS::PSLPFormulation::ScanLess::operator()
bool operator()(IndexTriple const &left, IndexTriple const &right) const
Definition: PSLPFormulation.h:155
OpenMS::String
A more convenient string class.
Definition: String.h:59
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::LPWrapper
Definition: LPWrapper.h:67
OpenMS::PSLPFormulation::IndexTriple::rt_probability
double rt_probability
Definition: PSLPFormulation.h:75
OpenMS::PSLPFormulation::IndexTriple
Struct that holds the indices of the precursors in the feature map and the ilp formulation.
Definition: PSLPFormulation.h:70
OpenMS::PSLPFormulation::solver_
LPWrapper::SOLVER solver_
Definition: PSLPFormulation.h:231
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
OpenMS::PSLPFormulation::IndexTriple::scan
Int scan
Definition: PSLPFormulation.h:73
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::PSLPFormulation::ScanLess
Definition: PSLPFormulation.h:152
int
OpenMS::PSLPFormulation
Implements ILP formulation of precursor selection problems.
Definition: PSLPFormulation.h:55
FeatureMap.h
OpenMS::PSLPFormulation::getLPSolver
LPWrapper::SOLVER getLPSolver()
Definition: PSLPFormulation.h:135
OpenMS::PSLPFormulation::setLPSolver
void setLPSolver(LPWrapper::SOLVER solver)
Definition: PSLPFormulation.h:130
OpenMS::PSLPFormulation::IndexTriple::variable
Size variable
Definition: PSLPFormulation.h:74
OpenMS::operator<<
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::PSLPFormulation::IndexTriple::feature
Size feature
Definition: PSLPFormulation.h:72
MSExperiment.h
OpenMS::PSProteinInference
This class implements protein inference for the precursor ion selection strategies.
Definition: PSProteinInference.h:52
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:97
OpenMS::Feature
An LC-MS feature.
Definition: Feature.h:70
OpenMS::PSLPFormulation::VariableIndexLess
Definition: PSLPFormulation.h:163
LPWrapper.h
OpenMS::LPWrapper::SOLVER
SOLVER
Definition: LPWrapper.h:130
OpenSwath::normalize
OPENSWATHALGO_DLLAPI void normalize(const std::vector< double > &intensities, double normalization_factor, std::vector< double > &normalized_intensities)
Normalize intensities in vector by normalization_factor.
OpenMS::PSLPFormulation::IndexLess::operator()
bool operator()(IndexTriple const &left, IndexTriple const &right) const
Definition: PSLPFormulation.h:143
OpenMS::PSLPFormulation::IndexTriple::signal_weight
double signal_weight
Definition: PSLPFormulation.h:76
StandardTypes.h
OpenMS::PrecursorIonSelectionPreprocessing
This class implements the database preprocessing needing for precursor ion selection.
Definition: PrecursorIonSelectionPreprocessing.h:55
OpenMS::PSLPFormulation::IndexTriple::prot_acc
String prot_acc
Definition: PSLPFormulation.h:77
OpenMS::PSLPFormulation::VariableIndexLess::operator()
bool operator()(IndexTriple const &left, IndexTriple const &right) const
Definition: PSLPFormulation.h:166
OpenMS::PSLPFormulation::model_
LPWrapper * model_
Definition: PSLPFormulation.h:230