OpenMS  2.8.0
PrecursorIonSelection.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 
36 #pragma once
37 
41 #include <set>
42 
43 namespace OpenMS
44 {
45  class PrecursorIonSelectionPreprocessing;
46  class PSProteinInference;
52  class OPENMS_DLLAPI PrecursorIonSelection :
53  public DefaultParamHandler
54  {
55 public:
56 
74  enum Type
75  {
76  IPS,
78  SPS,
81  DEX
82  };
83 
87 
88  const double & getMaxScore() const;
89  void setMaxScore(const double & max_score);
90 
91 
94  {
95  inline bool operator()(Feature const & left, Feature const & right) const
96  {
97  return (double)left.getMetaValue("msms_score") > (double)right.getMetaValue("msms_score");
98  }
99 
100  };
101 
104  {
105  inline bool operator()(Feature const & left, Feature const & right) const
106  {
107  if (left.getRT() < right.getRT()) return true;
108  else if (left.getRT() > right.getRT()) return false;
109  else return (double)left.getMetaValue("msms_score") > (double)right.getMetaValue("msms_score");
110  }
111 
112  };
113 
114 
118  void sortByTotalScore(FeatureMap & features)
119  {
120  FeatureMap::Iterator beg = features.begin();
121  FeatureMap::Iterator end = features.end();
122  std::sort(beg, end, TotalScoreMore());
123  }
124 
132  void getNextPrecursors(FeatureMap & features, FeatureMap & next_features, UInt number);
133  void getNextPrecursorsSeq(FeatureMap & features, FeatureMap & next_features, UInt number, double & rt);
134  void getNextPrecursors(std::vector<Int> & solution_indices, std::vector<PSLPFormulation::IndexTriple> & variable_indices, std::set<Int> & measured_variables,
135  FeatureMap & features, FeatureMap & new_features, UInt step_size, PSLPFormulation & ilp);
136 
137 // /**
138 // @brief Change scoring of features using peptide identifications only from spectra of the last
139 // iteration
140 //
141 // @param features FeatureMap with all possible precursors
142 // @param new_pep_ids Peptide identifications
143 // @param preprocessed_db Information from preprocessed database
144 //
145 // */
146 // void rescoreIncremental(FeatureMap& features,std::vector<PeptideIdentification>& new_pep_ids,
147 // std::vector<ProteinIdentification>& prot_ids,
148 // PrecursorIonSelectionPreprocessing& preprocessed_db);
149 
150 
160  void rescore(FeatureMap & features, std::vector<PeptideIdentification> & new_pep_ids,
161  std::vector<ProteinIdentification> & prot_ids,
162  PrecursorIonSelectionPreprocessing & preprocessed_db, bool check_meta_values = true);
163 
164 
175  void simulateRun(FeatureMap & features, std::vector<PeptideIdentification> & pep_ids,
176  std::vector<ProteinIdentification> & prot_ids,
177  PrecursorIonSelectionPreprocessing & preprocessed_db,
178  String path, PeakMap & experiment, String precursor_path = "");
179 
181  {
182  solver_ = solver;
183  std::cout << " LPSolver set to " << solver_ << std::endl;
184  }
185 
187  {
188  return solver_;
189  }
190 
191  void reset();
192 
193  const std::map<String, std::set<String> > & getPeptideProteinCounter()
194  {
195  return prot_id_counter_;
196  }
197 
198 private:
199  void simulateILPBasedIPSRun_(FeatureMap & features, PeakMap & experiment,
200  std::vector<PeptideIdentification> & pep_ids,
201  std::vector<ProteinIdentification> & prot_ids,
202  PrecursorIonSelectionPreprocessing & preprocessed_db,
203  String output_path, String precursor_path = "");
204 
205  void simulateRun_(FeatureMap & features, std::vector<PeptideIdentification> & pep_ids,
206  std::vector<ProteinIdentification> & prot_ids,
207  PrecursorIonSelectionPreprocessing & preprocessed_db, String path, String precursor_path = "");
208 
209  void shiftDown_(FeatureMap & features, PrecursorIonSelectionPreprocessing & preprocessed_db, String protein_acc);
210 
211  void shiftUp_(FeatureMap & features, PrecursorIonSelectionPreprocessing & preprocessed_db, String protein_acc);
212 
214  void updateMembers_() override;
215 
216  void rescore_(FeatureMap & features, std::vector<PeptideIdentification> & new_pep_ids,
217  PrecursorIonSelectionPreprocessing & preprocessed_db, PSProteinInference & protein_inference);
218 
225 
231  UInt filterProtIds_(std::vector<ProteinIdentification> & prot_ids);
232 
233  std::vector<PeptideIdentification> filterPeptideIds_(std::vector<PeptideIdentification> & pep_ids);
234 
235  void convertPeptideIdScores_(std::vector<PeptideIdentification> & pep_ids);
236 
240  double max_score_;
244  std::map<String, std::set<String> > prot_id_counter_;
246  std::vector<Size> fraction_counter_;
254 
256 
257  };
258 
259 }
260 
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:93
A container for features.
Definition: FeatureMap.h:106
Base::iterator Iterator
Definition: FeatureMap.h:143
An LC-MS feature.
Definition: Feature.h:72
SOLVER
Definition: LPWrapper.h:131
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:73
const DataValue & getMetaValue(const String &name, const DataValue &default_value=DataValue::EMPTY) const
Returns the value corresponding to a string, or a default value (default: DataValue::EMPTY) if not fo...
Implements ILP formulation of precursor selection problems.
Definition: PSLPFormulation.h:57
This class implements protein inference for the precursor ion selection strategies.
Definition: PSProteinInference.h:48
CoordinateType getRT() const
Returns the RT coordinate (index 0)
Definition: Peak2D.h:208
This class implements the database preprocessing needing for precursor ion selection.
Definition: PrecursorIonSelectionPreprocessing.h:54
This class implements different precursor ion selection strategies.
Definition: PrecursorIonSelection.h:54
void getNextPrecursors(std::vector< Int > &solution_indices, std::vector< PSLPFormulation::IndexTriple > &variable_indices, std::set< Int > &measured_variables, FeatureMap &features, FeatureMap &new_features, UInt step_size, PSLPFormulation &ilp)
String mz_tolerance_unit_
precursor ion error tolerance unit (ppm or Da)
Definition: PrecursorIonSelection.h:250
std::vector< Size > fraction_counter_
stores the number of selected precursors per fraction
Definition: PrecursorIonSelection.h:246
void shiftDown_(FeatureMap &features, PrecursorIonSelectionPreprocessing &preprocessed_db, String protein_acc)
void simulateRun_(FeatureMap &features, std::vector< PeptideIdentification > &pep_ids, std::vector< ProteinIdentification > &prot_ids, PrecursorIonSelectionPreprocessing &preprocessed_db, String path, String precursor_path="")
Type
Precursor ion selection type (iterative, static, upshift, downshift, dynamic exclusion).
Definition: PrecursorIonSelection.h:75
@ ILP_IPS
Definition: PrecursorIonSelection.h:77
@ SPS
Definition: PrecursorIonSelection.h:78
@ DOWNSHIFT
Definition: PrecursorIonSelection.h:80
@ UPSHIFT
Definition: PrecursorIonSelection.h:79
@ IPS
Definition: PrecursorIonSelection.h:76
UInt min_pep_ids_
minimal number of peptides identified for a protein to be declared identified
Definition: PrecursorIonSelection.h:238
void convertPeptideIdScores_(std::vector< PeptideIdentification > &pep_ids)
double max_score_
maximal score in the FeatureMap
Definition: PrecursorIonSelection.h:240
void setLPSolver(LPWrapper::SOLVER solver)
Definition: PrecursorIonSelection.h:180
PrecursorIonSelection(const PrecursorIonSelection &source)
void checkForRequiredUserParams_(FeatureMap &features)
Adds user params, required for the use of IPS, to a feature map using default values.
Size x_variable_number_
Definition: PrecursorIonSelection.h:253
void simulateRun(FeatureMap &features, std::vector< PeptideIdentification > &pep_ids, std::vector< ProteinIdentification > &prot_ids, PrecursorIonSelectionPreprocessing &preprocessed_db, String path, PeakMap &experiment, String precursor_path="")
Simulate the iterative precursor ion selection.
UInt max_iteration_
maximal number of iterations
Definition: PrecursorIonSelection.h:252
double mz_tolerance_
precursor ion error tolerance
Definition: PrecursorIonSelection.h:248
std::vector< PeptideIdentification > filterPeptideIds_(std::vector< PeptideIdentification > &pep_ids)
UInt filterProtIds_(std::vector< ProteinIdentification > &prot_ids)
Groups protein identifications that cannot be distinguished by their peptide identifications.
void getNextPrecursors(FeatureMap &features, FeatureMap &next_features, UInt number)
Returns features with highest score for MS/MS.
const double & getMaxScore() const
void simulateILPBasedIPSRun_(FeatureMap &features, PeakMap &experiment, std::vector< PeptideIdentification > &pep_ids, std::vector< ProteinIdentification > &prot_ids, PrecursorIonSelectionPreprocessing &preprocessed_db, String output_path, String precursor_path="")
void getNextPrecursorsSeq(FeatureMap &features, FeatureMap &next_features, UInt number, double &rt)
void rescore_(FeatureMap &features, std::vector< PeptideIdentification > &new_pep_ids, PrecursorIonSelectionPreprocessing &preprocessed_db, PSProteinInference &protein_inference)
void updateMembers_() override
update members method from DefaultParamHandler to update the members
void rescore(FeatureMap &features, std::vector< PeptideIdentification > &new_pep_ids, std::vector< ProteinIdentification > &prot_ids, PrecursorIonSelectionPreprocessing &preprocessed_db, bool check_meta_values=true)
Change scoring of features using peptide identifications from all spectra.
LPWrapper::SOLVER getLPSolver()
Definition: PrecursorIonSelection.h:186
void shiftUp_(FeatureMap &features, PrecursorIonSelectionPreprocessing &preprocessed_db, String protein_acc)
const std::map< String, std::set< String > > & getPeptideProteinCounter()
Definition: PrecursorIonSelection.h:193
std::map< String, std::set< String > > prot_id_counter_
stores the peptide sequences for all protein identifications
Definition: PrecursorIonSelection.h:244
Type type_
precursor ion selection strategy
Definition: PrecursorIonSelection.h:242
void sortByTotalScore(FeatureMap &features)
Sort features by total score.
Definition: PrecursorIonSelection.h:118
void setMaxScore(const double &max_score)
LPWrapper::SOLVER solver_
Definition: PrecursorIonSelection.h:255
A more convenient string class.
Definition: String.h:60
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
static String number(double d, UInt n)
Definition: StringUtils.h:196
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Compare by score.
Definition: PrecursorIonSelection.h:104
bool operator()(Feature const &left, Feature const &right) const
Definition: PrecursorIonSelection.h:105
Compare by score.
Definition: PrecursorIonSelection.h:94
bool operator()(Feature const &left, Feature const &right) const
Definition: PrecursorIonSelection.h:95