OpenMS  3.0.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-2022.
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  {
142  inline bool operator()(IndexTriple const& left,
143  IndexTriple const& right) const
144  {
145  return left.feature < right.feature;
146  }
147 
148  };
149 
150 
151  struct ScanLess
152  {
153  inline bool operator()(IndexTriple const& left,
154  IndexTriple const& right) const
155  {
156  return left.scan < right.scan;
157  }
158 
159  };
160 
162  {
163  inline bool operator()(IndexTriple const& left,
164  IndexTriple const& right) const
165  {
166  return left.variable < right.variable;
167  }
168 
169  };
170 
171 protected:
172 
173  void getXIC_(const std::vector<std::pair<Size, Size> >& end_points,
174  std::vector<double>& weights,
175  const PeakMap& experiment,
176  const bool normalize);
177 
181  void calculateXICs_(std::vector<std::vector<double> >& xics,
182  const FeatureMap& features,
183  const PeakMap& experiment,
184  const std::vector<std::vector<std::pair<Size, Size> > >& mass_ranges,
185  const bool normalize);
186 
190  void createAndSolveILP_(const FeatureMap& features, std::vector<std::vector<double> >& intensity_weights,
191  std::set<Int>& charges_set, std::vector<std::vector<std::pair<Size, Size> > >& mass_ranges,
192  std::vector<IndexTriple>& variable_indices, std::vector<int>& solution_indices,
193  UInt ms2_spectra_per_rt_bin, Size number_of_scans);
194 
195  void createAndSolveCombinedLPFeatureBased_(const FeatureMap& features, std::vector<std::vector<double> >& intensity_weights,
196  std::set<Int>& charges_set, std::vector<std::vector<std::pair<Size, Size> > >& mass_ranges,
197  std::vector<IndexTriple>& variable_indices, std::vector<Int>& solution_indices,
198  UInt ms2_spectra_per_rt_bin, Size number_of_scans, Size step_size = 0, bool sequential_order = false);
199 
200  void addProteinToILP_(PrecursorIonSelectionPreprocessing& preprocessing,
201  std::map<String, std::vector<double> >::const_iterator map_iter,
202  Size& counter, Size& pep_counter, Size& feature_counter,
203  std::vector<IndexTriple>& variable_indices,
204  std::map<String, Size>& protein_penalty_index_map, FeatureMap& precursors);
205 
206  void addPrecursorAcquisitionNumberConstraint_(std::vector<IndexTriple>& variable_indices, Size number_of_features, UInt number_of_msms_per_precursor);
207 
208  void addMaxInclusionListSizeConstraints_(std::vector<IndexTriple>& variable_indices, /*Size number_of_features,*/ UInt max_list_size);
209 
210  void addRTBinCapacityConstraint_(std::vector<IndexTriple>& variable_indices,
211  Size max_rt_index, UInt ms2_spectra_per_rt_bin, bool sequential_order = false);
212 
213  void addProteinCoverageConstraint_(std::vector<IndexTriple>& variable_indices,
214  PrecursorIonSelectionPreprocessing& preprocessing,
215  std::map<String, Size> protein_variable_index_map);
216 
217  void addStepSizeConstraint_(std::vector<IndexTriple>& variable_indices, UInt step_size);
218 
219 
220  void assembleInclusionListForProteinBasedLP_(std::vector<IndexTriple>& variable_indices, FeatureMap& precursors, std::vector<int>& solution_indices, PrecursorIonSelectionPreprocessing& preprocessing);
221 
222  void updateObjFunction_(String acc, FeatureMap& features, PrecursorIonSelectionPreprocessing& preprocessed_db, std::vector<IndexTriple>& variable_indices);
223 
224 
225  Int getNumberOfPrecsInSpectrum_(Int constr_idx);
226 
229  };
230 
231  inline OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const PSLPFormulation::IndexTriple& triple)
232  {
233  os << "feature: " << triple.feature << " scan: " << triple.scan << " variable: " << triple.variable << " prot_acc: " << triple.prot_acc;
234  return os;
235  }
236 
237 } // namespace
238 
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:153
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:70
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:228
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::Int
int Int
Signed integer type.
Definition: Types.h:102
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::PSLPFormulation::ScanLess
Definition: PSLPFormulation.h:151
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:47
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:98
OpenMS::Feature
An LC-MS feature.
Definition: Feature.h:70
OpenMS::PSLPFormulation::VariableIndexLess
Definition: PSLPFormulation.h:161
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:142
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:52
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:163
OpenMS::PSLPFormulation::model_
LPWrapper * model_
Definition: PSLPFormulation.h:227