OpenMS
MetaboTargetedAssay.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-2023.
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: Oliver Alka $
32 // $Authors: Oliver Alka $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
38 #include <map> //insert
39 
42 #include <OpenMS/ANALYSIS/ID/SiriusMSConverter.h> //SiriusMSFile
43 #include <OpenMS/FORMAT/DATAACCESS/SiriusFragmentAnnotation.h> //SiriusTargetDecoySpectra
44 
46 
47 namespace OpenMS
48 {
53  class OPENMS_DLLAPI MetaboTargetedAssay
54  {
55  public:
59  double precursor_int;
61  double precursor_mz;
62  double compound_rt;
68  std::vector<ReactionMonitoringTransition> potential_rmts;
69 
74  {
75  public:
78 
81  compound_info(std::move(info)),
82  target_decoy_spectra(std::move(td_spectra))
83  {}
84  };
85 
90  {
91  public:
94 
95  CompoundSpectrumPair() = default;
97  compound_info(std::move(info)),
98  spectrum(std::move(spectrum))
99  {}
100  };
101 
107  {
108  int target_index = -1;
109  int decoy_index = -1;
110  double target_mz = 0.0;
111  double target_rt = 0.0;
112  double decoy_mz = 0.0;
113  double decoy_rt = 0.0;
114  int target_file_number = 0;
115  int decoy_file_number = 0;
116  };
117 
135  static std::vector<MetaboTargetedAssay> extractMetaboTargetedAssay(const MSExperiment& spectra,
136  const FeatureMapping::FeatureToMs2Indices& feature_ms2_index,
137  const double& precursor_rt_tol,
138  const double& precursor_mz_distance,
139  const double& cosine_sim_threshold,
140  const double& transition_threshold,
141  const double& min_fragment_mz,
142  const double& max_fragment_mz,
143  const bool& method_consensus_spectrum,
144  const bool& exclude_ms2_precursor,
145  const unsigned int& file_counter);
146 
160  static std::vector<MetaboTargetedAssay> extractMetaboTargetedAssayFragmentAnnotation(const std::vector< CompoundTargetDecoyPair >& v_cmp_spec,
161  const double& transition_threshold,
162  const double& min_fragment_mz,
163  const double& max_fragment_mz,
164  const bool& use_exact_mass,
165  const bool& exclude_ms2_precursor,
166  const unsigned int& file_counter);
167 
177  static std::vector< MetaboTargetedAssay::CompoundTargetDecoyPair > pairCompoundWithAnnotatedTDSpectraPairs(const std::vector<SiriusMSFile::CompoundInfo>& v_cmpinfo,
178  const std::vector<SiriusFragmentAnnotation::SiriusTargetDecoySpectra>& annotated_spectra);
179  static std::vector< MetaboTargetedAssay::CompoundSpectrumPair > pairCompoundWithAnnotatedSpectra(const std::vector<SiriusMSFile::CompoundInfo>& v_cmpinfo,
180  const std::vector<MSSpectrum>& annotated_spectra);
181 
193  static std::unordered_map< UInt64, std::vector<MetaboTargetedAssay> > buildAmbiguityGroup(const std::vector<MetaboTargetedAssay>& v_mta,
194  const double& ar_mz_tol,
195  const double& ar_rt_tol,
196  const String& ar_mz_tol_unit_res, size_t in_files_size);
197 
206  static void resolveAmbiguityGroup(std::unordered_map< UInt64, std::vector<MetaboTargetedAssay> >& map_mta_filter,
207  const double& total_occurrence_filter,
208  size_t in_files_size);
209 
210  protected:
211 
213  static constexpr float noise_threshold_constant_ = 1.1;
214 
218  static bool intensityLess_(const Peak1D& a, const Peak1D& b);
219 
223  static int getChargeFromAdduct_(const String& adduct);
224 
233  static void filterBasedOnTotalOccurrence_(std::vector<MetaboTargetedAssay>& mta, double total_occurrence_filter, size_t in_files_size);
234 
240  static void filterBasedOnMolFormAdductOccurrence_(std::vector<MetaboTargetedAssay>& mta);
241 
245  static void sortByPrecursorInt(std::vector<MetaboTargetedAssay>& vec_mta);
246  };
247 
248 } // namespace OpenMS
Stores preprocessed feature mapping information.
Definition: FeatureMapping.h:59
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:72
The representation of a 1D spectrum.
Definition: MSSpectrum.h:70
CompoundTargetDecoyPair stores a pair of CompoundInfo and MSSpectrum.
Definition: MetaboTargetedAssay.h:90
CompoundSpectrumPair(SiriusMSFile::CompoundInfo info, MSSpectrum spectrum)
Definition: MetaboTargetedAssay.h:96
SiriusMSFile::CompoundInfo compound_info
Definition: MetaboTargetedAssay.h:92
MSSpectrum spectrum
Definition: MetaboTargetedAssay.h:93
CompoundTargetDecoyPair stores a pair of CompoundInfo and MSSpectrum (target, decoy)
Definition: MetaboTargetedAssay.h:74
SiriusMSFile::CompoundInfo compound_info
Definition: MetaboTargetedAssay.h:76
CompoundTargetDecoyPair(SiriusMSFile::CompoundInfo info, SiriusFragmentAnnotation::SiriusTargetDecoySpectra td_spectra)
Definition: MetaboTargetedAssay.h:80
SiriusFragmentAnnotation::SiriusTargetDecoySpectra target_decoy_spectra
Definition: MetaboTargetedAssay.h:77
This class provides methods for the extraction of targeted assays for metabolomics.
Definition: MetaboTargetedAssay.h:54
static void filterBasedOnTotalOccurrence_(std::vector< MetaboTargetedAssay > &mta, double total_occurrence_filter, size_t in_files_size)
Filter one ambiguity group based on occurrence in samples (e.g. at least in 20% of the samples)
static int getChargeFromAdduct_(const String &adduct)
Gets charge from a singly charged adduct ([M+H]+/[M-H]-)
TargetedExperiment::Compound potential_cmp
compound information stored in a TargetedExperiment
Definition: MetaboTargetedAssay.h:67
static bool intensityLess_(const Peak1D &a, const Peak1D &b)
Compare two peaks based on their intensity.
String molecular_formula
< (putative) molecular formula
Definition: MetaboTargetedAssay.h:63
double transition_quality_score
transitions quality score (not yet used)
Definition: MetaboTargetedAssay.h:60
String compound_name
compound name
Definition: MetaboTargetedAssay.h:65
std::vector< ReactionMonitoringTransition > potential_rmts
vector of transitions belonging to the compound
Definition: MetaboTargetedAssay.h:68
static std::vector< MetaboTargetedAssay::CompoundSpectrumPair > pairCompoundWithAnnotatedSpectra(const std::vector< SiriusMSFile::CompoundInfo > &v_cmpinfo, const std::vector< MSSpectrum > &annotated_spectra)
static std::vector< MetaboTargetedAssay::CompoundTargetDecoyPair > pairCompoundWithAnnotatedTDSpectraPairs(const std::vector< SiriusMSFile::CompoundInfo > &v_cmpinfo, const std::vector< SiriusFragmentAnnotation::SiriusTargetDecoySpectra > &annotated_spectra)
Pair compound information (SiriusMSFile) with the annotated target and decoy spectrum from SIRIUS/Pas...
static std::vector< MetaboTargetedAssay > extractMetaboTargetedAssayFragmentAnnotation(const std::vector< CompoundTargetDecoyPair > &v_cmp_spec, const double &transition_threshold, const double &min_fragment_mz, const double &max_fragment_mz, const bool &use_exact_mass, const bool &exclude_ms2_precursor, const unsigned int &file_counter)
Extract a vector of MetaboTargetedAssays using fragment annotation.
static std::vector< MetaboTargetedAssay > extractMetaboTargetedAssay(const MSExperiment &spectra, const FeatureMapping::FeatureToMs2Indices &feature_ms2_index, const double &precursor_rt_tol, const double &precursor_mz_distance, const double &cosine_sim_threshold, const double &transition_threshold, const double &min_fragment_mz, const double &max_fragment_mz, const bool &method_consensus_spectrum, const bool &exclude_ms2_precursor, const unsigned int &file_counter)
Extract a vector of MetaboTargetedAssays without using fragment annotation.
int compound_file
integer of file it belongs to in a list of files
Definition: MetaboTargetedAssay.h:64
String compound_adduct
compound adduct
Definition: MetaboTargetedAssay.h:66
double precursor_int
MetaboTargetedAssay is able to store a precursor, metadata as well as compound information.
Definition: MetaboTargetedAssay.h:59
static void filterBasedOnMolFormAdductOccurrence_(std::vector< MetaboTargetedAssay > &mta)
Filter one ambiguity group with multiple possible identifications to use the one with the highest occ...
double compound_rt
compound retention time
Definition: MetaboTargetedAssay.h:62
static void sortByPrecursorInt(std::vector< MetaboTargetedAssay > &vec_mta)
Sort vector of MetaboTargetedAssay by precursor ion intensity.
double precursor_mz
precursor mass-to-charge
Definition: MetaboTargetedAssay.h:61
static void resolveAmbiguityGroup(std::unordered_map< UInt64, std::vector< MetaboTargetedAssay > > &map_mta_filter, const double &total_occurrence_filter, size_t in_files_size)
Resolve ambiguity groups based on occurrence in samples (e.g. at least in 20% of the samples) and if ...
static std::unordered_map< UInt64, std::vector< MetaboTargetedAssay > > buildAmbiguityGroup(const std::vector< MetaboTargetedAssay > &v_mta, const double &ar_mz_tol, const double &ar_rt_tol, const String &ar_mz_tol_unit_res, size_t in_files_size)
Perform feature linking to build ambiguity groups based on the target and decoy position in the vecto...
TargetDecoyGroup stores the mz, rt and file number in correspondence to the index of a MetaboTargeted...
Definition: MetaboTargetedAssay.h:107
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:54
SiriusTargetDecoySpectra holds the target and/or decoy information for one entry (subdirectory from S...
Definition: SiriusFragmentAnnotation.h:49
Definition: SiriusMSConverter.h:64
A more convenient string class.
Definition: String.h:60
Represents a compound (small molecule)
Definition: TargetedExperimentHelper.h:323
OPENMS_UINT64_TYPE UInt64
Unsigned integer type (64bit)
Definition: Types.h:77
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48