OpenMS  2.4.0
FeatureMap.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-2018.
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: Chris Bielow $
32 // $Authors: Marc Sturm, Chris Bielow, Clemens Groepl $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/KERNEL/Feature.h>
41 
42 #include <OpenMS/CONCEPT/Types.h>
46 #include <OpenMS/OpenMSConfig.h>
47 
48 #include <algorithm>
49 #include <exception>
50 #include <vector>
51 
52 namespace OpenMS
53 {
54  class ProteinIdentification;
55  class PeptideIdentification;
56  class DataProcessing;
57 
60  struct OPENMS_DLLAPI AnnotationStatistics
61  {
62  std::vector<Size> states;
63 
65 
67 
68  AnnotationStatistics& operator=(const AnnotationStatistics& rhs);
69 
70  bool operator==(const AnnotationStatistics& rhs) const;
71 
73  };
74 
75 
77  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const AnnotationStatistics& ann);
78 
93  class FeatureMap :
94  private std::vector<Feature>,
95  public MetaInfoInterface,
96  public RangeManager<2>,
97  public DocumentIdentifier,
98  public UniqueIdInterface,
99  public UniqueIdIndexer<FeatureMap>
100  {
101 public:
105  typedef std::vector<Feature> privvec;
106 
107  // types
108  using privvec::value_type;
109  using privvec::iterator;
110  using privvec::const_iterator;
111  using privvec::size_type;
112  using privvec::pointer; // ConstRefVector
113  using privvec::reference; // ConstRefVector
114  using privvec::const_reference; // ConstRefVector
115  using privvec::difference_type; // ConstRefVector
116 
117  // functions
118  using privvec::begin;
119  using privvec::end;
120 
121  using privvec::size;
122  using privvec::resize; // ConsensusMap, FeatureXMLFile
123  using privvec::empty;
124  using privvec::reserve;
125  using privvec::operator[];
126  using privvec::at; // UniqueIdIndexer
127  using privvec::back; // FeatureXMLFile
128 
129  using privvec::push_back;
130  using privvec::pop_back; // FeatureXMLFile
131  using privvec::erase; // source/VISUAL/Spectrum2DCanvas.cpp 2871, FeatureMap_test 599
132 
136  typedef std::vector<FeatureType> Base;
137  typedef Base::iterator Iterator;
138  typedef Base::const_iterator ConstIterator;
139  typedef Base::reverse_iterator ReverseIterator;
140  typedef Base::const_reverse_iterator ConstReverseIterator;
142  typedef const FeatureType& ConstReference;
144 
149 
151  OPENMS_DLLAPI FeatureMap();
152 
154  OPENMS_DLLAPI FeatureMap(const FeatureMap& source);
155 
157  OPENMS_DLLAPI ~FeatureMap() override;
159 
161  OPENMS_DLLAPI FeatureMap& operator=(const FeatureMap& rhs);
162 
164  OPENMS_DLLAPI bool operator==(const FeatureMap& rhs) const;
165 
167  OPENMS_DLLAPI bool operator!=(const FeatureMap& rhs) const;
168 
174  OPENMS_DLLAPI FeatureMap operator+(const FeatureMap& rhs) const;
175 
188  OPENMS_DLLAPI FeatureMap& operator+=(const FeatureMap& rhs);
189 
196  OPENMS_DLLAPI void sortByIntensity(bool reverse = false);
198 
200  OPENMS_DLLAPI void sortByPosition();
201 
203  OPENMS_DLLAPI void sortByRT();
204 
206  OPENMS_DLLAPI void sortByMZ();
207 
209  OPENMS_DLLAPI void sortByOverallQuality(bool reverse = false);
210 
212 
213  // Docu in base class
214  OPENMS_DLLAPI void updateRanges() override;
215 
217  OPENMS_DLLAPI void swapFeaturesOnly(FeatureMap& from);
218 
219  OPENMS_DLLAPI void swap(FeatureMap& from);
220 
222  OPENMS_DLLAPI const std::vector<ProteinIdentification>& getProteinIdentifications() const;
223 
225  OPENMS_DLLAPI std::vector<ProteinIdentification>& getProteinIdentifications();
226 
228  OPENMS_DLLAPI void setProteinIdentifications(const std::vector<ProteinIdentification>& protein_identifications);
229 
231  OPENMS_DLLAPI const std::vector<PeptideIdentification>& getUnassignedPeptideIdentifications() const;
232 
234  OPENMS_DLLAPI std::vector<PeptideIdentification>& getUnassignedPeptideIdentifications();
235 
237  OPENMS_DLLAPI void setUnassignedPeptideIdentifications(const std::vector<PeptideIdentification>& unassigned_peptide_identifications);
238 
240  OPENMS_DLLAPI const std::vector<DataProcessing>& getDataProcessing() const;
241 
243  OPENMS_DLLAPI std::vector<DataProcessing>& getDataProcessing();
244 
246  OPENMS_DLLAPI void setDataProcessing(const std::vector<DataProcessing>& processing_method);
247 
249  OPENMS_DLLAPI void setPrimaryMSRunPath(const StringList& s);
250 
252  OPENMS_DLLAPI void getPrimaryMSRunPath(StringList& toFill) const;
253 
259  OPENMS_DLLAPI void clear(bool clear_meta_data = true);
260 
273  template <typename Type>
274  Size applyMemberFunction(Size (Type::* member_function)())
275  {
276  Size assignments = 0;
277  assignments += ((*this).*member_function)();
278  for (Iterator iter = this->begin(); iter != this->end(); ++iter)
279  {
280  assignments += iter->applyMemberFunction(member_function);
281  }
282  return assignments;
283  }
284 
286  template <typename Type>
287  Size applyMemberFunction(Size (Type::* member_function)() const) const
288  {
289  Size assignments = 0;
290  assignments += ((*this).*member_function)();
291  for (ConstIterator iter = this->begin(); iter != this->end(); ++iter)
292  {
293  assignments += iter->applyMemberFunction(member_function);
294  }
295  return assignments;
296  }
297 
298  OPENMS_DLLAPI AnnotationStatistics getAnnotationStatistics() const;
299 
300 protected:
301 
303  std::vector<ProteinIdentification> protein_identifications_;
304 
306  std::vector<PeptideIdentification> unassigned_peptide_identifications_;
307 
309  std::vector<DataProcessing> data_processing_;
310  };
311 
312  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const FeatureMap& map);
313 
314 } // namespace OpenMS
315 
Base::const_iterator ConstIterator
Definition: FeatureMap.h:138
void sortByMZ()
Sort features by m/z position.
void sortByRT()
Sort features by RT position.
~FeatureMap() override
Destructor.
std::vector< Size > states
count each state, indexing by BaseFeature::AnnotationState
Definition: FeatureMap.h:62
FeatureMap()
Default constructor.
void getPrimaryMSRunPath(StringList &toFill) const
get the file path to the first MS run
Size applyMemberFunction(Size(Type::*member_function)() const) const
The "const" variant.
Definition: FeatureMap.h:287
FeatureMap & operator+=(const FeatureMap &rhs)
Add one feature map to another.
void swap(FeatureMap &from)
A container for features.
Definition: FeatureMap.h:93
void setPrimaryMSRunPath(const StringList &s)
set the file path to the primary MS run (usually the mzML file obtained after data conversion from ra...
Base::reverse_iterator ReverseIterator
Definition: FeatureMap.h:139
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806
FeatureType & Reference
Definition: FeatureMap.h:141
Feature FeatureType
Definition: FeatureMap.h:134
Size applyMemberFunction(Size(Type::*member_function)())
Applies a member function of Type to the container itself and all features (including subordinates)...
Definition: FeatureMap.h:274
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
const std::vector< PeptideIdentification > & getUnassignedPeptideIdentifications() const
non-mutable access to the unassigned peptide identifications
Base::const_reverse_iterator ConstReverseIterator
Definition: FeatureMap.h:140
void setDataProcessing(const std::vector< DataProcessing > &processing_method)
sets the description of the applied data processing
const FeatureType & ConstReference
Definition: FeatureMap.h:142
RangeManager< 2 > RangeManagerType
Definition: FeatureMap.h:135
void setProteinIdentifications(const std::vector< ProteinIdentification > &protein_identifications)
sets the protein identifications
bool operator!=(const FeatureMap &rhs) const
Equality operator.
FeatureMap & operator=(const FeatureMap &rhs)
Assignment operator.
bool operator==(const FeatureMap &rhs) const
Equality operator.
std::vector< ProteinIdentification > protein_identifications_
protein identifications
Definition: FeatureMap.h:303
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
void sortByPosition()
Sort features by position. Lexicographical comparison (first RT then m/z) is done.
A base class for random access containers for classes derived from UniqueIdInterface that adds functi...
Definition: UniqueIdIndexer.h:63
Base::iterator Iterator
Definition: FeatureMap.h:137
An LC-MS feature.
Definition: Feature.h:70
std::vector< Feature > privvec
Definition: FeatureMap.h:105
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:55
std::vector< PeptideIdentification > unassigned_peptide_identifications_
peptide identifications not matched to a specific feature
Definition: FeatureMap.h:306
A base class defining a common interface for all classes having a unique id.
Definition: UniqueIdInterface.h:51
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:73
std::vector< FeatureType > Base
Definition: FeatureMap.h:136
void swapFeaturesOnly(FeatureMap &from)
Swaps the feature content (plus its range information) of this map with the content of from...
std::vector< DataProcessing > data_processing_
applied data processing
Definition: FeatureMap.h:309
void updateRanges() override
Updates minimum and maximum position/intensity.
const std::vector< DataProcessing > & getDataProcessing() const
returns a const reference to the description of the applied data processing
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
AnnotationState
state of identification, use getIDState() to query it
Definition: BaseFeature.h:69
void sortByOverallQuality(bool reverse=false)
Sort features by ascending overall quality.
Definition: FeatureMap.h:60
Handles the management of a position and intensity range.
Definition: RangeManager.h:47
const std::vector< ProteinIdentification > & getProteinIdentifications() const
non-mutable access to the protein identifications
void sortByIntensity(bool reverse=false)
Sorts the peaks according to ascending intensity.
AnnotationStatistics getAnnotationStatistics() const
void clear(bool clear_meta_data=true)
Clears all data and meta data.
Manage source document information.
Definition: DocumentIdentifier.h:55
FeatureMap operator+(const FeatureMap &rhs) const
Joins two feature maps.
void setUnassignedPeptideIdentifications(const std::vector< PeptideIdentification > &unassigned_peptide_identifications)
sets the unassigned peptide identifications