OpenMS
MRMFeatureAccessOpenMS.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Hannes Roest $
6 // $Authors: Hannes Roest $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
12 
13 #include <OpenMS/KERNEL/Feature.h>
17 
18 #include <boost/shared_ptr.hpp>
19 
20 // These classes are minimal implementations of the interfaces defined in ITransition:
21 // - IFeature
22 // - IMRMFeature
23 // - ITransitionGroup
24 // - ISignalToNoise
25 
26 namespace OpenMS
27 {
32  class OPENMS_DLLAPI FeatureOpenMS :
33  public OpenSwath::IFeature
34  {
35 public:
36 
37  explicit FeatureOpenMS(Feature& feature);
38 
39  ~FeatureOpenMS() override;
40 
41  void getRT(std::vector<double>& rt) const override;
42 
43  void getIntensity(std::vector<double>& intens) const override;
44 
45  float getIntensity() const override;
46 
47  double getRT() const override;
48 
49 private:
51  };
52 
57  class OPENMS_DLLAPI MRMFeatureOpenMS :
59  {
60 public:
61 
62  explicit MRMFeatureOpenMS(MRMFeature& mrmfeature);
63 
64  ~MRMFeatureOpenMS() override;
65 
66  boost::shared_ptr<OpenSwath::IFeature> getFeature(std::string nativeID) override;
67 
68  boost::shared_ptr<OpenSwath::IFeature> getPrecursorFeature(std::string nativeID) override;
69 
70  std::vector<std::string> getNativeIDs() const override;
71 
72  std::vector<std::string> getPrecursorIDs() const override;
73 
74  float getIntensity() const override;
75 
76  double getRT() const override;
77 
78  size_t size() const override;
79 
80 private:
82  std::map<std::string, boost::shared_ptr<FeatureOpenMS> > features_;
83  std::map<std::string, boost::shared_ptr<FeatureOpenMS> > precursor_features_;
84  };
85 
90  template <typename SpectrumT, typename TransitionT>
93  {
94 public:
95 
97  trgroup_(trgroup)
98  {
99  }
100 
102  {
103  }
104 
105  std::size_t size() const override
106  {
107  return trgroup_.size();
108  }
109 
110  std::vector<std::string> getNativeIDs() const override
111  {
112  std::vector<std::string> result;
113  for (std::size_t i = 0; i < this->size(); i++)
114  {
115  result.push_back(trgroup_.getChromatograms()[i].getNativeID());
116  }
117  return result;
118  }
119 
120  void getLibraryIntensities(std::vector<double>& intensities) const override
121  {
122  trgroup_.getLibraryIntensity(intensities);
123  }
124 
125 private:
127  };
128 
133  template <typename ContainerT>
136  {
137 public:
138 
139  SignalToNoiseOpenMS(ContainerT& chromat,
140  double sn_win_len_, unsigned int sn_bin_count_, bool write_log_messages) :
141  chromatogram_(chromat), sn_()
142  {
143  OpenMS::Param snt_parameters = sn_.getParameters();
144  snt_parameters.setValue("win_len", sn_win_len_);
145  snt_parameters.setValue("bin_count", sn_bin_count_);
146 
147  if (write_log_messages)
148  {
149  snt_parameters.setValue("write_log_messages", "true");
150  }
151  else
152  {
153  snt_parameters.setValue("write_log_messages", "false");
154  }
155 
156  sn_.setParameters(snt_parameters);
158  }
159 
160  double getValueAtRT(double RT) override
161  {
162  if (chromatogram_.empty()) {return -1;}
163 
164  // Note that MZBegin does not seem to return the same iterator on
165  // different setups, see https://github.com/OpenMS/OpenMS/issues/1163
166  typename ContainerT::const_iterator iter = chromatogram_.MZEnd(RT);
167 
168  // ensure that iter is valid
169  if (iter == chromatogram_.end())
170  {
171  iter--;
172  }
173 
174  typename ContainerT::const_iterator prev = iter;
175  if (prev != chromatogram_.begin() )
176  {
177  prev--;
178  }
179 
180  if (std::fabs(prev->getMZ() - RT) < std::fabs(iter->getMZ() - RT) )
181  {
182  // prev is closer to the apex
183  return sn_.getSignalToNoise((Size) distance(chromatogram_.begin(),prev));
184  }
185  else
186  {
187  // iter is closer to the apex
188  return sn_.getSignalToNoise((Size) distance(chromatogram_.begin(),iter));
189  }
190  }
191 
192 private:
193 
194  const ContainerT& chromatogram_;
196 
197  };
198 
199 }
200 
201 
const Param & getParameters() const
Non-mutable access to the parameters.
void setParameters(const Param &param)
Sets the parameters.
An implementation of the OpenSWATH Feature Access interface using OpenMS.
Definition: MRMFeatureAccessOpenMS.h:34
void getRT(std::vector< double > &rt) const override
~FeatureOpenMS() override
double getRT() const override
float getIntensity() const override
Feature * feature_
Definition: MRMFeatureAccessOpenMS.h:50
FeatureOpenMS(Feature &feature)
void getIntensity(std::vector< double > &intens) const override
An LC-MS feature.
Definition: Feature.h:46
An implementation of the OpenSWATH MRM Feature Access interface using OpenMS.
Definition: MRMFeatureAccessOpenMS.h:59
boost::shared_ptr< OpenSwath::IFeature > getPrecursorFeature(std::string nativeID) override
MRMFeatureOpenMS(MRMFeature &mrmfeature)
boost::shared_ptr< OpenSwath::IFeature > getFeature(std::string nativeID) override
double getRT() const override
std::vector< std::string > getNativeIDs() const override
float getIntensity() const override
const MRMFeature & mrmfeature_
Definition: MRMFeatureAccessOpenMS.h:81
std::map< std::string, boost::shared_ptr< FeatureOpenMS > > precursor_features_
Definition: MRMFeatureAccessOpenMS.h:83
size_t size() const override
std::map< std::string, boost::shared_ptr< FeatureOpenMS > > features_
Definition: MRMFeatureAccessOpenMS.h:82
std::vector< std::string > getPrecursorIDs() const override
A multi-chromatogram MRM feature.
Definition: MRMFeature.h:26
Size size() const
Definition: MRMTransitionGroup.h:99
std::vector< ChromatogramType > & getChromatograms()
Definition: MRMTransitionGroup.h:160
void getLibraryIntensity(std::vector< double > &result) const
Definition: MRMTransitionGroup.h:319
Management and storage of parameters / INI files.
Definition: Param.h:44
void setValue(const std::string &key, const ParamValue &value, const std::string &description="", const std::vector< std::string > &tags=std::vector< std::string >())
Sets a value.
virtual void init(const Container &c)
Set the start and endpoint of the raw data interval, for which signal to noise ratios will be estimat...
Definition: SignalToNoiseEstimator.h:75
virtual double getSignalToNoise(const Size index) const
Definition: SignalToNoiseEstimator.h:83
An implementation of the OpenSWATH SignalToNoise Access interface using OpenMS.
Definition: MRMFeatureAccessOpenMS.h:136
OpenMS::SignalToNoiseEstimatorMedian< ContainerT > sn_
Definition: MRMFeatureAccessOpenMS.h:195
SignalToNoiseOpenMS(ContainerT &chromat, double sn_win_len_, unsigned int sn_bin_count_, bool write_log_messages)
Definition: MRMFeatureAccessOpenMS.h:139
const ContainerT & chromatogram_
Definition: MRMFeatureAccessOpenMS.h:194
double getValueAtRT(double RT) override
Definition: MRMFeatureAccessOpenMS.h:160
An implementation of the OpenSWATH Transition Group Access interface using OpenMS.
Definition: MRMFeatureAccessOpenMS.h:93
~TransitionGroupOpenMS() override
Definition: MRMFeatureAccessOpenMS.h:101
std::vector< std::string > getNativeIDs() const override
Definition: MRMFeatureAccessOpenMS.h:110
const MRMTransitionGroup< SpectrumT, TransitionT > & trgroup_
Definition: MRMFeatureAccessOpenMS.h:126
TransitionGroupOpenMS(MRMTransitionGroup< SpectrumT, TransitionT > &trgroup)
Definition: MRMFeatureAccessOpenMS.h:96
void getLibraryIntensities(std::vector< double > &intensities) const override
Definition: MRMFeatureAccessOpenMS.h:120
std::size_t size() const override
Definition: MRMFeatureAccessOpenMS.h:105
Definition: ITransition.h:21
Definition: ITransition.h:31
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
@ RT
RT in seconds.
Definition: ITransition.h:52
Definition: ITransition.h:44