| OpenMS 2.5.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-2020.
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
37 #include <OpenMS/OPENSWATHALGO/DATAACCESS/ITransition.h>
38
39 #include <OpenMS/KERNEL/Feature.h>
40 #include <OpenMS/KERNEL/MRMFeature.h>
41 #include <OpenMS/KERNEL/MRMTransitionGroup.h>
42 #include <OpenMS/FILTERING/NOISEESTIMATION/SignalToNoiseEstimatorMedian.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:
76 Feature* feature_;
77 };
78
83 class OPENMS_DLLAPI MRMFeatureOpenMS :
84 public OpenSwath::IMRMFeature
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:
107 const MRMFeature& mrmfeature_;
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>
117 class TransitionGroupOpenMS :
118 public OpenSwath::ITransitionGroup
119 {
120 public:
121
122 TransitionGroupOpenMS(MRMTransitionGroup<SpectrumT, TransitionT>& trgroup) :
123 trgroup_(trgroup)
124 {
125 }
126
127 ~TransitionGroupOpenMS() override
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:
152 const MRMTransitionGroup<SpectrumT, TransitionT>& trgroup_;
153 };
154
159 template <typename ContainerT>
160 class SignalToNoiseOpenMS :
161 public OpenSwath::ISignalToNoise
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);
183 sn_.init(chromatogram_);
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(*prev);
210 }
211 else
212 {
213 // iter is closer to the apex
214 return sn_.getSignalToNoise(*iter);
215 }
216 }
217
218 private:
219
220 const ContainerT& chromatogram_;
221 OpenMS::SignalToNoiseEstimatorMedian< ContainerT > sn_;
222
223 };
224
225 }
226
227
OpenMS::Feature
An LC-MS feature.
Definition: Feature.h:70
OpenMS::TransitionGroupOpenMS::TransitionGroupOpenMS
TransitionGroupOpenMS(MRMTransitionGroup< SpectrumT, TransitionT > &trgroup)
Definition: MRMFeatureAccessOpenMS.h:122
Feature.h
OpenMS::SignalToNoiseOpenMS::getValueAtRT
double getValueAtRT(double RT) override
Definition: MRMFeatureAccessOpenMS.h:186
OpenSwath::IMRMFeature
Definition: ITransition.h:56
OpenMS::TransitionGroupOpenMS
An implementation of the OpenSWATH Transition Group Access interface using OpenMS.
Definition: MRMFeatureAccessOpenMS.h:117
OpenMS::MRMTransitionGroup::size
Size size() const
Definition: MRMTransitionGroup.h:125
OpenMS::TransitionGroupOpenMS::trgroup_
const MRMTransitionGroup< SpectrumT, TransitionT > & trgroup_
Definition: MRMFeatureAccessOpenMS.h:152
SignalToNoiseEstimatorMedian.h
OpenMS::MRMTransitionGroup< SpectrumT, TransitionT >
OpenMS::DefaultParamHandler::getParameters
const Param & getParameters() const
Non-mutable access to the parameters.
OpenMS::TransitionGroupOpenMS::getNativeIDs
std::vector< std::string > getNativeIDs() const override
Definition: MRMFeatureAccessOpenMS.h:136
OpenMS::MRMFeatureOpenMS::features_
std::map< std::string, boost::shared_ptr< FeatureOpenMS > > features_
Definition: MRMFeatureAccessOpenMS.h:108
OpenMS::MRMTransitionGroup::getLibraryIntensity
void getLibraryIntensity(std::vector< double > &result) const
Definition: MRMTransitionGroup.h:320
OpenMS::MRMFeatureOpenMS
An implementation of the OpenSWATH MRM Feature Access interface using OpenMS.
Definition: MRMFeatureAccessOpenMS.h:83
OpenMS::SignalToNoiseEstimatorMedian< ContainerT >
OpenMS::MRMFeatureOpenMS::precursor_features_
std::map< std::string, boost::shared_ptr< FeatureOpenMS > > precursor_features_
Definition: MRMFeatureAccessOpenMS.h:109
OpenMS::SignalToNoiseOpenMS::chromatogram_
const ContainerT & chromatogram_
Definition: MRMFeatureAccessOpenMS.h:220
OpenMS::SignalToNoiseOpenMS
An implementation of the OpenSWATH SignalToNoise Access interface using OpenMS.
Definition: MRMFeatureAccessOpenMS.h:160
OpenSwath::ISignalToNoise
Definition: ITransition.h:77
OpenMS::SignalToNoiseOpenMS::sn_
OpenMS::SignalToNoiseEstimatorMedian< ContainerT > sn_
Definition: MRMFeatureAccessOpenMS.h:221
OpenSwath::IFeature
Definition: ITransition.h:46
OpenMS::FeatureOpenMS::feature_
Feature * feature_
Definition: MRMFeatureAccessOpenMS.h:76
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::SignalToNoiseOpenMS::SignalToNoiseOpenMS
SignalToNoiseOpenMS(ContainerT &chromat, double sn_win_len_, unsigned int sn_bin_count_, bool write_log_messages)
Definition: MRMFeatureAccessOpenMS.h:165
OpenMS::TransitionGroupOpenMS::size
std::size_t size() const override
Definition: MRMFeatureAccessOpenMS.h:131
OpenMS::Param::setValue
void setValue(const String &key, const DataValue &value, const String &description="", const StringList &tags=StringList())
Sets a value.
OpenMS::TransitionGroupOpenMS::getLibraryIntensities
void getLibraryIntensities(std::vector< double > &intensities) const override
Definition: MRMFeatureAccessOpenMS.h:146
OpenSwath::ITransitionGroup
Definition: ITransition.h:69
OpenMS::MRMTransitionGroup::getChromatograms
std::vector< ChromatogramType > & getChromatograms()
Definition: MRMTransitionGroup.h:174
MRMFeature.h
OpenMS::TransitionGroupOpenMS::~TransitionGroupOpenMS
~TransitionGroupOpenMS() override
Definition: MRMFeatureAccessOpenMS.h:127
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:73
OpenMS::DefaultParamHandler::setParameters
void setParameters(const Param &param)
Sets the parameters.
OpenMS::MRMFeature
A multi-chromatogram MRM feature.
Definition: MRMFeature.h:50
OpenMS::SignalToNoiseEstimator::init
virtual void init(const PeakIterator &it_begin, const PeakIterator &it_end)
Set the start and endpoint of the raw data interval, for which signal to noise ratios will be estimat...
Definition: SignalToNoiseEstimator.h:109
MRMTransitionGroup.h
ITransition.h
OpenMS::SignalToNoiseEstimator::getSignalToNoise
virtual double getSignalToNoise(const PeakIterator &data_point)
Definition: SignalToNoiseEstimator.h:128
OpenMS::FeatureOpenMS
An implementation of the OpenSWATH Feature Access interface using OpenMS.
Definition: MRMFeatureAccessOpenMS.h:58
OpenMS::MRMFeatureOpenMS::mrmfeature_
const MRMFeature & mrmfeature_
Definition: MRMFeatureAccessOpenMS.h:107