OpenMS  3.0.0
FeatureFinderAlgorithmMetaboIdent.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: Timo Sachsenberg, Hendrik Weisser $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
45 
46 #include <map>
47 #include <vector>
48 
49 namespace OpenMS
50 {
51 class IsotopeDistribution;
52 
53 class OPENMS_DLLAPI FeatureFinderAlgorithmMetaboIdent :
54  public DefaultParamHandler
55 {
56 public:
58  struct OPENMS_DLLAPI FeatureFinderMetaboIdentCompound
59  {
61  const String& _formula,
62  double _mass,
63  const std::vector<int>& _charges,
64  const std::vector<double>& _rts,
65  const std::vector<double>& _rt_ranges,
66  const std::vector<double>& _iso_distrib):
67  name_(_name),
68  formula_(_formula),
69  mass_(_mass),
70  charges_(_charges),
71  rts_(_rts),
72  rt_ranges_(_rt_ranges),
73  iso_distrib_(_iso_distrib)
74  {
75  }
76 
77  private:
80  double mass_;
81  std::vector<int> charges_;
82  std::vector<double> rts_;
83  std::vector<double> rt_ranges_;
84  std::vector<double> iso_distrib_;
85 
86  public:
87  const String& getName() const {
88  return name_;
89  }
90 
91  const String& getFormula() const {
92  return formula_;
93  }
94 
95  double getMass() const {
96  return mass_;
97  }
98 
99  const std::vector<int>& getCharges() const {
100  return charges_;
101  }
102 
103  const std::vector<double>& getRTs() const {
104  return rts_;
105  }
106 
107  const std::vector<double> getRTRanges() const {
108  return rt_ranges_;
109  }
110 
111  const std::vector<double>& getIsotopeDistribution() const {
112  return iso_distrib_;
113  }
114  };
115 
118 
123  void run(const std::vector<FeatureFinderMetaboIdentCompound>& metaboIdentTable, FeatureMap& features, String spectra_file = "");
124 
126  PeakMap& getMSData() { return ms_data_; }
127  const PeakMap& getMSData() const { return ms_data_; }
128 
130  void setMSData(const PeakMap& m); // needed because pyOpenMS can't wrap the non-const reference version
131 
132  void setMSData(PeakMap&& m); // moves peak data and saves the copy. Note that getMSData() will give back a processed/modified version.
133 
135  const PeakMap& getChromatograms() const { return chrom_data_; }
136  PeakMap& getChromatograms() { return chrom_data_; }
137 
139  const TargetedExperiment& getLibrary() const { return library_; }
140 
142  const TransformationDescription& getTransformations() const { return trafo_; }
143 
145  size_t getNShared() const { return n_shared_; }
146 
147  String prettyPrintCompound(const TargetedExperiment::Compound& compound);
148 protected:
149 
152  {
154  double rt_min, rt_max, mz_min, mz_max;
155  };
156 
158  typedef std::map<UInt64, std::vector<MassTraceBounds> > FeatureBoundsMap;
159 
162 
163  typedef std::vector<Feature*> FeatureGroup;
164 
167  {
168  bool operator()(const Feature& feature)
169  {
170  return feature.metaValueExists("FFMetId_remove");
171  }
172  } feature_filter_;
173 
176  {
177  bool operator()(const Feature& f1, const Feature& f2)
178  {
179  const String& ref1 = f1.getMetaValue("PeptideRef");
180  const String& ref2 = f2.getMetaValue("PeptideRef");
181  if (ref1 == ref2)
182  {
183  return f1.getRT() < f2.getRT();
184  }
185  return ref1 < ref2;
186  }
187  } feature_compare_;
188 
189 
190  void extractTransformations_(const FeatureMap& features);
191 
193  void addTargetToLibrary_(const String& name, const String& formula,
194  double mass, const std::vector<Int>& charges,
195  const std::vector<double>& rts,
196  std::vector<double> rt_ranges,
197  const std::vector<double>& iso_distrib);
198 
200  Size addTargetAnnotations_(FeatureMap& features);
201 
202  void addTargetRT_(TargetedExperiment::Compound& target, double rt);
203 
205  double calculateMZ_(double mass, Int charge) const;
206 
207  void generateTransitions_(const String& target_id, double mz, Int charge,
208  const IsotopeDistribution& iso_dist);
209 
211  bool hasOverlappingBounds_(const std::vector<MassTraceBounds>& mtb1,
212  const std::vector<MassTraceBounds>& mtb2) const;
213 
214  void getFeatureBounds_(const FeatureMap& features,
215  FeatureBoundsMap& feature_bounds);
216 
217 
218  bool hasOverlappingFeature_(const Feature& feature, const FeatureGroup& group,
219  const FeatureBoundsMap& feature_bounds) const;
220 
221  void findOverlappingFeatures_(FeatureMap& features,
222  const FeatureBoundsMap& feature_bounds,
223  std::vector<FeatureGroup>& overlap_groups);
224 
225  void resolveOverlappingFeatures_(FeatureGroup& group,
226  const FeatureBoundsMap& feature_bounds);
227 
228  void annotateFeatures_(FeatureMap& features);
229 
230  void ensureConvexHulls_(Feature& feature) const;
231 
232  void selectFeaturesFromCandidates_(FeatureMap& features);
233 
234  double rt_window_;
235  double mz_window_;
237 
238  double isotope_pmin_;
240 
241  double peak_width_;
244 
246 
247  // output file (before filtering)
249 
251 
252  void updateMembers_() override;
253 
256 
258 
260 
262 
264  std::map<String, double> isotope_probs_;
265  std::map<String, double> target_rts_;
266 
267  size_t n_shared_ = 0;
268 };
269 
270 } // namespace OpenMS
std::vector< double > rt_ranges_
Definition: FeatureFinderAlgorithmMetaboIdent.h:83
FeatureFinderMetaboIdentCompound(const String &_name, const String &_formula, double _mass, const std::vector< int > &_charges, const std::vector< double > &_rts, const std::vector< double > &_rt_ranges, const std::vector< double > &_iso_distrib)
Definition: FeatureFinderAlgorithmMetaboIdent.h:60
double rt_window_
RT window width.
Definition: FeatureFinderAlgorithmMetaboIdent.h:234
double isotope_pmin_
min. isotope probability for peptide assay
Definition: FeatureFinderAlgorithmMetaboIdent.h:238
TargetedExperiment library_
accumulated assays for targets
Definition: FeatureFinderAlgorithmMetaboIdent.h:259
bool operator()(const Feature &f1, const Feature &f2)
Definition: FeatureFinderAlgorithmMetaboIdent.h:177
bool operator()(const Feature &feature)
Definition: FeatureFinderAlgorithmMetaboIdent.h:168
A more convenient string class.
Definition: String.h:58
Isotope pattern generator for coarse isotope distributions.
Definition: CoarseIsotopePatternGenerator.h:103
double getMass() const
Definition: FeatureFinderAlgorithmMetaboIdent.h:95
FeatureFinderAlgorithmPickedHelperStructs::MassTrace MassTrace
Definition: FeatureFinderAlgorithmMetaboIdent.h:160
Size n_isotopes_
number of isotopes for peptide assay
Definition: FeatureFinderAlgorithmMetaboIdent.h:239
double mass_
Definition: FeatureFinderAlgorithmMetaboIdent.h:80
TransformationDescription trafo_
Definition: FeatureFinderAlgorithmMetaboIdent.h:261
Helper struct for a collection of mass traces used in FeatureFinderAlgorithmPicked.
Definition: FeatureFinderAlgorithmPickedHelperStructs.h:109
A container for features.
Definition: FeatureMap.h:98
FeatureFinderAlgorithmPickedHelperStructs::MassTraces MassTraces
Definition: FeatureFinderAlgorithmMetaboIdent.h:161
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...
The MRMFeatureFinder finds and scores peaks of transitions that co-elute.
Definition: MRMFeatureFinderScoring.h:89
PeakMap & getMSData()
Retrieve chromatograms (empty if run was not executed)
Definition: FeatureFinderAlgorithmMetaboIdent.h:126
Definition: IsotopeDistribution.h:64
double min_peak_width_
Definition: FeatureFinderAlgorithmMetaboIdent.h:242
const PeakMap & getMSData() const
Definition: FeatureFinderAlgorithmMetaboIdent.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
represents a compound in the assay library
Definition: FeatureFinderAlgorithmMetaboIdent.h:58
double signal_to_noise_
Definition: FeatureFinderAlgorithmMetaboIdent.h:243
const PeakMap & getChromatograms() const
Retrieve chromatograms (empty if run was not executed)
Definition: FeatureFinderAlgorithmMetaboIdent.h:135
const std::vector< int > & getCharges() const
Definition: FeatureFinderAlgorithmMetaboIdent.h:99
PeakMap & getChromatograms()
Definition: FeatureFinderAlgorithmMetaboIdent.h:136
std::vector< double > rts_
Definition: FeatureFinderAlgorithmMetaboIdent.h:82
size_t getNShared() const
Retrieve number of features with shared identifications.
Definition: FeatureFinderAlgorithmMetaboIdent.h:145
std::vector< double > iso_distrib_
Definition: FeatureFinderAlgorithmMetaboIdent.h:84
std::vector< int > charges_
Definition: FeatureFinderAlgorithmMetaboIdent.h:81
bool metaValueExists(const String &name) const
Returns whether an entry with the given name exists.
String formula_
Definition: FeatureFinderAlgorithmMetaboIdent.h:79
PeakMap chrom_data_
accumulated chromatograms (XICs)
Definition: FeatureFinderAlgorithmMetaboIdent.h:255
double rt_min
Definition: FeatureFinderAlgorithmMetaboIdent.h:154
const std::vector< double > getRTRanges() const
Definition: FeatureFinderAlgorithmMetaboIdent.h:107
MRMFeatureFinderScoring feat_finder_
OpenSWATH feature finder.
Definition: FeatureFinderAlgorithmMetaboIdent.h:257
Size sub_index
Definition: FeatureFinderAlgorithmMetaboIdent.h:153
double peak_width_
Definition: FeatureFinderAlgorithmMetaboIdent.h:241
Boundaries for a mass trace in a feature.
Definition: FeatureFinderAlgorithmMetaboIdent.h:151
An LC-MS feature.
Definition: Feature.h:70
std::map< String, double > target_rts_
RTs of targets (assays)
Definition: FeatureFinderAlgorithmMetaboIdent.h:265
Comparison functor for features.
Definition: FeatureFinderAlgorithmMetaboIdent.h:175
Represents a compound (small molecule)
Definition: TargetedExperimentHelper.h:321
CoarseIsotopePatternGenerator iso_gen_
isotope pattern generator
Definition: FeatureFinderAlgorithmMetaboIdent.h:263
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:70
CoordinateType getRT() const
Returns the RT coordinate (index 0)
Definition: Peak2D.h:210
String candidates_out_
Definition: FeatureFinderAlgorithmMetaboIdent.h:248
Predicate for filtering features by overall quality.
Definition: FeatureFinderAlgorithmMetaboIdent.h:166
const TargetedExperiment & getLibrary() const
Retrieve the assay library (e.g., to store as TraML, empty if run was not executed) ...
Definition: FeatureFinderAlgorithmMetaboIdent.h:139
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Size debug_level_
Definition: FeatureFinderAlgorithmMetaboIdent.h:250
A description of a targeted experiment containing precursor and production ions.
Definition: TargetedExperiment.h:64
bool mz_window_ppm_
m/z window width is given in PPM (not Da)?
Definition: FeatureFinderAlgorithmMetaboIdent.h:236
const std::vector< double > & getRTs() const
Definition: FeatureFinderAlgorithmMetaboIdent.h:103
std::vector< Feature * > FeatureGroup
group of (overlapping) features
Definition: FeatureFinderAlgorithmMetaboIdent.h:163
const std::vector< double > & getIsotopeDistribution() const
Definition: FeatureFinderAlgorithmMetaboIdent.h:111
const String & getFormula() const
Definition: FeatureFinderAlgorithmMetaboIdent.h:91
Generic description of a coordinate transformation.
Definition: TransformationDescription.h:62
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
String name_
Definition: FeatureFinderAlgorithmMetaboIdent.h:78
Definition: FeatureFinderAlgorithmMetaboIdent.h:53
std::map< String, double > isotope_probs_
isotope probabilities of transitions
Definition: FeatureFinderAlgorithmMetaboIdent.h:264
const TransformationDescription & getTransformations() const
Retrieve deviations between provided coordinates and extracted ones (e.g., to store as TrafoXML or fo...
Definition: FeatureFinderAlgorithmMetaboIdent.h:142
PeakMap ms_data_
input LC-MS data
Definition: FeatureFinderAlgorithmMetaboIdent.h:254
String elution_model_
Definition: FeatureFinderAlgorithmMetaboIdent.h:245
int Int
Signed integer type.
Definition: Types.h:102
std::map< UInt64, std::vector< MassTraceBounds > > FeatureBoundsMap
Boundaries for all mass traces per feature.
Definition: FeatureFinderAlgorithmMetaboIdent.h:158
double mz_window_
m/z window width
Definition: FeatureFinderAlgorithmMetaboIdent.h:235
const String & getName() const
Definition: FeatureFinderAlgorithmMetaboIdent.h:87
Helper struct for mass traces used in FeatureFinderAlgorithmPicked.
Definition: FeatureFinderAlgorithmPickedHelperStructs.h:79