OpenMS  2.7.0
FeatureFinderIdentificationAlgorithm.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: Hendrik Weisser $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERIDENTIFICATIONALGORITHM_H
36 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERIDENTIFICATIONALGORITHM_H
37 
45 
46 #include <vector>
47 #include <fstream>
48 #include <map>
49 
50 namespace OpenMS
51 {
52  class IsotopeDistribution;
53 
54 
55 
57  public DefaultParamHandler
58 {
59 public:
62 
71  void run(
72  std::vector<PeptideIdentification> peptides,
73  const std::vector<ProteinIdentification>& proteins,
74  std::vector<PeptideIdentification> peptides_ext,
75  std::vector<ProteinIdentification> proteins_ext,
76  FeatureMap& features,
77  const FeatureMap& seeds = FeatureMap()
78  );
79 
80  void runOnCandidates(FeatureMap& features);
81 
83  const PeakMap& getMSData() const;
84 
85  void setMSData(const PeakMap& ms_data);
86 
88  const PeakMap& getChromatograms() const;
89 
92 
95 
96 protected:
99 
101  typedef std::multimap<double, PeptideIdentification*> RTMap;
103  typedef std::map<Int, std::pair<RTMap, RTMap> > ChargeMap;
105  typedef std::map<AASequence, ChargeMap> PeptideMap;
107  typedef std::map<String, std::pair<RTMap, RTMap> > PeptideRefRTMap;
108 
110 
113 
115  double rt_window_;
116  double mz_window_;
118 
120 
121  double isotope_pmin_;
123 
124  double rt_quantile_;
125 
126  double peak_width_;
129 
131 
132  // SVM related parameters
139 
140  // output file (before filtering)
142 
144 
145  void updateMembers_() override;
146 
148  struct RTRegion
149  {
150  double start, end;
152  };
153 
156  {
157  bool operator()(const Feature& feature)
158  {
159  return feature.getOverallQuality() == 0.0;
160  }
161  } feature_filter_quality_;
162 
165  {
166  bool operator()(const Feature& feature)
167  {
168  return feature.getPeptideIdentifications().empty();
169  }
170  } feature_filter_peptides_;
171 
174  {
176  const PeptideIdentification& p2)
177  {
178  const String& seq1 = p1.getHits()[0].getSequence().toString();
179  const String& seq2 = p2.getHits()[0].getSequence().toString();
180  if (seq1 == seq2)
181  {
182  Int charge1 = p1.getHits()[0].getCharge();
183  Int charge2 = p2.getHits()[0].getCharge();
184  if (charge1 == charge2)
185  {
186  return p1.getRT() < p2.getRT();
187  }
188  return charge1 < charge2;
189  }
190  return seq1 < seq2;
191  }
192  } peptide_compare_;
193 
196  {
197  bool operator()(const Feature& f1, const Feature& f2)
198  {
199  const String& ref1 = f1.getMetaValue("PeptideRef");
200  const String& ref2 = f2.getMetaValue("PeptideRef");
201  if (ref1 == ref2)
202  {
203  return f1.getRT() < f2.getRT();
204  }
205  return ref1 < ref2;
206  }
207  } feature_compare_;
208 
212 
214 
215  const double seed_rt_window_ = 60.0;
216 
218  std::map<double, std::pair<Size, Size> > svm_probs_internal_;
220  std::multiset<double> svm_probs_external_;
225  std::map<String, double> isotope_probs_;
227 
229 
231  void generateTransitions_(const String& peptide_id, double mz, Int charge,
232  const IsotopeDistribution& iso_dist);
233 
234  void addPeptideRT_(TargetedExperiment::Peptide& peptide, double rt) const;
235 
237  void getRTRegions_(ChargeMap& peptide_data, std::vector<RTRegion>& rt_regions, bool clear_IDs = true) const;
238 
240  FeatureMap& features,
241  std::map<Size, std::vector<PeptideIdentification*> >& feat_ids,
242  RTMap& rt_internal);
243 
245  void annotateFeatures_(FeatureMap& features, PeptideRefRTMap& ref_rt_map);
246 
247  void ensureConvexHulls_(Feature& feature);
248 
249  void postProcess_(FeatureMap& features, bool with_external_ids);
250 
252  void statistics_(const FeatureMap& features) const;
253 
257  void createAssayLibrary_(const PeptideMap::iterator& begin, const PeptideMap::iterator& end, PeptideRefRTMap& ref_rt_map, bool clear_IDs = true);
258 
263  PeptideMap& peptide_map,
264  bool external = false) const;
265 
266  void checkNumObservations_(Size n_pos, Size n_neg, const String& note = "") const;
267 
268  void getUnbiasedSample_(const std::multimap<double, std::pair<Size, bool> >& valid_obs,
269  std::map<Size, Int>& training_labels);
270 
271  void getRandomSample_(std::map<Size, Int>& training_labels);
272 
273  void classifyFeatures_(FeatureMap& features);
274 
275  void filterFeaturesFinalizeAssay_(Feature& best_feature, double best_quality,
276  const double quality_cutoff);
277 
278  void filterFeatures_(FeatureMap& features, bool classified);
279 
280  void calculateFDR_(FeatureMap& features);
281 
284  template <typename It>
285  std::vector<std::pair<It,It>>
286  chunk_(It range_from, It range_to, const std::ptrdiff_t batch_size)
287  {
288  /* Aliases, to make the rest of the code more readable. */
289  using std::vector;
290  using std::pair;
291  using std::make_pair;
292  using std::distance;
293  using diff_t = std::ptrdiff_t;
294 
295  /* Total item number and batch_size size. */
296  const diff_t total {distance(range_from, range_to)};
297  const diff_t num {total / batch_size};
298 
299  vector<pair<It,It>> chunks(num);
300 
301  It batch_end {range_from};
302 
303  /* Use the 'generate' algorithm to create batches. */
304  std::generate(begin(chunks), end(chunks), [&batch_end, batch_size]()
305  {
306  It batch_start {batch_end };
307 
308  std::advance(batch_end, batch_size);
309  return make_pair(batch_start, batch_end);
310  });
311 
312  /* The last batch_size's end must always be 'range_to'. */
313  if (chunks.empty())
314  {
315  chunks.emplace_back(range_from, range_to);
316  }
317  else
318  {
319  chunks.back().second = range_to;
320  }
321 
322  return chunks;
323  }
324 };
325 
326 } // namespace OpenMS
327 
328 #endif
329 
const std::vector< PeptideIdentification > & getPeptideIdentifications() const
returns a const reference to the PeptideIdentification vector
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:93
Definition: FeatureFinderIdentificationAlgorithm.h:58
FeatureFinderAlgorithmPickedHelperStructs::MassTraces MassTraces
Definition: FeatureFinderIdentificationAlgorithm.h:98
void postProcess_(FeatureMap &features, bool with_external_ids)
double rt_window_
RT window width.
Definition: FeatureFinderIdentificationAlgorithm.h:115
void getRTRegions_(ChargeMap &peptide_data, std::vector< RTRegion > &rt_regions, bool clear_IDs=true) const
get regions in which peptide eludes (ideally only one) by clustering RT elution times
void runOnCandidates(FeatureMap &features)
std::map< AASequence, ChargeMap > PeptideMap
mapping: sequence -> charge -> internal/external ID information
Definition: FeatureFinderIdentificationAlgorithm.h:105
const TargetedExperiment & getLibrary() const
void createAssayLibrary_(const PeptideMap::iterator &begin, const PeptideMap::iterator &end, PeptideRefRTMap &ref_rt_map, bool clear_IDs=true)
String svm_xval_out_
Definition: FeatureFinderIdentificationAlgorithm.h:135
String elution_model_
Definition: FeatureFinderIdentificationAlgorithm.h:130
PeptideMap peptide_map_
Definition: FeatureFinderIdentificationAlgorithm.h:109
void filterFeaturesFinalizeAssay_(Feature &best_feature, double best_quality, const double quality_cutoff)
double end
Definition: FeatureFinderIdentificationAlgorithm.h:150
MRMFeatureFinderScoring feat_finder_
OpenSWATH feature finder.
Definition: FeatureFinderIdentificationAlgorithm.h:226
FeatureFinderIdentificationAlgorithm()
default constructor
void filterFeatures_(FeatureMap &features, bool classified)
Size n_external_peps_
number of external peptides
Definition: FeatureFinderIdentificationAlgorithm.h:112
double signal_to_noise_
Definition: FeatureFinderIdentificationAlgorithm.h:128
void getRandomSample_(std::map< Size, Int > &training_labels)
void generateTransitions_(const String &peptide_id, double mz, Int charge, const IsotopeDistribution &iso_dist)
generate transitions (isotopic traces) for a peptide ion and add them to the library:
const ProgressLogger & getProgressLogger() const
void run(std::vector< PeptideIdentification > peptides, const std::vector< ProteinIdentification > &proteins, std::vector< PeptideIdentification > peptides_ext, std::vector< ProteinIdentification > proteins_ext, FeatureMap &features, const FeatureMap &seeds=FeatureMap())
TransformationDescription trafo_external_
TransformationDescription trafo_; // RT transformation (to range 0-1)
Definition: FeatureFinderIdentificationAlgorithm.h:224
bool quantify_decoys_
Definition: FeatureFinderIdentificationAlgorithm.h:213
TargetedExperiment library_
accumulated assays for peptides
Definition: FeatureFinderIdentificationAlgorithm.h:211
void annotateFeaturesFinalizeAssay_(FeatureMap &features, std::map< Size, std::vector< PeptideIdentification * > > &feat_ids, RTMap &rt_internal)
double min_peak_width_
Definition: FeatureFinderIdentificationAlgorithm.h:127
void calculateFDR_(FeatureMap &features)
StringList svm_predictor_names_
Definition: FeatureFinderIdentificationAlgorithm.h:134
void setMSData(const PeakMap &ms_data)
std::map< Int, std::pair< RTMap, RTMap > > ChargeMap
mapping: charge -> internal/external: (RT -> pointer to peptide)
Definition: FeatureFinderIdentificationAlgorithm.h:103
Size svm_n_parts_
number of partitions for SVM cross-validation
Definition: FeatureFinderIdentificationAlgorithm.h:137
Size svm_n_samples_
number of samples for SVM training
Definition: FeatureFinderIdentificationAlgorithm.h:138
Size n_internal_peps_
number of internal peptide
Definition: FeatureFinderIdentificationAlgorithm.h:111
void getUnbiasedSample_(const std::multimap< double, std::pair< Size, bool > > &valid_obs, std::map< Size, Int > &training_labels)
Size n_internal_features_
internal feature counter (for FDR calculation)
Definition: FeatureFinderIdentificationAlgorithm.h:221
void addPeptideToMap_(PeptideIdentification &peptide, PeptideMap &peptide_map, bool external=false) const
ProgressLogger prog_log_
Definition: FeatureFinderIdentificationAlgorithm.h:228
PeakMap ms_data_
input LC-MS data
Definition: FeatureFinderIdentificationAlgorithm.h:209
void statistics_(const FeatureMap &features) const
some statistics on detected features
Size batch_size_
nr of peptides to use at the same time during chromatogram extraction
Definition: FeatureFinderIdentificationAlgorithm.h:114
double mz_window_
m/z window width
Definition: FeatureFinderIdentificationAlgorithm.h:116
double svm_min_prob_
Definition: FeatureFinderIdentificationAlgorithm.h:133
std::map< String, double > isotope_probs_
isotope probabilities of transitions
Definition: FeatureFinderIdentificationAlgorithm.h:225
void checkNumObservations_(Size n_pos, Size n_neg, const String &note="") const
double peak_width_
Definition: FeatureFinderIdentificationAlgorithm.h:126
Size n_external_features_
Definition: FeatureFinderIdentificationAlgorithm.h:222
FeatureFinderAlgorithmPickedHelperStructs::MassTrace MassTrace
Definition: FeatureFinderIdentificationAlgorithm.h:97
Size n_isotopes_
number of isotopes for peptide assay
Definition: FeatureFinderIdentificationAlgorithm.h:122
double mapping_tolerance_
RT tolerance for mapping IDs to features.
Definition: FeatureFinderIdentificationAlgorithm.h:119
std::map< String, std::pair< RTMap, RTMap > > PeptideRefRTMap
mapping: peptide ref. -> int./ext.: (RT -> pointer to peptide)
Definition: FeatureFinderIdentificationAlgorithm.h:107
Size debug_level_
Definition: FeatureFinderIdentificationAlgorithm.h:143
double rt_quantile_
Definition: FeatureFinderIdentificationAlgorithm.h:124
std::vector< std::pair< It, It > > chunk_(It range_from, It range_to, const std::ptrdiff_t batch_size)
Definition: FeatureFinderIdentificationAlgorithm.h:286
std::multiset< double > svm_probs_external_
SVM probabilities for "external" features (for FDR calculation):
Definition: FeatureFinderIdentificationAlgorithm.h:220
ChargeMap ids
internal/external peptide IDs (per charge) in this region
Definition: FeatureFinderIdentificationAlgorithm.h:151
bool mz_window_ppm_
m/z window width is given in PPM (not Da)?
Definition: FeatureFinderIdentificationAlgorithm.h:117
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
void classifyFeatures_(FeatureMap &features)
void addPeptideRT_(TargetedExperiment::Peptide &peptide, double rt) const
PeakMap chrom_data_
accumulated chromatograms (XICs)
Definition: FeatureFinderIdentificationAlgorithm.h:210
std::multimap< double, PeptideIdentification * > RTMap
mapping: RT (not necessarily unique) -> pointer to peptide
Definition: FeatureFinderIdentificationAlgorithm.h:101
void annotateFeatures_(FeatureMap &features, PeptideRefRTMap &ref_rt_map)
annotate identified features with m/z, isotope probabilities, etc.
String candidates_out_
Definition: FeatureFinderIdentificationAlgorithm.h:141
double isotope_pmin_
min. isotope probability for peptide assay
Definition: FeatureFinderIdentificationAlgorithm.h:121
double svm_quality_cutoff
Definition: FeatureFinderIdentificationAlgorithm.h:136
std::map< double, std::pair< Size, Size > > svm_probs_internal_
SVM probability -> number of pos./neg. features (for FDR calculation):
Definition: FeatureFinderIdentificationAlgorithm.h:218
region in RT in which a peptide elutes:
Definition: FeatureFinderIdentificationAlgorithm.h:149
A container for features.
Definition: FeatureMap.h:105
An LC-MS feature.
Definition: Feature.h:72
QualityType getOverallQuality() const
Non-mutable access to the overall quality.
Definition: IsotopeDistribution.h:65
The MRMFeatureFinder finds and scores peaks of transitions that co-elute.
Definition: MRMFeatureFinderScoring.h:96
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:80
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...
CoordinateType getRT() const
Returns the RT coordinate (index 0)
Definition: Peak2D.h:208
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:65
double getRT() const
returns the RT of the MS2 spectrum where the identification occurred
const std::vector< PeptideHit > & getHits() const
returns the peptide hits as const
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
A more convenient string class.
Definition: String.h:61
Represents a peptide (amino acid sequence)
Definition: TargetedExperimentHelper.h:360
A description of a targeted experiment containing precursor and production ions.
Definition: TargetedExperiment.h:65
Generic description of a coordinate transformation.
Definition: TransformationDescription.h:63
int Int
Signed integer type.
Definition: Types.h:102
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Helper struct for mass traces used in FeatureFinderAlgorithmPicked.
Definition: FeatureFinderAlgorithmPickedHelperStructs.h:80
Helper struct for a collection of mass traces used in FeatureFinderAlgorithmPicked.
Definition: FeatureFinderAlgorithmPickedHelperStructs.h:111
comparison functor for features
Definition: FeatureFinderIdentificationAlgorithm.h:196
bool operator()(const Feature &f1, const Feature &f2)
Definition: FeatureFinderIdentificationAlgorithm.h:197
predicate for filtering features by assigned peptides:
Definition: FeatureFinderIdentificationAlgorithm.h:165
bool operator()(const Feature &feature)
Definition: FeatureFinderIdentificationAlgorithm.h:166
predicate for filtering features by overall quality:
Definition: FeatureFinderIdentificationAlgorithm.h:156
bool operator()(const Feature &feature)
Definition: FeatureFinderIdentificationAlgorithm.h:157
comparison functor for (unassigned) peptide IDs
Definition: FeatureFinderIdentificationAlgorithm.h:174
bool operator()(const PeptideIdentification &p1, const PeptideIdentification &p2)
Definition: FeatureFinderIdentificationAlgorithm.h:175