OpenMS  2.8.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-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: 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 
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 
104  UInt ms2_spectra_per_rt_bin, UInt max_list_size,
105  FeatureMap& precursors,
106  bool solve_ILP = true);
107 
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 
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 
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 
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:93
A container for features.
Definition: FeatureMap.h:106
An LC-MS feature.
Definition: Feature.h:72
Definition: LPWrapper.h:68
SOLVER
Definition: LPWrapper.h:131
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:73
Implements ILP formulation of precursor selection problems.
Definition: PSLPFormulation.h:57
void updateStepSizeConstraint(Size iteration, UInt step_size)
void updateFeatureILPVariables(FeatureMap &new_features, std::vector< IndexTriple > &variable_indices, std::map< Size, std::vector< String > > &feature_constraints_map)
void addProteinToILP_(PrecursorIonSelectionPreprocessing &preprocessing, std::map< String, std::vector< double > >::const_iterator map_iter, Size &counter, Size &pep_counter, Size &feature_counter, std::vector< IndexTriple > &variable_indices, std::map< String, Size > &protein_penalty_index_map, FeatureMap &precursors)
String prot_acc
Definition: PSLPFormulation.h:77
Size feature
Definition: PSLPFormulation.h:72
void setLPSolver(LPWrapper::SOLVER solver)
Definition: PSLPFormulation.h:130
void addRTBinCapacityConstraint_(std::vector< IndexTriple > &variable_indices, Size max_rt_index, UInt ms2_spectra_per_rt_bin, bool sequential_order=false)
void updateObjFunction_(String acc, FeatureMap &features, PrecursorIonSelectionPreprocessing &preprocessed_db, std::vector< IndexTriple > &variable_indices)
void createAndSolveILPForInclusionListCreation(PrecursorIonSelectionPreprocessing &preprocessing, UInt ms2_spectra_per_rt_bin, UInt max_list_size, FeatureMap &precursors, bool solve_ILP=true)
Find a set of precursors, so that the protein coverage is maximal and that the number of precursors p...
void updateCombinedILP(FeatureMap &features, PrecursorIonSelectionPreprocessing &preprocessed_db, std::vector< IndexTriple > &variable_indices, std::vector< String > &new_protein_accs, std::vector< String > &protein_accs, PSProteinInference &prot_inference, Size &variable_counter, std::map< String, std::vector< Size > > &protein_feature_map, Feature &new_feature, std::map< String, Size > &protein_variable_index_map, std::map< String, std::set< String > > &prot_id_counter)
LPWrapper * model_
Definition: PSLPFormulation.h:227
double signal_weight
Definition: PSLPFormulation.h:76
Int scan
Definition: PSLPFormulation.h:73
void createAndSolveILPForKnownLCMSMapFeatureBased(const FeatureMap &features, const PeakMap &experiment, std::vector< IndexTriple > &variable_indices, std::vector< std::vector< std::pair< Size, Size > > > &mass_ranges, std::set< Int > &charges_set, UInt ms2_spectra_per_rt_bin, std::vector< int > &solution_indices)
Encode ILP formulation for a given LC-MS map, but unknown protein sample.
void assembleInclusionListForProteinBasedLP_(std::vector< IndexTriple > &variable_indices, FeatureMap &precursors, std::vector< int > &solution_indices, PrecursorIonSelectionPreprocessing &preprocessing)
void addProteinCoverageConstraint_(std::vector< IndexTriple > &variable_indices, PrecursorIonSelectionPreprocessing &preprocessing, std::map< String, Size > protein_variable_index_map)
void createAndSolveCombinedLPFeatureBased_(const FeatureMap &features, std::vector< std::vector< double > > &intensity_weights, std::set< Int > &charges_set, std::vector< std::vector< std::pair< Size, Size > > > &mass_ranges, std::vector< IndexTriple > &variable_indices, std::vector< Int > &solution_indices, UInt ms2_spectra_per_rt_bin, Size number_of_scans, Size step_size=0, bool sequential_order=false)
Int getNumberOfPrecsInSpectrum_(Int constr_idx)
void calculateXICs_(std::vector< std::vector< double > > &xics, const FeatureMap &features, const PeakMap &experiment, const std::vector< std::vector< std::pair< Size, Size > > > &mass_ranges, const bool normalize)
Calculates the XICs for all features.
void createAndSolveCombinedLPForKnownLCMSMapFeatureBased(const FeatureMap &features, const PeakMap &experiment, std::vector< IndexTriple > &variable_indices, std::vector< int > &solution_indices, std::vector< std::vector< std::pair< Size, Size > > > &mass_ranges, std::set< Int > &charges_set, UInt ms2_spectra_per_rt_bin, Size step_size=0, bool sequential_order=false)
void updateRTConstraintsForSequentialILP(Size &rt_index, UInt ms2_spectra_per_rt_bin, Size max_rt_index)
void solveILP(std::vector< int > &solution_indices)
Solve the ILP.
void addStepSizeConstraint_(std::vector< IndexTriple > &variable_indices, UInt step_size)
void getXIC_(const std::vector< std::pair< Size, Size > > &end_points, std::vector< double > &weights, const PeakMap &experiment, const bool normalize)
double rt_probability
Definition: PSLPFormulation.h:75
Size variable
Definition: PSLPFormulation.h:74
LPWrapper::SOLVER getLPSolver()
Definition: PSLPFormulation.h:135
void addMaxInclusionListSizeConstraints_(std::vector< IndexTriple > &variable_indices, UInt max_list_size)
void createAndSolveILP_(const FeatureMap &features, std::vector< std::vector< double > > &intensity_weights, std::set< Int > &charges_set, std::vector< std::vector< std::pair< Size, Size > > > &mass_ranges, std::vector< IndexTriple > &variable_indices, std::vector< int > &solution_indices, UInt ms2_spectra_per_rt_bin, Size number_of_scans)
Creates and solves the ILP.
void addPrecursorAcquisitionNumberConstraint_(std::vector< IndexTriple > &variable_indices, Size number_of_features, UInt number_of_msms_per_precursor)
LPWrapper::SOLVER solver_
Definition: PSLPFormulation.h:228
Struct that holds the indices of the precursors in the feature map and the ilp formulation.
Definition: PSLPFormulation.h:71
This class implements protein inference for the precursor ion selection strategies.
Definition: PSProteinInference.h:48
This class implements the database preprocessing needing for precursor ion selection.
Definition: PrecursorIonSelectionPreprocessing.h:54
A more convenient string class.
Definition: String.h:60
int Int
Signed integer type.
Definition: Types.h:102
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
OPENSWATHALGO_DLLAPI void normalize(const std::vector< double > &intensities, double normalization_factor, std::vector< double > &normalized_intensities)
Normalize intensities in vector by normalization_factor.
Definition: PSLPFormulation.h:141
bool operator()(IndexTriple const &left, IndexTriple const &right) const
Definition: PSLPFormulation.h:142
Definition: PSLPFormulation.h:152
bool operator()(IndexTriple const &left, IndexTriple const &right) const
Definition: PSLPFormulation.h:153
Definition: PSLPFormulation.h:162
bool operator()(IndexTriple const &left, IndexTriple const &right) const
Definition: PSLPFormulation.h:163