OpenMS  2.8.0
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-2021.
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>
50 #include <OpenMS/OpenMSConfig.h>
51 
52 #include <map>
53 #include <vector>
54 #include <iosfwd>
55 
56 namespace OpenMS
57 {
58  class PeptideIdentification;
59  class PeptideHit;
60  class ProteinIdentification;
61  class DataProcessing;
62  namespace Logger
63  {
64  class LogStream;
65  }
66 
82  class ConsensusMap : // no OPENMS_DLLAPI here, since the class is derived from an STL class - we do not want parts of the STL lib in OpenMS.lib, since it will cause linker errors
83  private std::vector<ConsensusFeature>,
84  public MetaInfoInterface,
85  public RangeManagerContainer<RangeRT, RangeMZ, RangeIntensity>,
86  public DocumentIdentifier,
87  public UniqueIdInterface,
88  public UniqueIdIndexer<ConsensusMap>,
89  public MapUtilities<ConsensusMap>
90  {
91 
92 public:
93  typedef std::vector<ConsensusFeature> privvec;
94 
95  // types
96  using privvec::value_type;
97  using privvec::iterator;
98  using privvec::const_iterator;
99  using privvec::size_type;
100  using privvec::pointer; // ConstRefVector
101  using privvec::reference; // ConstRefVector
102  using privvec::const_reference; // ConstRefVector
103  using privvec::difference_type; // ConstRefVector
104 
105  // functions
106  using privvec::begin;
107  using privvec::end;
108 
109  using privvec::size;
110  using privvec::resize;
111  using privvec::empty;
112  using privvec::reserve;
113  using privvec::operator[];
114  using privvec::at;
115  using privvec::back;
116  using privvec::push_back;
117  using privvec::emplace_back;
118  using privvec::erase;
119 
120  enum class SplitMeta
121  {
122  DISCARD,
123  COPY_ALL,
124  COPY_FIRST
125  };
126 
128  struct OPENMS_DLLAPI ColumnHeader :
129  public MetaInfoInterface
130  {
132  ColumnHeader() = default;
133 
135  ColumnHeader(const ColumnHeader&) = default;
136 
138  ColumnHeader& operator=(const ColumnHeader&) = default;
139 
142 
145 
148  Size size = 0;
149 
152 
153  unsigned getLabelAsUInt(const String& experiment_type) const;
154  };
155 
157 
159  typedef std::vector<ConsensusFeature> Base;
162  typedef std::map<UInt64, ColumnHeader> ColumnHeaders;
164  typedef std::vector<ConsensusFeature>::iterator Iterator;
166  typedef std::vector<ConsensusFeature>::const_iterator ConstIterator;
168  typedef std::vector<ConsensusFeature>::reverse_iterator ReverseIterator;
170  typedef std::vector<ConsensusFeature>::const_reverse_iterator ConstReverseIterator;
172 
174  OPENMS_DLLAPI ConsensusMap();
175 
177  OPENMS_DLLAPI ConsensusMap(const ConsensusMap& source);
178 
180  OPENMS_DLLAPI ~ConsensusMap() override;
181 
183  OPENMS_DLLAPI explicit ConsensusMap(Base::size_type n);
184 
186  OPENMS_DLLAPI ConsensusMap& operator=(const ConsensusMap& source);
187 
197  OPENMS_DLLAPI ConsensusMap& appendRows(const ConsensusMap& rhs);
198 
206  OPENMS_DLLAPI ConsensusMap& appendColumns(const ConsensusMap& rhs);
207 
208 
214  OPENMS_DLLAPI void clear(bool clear_meta_data = true);
215 
217  OPENMS_DLLAPI const ColumnHeaders& getColumnHeaders() const;
218 
220  OPENMS_DLLAPI ColumnHeaders& getColumnHeaders();
221 
223  OPENMS_DLLAPI void setColumnHeaders(const ColumnHeaders& column_description);
224 
226  OPENMS_DLLAPI const String& getExperimentType() const;
227 
229  OPENMS_DLLAPI void setExperimentType(const String& experiment_type);
230 
239  OPENMS_DLLAPI void sortByIntensity(bool reverse = false);
240 
242  OPENMS_DLLAPI void sortByRT();
243 
245  OPENMS_DLLAPI void sortByMZ();
246 
248  OPENMS_DLLAPI void sortByPosition();
249 
251  OPENMS_DLLAPI void sortByQuality(bool reverse = false);
252 
254  OPENMS_DLLAPI void sortBySize();
255 
257  OPENMS_DLLAPI void sortByMaps();
258 
262 
263  // Docu in base class
264  OPENMS_DLLAPI void updateRanges() override;
265 
267  OPENMS_DLLAPI void swap(ConsensusMap& from);
268 
270  OPENMS_DLLAPI const std::vector<ProteinIdentification>& getProteinIdentifications() const;
271 
273  OPENMS_DLLAPI std::vector<ProteinIdentification>& getProteinIdentifications();
274 
276  OPENMS_DLLAPI void setProteinIdentifications(const std::vector<ProteinIdentification>& protein_identifications);
277 
279  OPENMS_DLLAPI void setProteinIdentifications(std::vector<ProteinIdentification>&& protein_identifications);
280 
282  OPENMS_DLLAPI const std::vector<PeptideIdentification>& getUnassignedPeptideIdentifications() const;
283 
285  OPENMS_DLLAPI std::vector<PeptideIdentification>& getUnassignedPeptideIdentifications();
286 
288  OPENMS_DLLAPI void setUnassignedPeptideIdentifications(const std::vector<PeptideIdentification>& unassigned_peptide_identifications);
289 
291  OPENMS_DLLAPI const std::vector<DataProcessing>& getDataProcessing() const;
292 
294  OPENMS_DLLAPI std::vector<DataProcessing>& getDataProcessing();
295 
297  OPENMS_DLLAPI void setDataProcessing(const std::vector<DataProcessing>& processing_method);
298 
300  OPENMS_DLLAPI void setPrimaryMSRunPath(const StringList& s);
301 
306  OPENMS_DLLAPI void setPrimaryMSRunPath(const StringList& s, MSExperiment & e);
307 
309  OPENMS_DLLAPI void getPrimaryMSRunPath(StringList& toFill) const;
310 
312  OPENMS_DLLAPI bool operator==(const ConsensusMap& rhs) const;
313 
315  OPENMS_DLLAPI bool operator!=(const ConsensusMap& rhs) const;
316 
330  template <typename Type>
331  Size applyMemberFunction(Size (Type::* member_function)())
332  {
333  Size assignments = 0;
334  assignments += ((*this).*member_function)();
335  for (Iterator iter = this->begin(); iter != this->end(); ++iter)
336  {
337  assignments += ((*iter).*member_function)();
338  }
339  return assignments;
340  }
341 
343  template <typename Type>
344  Size applyMemberFunction(Size (Type::* member_function)() const) const
345  {
346  Size assignments = 0;
347  assignments += ((*this).*member_function)();
348  for (ConstIterator iter = this->begin(); iter != this->end(); ++iter)
349  {
350  assignments += ((*iter).*member_function)();
351  }
352  return assignments;
353  }
354 
367  OPENMS_DLLAPI bool isMapConsistent(Logger::LogStream* stream = nullptr) const;
368 
382  OPENMS_DLLAPI std::vector<FeatureMap> split(SplitMeta mode = SplitMeta::DISCARD) const;
383 
384 protected:
385 
388 
390  String experiment_type_ = "label-free";
391 
393  std::vector<ProteinIdentification> protein_identifications_;
394 
396  std::vector<PeptideIdentification> unassigned_peptide_identifications_;
397 
399  std::vector<DataProcessing> data_processing_;
400 
401  };
402 
404  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const ConsensusMap& cons_map);
405 
406 } // namespace OpenMS
407 
A consensus feature spanning multiple LC-MS/MS experiments.
Definition: ConsensusFeature.h:71
A container for consensus elements.
Definition: ConsensusMap.h:90
SplitMeta
Definition: ConsensusMap.h:121
@ COPY_FIRST
copy all meta values to first feature map
@ COPY_ALL
copy all meta values to all feature maps
@ DISCARD
do not copy any meta values
String experiment_type_
type of experiment (label-free, labeled_MS1, labeled_MS2)
Definition: ConsensusMap.h:390
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:161
Size applyMemberFunction(Size(Type::*member_function)())
Applies a member function of Type to the container itself and all consensus features....
Definition: ConsensusMap.h:331
ConsensusMap & operator=(const ConsensusMap &source)
Assignment operator.
std::vector< ConsensusFeature > Base
Definition: ConsensusMap.h:159
void setUnassignedPeptideIdentifications(const std::vector< PeptideIdentification > &unassigned_peptide_identifications)
sets the unassigned peptide identifications
std::vector< ConsensusFeature >::iterator Iterator
Mutable iterator.
Definition: ConsensusMap.h:164
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:399
ConsensusMap & appendColumns(const ConsensusMap &rhs)
Add consensus map entries as new columns.
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
bool operator!=(const ConsensusMap &rhs) const
Equality operator.
void setProteinIdentifications(const std::vector< ProteinIdentification > &protein_identifications)
sets the protein identifications
std::vector< ConsensusFeature >::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition: ConsensusMap.h:170
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:158
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:160
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::vector< ConsensusFeature >::const_iterator ConstIterator
Non-mutable iterator.
Definition: ConsensusMap.h:166
ConsensusMap(Base::size_type n)
Creates a ConsensusMap with n elements.
std::map< UInt64, ColumnHeader > ColumnHeaders
Definition: ConsensusMap.h:162
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:396
~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.
std::vector< ConsensusFeature >::reverse_iterator ReverseIterator
Mutable reverse iterator.
Definition: ConsensusMap.h:168
void sortByQuality(bool reverse=false)
Sorts the peaks according to ascending quality.
ColumnHeaders column_description_
Map from index to file description.
Definition: ConsensusMap.h:387
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:393
ColumnHeaders & getColumnHeaders()
Mutable access to the file descriptions.
ConsensusMap(const ConsensusMap &source)
Copy constructor.
void updateRanges() override
void setPrimaryMSRunPath(const StringList &s, MSExperiment &e)
std::vector< ConsensusFeature > privvec
Definition: ConsensusMap.h:93
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:344
Manage source document information.
Definition: DocumentIdentifier.h:56
Log Stream Class.
Definition: LogStream.h:313
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:73
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:652
Handles the management of a multidimensional range, e.g. RangeMZ and RangeIntensity for spectra.
Definition: RangeManager.h:455
A more convenient string class.
Definition: String.h:60
A base class for random access containers for classes derived from UniqueIdInterface that adds functi...
Definition: UniqueIdIndexer.h:64
A base class defining a common interface for all classes having a unique id.
Definition: UniqueIdInterface.h:52
@ INVALID
Definition: UniqueIdInterface.h:61
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:350
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
Description of the columns in a consensus map.
Definition: ConsensusMap.h:130
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:141
String label
Label e.g. 'heavy' and 'light' for ICAT, or 'sample1' and 'sample2' for label-free quantitation.
Definition: ConsensusMap.h:144