OpenMS  2.9.1
ConsensusMap.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-2022.
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: Timo Sachsenberg $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
42 
45 
46 #include <OpenMS/CONCEPT/Types.h>
51 #include <OpenMS/OpenMSConfig.h>
52 
53 #include <map>
54 #include <vector>
55 #include <iosfwd>
56 
57 namespace OpenMS
58 {
59  class PeptideIdentification;
60  class PeptideHit;
61  class ProteinIdentification;
62  class DataProcessing;
63  namespace Logger
64  {
65  class LogStream;
66  }
67 
83  class OPENMS_DLLAPI ConsensusMap :
84  public MetaInfoInterface,
85  public RangeManagerContainer<RangeRT, RangeMZ, RangeIntensity>,
86  public DocumentIdentifier,
87  public ExposedVector<ConsensusFeature>,
88  public UniqueIdInterface,
89  public UniqueIdIndexer<ConsensusMap>,
90  public MapUtilities<ConsensusMap>
91  {
92 public:
94 
95  enum class SplitMeta
96  {
97  DISCARD,
98  COPY_ALL,
99  COPY_FIRST
100  };
101 
103  struct ColumnHeader :
104  public MetaInfoInterface
105  {
107  ColumnHeader() = default;
108 
110  ColumnHeader(const ColumnHeader&) = default;
111 
113  ColumnHeader& operator=(const ColumnHeader&) = default;
114 
117 
120 
123  Size size = 0;
124 
127 
128  unsigned getLabelAsUInt(const String& experiment_type) const;
129  };
130 
132 
134  typedef std::map<UInt64, ColumnHeader> ColumnHeaders;
135 
143 
146 
148  ConsensusMap(const ConsensusMap& source);
151 
153  ~ConsensusMap() override;
154 
156  explicit ConsensusMap(size_type n);
157 
161  ConsensusMap& operator=(ConsensusMap&& source) = default;
162 
173 
182 
183 
189  void clear(bool clear_meta_data = true);
190 
193 
196 
198  void setColumnHeaders(const ColumnHeaders& column_description);
199 
201  const String& getExperimentType() const;
202 
204  void setExperimentType(const String& experiment_type);
205 
214  void sortByIntensity(bool reverse = false);
215 
217  void sortByRT();
218 
220  void sortByMZ();
221 
224 
226  void sortByQuality(bool reverse = false);
227 
229  void sortBySize();
230 
232  void sortByMaps();
233 
237 
238  // Docu in base class
239  void updateRanges() override;
240 
242  void swap(ConsensusMap& from);
243 
245  const std::vector<ProteinIdentification>& getProteinIdentifications() const;
246 
248  std::vector<ProteinIdentification>& getProteinIdentifications();
249 
251  void setProteinIdentifications(const std::vector<ProteinIdentification>& protein_identifications);
252 
254  void setProteinIdentifications(std::vector<ProteinIdentification>&& protein_identifications);
255 
257  const std::vector<PeptideIdentification>& getUnassignedPeptideIdentifications() const;
258 
260  std::vector<PeptideIdentification>& getUnassignedPeptideIdentifications();
261 
263  void setUnassignedPeptideIdentifications(const std::vector<PeptideIdentification>& unassigned_peptide_identifications);
264 
266  const std::vector<DataProcessing>& getDataProcessing() const;
267 
269  std::vector<DataProcessing>& getDataProcessing();
270 
272  void setDataProcessing(const std::vector<DataProcessing>& processing_method);
273 
276 
282 
284  void getPrimaryMSRunPath(StringList& toFill) const;
285 
287  bool operator==(const ConsensusMap& rhs) const;
288 
290  bool operator!=(const ConsensusMap& rhs) const;
291 
305  template <typename Type>
306  Size applyMemberFunction(Size (Type::* member_function)())
307  {
308  Size assignments = 0;
309  assignments += ((*this).*member_function)();
310  for (Iterator iter = this->begin(); iter != this->end(); ++iter)
311  {
312  assignments += ((*iter).*member_function)();
313  }
314  return assignments;
315  }
316 
318  template <typename Type>
319  Size applyMemberFunction(Size (Type::* member_function)() const) const
320  {
321  Size assignments = 0;
322  assignments += ((*this).*member_function)();
323  for (ConstIterator iter = this->begin(); iter != this->end(); ++iter)
324  {
325  assignments += ((*iter).*member_function)();
326  }
327  return assignments;
328  }
329 
342  bool isMapConsistent(Logger::LogStream* stream = nullptr) const;
343 
357  std::vector<FeatureMap> split(SplitMeta mode = SplitMeta::DISCARD) const;
358 
359 protected:
362 
364  String experiment_type_ = "label-free";
365 
367  std::vector<ProteinIdentification> protein_identifications_;
368 
370  std::vector<PeptideIdentification> unassigned_peptide_identifications_;
371 
373  std::vector<DataProcessing> data_processing_;
374  };
375 
377  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const ConsensusMap& cons_map);
378 
379 } // namespace OpenMS
380 
#define EXPOSED_VECTOR_INTERFACE(InnerElement)
Macro to expose common dependent types, such as iterator in the derived class.
Definition: ExposedVector.h:45
A consensus feature spanning multiple LC-MS/MS experiments.
Definition: ConsensusFeature.h:71
A container for consensus elements.
Definition: ConsensusMap.h:91
ConsensusMap & operator=(ConsensusMap &&source)=default
MoveAssignment operator.
SplitMeta
Definition: ConsensusMap.h:96
ConsensusMap(ConsensusMap &&source)
Move constructor.
const_reverse_iterator ConstReverseIterator
Definition: ConsensusMap.h:141
void sortByRT()
Sorts the peaks to RT position.
const std::vector< DataProcessing > & getDataProcessing() const
returns a const reference to the description of the applied data processing
std::vector< PeptideIdentification > & getUnassignedPeptideIdentifications()
mutable access to the unassigned peptide identifications
RangeManager< RangeRT, RangeMZ, RangeIntensity > RangeManagerType
Definition: ConsensusMap.h:137
Size applyMemberFunction(Size(Type::*member_function)())
Applies a member function of Type to the container itself and all consensus features....
Definition: ConsensusMap.h:306
ConsensusMap & operator=(const ConsensusMap &source)
Assignment operator.
void setUnassignedPeptideIdentifications(const std::vector< PeptideIdentification > &unassigned_peptide_identifications)
sets the unassigned peptide identifications
reverse_iterator ReverseIterator
Definition: ConsensusMap.h:140
void setPrimaryMSRunPath(const StringList &s)
set the file paths to the primary MS run (stored in ColumnHeaders)
void sortByMaps()
Sorts with respect to the sets of maps covered by the consensus features (lexicographically).
bool isMapConsistent(Logger::LogStream *stream=nullptr) const
checks if the given maps are unique and all FeatureHandles actually refer to a registered map
std::vector< DataProcessing > data_processing_
applied data processing
Definition: ConsensusMap.h:373
ConsensusMap & appendColumns(const ConsensusMap &rhs)
Add consensus map entries as new columns.
iterator Iterator
Definition: ConsensusMap.h:138
void sortPeptideIdentificationsByMapIndex()
Sorts PeptideIdentifications of consensus features with respect to their map index.
void sortByMZ()
Sorts the peaks to m/z position.
std::vector< ProteinIdentification > & getProteinIdentifications()
mutable access to the protein identifications
const_iterator ConstIterator
Definition: ConsensusMap.h:139
bool operator!=(const ConsensusMap &rhs) const
Equality operator.
void setProteinIdentifications(const std::vector< ProteinIdentification > &protein_identifications)
sets the protein identifications
ConsensusMap(size_type n)
Creates a ConsensusMap with n elements.
const ColumnHeaders & getColumnHeaders() const
Non-mutable access to the file descriptions.
bool operator==(const ConsensusMap &rhs) const
Equality operator.
void sortBySize()
Sorts with respect to the size (number of elements)
ConsensusFeature FeatureType
Definition: ConsensusMap.h:133
void clear(bool clear_meta_data=true)
Clears all data and meta data.
ConsensusMap()
Default constructor.
std::vector< FeatureMap > split(SplitMeta mode=SplitMeta::DISCARD) const
splits ConsensusMap into its original FeatureMaps
void setProteinIdentifications(std::vector< ProteinIdentification > &&protein_identifications)
sets the protein identifications by moving
void sortByPosition()
Lexicographically sorts the peaks by their position (First RT then m/z).
const String & getExperimentType() const
Non-mutable access to the experiment type.
void setDataProcessing(const std::vector< DataProcessing > &processing_method)
sets the description of the applied data processing
void sortByIntensity(bool reverse=false)
Sorts the peaks according to ascending intensity.
RangeManagerContainer< RangeRT, RangeMZ, RangeIntensity > RangeManagerContainerType
Definition: ConsensusMap.h:136
std::vector< DataProcessing > & getDataProcessing()
returns a mutable reference to the description of the applied data processing
void getPrimaryMSRunPath(StringList &toFill) const
returns the MS run path (stored in ColumnHeaders)
std::map< UInt64, ColumnHeader > ColumnHeaders
Definition: ConsensusMap.h:134
ConsensusMap & appendRows(const ConsensusMap &rhs)
Add consensus map entries as new rows.
std::vector< PeptideIdentification > unassigned_peptide_identifications_
unassigned peptide identifications (without feature)
Definition: ConsensusMap.h:370
~ConsensusMap() override
Destructor.
const std::vector< ProteinIdentification > & getProteinIdentifications() const
non-mutable access to the protein identifications
const std::vector< PeptideIdentification > & getUnassignedPeptideIdentifications() const
non-mutable access to the unassigned peptide identifications
void setColumnHeaders(const ColumnHeaders &column_description)
Mutable access to the file descriptions.
void sortByQuality(bool reverse=false)
Sorts the peaks according to ascending quality.
ColumnHeaders column_description_
Map from index to file description.
Definition: ConsensusMap.h:361
void swap(ConsensusMap &from)
Swaps the content of this map with the content of from.
std::vector< ProteinIdentification > protein_identifications_
protein identifications
Definition: ConsensusMap.h:367
ColumnHeaders & getColumnHeaders()
Mutable access to the file descriptions.
ConsensusMap(const ConsensusMap &source)
Copy constructor.
void updateRanges() override
void setPrimaryMSRunPath(const StringList &s, MSExperiment &e)
void setExperimentType(const String &experiment_type)
Mutable access to the experiment type.
Size applyMemberFunction(Size(Type::*member_function)() const) const
The "const" variant.
Definition: ConsensusMap.h:319
Manage source document information.
Definition: DocumentIdentifier.h:56
Makes a vector<VectorElement> available in the derived class and exposed commonly used vector member ...
Definition: ExposedVector.h:81
typename VecMember::iterator iterator
Definition: ExposedVector.h:87
typename VecMember::const_iterator const_iterator
Definition: ExposedVector.h:88
typename VecMember::size_type size_type
Definition: ExposedVector.h:91
typename VecMember::reverse_iterator reverse_iterator
Definition: ExposedVector.h:89
typename VecMember::const_reverse_iterator const_reverse_iterator
Definition: ExposedVector.h:90
Log Stream Class.
Definition: LogStream.h:318
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:72
Utilities for Feature and ConsensusMap.
Definition: MapUtilities.h:50
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:61
Definition: RangeManager.h:898
Handles the management of a multidimensional range, e.g. RangeMZ and RangeIntensity for spectra.
Definition: RangeManager.h:566
A more convenient string class.
Definition: String.h:60
A base class for containers with elements derived from UniqueIdInterface. This adds functionality to ...
Definition: UniqueIdIndexer.h:67
A base class defining a common interface for all classes having a unique id.
Definition: UniqueIdInterface.h:51
@ INVALID
Definition: UniqueIdInterface.h:60
OPENMS_UINT64_TYPE UInt64
Unsigned integer type (64bit)
Definition: Types.h:77
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
static String & reverse(String &this_s)
Definition: StringUtilsSimple.h:355
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
Description of the columns in a consensus map.
Definition: ConsensusMap.h:105
ColumnHeader & operator=(const ColumnHeader &)=default
Copy assignment.
ColumnHeader()=default
Default constructor.
ColumnHeader(const ColumnHeader &)=default
Copy constructor.
unsigned getLabelAsUInt(const String &experiment_type) const
String filename
File name of the mzML file.
Definition: ConsensusMap.h:116
String label
Label e.g. 'heavy' and 'light' for ICAT, or 'sample1' and 'sample2' for label-free quantitation.
Definition: ConsensusMap.h:119