OpenMS  2.8.0
MRMFeatureAccessOpenMS.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: Hannes Roest $
32 // $Authors: Hannes Roest $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
38 
39 #include <OpenMS/KERNEL/Feature.h>
43 
44 #include <boost/shared_ptr.hpp>
45 
46 // These classes are minimal implementations of the interfaces defined in ITransition:
47 // - IFeature
48 // - IMRMFeature
49 // - ITransitionGroup
50 // - ISignalToNoise
51 
52 namespace OpenMS
53 {
58  class OPENMS_DLLAPI FeatureOpenMS :
59  public OpenSwath::IFeature
60  {
61 public:
62 
63  explicit FeatureOpenMS(Feature& feature);
64 
65  ~FeatureOpenMS() override;
66 
67  void getRT(std::vector<double>& rt) const override;
68 
69  void getIntensity(std::vector<double>& intens) const override;
70 
71  float getIntensity() const override;
72 
73  double getRT() const override;
74 
75 private:
77  };
78 
83  class OPENMS_DLLAPI MRMFeatureOpenMS :
85  {
86 public:
87 
88  explicit MRMFeatureOpenMS(MRMFeature& mrmfeature);
89 
90  ~MRMFeatureOpenMS() override;
91 
92  boost::shared_ptr<OpenSwath::IFeature> getFeature(std::string nativeID) override;
93 
94  boost::shared_ptr<OpenSwath::IFeature> getPrecursorFeature(std::string nativeID) override;
95 
96  std::vector<std::string> getNativeIDs() const override;
97 
98  std::vector<std::string> getPrecursorIDs() const override;
99 
100  float getIntensity() const override;
101 
102  double getRT() const override;
103 
104  size_t size() const override;
105 
106 private:
108  std::map<std::string, boost::shared_ptr<FeatureOpenMS> > features_;
109  std::map<std::string, boost::shared_ptr<FeatureOpenMS> > precursor_features_;
110  };
111 
116  template <typename SpectrumT, typename TransitionT>
119  {
120 public:
121 
123  trgroup_(trgroup)
124  {
125  }
126 
128  {
129  }
130 
131  std::size_t size() const override
132  {
133  return trgroup_.size();
134  }
135 
136  std::vector<std::string> getNativeIDs() const override
137  {
138  std::vector<std::string> result;
139  for (std::size_t i = 0; i < this->size(); i++)
140  {
141  result.push_back(trgroup_.getChromatograms()[i].getNativeID());
142  }
143  return result;
144  }
145 
146  void getLibraryIntensities(std::vector<double>& intensities) const override
147  {
148  trgroup_.getLibraryIntensity(intensities);
149  }
150 
151 private:
153  };
154 
159  template <typename ContainerT>
162  {
163 public:
164 
165  SignalToNoiseOpenMS(ContainerT& chromat,
166  double sn_win_len_, unsigned int sn_bin_count_, bool write_log_messages) :
167  chromatogram_(chromat), sn_()
168  {
169  OpenMS::Param snt_parameters = sn_.getParameters();
170  snt_parameters.setValue("win_len", sn_win_len_);
171  snt_parameters.setValue("bin_count", sn_bin_count_);
172 
173  if (write_log_messages)
174  {
175  snt_parameters.setValue("write_log_messages", "true");
176  }
177  else
178  {
179  snt_parameters.setValue("write_log_messages", "false");
180  }
181 
182  sn_.setParameters(snt_parameters);
184  }
185 
186  double getValueAtRT(double RT) override
187  {
188  if (chromatogram_.empty()) {return -1;}
189 
190  // Note that MZBegin does not seem to return the same iterator on
191  // different setups, see https://github.com/OpenMS/OpenMS/issues/1163
192  typename ContainerT::const_iterator iter = chromatogram_.MZEnd(RT);
193 
194  // ensure that iter is valid
195  if (iter == chromatogram_.end())
196  {
197  iter--;
198  }
199 
200  typename ContainerT::const_iterator prev = iter;
201  if (prev != chromatogram_.begin() )
202  {
203  prev--;
204  }
205 
206  if (std::fabs(prev->getMZ() - RT) < std::fabs(iter->getMZ() - RT) )
207  {
208  // prev is closer to the apex
209  return sn_.getSignalToNoise((Size) distance(chromatogram_.begin(),prev));
210  }
211  else
212  {
213  // iter is closer to the apex
214  return sn_.getSignalToNoise((Size) distance(chromatogram_.begin(),iter));
215  }
216  }
217 
218 private:
219 
220  const ContainerT& chromatogram_;
222 
223  };
224 
225 }
226 
227 
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:60
void getRT(std::vector< double > &rt) const override
~FeatureOpenMS() override
double getRT() const override
float getIntensity() const override
Feature * feature_
Definition: MRMFeatureAccessOpenMS.h:76
FeatureOpenMS(Feature &feature)
void getIntensity(std::vector< double > &intens) const override
An LC-MS feature.
Definition: Feature.h:72
An implementation of the OpenSWATH MRM Feature Access interface using OpenMS.
Definition: MRMFeatureAccessOpenMS.h:85
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:107
std::map< std::string, boost::shared_ptr< FeatureOpenMS > > precursor_features_
Definition: MRMFeatureAccessOpenMS.h:109
size_t size() const override
std::map< std::string, boost::shared_ptr< FeatureOpenMS > > features_
Definition: MRMFeatureAccessOpenMS.h:108
std::vector< std::string > getPrecursorIDs() const override
A multi-chromatogram MRM feature.
Definition: MRMFeature.h:52
Size size() const
Definition: MRMTransitionGroup.h:125
std::vector< ChromatogramType > & getChromatograms()
Definition: MRMTransitionGroup.h:186
void getLibraryIntensity(std::vector< double > &result) const
Definition: MRMTransitionGroup.h:344
Management and storage of parameters / INI files.
Definition: Param.h:70
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:101
virtual double getSignalToNoise(const Size index) const
Definition: SignalToNoiseEstimator.h:109
An implementation of the OpenSWATH SignalToNoise Access interface using OpenMS.
Definition: MRMFeatureAccessOpenMS.h:162
OpenMS::SignalToNoiseEstimatorMedian< ContainerT > sn_
Definition: MRMFeatureAccessOpenMS.h:221
SignalToNoiseOpenMS(ContainerT &chromat, double sn_win_len_, unsigned int sn_bin_count_, bool write_log_messages)
Definition: MRMFeatureAccessOpenMS.h:165
const ContainerT & chromatogram_
Definition: MRMFeatureAccessOpenMS.h:220
double getValueAtRT(double RT) override
Definition: MRMFeatureAccessOpenMS.h:186
An implementation of the OpenSWATH Transition Group Access interface using OpenMS.
Definition: MRMFeatureAccessOpenMS.h:119
~TransitionGroupOpenMS() override
Definition: MRMFeatureAccessOpenMS.h:127
std::vector< std::string > getNativeIDs() const override
Definition: MRMFeatureAccessOpenMS.h:136
const MRMTransitionGroup< SpectrumT, TransitionT > & trgroup_
Definition: MRMFeatureAccessOpenMS.h:152
TransitionGroupOpenMS(MRMTransitionGroup< SpectrumT, TransitionT > &trgroup)
Definition: MRMFeatureAccessOpenMS.h:122
void getLibraryIntensities(std::vector< double > &intensities) const override
Definition: MRMFeatureAccessOpenMS.h:146
std::size_t size() const override
Definition: MRMFeatureAccessOpenMS.h:131
Definition: ITransition.h:47
Definition: ITransition.h:57
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Definition: ITransition.h:78
Definition: ITransition.h:70