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-2015.
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
37 
40 
43 
44 //#define DEBUG_OPS
45 namespace OpenMS
46 {
47  class PrecursorIonSelectionPreprocessing;
48  class PSProteinInference;
54  class OPENMS_DLLAPI PSLPFormulation :
55  public DefaultParamHandler
56  {
57 
58 
59 
60 public:
61 
63 
64  virtual ~PSLPFormulation();
65 
69  struct IndexTriple
70  {
75  double signal_weight;
77  };
78 
79 
91  template <typename InputPeakType>
92  void createAndSolveILPForKnownLCMSMapFeatureBased(const FeatureMap& features,
93  const MSExperiment<InputPeakType>& 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  template <typename InputPeakType>
109  void createAndSolveCombinedLPForKnownLCMSMapFeatureBased(const FeatureMap& features,
110  const MSExperiment<InputPeakType>& experiment,
111  std::vector<IndexTriple>& variable_indices,
112  std::vector<int>& solution_indices,
113  std::vector<std::vector<std::pair<Size, Size> > >& mass_ranges,
114  std::set<Int>& charges_set, UInt ms2_spectra_per_rt_bin,
115  Size step_size = 0, bool sequential_order = false);
116 
117  void updateStepSizeConstraint(Size iteration, UInt step_size);
118  void updateFeatureILPVariables(FeatureMap& new_features, std::vector<IndexTriple>& variable_indices, std::map<Size, std::vector<String> >& feature_constraints_map);
119  void updateRTConstraintsForSequentialILP(Size& rt_index, UInt ms2_spectra_per_rt_bin, Size max_rt_index);
120  void updateCombinedILP(FeatureMap& features, PrecursorIonSelectionPreprocessing& preprocessed_db, std::vector<IndexTriple>& variable_indices,
121  std::vector<String>& new_protein_accs, std::vector<String>& protein_accs, PSProteinInference& prot_inference, Size& variable_counter,
122  std::map<String, std::vector<Size> >& protein_feature_map, Feature& new_feature, std::map<String, Size>& protein_variable_index_map,
123  std::map<String, std::set<String> >& prot_id_counter);
124 
125 
129  void solveILP(std::vector<int>& solution_indices);
130 
132  {
133  solver_ = solver;
134  }
135 
137  {
138  return solver_;
139  }
140 
141  struct IndexLess :
142  std::binary_function<IndexTriple, IndexTriple, bool>
143  {
144  inline bool operator()(IndexTriple const& left,
145  IndexTriple const& right) const
146  {
147  return left.feature < right.feature;
148  }
149 
150  };
151 
152 
153  struct ScanLess :
154  std::binary_function<IndexTriple, IndexTriple, bool>
155  {
156  inline bool operator()(IndexTriple const& left,
157  IndexTriple const& right) const
158  {
159  return left.scan < right.scan;
160  }
161 
162  };
163 
165  std::binary_function<IndexTriple, IndexTriple, bool>
166  {
167  inline bool operator()(IndexTriple const& left,
168  IndexTriple const& right) const
169  {
170  return left.variable < right.variable;
171  }
172 
173  };
174 
175 protected:
176 
177  template <typename InputPeakType>
178  void getXIC_(const std::vector<std::pair<Size, Size> >& end_points,
179  std::vector<double>& weights,
180  const MSExperiment<InputPeakType>& experiment,
181  const bool normalize);
182 
186  template <typename InputPeakType>
187  void calculateXICs_(std::vector<std::vector<double> >& xics,
188  const FeatureMap& features,
189  const MSExperiment<InputPeakType>& experiment,
190  const std::vector<std::vector<std::pair<Size, Size> > >& mass_ranges,
191  const bool normalize);
192 
196  void createAndSolveILP_(const FeatureMap& features, std::vector<std::vector<double> >& intensity_weights,
197  std::set<Int>& charges_set, std::vector<std::vector<std::pair<Size, Size> > >& mass_ranges,
198  std::vector<IndexTriple>& variable_indices, std::vector<int>& solution_indices,
199  UInt ms2_spectra_per_rt_bin, Size number_of_scans);
200 
201  void createAndSolveCombinedLPFeatureBased_(const FeatureMap& features, std::vector<std::vector<double> >& intensity_weights,
202  std::set<Int>& charges_set, std::vector<std::vector<std::pair<Size, Size> > >& mass_ranges,
203  std::vector<IndexTriple>& variable_indices, std::vector<Int>& solution_indices,
204  UInt ms2_spectra_per_rt_bin, Size number_of_scans, Size step_size = 0, bool sequential_order = false);
205 
206  void addProteinToILP_(PrecursorIonSelectionPreprocessing& preprocessing,
207  std::map<String, std::vector<double> >::const_iterator map_iter,
208  Size& counter, Size& pep_counter, Size& feature_counter,
209  std::vector<IndexTriple>& variable_indices,
210  std::map<String, Size>& protein_penalty_index_map, FeatureMap& precursors);
211 
212  void addPrecursorAcquisitionNumberConstraint_(std::vector<IndexTriple>& variable_indices, Size number_of_features, UInt number_of_msms_per_precursor);
213 
214  void addMaxInclusionListSizeConstraints_(std::vector<IndexTriple>& variable_indices, /*Size number_of_features,*/ UInt max_list_size);
215 
216  void addRTBinCapacityConstraint_(std::vector<IndexTriple>& variable_indices,
217  Size max_rt_index, UInt ms2_spectra_per_rt_bin, bool sequential_order = false);
218 
219  void addProteinCoverageConstraint_(std::vector<IndexTriple>& variable_indices,
220  PrecursorIonSelectionPreprocessing& preprocessing,
221  std::map<String, Size> protein_variable_index_map);
222 
223  void addStepSizeConstraint_(std::vector<IndexTriple>& variable_indices, UInt step_size);
224 
225 
226  void assembleInclusionListForProteinBasedLP_(std::vector<IndexTriple>& variable_indices, FeatureMap& precursors, std::vector<int>& solution_indices, PrecursorIonSelectionPreprocessing& preprocessing);
227 
228  void updateObjFunction_(String acc, FeatureMap& features, PrecursorIonSelectionPreprocessing& preprocessed_db, std::vector<IndexTriple>& variable_indices);
229 
230 
231  Int getNumberOfPrecsInSpectrum_(Int constr_idx);
232 
235  };
236 
237  template <typename InputPeakType>
238  void PSLPFormulation::getXIC_(const std::vector<std::pair<Size, Size> >& end_points,
239  std::vector<double>& weights,
240  const MSExperiment<InputPeakType>& experiment,
241  const bool normalize)
242  {
243  double max_weight = 0.;
244  weights.clear();
245  for (Size i = 0; i < end_points.size(); i += 2)
246  {
247  double weight = 0.;
248  for (Size j = end_points[i].second; j <= end_points[i + 1].second; ++j)
249  {
250  weight += experiment[end_points[i].first][j].getIntensity();
251  // std::cout << " add "<<experiment[end_points[i].first][j].getIntensity()<<std::endl;
252  }
253  if (weight > max_weight)
254  max_weight = weight;
255 
256  weights.push_back(weight);
257  }
258 
259  if (normalize)
260  {
261  // normalize weights
262  for (Size i = 0; i < weights.size(); ++i)
263  {
264 #ifdef DEBUG_OPS
265  if (end_points.size() >= i)
266  {
267  std::cout << "scan " << end_points[i].first << " " << weights[i] << " " << max_weight
268  << " " << weights[i] / max_weight << std::endl;
269  }
270 #endif
271  weights[i] /= max_weight;
272  }
273  }
274  }
275 
276  template <typename InputPeakType>
277  void PSLPFormulation::calculateXICs_(std::vector<std::vector<double> >& xics,
278  const FeatureMap& features,
279  const MSExperiment<InputPeakType>& experiment,
280  const std::vector<std::vector<std::pair<Size, Size> > >& mass_ranges,
281  const bool normalize)
282  {
283  xics.clear();
284  xics.resize(features.size());
285  for (Size i = 0; i < features.size(); ++i)
286  {
287  getXIC_(mass_ranges[i], xics[i], experiment, normalize);
288  }
289  }
290 
291  template <typename InputPeakType>
293  const MSExperiment<InputPeakType>& experiment,
294  std::vector<IndexTriple>& variable_indices,
295  std::vector<std::vector<std::pair<Size, Size> > >& mass_ranges,
296  std::set<Int>& charges_set, UInt ms2_spectra_per_rt_bin,
297  std::vector<int>& solution_indices)
298  {
299 
300  std::vector<std::vector<double> > intensity_weights;
301  if (param_.getValue("feature_based:no_intensity_normalization") == "false")
302  {
303  calculateXICs_(intensity_weights, features, experiment, mass_ranges, true);
304  }
305  else
306  {
307  calculateXICs_(intensity_weights, features, experiment, mass_ranges, false);
308  }
309 #ifdef DEBUG_OPS
310  std::cout << "got xics" << std::endl;
311 #endif
312 
313  createAndSolveILP_(features, intensity_weights, charges_set, mass_ranges, variable_indices, solution_indices,
314  ms2_spectra_per_rt_bin, experiment.size());
315  }
316 
317  inline OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const PSLPFormulation::IndexTriple& triple)
318  {
319  os << "feature: " << triple.feature << " scan: " << triple.scan << " variable: " << triple.variable << " prot_acc: " << triple.prot_acc;
320  return os;
321  }
322 
323  template <typename InputPeakType>
325  const MSExperiment<InputPeakType>& experiment,
326  std::vector<IndexTriple>& variable_indices,
327  std::vector<Int>& solution_indices,
328  std::vector<std::vector<std::pair<Size, Size> > >& mass_ranges,
329  std::set<Int>& charges_set, UInt ms2_spectra_per_rt_bin,
330  Size step_size, bool sequential_order)
331  {
332 
333  std::vector<std::vector<double> > intensity_weights;
334  calculateXICs_(intensity_weights, features, experiment, mass_ranges, true);
335 #ifdef DEBUG_OPS
336  std::cout << "got xics" << std::endl;
337 #endif
338 
339  createAndSolveCombinedLPFeatureBased_(features, intensity_weights, charges_set, mass_ranges, variable_indices, solution_indices, ms2_spectra_per_rt_bin,
340  experiment.size(), step_size, sequential_order);
341  }
342 
343 } // namespace
344 
345 #endif // OPENMS_ANALYSIS_ID_PSLPFORMULATION_H
A more convenient string class.
Definition: String.h:57
Size size() const
Definition: MSExperiment.h:117
Param param_
Container for current parameters.
Definition: DefaultParamHandler.h:150
SOLVER
Definition: LPWrapper.h:129
bool operator()(IndexTriple const &left, IndexTriple const &right) const
Definition: PSLPFormulation.h:144
Definition: PSLPFormulation.h:141
A container for features.
Definition: FeatureMap.h:93
Struct that holds the indices of the precursors in the feature map and the ilp formulation.
Definition: PSLPFormulation.h:69
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:292
void getXIC_(const std::vector< std::pair< Size, Size > > &end_points, std::vector< double > &weights, const MSExperiment< InputPeakType > &experiment, const bool normalize)
Definition: PSLPFormulation.h:238
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.
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Definition: LPWrapper.h:66
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:164
Definition: PSLPFormulation.h:153
LPWrapper::SOLVER solver_
Definition: PSLPFormulation.h:234
void setLPSolver(LPWrapper::SOLVER solver)
Definition: PSLPFormulation.h:131
double rt_probability
Definition: PSLPFormulation.h:74
const DataValue & getValue(const String &key) const
Returns a value of a parameter.
This class implements the database preprocessing needing for precursor ion selection.
Definition: PrecursorIonSelectionPreprocessing.h:56
Size feature
Definition: PSLPFormulation.h:71
Size variable
Definition: PSLPFormulation.h:73
double signal_weight
Definition: PSLPFormulation.h:75
bool operator()(IndexTriple const &left, IndexTriple const &right) const
Definition: PSLPFormulation.h:156
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
bool operator()(IndexTriple const &left, IndexTriple const &right) const
Definition: PSLPFormulation.h:167
LPWrapper::SOLVER getLPSolver()
Definition: PSLPFormulation.h:136
An LC-MS feature.
Definition: Feature.h:70
This class implements protein inference for the precursor ion selection strategies.
Definition: PSProteinInference.h:53
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:69
void calculateXICs_(std::vector< std::vector< double > > &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:277
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:324
String prot_acc
Definition: PSLPFormulation.h:76
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)
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
LPWrapper * model_
Definition: PSLPFormulation.h:233
Int scan
Definition: PSLPFormulation.h:72
int Int
Signed integer type.
Definition: Types.h:96
Implements ILP formulation of precursor selection problems.
Definition: PSLPFormulation.h:54

OpenMS / TOPP release 2.0.0 Documentation generated on Tue Aug 25 2015 05:53:52 using doxygen 1.8.9.1