1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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-2013.
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.
23
30
// --------------------------------------------------------------------------
24
31
// $Maintainer: Erhan Kenar $
41
@brief A 2-dimensional consensus feature.
43
A consensus feature represents corresponding features in multiple feature
44
maps. The corresponding features are represented a set of @ref
45
FeatureHandle instances. Each ConsensusFeature "contains" zero or more
52
class OPENMS_DLLAPI ConsensusFeature
54
public std::set<FeatureHandle, FeatureHandle::IndexLess>
59
typedef std::set<FeatureHandle, FeatureHandle::IndexLess> HandleSetType;
62
/// Compare by size(), the number of consensus elements
64
: std::binary_function < ConsensusFeature, ConsensusFeature, bool >
66
inline bool operator () ( ConsensusFeature const & left, ConsensusFeature const & right ) const
68
return ( left.size() < right.size() );
70
inline bool operator () ( ConsensusFeature const & left, UInt64 const & right ) const
72
return ( left.size() < right );
74
inline bool operator () ( UInt64 const & left, ConsensusFeature const & right ) const
76
return ( left< right.size() );
78
inline bool operator () ( const UInt64 & left, const UInt64 & right ) const
80
return ( left < right );
84
/// Compare by the sets of consensus elements (lexicographically)
86
: std::binary_function < ConsensusFeature, ConsensusFeature, bool >
88
inline bool operator () ( ConsensusFeature const & left, ConsensusFeature const & right ) const
90
return std::lexicographical_compare( left.begin(), left.end(), right.begin(), right.end(), FeatureHandle::IndexLess() );
95
///@name Constructors and Destructor
97
/// Default constructor
101
ConsensusFeature(const ConsensusFeature& rhs);
103
/// Constructor from basic feature
104
ConsensusFeature(const BaseFeature& feature);
107
@brief Constructor with map and element index for a singleton consensus
110
Sets the consensus feature position and intensity to the values of @p element as well.
112
ConsensusFeature(UInt64 map_index, const Peak2D& element, UInt64 element_index);
115
@brief Constructor with map index for a singleton consensus feature.
117
Sets the consensus feature position, intensity, charge, quality, and peptide identifications to the values of @p element as well.
119
ConsensusFeature(UInt64 map_index, const BaseFeature& element);
121
/// Assignment operator
122
ConsensusFeature& operator=(const ConsensusFeature& rhs);
125
virtual ~ConsensusFeature();
129
///@name Management of feature handles
132
@brief Adds an feature handle into the consensus feature
134
@exception Exception::InvalidValue is thrown if a handle with the same map index and unique id already exists.
136
void insert(const FeatureHandle& handle);
138
/// Adds all feature handles in @p handle_set to this consensus feature.
139
void insert(const HandleSetType& handle_set);
142
@brief Creates a FeatureHandle and adds it
144
@exception Exception::InvalidValue is thrown if a handle with the same map index and unique id already exists.
146
void insert(UInt64 map_index, const Peak2D& element, UInt64 element_index);
149
@brief Creates a FeatureHandle and adds it
151
@exception Exception::InvalidValue is thrown if a handle with the same map index and unique id already exists.
153
void insert(UInt64 map_index, const BaseFeature& element);
155
/// Non-mutable access to the contained feature handles
156
const HandleSetType& getFeatures() const;
161
/// Returns the position range of the contained elements
162
DRange<2> getPositionRange() const;
163
/// Returns the intensity range of the contained elements
164
DRange<1> getIntensityRange() const;
169
@brief Computes and updates the consensus position, intensity, and charge.
171
The position and intensity of the contained feature handles is averaged.
172
The most frequent charge state wins, while the tie breaking prefers
173
smaller (absolute) charges.
175
@note This method has to be called explicitly, <i>after</i> adding the feature handles.
177
void computeConsensus();
180
@brief Computes and updates the consensus position, intensity, and charge.
182
The m/z position is the lowest m/z value of the feature handles. The RT position and intensity of the contained feature handles is averaged.
183
The most frequent charge state wins, while the tie breaking prefers
184
smaller (absolute) charges.
186
@note This method has to be called explicitly, <i>after</i> adding the feature handles.
188
void computeMonoisotopicConsensus();
191
@brief Computes the uncharged parent RT & mass, assuming the handles are charge variants.
193
The position of the feature handles (decharged) is averaged (using intensity as weights if @param intensity_weighted_averaging is true).
194
Intensities are summed up.
196
Mass calculation: If the given features contain a metavalue "dc_charge_adduct_mass" then this will be used as adduct mass instead of
199
@note This method has to be called explicitly, <i>after</i> adding the feature handles.
201
@param fm Input feature map, which provides additional information on the features
202
@param intensity_weighted_averaging Use unweighted averaging (default) or weighted by intensity
204
void computeDechargeConsensus(const FeatureMap<>& fm, bool intensity_weighted_averaging=false);
208
///Print the contents of a ConsensusFeature to a stream
209
OPENMS_DLLAPI std::ostream& operator << (std::ostream& os, const ConsensusFeature& cons);
48
@brief A 2-dimensional consensus feature.
50
A consensus feature represents corresponding features in multiple feature
51
maps. The corresponding features are represented a set of @ref
52
FeatureHandle instances. Each ConsensusFeature "contains" zero or more
59
class OPENMS_DLLAPI ConsensusFeature :
65
typedef std::set<FeatureHandle, FeatureHandle::IndexLess> HandleSetType;
66
typedef HandleSetType::const_iterator const_iterator;
67
typedef HandleSetType::iterator iterator;
68
typedef HandleSetType::const_reverse_iterator const_reverse_iterator;
69
typedef HandleSetType::reverse_iterator reverse_iterator;
72
/// Compare by size(), the number of consensus elements
74
std::binary_function<ConsensusFeature, ConsensusFeature, bool>
76
inline bool operator()(ConsensusFeature const & left, ConsensusFeature const & right) const
78
return left.size() < right.size();
81
inline bool operator()(ConsensusFeature const & left, UInt64 const & right) const
83
return left.size() < right;
86
inline bool operator()(UInt64 const & left, ConsensusFeature const & right) const
88
return left < right.size();
91
inline bool operator()(const UInt64 & left, const UInt64 & right) const
98
/// Compare by the sets of consensus elements (lexicographically)
100
std::binary_function<ConsensusFeature, ConsensusFeature, bool>
102
inline bool operator()(ConsensusFeature const & left, ConsensusFeature const & right) const
104
return std::lexicographical_compare(left.begin(), left.end(), right.begin(), right.end(), FeatureHandle::IndexLess());
109
/// slim struct to feed the need for systematically storing of ratios ( @see MSQuantifications ).
116
Ratio(const Ratio & rhs)
118
ratio_value_ = rhs.ratio_value_;
119
denominator_ref_ = rhs.denominator_ref_;
120
numerator_ref_ = rhs.numerator_ref_;
121
description_ = rhs.description_;
128
Ratio & operator=(const Ratio & rhs)
132
ratio_value_ = rhs.ratio_value_;
133
denominator_ref_ = rhs.denominator_ref_;
134
numerator_ref_ = rhs.numerator_ref_;
135
description_ = rhs.description_;
140
DoubleReal ratio_value_;
141
String denominator_ref_;
142
String numerator_ref_;
143
std::vector<String> description_;
147
///@name Constructors and Destructor
149
/// Default constructor
153
ConsensusFeature(const ConsensusFeature & rhs);
155
/// Constructor from basic feature
156
explicit ConsensusFeature(const BaseFeature & feature);
159
@brief Constructor with map and element index for a singleton consensus
162
Sets the consensus feature position and intensity to the values of @p element as well.
164
ConsensusFeature(UInt64 map_index, const Peak2D & element, UInt64 element_index);
167
@brief Constructor with map index for a singleton consensus feature.
169
Sets the consensus feature position, intensity, charge, quality, and peptide identifications
170
to the values of @p element as well.
172
ConsensusFeature(UInt64 map_index, const BaseFeature & element);
174
/// Assignment operator
175
ConsensusFeature & operator=(const ConsensusFeature & rhs);
178
virtual ~ConsensusFeature();
182
///@name Management of feature handles
186
@brief Adds all feature handles (of the CF) into the consensus feature
188
void insert(const ConsensusFeature & cf);
191
@brief Adds an feature handle into the consensus feature
193
@exception Exception::InvalidValue is thrown if a handle with the same map index and unique
196
void insert(const FeatureHandle & handle);
198
/// Adds all feature handles in @p handle_set to this consensus feature.
199
void insert(const HandleSetType & handle_set);
202
@brief Creates a FeatureHandle and adds it
204
@exception Exception::InvalidValue is thrown if a handle with the same map index and unique
207
void insert(UInt64 map_index, const Peak2D & element, UInt64 element_index);
210
@brief Creates a FeatureHandle and adds it
212
@exception Exception::InvalidValue is thrown if a handle with the same map index and unique
215
void insert(UInt64 map_index, const BaseFeature & element);
217
/// Non-mutable access to the contained feature handles
218
const HandleSetType & getFeatures() const;
223
/// Returns the position range of the contained elements
224
DRange<2> getPositionRange() const;
225
/// Returns the intensity range of the contained elements
226
DRange<1> getIntensityRange() const;
231
@brief Computes and updates the consensus position, intensity, and charge.
233
The position and intensity of the contained feature handles is averaged.
234
The most frequent charge state wins, while the tie breaking prefers
235
smaller (absolute) charges.
237
@note This method has to be called explicitly, <i>after</i> adding the feature handles.
239
void computeConsensus();
242
@brief Computes and updates the consensus position, intensity, and charge.
244
The m/z position is the lowest m/z value of the feature handles. The RT position and intensity
245
of the contained feature handles is averaged. The most frequent charge state wins, while the
246
tie breaking prefers smaller (absolute) charges.
248
@note This method has to be called explicitly, <i>after</i> adding the feature handles.
250
void computeMonoisotopicConsensus();
253
@brief Computes the uncharged parent RT & mass, assuming the handles are charge variants.
255
The position of the feature handles (decharged) is averaged (using intensity as weights if
256
@param intensity_weighted_averaging is true). Intensities are summed up. Charge is set to 0.
257
Mass calculation: If the given features contain a metavalue "dc_charge_adduct_mass" then this
258
will be used as adduct mass instead of weight(H+) * charge.
260
@note This method has to be called explicitly, <i>after</i> adding the feature handles.
262
@param fm Input feature map, which provides additional information on the features
263
@param intensity_weighted_averaging Use unweighted averaging (default) or weighted by intensity
265
void computeDechargeConsensus(const FeatureMap<> & fm, bool intensity_weighted_averaging = false);
270
Connects a ratio to the ConsensusFeature.
272
@note still experimental. consensusfeaturehandler will ignore it.
274
void addRatio(const Ratio & r);
277
@brief Add a ratio vector.
279
Connects the ratios to the ConsensusFeature.
281
@note still experimental. consensusfeaturehandler will ignore it.
283
void setRatios(std::vector<Ratio> & rs);
286
@brief Get the ratio vector.
288
std::vector<Ratio> getRatios() const;
291
@brief Get the ratio vector.
293
std::vector<Ratio> & getRatios();
295
///@name Accessors for set of FeatureHandles
299
const_iterator begin() const;
303
const_iterator end() const;
307
const_reverse_iterator rbegin() const;
309
reverse_iterator rbegin();
311
const_reverse_iterator rend() const;
313
reverse_iterator rend();
321
HandleSetType handles_;
322
std::vector<Ratio> ratios_;
326
///Print the contents of a ConsensusFeature to a stream
327
OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const ConsensusFeature & cons);
211
329
} // namespace OpenMS