OpenMS
Loading...
Searching...
No Matches
MRMFeatureAccessOpenMS.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- 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
18
19#include <cstddef>
20#include <memory>
21#include <string>
22#include <utility>
23#include <vector>
24
25// These classes are minimal implementations of the interfaces defined in ITransition:
26// - IFeature
27// - IMRMFeature
28// - ITransitionGroup
29// - ISignalToNoise
30
31namespace OpenMS
32{
37 class OPENMS_DLLAPI FeatureOpenMS :
39 {
40public:
41
42 explicit FeatureOpenMS(const Feature& feature);
43
44 ~FeatureOpenMS() override;
45
46 void getRT(std::vector<double>& rt) const override;
47
48 void getIntensity(std::vector<double>& intens) const override;
49
50 float getIntensity() const override;
51
52 double getRT() const override;
53
54private:
56 };
57
62 class OPENMS_DLLAPI MRMFeatureOpenMS :
64 {
65public:
66
68 explicit MRMFeatureOpenMS(MRMFeature& mrmfeature);
69
72 const std::vector<std::string>& feature_ids,
73 const std::vector<std::string>& precursor_feature_ids);
74
85 const std::vector<std::string>& feature_ids,
86 const std::vector<std::string>& precursor_feature_ids,
87 const std::vector<std::string>& feature_lookup_ids,
88 const std::vector<std::string>& precursor_feature_lookup_ids);
89
91
92 std::shared_ptr<OpenSwath::IFeature> getFeature(std::string nativeID) override;
93
94 std::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 double getMetaValue(std::string name) const;
105
106 size_t size() const override;
107
108 void getFeatureIntensities(const std::vector<std::string>& native_ids, std::vector<std::vector<double>>& intensities) const;
109
110 void getPrecursorFeatureIntensities(const std::vector<std::string>& native_ids, std::vector<std::vector<double>>& intensities) const;
111
120 float getFeatureIntensity(const std::string& native_id, Size expected_index) const;
121
122private:
149 struct FeatureLane_;
150
153 std::unique_ptr<FeatureLane_> feature_lane_;
155 std::unique_ptr<FeatureLane_> precursor_feature_lane_;
156 };
157
162 template <typename SpectrumT, typename TransitionT>
165 {
166public:
167
172
174 {
175 }
176
177 std::size_t size() const override
178 {
179 return trgroup_.size();
180 }
181
182 std::vector<std::string> getNativeIDs() const override
183 {
184 std::vector<std::string> result;
185 for (std::size_t i = 0; i < this->size(); i++)
186 {
187 result.push_back(trgroup_.getChromatograms()[i].getNativeID());
188 }
189 return result;
190 }
191
192 void getLibraryIntensities(std::vector<double>& intensities) const override
193 {
194 trgroup_.getLibraryIntensity(intensities);
195 }
196
197private:
199 };
200
205 template <typename ContainerT>
208 {
209public:
210
211 SignalToNoiseOpenMS(const ContainerT& chromat,
212 double sn_win_len_, unsigned int sn_bin_count_, bool write_log_messages) :
213 chromatogram_(chromat), sn_()
214 {
215 OpenMS::Param snt_parameters = sn_.getParameters();
216 snt_parameters.setValue("win_len", sn_win_len_);
217 snt_parameters.setValue("bin_count", sn_bin_count_);
218
219 if (write_log_messages)
220 {
221 snt_parameters.setValue("write_log_messages", "true");
222 }
223 else
224 {
225 snt_parameters.setValue("write_log_messages", "false");
226 }
227
228 sn_.setParameters(snt_parameters);
230 }
231
232 double getValueAtRT(double RT) override
233 {
234 if (chromatogram_.empty()) {return -1;}
235
236 // Note that MZBegin does not seem to return the same iterator on
237 // different setups, see https://github.com/OpenMS/OpenMS/issues/1163
238 auto iter = chromatogram_.PosEnd(RT);
239
240 // ensure that iter is valid
241 if (iter == chromatogram_.end())
242 {
243 iter--;
244 }
245
246 auto prev = iter;
247 if (prev != chromatogram_.begin())
248 {
249 prev--;
250 }
251
252 if (std::fabs(prev->getPos() - RT) < std::fabs(iter->getPos() - RT) )
253 {
254 // prev is closer to the apex
255 return sn_.getSignalToNoise((Size) distance(chromatogram_.begin(),prev));
256 }
257 else
258 {
259 // iter is closer to the apex
260 return sn_.getSignalToNoise((Size) distance(chromatogram_.begin(),iter));
261 }
262 }
263
264private:
265
266 const ContainerT& chromatogram_;
268
269 };
270
271}
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:39
void getRT(std::vector< double > &rt) const override
~FeatureOpenMS() override
double getRT() const override
float getIntensity() const override
FeatureOpenMS(const Feature &feature)
void getIntensity(std::vector< double > &intens) const override
const Feature * feature_
Definition MRMFeatureAccessOpenMS.h:55
An LC-MS feature.
Definition Feature.h:46
An implementation of the OpenSWATH MRM Feature Access interface using OpenMS.
Definition MRMFeatureAccessOpenMS.h:64
std::unique_ptr< FeatureLane_ > precursor_feature_lane_
Precursor-feature access lane for precursor chromatogram features.
Definition MRMFeatureAccessOpenMS.h:155
void getFeatureIntensities(const std::vector< std::string > &native_ids, std::vector< std::vector< double > > &intensities) const
std::vector< std::string > getNativeIDs() const override
MRMFeatureOpenMS(MRMFeature &mrmfeature)
Build access lanes from the native-id maps stored in mrmfeature.
float getFeatureIntensity(const std::string &native_id, Size expected_index) const
Return the fragment-feature intensity for native_id.
double getRT() const override
float getIntensity() const override
std::shared_ptr< OpenSwath::IFeature > getFeature(std::string nativeID) override
void getPrecursorFeatureIntensities(const std::vector< std::string > &native_ids, std::vector< std::vector< double > > &intensities) const
std::vector< std::string > getPrecursorIDs() const override
MRMFeatureOpenMS(MRMFeature &mrmfeature, const std::vector< std::string > &feature_ids, const std::vector< std::string > &precursor_feature_ids, const std::vector< std::string > &feature_lookup_ids, const std::vector< std::string > &precursor_feature_lookup_ids)
Build access lanes with externally aligned native-id order.
const MRMFeature & mrmfeature_
Definition MRMFeatureAccessOpenMS.h:151
size_t size() const override
std::unique_ptr< FeatureLane_ > feature_lane_
Fragment-feature access lane. May use aligned ids when the caller provides storage-aligned feature id...
Definition MRMFeatureAccessOpenMS.h:153
double getMetaValue(std::string name) const
std::shared_ptr< OpenSwath::IFeature > getPrecursorFeature(std::string nativeID) override
MRMFeatureOpenMS(MRMFeature &mrmfeature, const std::vector< std::string > &feature_ids, const std::vector< std::string > &precursor_feature_ids)
Build pointer-based access lanes from explicit fragment and precursor native-id lists.
A multi-chromatogram MRM feature.
Definition MRMFeature.h:26
The representation of a group of transitions in a targeted proteomics experiment.
Definition MRMTransitionGroup.h:42
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:46
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:208
OpenMS::SignalToNoiseEstimatorMedian< ContainerT > sn_
Definition MRMFeatureAccessOpenMS.h:267
SignalToNoiseOpenMS(const ContainerT &chromat, double sn_win_len_, unsigned int sn_bin_count_, bool write_log_messages)
Definition MRMFeatureAccessOpenMS.h:211
const ContainerT & chromatogram_
Definition MRMFeatureAccessOpenMS.h:266
double getValueAtRT(double RT) override
Definition MRMFeatureAccessOpenMS.h:232
An implementation of the OpenSWATH Transition Group Access interface using OpenMS.
Definition MRMFeatureAccessOpenMS.h:165
~TransitionGroupOpenMS() override
Definition MRMFeatureAccessOpenMS.h:173
std::vector< std::string > getNativeIDs() const override
Definition MRMFeatureAccessOpenMS.h:182
const MRMTransitionGroup< SpectrumT, TransitionT > & trgroup_
Definition MRMFeatureAccessOpenMS.h:198
TransitionGroupOpenMS(MRMTransitionGroup< SpectrumT, TransitionT > &trgroup)
Definition MRMFeatureAccessOpenMS.h:168
void getLibraryIntensities(std::vector< double > &intensities) const override
Definition MRMFeatureAccessOpenMS.h:192
std::size_t size() const override
Definition MRMFeatureAccessOpenMS.h:177
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:53
Definition ITransition.h:45