OpenMS  3.0.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-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 
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 
86  ~PrecursorIonSelection() override;
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 
224  void checkForRequiredUserParams_(FeatureMap & features);
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 
double
OpenMS::PrecursorIonSelection::mz_tolerance_unit_
String mz_tolerance_unit_
precursor ion error tolerance unit (ppm or Da)
Definition: PrecursorIonSelection.h:250
OpenMS::FeatureMap::Iterator
Base::iterator Iterator
Definition: FeatureMap.h:144
OpenMS::MetaInfoInterface::getMetaValue
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...
OpenMS::PrecursorIonSelection::IPS
Definition: PrecursorIonSelection.h:76
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::PrecursorIonSelection
This class implements different precursor ion selection strategies.
Definition: PrecursorIonSelection.h:52
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:70
OpenMS::PrecursorIonSelection::SeqTotalScoreMore
Compare by score.
Definition: PrecursorIonSelection.h:103
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::PrecursorIonSelection::Type
Type
Precursor ion selection type (iterative, static, upshift, downshift, dynamic exclusion).
Definition: PrecursorIonSelection.h:74
OpenMS::PrecursorIonSelection::solver_
LPWrapper::SOLVER solver_
Definition: PrecursorIonSelection.h:255
OpenMS::PrecursorIonSelection::SeqTotalScoreMore::operator()
bool operator()(Feature const &left, Feature const &right) const
Definition: PrecursorIonSelection.h:105
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
OpenMS::PrecursorIonSelection::ILP_IPS
Definition: PrecursorIonSelection.h:77
OpenMS::PrecursorIonSelection::x_variable_number_
Size x_variable_number_
Definition: PrecursorIonSelection.h:253
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
PSLPFormulation.h
OpenMS::PrecursorIonSelection::fraction_counter_
std::vector< Size > fraction_counter_
stores the number of selected precursors per fraction
Definition: PrecursorIonSelection.h:246
OpenMS::PrecursorIonSelection::SPS
Definition: PrecursorIonSelection.h:78
OpenMS::PSLPFormulation
Implements ILP formulation of precursor selection problems.
Definition: PSLPFormulation.h:55
FeatureMap.h
OpenMS::PrecursorIonSelection::getPeptideProteinCounter
const std::map< String, std::set< String > > & getPeptideProteinCounter()
Definition: PrecursorIonSelection.h:193
OpenMS::PrecursorIonSelection::UPSHIFT
Definition: PrecursorIonSelection.h:79
OpenMS::PrecursorIonSelection::setLPSolver
void setLPSolver(LPWrapper::SOLVER solver)
Definition: PrecursorIonSelection.h:180
OpenMS::PrecursorIonSelection::max_iteration_
UInt max_iteration_
maximal number of iterations
Definition: PrecursorIonSelection.h:252
OpenMS::PrecursorIonSelection::min_pep_ids_
UInt min_pep_ids_
minimal number of peptides identified for a protein to be declared identified
Definition: PrecursorIonSelection.h:238
OpenMS::PrecursorIonSelection::TotalScoreMore
Compare by score.
Definition: PrecursorIonSelection.h:93
OpenMS::Peak2D::getRT
CoordinateType getRT() const
Returns the RT coordinate (index 0)
Definition: Peak2D.h:208
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::PrecursorIonSelection::prot_id_counter_
std::map< String, std::set< String > > prot_id_counter_
stores the peptide sequences for all protein identifications
Definition: PrecursorIonSelection.h:244
OpenMS::PrecursorIonSelection::getLPSolver
LPWrapper::SOLVER getLPSolver()
Definition: PrecursorIonSelection.h:186
OpenMS::PSProteinInference
This class implements protein inference for the precursor ion selection strategies.
Definition: PSProteinInference.h:47
OpenMS::PrecursorIonSelection::mz_tolerance_
double mz_tolerance_
precursor ion error tolerance
Definition: PrecursorIonSelection.h:248
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:98
OpenMS::Feature
An LC-MS feature.
Definition: Feature.h:70
OpenMS::StringUtils::number
static String number(double d, UInt n)
Definition: StringUtils.h:196
OpenMS::LPWrapper::SOLVER
SOLVER
Definition: LPWrapper.h:130
OpenMS::PrecursorIonSelection::max_score_
double max_score_
maximal score in the FeatureMap
Definition: PrecursorIonSelection.h:240
PeptideIdentification.h
OpenMS::PrecursorIonSelection::TotalScoreMore::operator()
bool operator()(Feature const &left, Feature const &right) const
Definition: PrecursorIonSelection.h:95
OpenMS::PrecursorIonSelection::type_
Type type_
precursor ion selection strategy
Definition: PrecursorIonSelection.h:242
OpenMS::PrecursorIonSelection::sortByTotalScore
void sortByTotalScore(FeatureMap &features)
Sort features by total score.
Definition: PrecursorIonSelection.h:118
OpenMS::PrecursorIonSelectionPreprocessing
This class implements the database preprocessing needing for precursor ion selection.
Definition: PrecursorIonSelectionPreprocessing.h:52
OpenMS::PrecursorIonSelection::DOWNSHIFT
Definition: PrecursorIonSelection.h:80