Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
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-2013.
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: Alexandra Zerck $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_ANALYSIS_TARGETED_PSLPFORMULATION_H
36 #define OPENMS_ANALYSIS_TARGETED_PSLPFORMULATION_H
39 
41 
42 namespace OpenMS
43 {
44  class PrecursorIonSelectionPreprocessing;
45  class PSProteinInference;
51  class OPENMS_DLLAPI PSLPFormulation :
52  public DefaultParamHandler
53  {
54 
55 
56 
57 public:
58 
60 
61  virtual ~PSLPFormulation();
62 
66  struct IndexTriple
67  {
74  };
75 
76 
88  template <typename InputPeakType>
89  void createAndSolveILPForKnownLCMSMapFeatureBased(const FeatureMap<> & features,
90  const MSExperiment<InputPeakType> & experiment,
91  std::vector<IndexTriple> & variable_indices,
92  std::vector<std::vector<std::pair<Size, Size> > > & mass_ranges,
93  std::set<Int> & charges_set, UInt ms2_spectra_per_rt_bin,
94  std::vector<int> & solution_indices);
95 
100  void createAndSolveILPForInclusionListCreation(PrecursorIonSelectionPreprocessing & preprocessing,
101  UInt ms2_spectra_per_rt_bin, UInt max_list_size,
102  FeatureMap<> & precursors,
103  bool solve_ILP = true);
104 
105  template <typename InputPeakType>
106  void createAndSolveCombinedLPForKnownLCMSMapFeatureBased(const FeatureMap<> & features,
107  const MSExperiment<InputPeakType> & experiment,
108  std::vector<IndexTriple> & variable_indices,
109  std::vector<int> & solution_indices,
110  std::vector<std::vector<std::pair<Size, Size> > > & mass_ranges,
111  std::set<Int> & charges_set, UInt ms2_spectra_per_rt_bin,
112  Size step_size = 0, bool sequential_order = false);
113 
114  void updateStepSizeConstraint(Size iteration, UInt step_size);
115  void updateFeatureILPVariables(FeatureMap<> & new_features, std::vector<IndexTriple> & variable_indices, std::map<Size, std::vector<String> > & feature_constraints_map);
116  void updateRTConstraintsForSequentialILP(Size & rt_index, UInt ms2_spectra_per_rt_bin, Size max_rt_index);
117  void updateCombinedILP(FeatureMap<> & features, PrecursorIonSelectionPreprocessing & preprocessed_db, std::vector<IndexTriple> & variable_indices,
118  std::vector<String> & new_protein_accs, std::vector<String> & protein_accs, PSProteinInference & prot_inference, Size & variable_counter,
119  std::map<String, std::vector<Size> > & protein_feature_map, Feature & new_feature, std::map<String, Size> & protein_variable_index_map,
120  std::map<String, std::set<String> > & prot_id_counter);
121 
122 
126  void solveILP(std::vector<int> & solution_indices);
127 
129  {
130  solver_ = solver;
131  }
132 
134  {
135  return solver_;
136  }
137 
138  struct IndexLess :
139  std::binary_function<IndexTriple, IndexTriple, bool>
140  {
141  inline bool operator()(IndexTriple const & left,
142  IndexTriple const & right) const
143  {
144  return left.feature < right.feature;
145  }
146 
147  };
148 
149 
150  struct ScanLess :
151  std::binary_function<IndexTriple, IndexTriple, bool>
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  std::binary_function<IndexTriple, IndexTriple, bool>
163  {
164  inline bool operator()(IndexTriple const & left,
165  IndexTriple const & right) const
166  {
167  return left.variable < right.variable;
168  }
169 
170  };
171 
172 protected:
173 
174  template <typename InputPeakType>
175  void getXIC_(const std::vector<std::pair<Size, Size> > & end_points,
176  std::vector<DoubleReal> & weights,
177  const MSExperiment<InputPeakType> & experiment,
178  const bool normalize);
179 
183  template <typename InputPeakType>
184  void calculateXICs_(std::vector<std::vector<DoubleReal> > & xics,
185  const FeatureMap<> & features,
186  const MSExperiment<InputPeakType> & 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<DoubleReal> > & 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<DoubleReal> > & 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<DoubleReal> >::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  template <typename InputPeakType>
235  void PSLPFormulation::getXIC_(const std::vector<std::pair<Size, Size> > & end_points,
236  std::vector<DoubleReal> & weights,
237  const MSExperiment<InputPeakType> & experiment,
238  const bool normalize)
239  {
240  DoubleReal max_weight = 0.;
241  weights.clear();
242  for (Size i = 0; i < end_points.size(); i += 2)
243  {
244  DoubleReal weight = 0.;
245  for (Size j = end_points[i].second; j <= end_points[i + 1].second; ++j)
246  {
247  weight += experiment[end_points[i].first][j].getIntensity();
248  // std::cout << " add "<<experiment[end_points[i].first][j].getIntensity()<<std::endl;
249  }
250  if (weight > max_weight)
251  max_weight = weight;
252 
253  weights.push_back(weight);
254  }
255 
256  if (normalize)
257  {
258  // normalize weights
259  for (Size i = 0; i < weights.size(); ++i)
260  {
261 #ifdef DEBUG_OPS
262  if (end_points.size() >= i)
263  {
264  std::cout << "scan " << end_points[i].first << " " << weights[i] << " " << max_weight
265  << " " << weights[i] / max_weight << std::endl;
266  }
267 #endif
268  weights[i] /= max_weight;
269  }
270  }
271  }
272 
273  template <typename InputPeakType>
274  void PSLPFormulation::calculateXICs_(std::vector<std::vector<DoubleReal> > & xics,
275  const FeatureMap<> & features,
276  const MSExperiment<InputPeakType> & experiment,
277  const std::vector<std::vector<std::pair<Size, Size> > > & mass_ranges,
278  const bool normalize)
279  {
280  xics.clear();
281  xics.resize(features.size());
282  for (Size i = 0; i < features.size(); ++i)
283  {
284  getXIC_(mass_ranges[i], xics[i], experiment, normalize);
285  }
286  }
287 
288  template <typename InputPeakType>
290  const MSExperiment<InputPeakType> & experiment,
291  std::vector<IndexTriple> & variable_indices,
292  std::vector<std::vector<std::pair<Size, Size> > > & mass_ranges,
293  std::set<Int> & charges_set, UInt ms2_spectra_per_rt_bin,
294  std::vector<int> & solution_indices)
295  {
296 
297  std::vector<std::vector<DoubleReal> > intensity_weights;
298  calculateXICs_(intensity_weights, features, experiment, mass_ranges, true);
299 #ifdef DEBUG_OPS
300  std::cout << "got xics" << std::endl;
301 #endif
302 
303  createAndSolveILP_(features, intensity_weights, charges_set, mass_ranges, variable_indices, solution_indices,
304  ms2_spectra_per_rt_bin, experiment.size());
305  }
306 
307  inline OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const PSLPFormulation::IndexTriple & triple)
308  {
309  os << "feature: " << triple.feature << " scan: " << triple.scan << " variable: " << triple.variable << " prot_acc: " << triple.prot_acc;
310  return os;
311  }
312 
313  template <typename InputPeakType>
315  const MSExperiment<InputPeakType> & experiment,
316  std::vector<IndexTriple> & variable_indices,
317  std::vector<Int> & solution_indices,
318  std::vector<std::vector<std::pair<Size, Size> > > & mass_ranges,
319  std::set<Int> & charges_set, UInt ms2_spectra_per_rt_bin,
320  Size step_size, bool sequential_order)
321  {
322 
323  std::vector<std::vector<DoubleReal> > intensity_weights;
324  calculateXICs_(intensity_weights, features, experiment, mass_ranges, true);
325 #ifdef DEBUG_OPS
326  std::cout << "got xics" << std::endl;
327 #endif
328 
329  createAndSolveCombinedLPFeatureBased_(features, intensity_weights, charges_set, mass_ranges, variable_indices, solution_indices, ms2_spectra_per_rt_bin,
330  experiment.size(), step_size, sequential_order);
331  }
332 
333 } // namespace
334 
335 #endif // OPENMS_ANALYSIS_ID_PSLPFORMULATION_H
DoubleReal signal_weight
Definition: PSLPFormulation.h:72
A more convenient string class.
Definition: String.h:56
Size size() const
Definition: MSExperiment.h:117
SOLVER
Definition: LPWrapper.h:124
bool operator()(IndexTriple const &left, IndexTriple const &right) const
Definition: PSLPFormulation.h:141
Definition: PSLPFormulation.h:138
std::ostream & operator<<(std::ostream &os, const ItraqQuantifier::ItraqQuantifierStats &stats)
Struct that holds the indices of the precursors in the feature map and the ilp formulation.
Definition: PSLPFormulation.h:66
void createAndSolveCombinedLPForKnownLCMSMapFeatureBased(const FeatureMap<> &features, const MSExperiment< InputPeakType > &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)
Definition: PSLPFormulation.h:314
Definition: LPWrapper.h:61
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:161
Definition: PSLPFormulation.h:150
void createAndSolveCombinedLPFeatureBased_(const FeatureMap<> &features, std::vector< std::vector< DoubleReal > > &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)
LPWrapper::SOLVER solver_
Definition: PSLPFormulation.h:231
void setLPSolver(LPWrapper::SOLVER solver)
Definition: PSLPFormulation.h:128
This class implements the database preprocessing needing for precursor ion selection.
Definition: PrecursorIonSelectionPreprocessing.h:56
Size feature
Definition: PSLPFormulation.h:68
Size variable
Definition: PSLPFormulation.h:70
bool operator()(IndexTriple const &left, IndexTriple const &right) const
Definition: PSLPFormulation.h:153
bool operator()(IndexTriple const &left, IndexTriple const &right) const
Definition: PSLPFormulation.h:164
LPWrapper::SOLVER getLPSolver()
Definition: PSLPFormulation.h:133
An LC-MS feature.
Definition: Feature.h:66
This class implements protein inference for the precursor ion selection strategies.
Definition: PSProteinInference.h:53
Representation of a mass spectrometry experiment.
Definition: MSExperiment.h:68
void createAndSolveILP_(const FeatureMap<> &features, std::vector< std::vector< DoubleReal > > &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.
DoubleReal rt_probability
Definition: PSLPFormulation.h:71
void createAndSolveILPForKnownLCMSMapFeatureBased(const FeatureMap<> &features, const MSExperiment< InputPeakType > &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.
Definition: PSLPFormulation.h:289
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
void getXIC_(const std::vector< std::pair< Size, Size > > &end_points, std::vector< DoubleReal > &weights, const MSExperiment< InputPeakType > &experiment, const bool normalize)
Definition: PSLPFormulation.h:235
String prot_acc
Definition: PSLPFormulation.h:73
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:90
void calculateXICs_(std::vector< std::vector< DoubleReal > > &xics, const FeatureMap<> &features, const MSExperiment< InputPeakType > &experiment, const std::vector< std::vector< std::pair< Size, Size > > > &mass_ranges, const bool normalize)
Calculates the XICs for all features.
Definition: PSLPFormulation.h:274
LPWrapper * model_
Definition: PSLPFormulation.h:230
Int scan
Definition: PSLPFormulation.h:69
int Int
Signed integer type.
Definition: Types.h:100
Implements ILP formulation of precursor selection problems.
Definition: PSLPFormulation.h:51

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:20 using doxygen 1.8.5