OpenMS  2.5.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-2020.
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>
48 #include <OpenMS/OpenMSConfig.h>
49 
50 #include <map>
51 #include <vector>
52 
53 namespace OpenMS
54 {
55  class PeptideIdentification;
56  class PeptideHit;
57  class ProteinIdentification;
58  class DataProcessing;
59  namespace Logger
60  {
61  class LogStream;
62  }
63 
79  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
80  private std::vector<ConsensusFeature>,
81  public MetaInfoInterface,
82  public RangeManager<2>,
83  public DocumentIdentifier,
84  public UniqueIdInterface,
85  public UniqueIdIndexer<ConsensusMap>
86  {
87 
88 public:
89  typedef std::vector<ConsensusFeature> privvec;
90 
91  // types
92  using privvec::value_type;
93  using privvec::iterator;
94  using privvec::const_iterator;
95  using privvec::size_type;
96  using privvec::pointer; // ConstRefVector
97  using privvec::reference; // ConstRefVector
98  using privvec::const_reference; // ConstRefVector
99  using privvec::difference_type; // ConstRefVector
100 
101  // functions
102  using privvec::begin;
103  using privvec::end;
104 
105  using privvec::size;
106  using privvec::resize;
107  using privvec::empty;
108  using privvec::reserve;
109  using privvec::operator[];
110  using privvec::at; // UniqueIdIndexer
111  using privvec::back; // source/ANALYSIS/DECHARGING/FeatureDeconvolution.cpp:977:
112 
113  using privvec::push_back;
114 
116  struct OPENMS_DLLAPI ColumnHeader :
117  public MetaInfoInterface
118  {
120  ColumnHeader();
121 
123  ColumnHeader(const ColumnHeader&);
124 
134 
135  unsigned getLabelAsUInt(const String& experiment_type) const
136  {
137  if (metaValueExists("channel_id"))
138  {
139  return static_cast<unsigned int>(getMetaValue("channel_id")) + 1;
140  }
141  else
142  {
143  if (experiment_type != "label-free")
144  {
145  // TODO There seem to be files in our test data from the Multiplex toolset that do not annotate
146  // a channel id but only add the "label" attribute with the SILAC modification. Add a fall-back here?
147  OPENMS_LOG_WARN << "No channel id annotated in labelled consensusXML. Assuming only a single channel was used." << std::endl;
148  }
149  return 1;
150  }
151  }
152  };
153 
155 
156  typedef std::vector<ConsensusFeature> Base;
158  typedef std::map<UInt64, ColumnHeader> ColumnHeaders;
160  typedef std::vector<ConsensusFeature>::iterator Iterator;
162  typedef std::vector<ConsensusFeature>::const_iterator ConstIterator;
164  typedef std::vector<ConsensusFeature>::reverse_iterator ReverseIterator;
166  typedef std::vector<ConsensusFeature>::const_reverse_iterator ConstReverseIterator;
168 
170  OPENMS_DLLAPI ConsensusMap();
171 
173  OPENMS_DLLAPI ConsensusMap(const ConsensusMap& source);
174 
176  OPENMS_DLLAPI ~ConsensusMap() override;
177 
179  OPENMS_DLLAPI explicit ConsensusMap(Base::size_type n);
180 
182  OPENMS_DLLAPI ConsensusMap& operator=(const ConsensusMap& source);
183 
193  OPENMS_DLLAPI ConsensusMap& appendRows(const ConsensusMap& rhs);
194 
202  OPENMS_DLLAPI ConsensusMap& appendColumns(const ConsensusMap& rhs);
203 
204 
210  OPENMS_DLLAPI void clear(bool clear_meta_data = true);
211 
213  OPENMS_DLLAPI const ColumnHeaders& getColumnHeaders() const;
214 
216  OPENMS_DLLAPI ColumnHeaders& getColumnHeaders();
217 
219  OPENMS_DLLAPI void setColumnHeaders(const ColumnHeaders& column_description);
220 
222  OPENMS_DLLAPI const String& getExperimentType() const;
223 
225  OPENMS_DLLAPI void setExperimentType(const String& experiment_type);
226 
234  OPENMS_DLLAPI void sortByIntensity(bool reverse = false);
236 
238  OPENMS_DLLAPI void sortByRT();
239 
241  OPENMS_DLLAPI void sortByMZ();
242 
244  OPENMS_DLLAPI void sortByPosition();
245 
247  OPENMS_DLLAPI void sortByQuality(bool reverse = false);
248 
250  OPENMS_DLLAPI void sortBySize();
251 
253  OPENMS_DLLAPI void sortByMaps();
254 
256  OPENMS_DLLAPI void sortPeptideIdentificationsByMapIndex();
258 
259  // Docu in base class
260  OPENMS_DLLAPI void updateRanges() override;
261 
263  OPENMS_DLLAPI void swap(ConsensusMap& from);
264 
266  OPENMS_DLLAPI const std::vector<ProteinIdentification>& getProteinIdentifications() const;
267 
269  OPENMS_DLLAPI std::vector<ProteinIdentification>& getProteinIdentifications();
270 
272  OPENMS_DLLAPI void setProteinIdentifications(const std::vector<ProteinIdentification>& protein_identifications);
273 
275  OPENMS_DLLAPI void setProteinIdentifications(std::vector<ProteinIdentification>&& protein_identifications);
276 
278  OPENMS_DLLAPI const std::vector<PeptideIdentification>& getUnassignedPeptideIdentifications() const;
279 
281  OPENMS_DLLAPI std::vector<PeptideIdentification>& getUnassignedPeptideIdentifications();
282 
284  OPENMS_DLLAPI void setUnassignedPeptideIdentifications(const std::vector<PeptideIdentification>& unassigned_peptide_identifications);
285 
287  OPENMS_DLLAPI const std::vector<DataProcessing>& getDataProcessing() const;
288 
290  OPENMS_DLLAPI std::vector<DataProcessing>& getDataProcessing();
291 
293  OPENMS_DLLAPI void setDataProcessing(const std::vector<DataProcessing>& processing_method);
294 
296  OPENMS_DLLAPI void setPrimaryMSRunPath(const StringList& s);
297 
300  OPENMS_DLLAPI void setPrimaryMSRunPath(const StringList& s, MSExperiment & e);
301 
303  OPENMS_DLLAPI void getPrimaryMSRunPath(StringList& toFill) const;
304 
306  OPENMS_DLLAPI void applyFunctionOnPeptideHits(std::function<void(PeptideHit&)>& f, bool include_unassigned = true);
307 
309  OPENMS_DLLAPI void applyFunctionOnPeptideIDs(std::function<void(PeptideIdentification&)>& f, bool include_unassigned = true);
310 
312  OPENMS_DLLAPI void applyFunctionOnPeptideHits(std::function<void(const PeptideHit&)>&, bool include_unassigned = true) const;
313 
315  OPENMS_DLLAPI void applyFunctionOnPeptideIDs(std::function<void(const PeptideIdentification&)>& f, bool include_unassigned = true) const;
316 
318  OPENMS_DLLAPI bool operator==(const ConsensusMap& rhs) const;
319 
321  OPENMS_DLLAPI bool operator!=(const ConsensusMap& rhs) const;
322 
336  template <typename Type>
337  Size applyMemberFunction(Size (Type::* member_function)())
338  {
339  Size assignments = 0;
340  assignments += ((*this).*member_function)();
341  for (Iterator iter = this->begin(); iter != this->end(); ++iter)
342  {
343  assignments += ((*iter).*member_function)();
344  }
345  return assignments;
346  }
347 
349  template <typename Type>
350  Size applyMemberFunction(Size (Type::* member_function)() const) const
351  {
352  Size assignments = 0;
353  assignments += ((*this).*member_function)();
354  for (ConstIterator iter = this->begin(); iter != this->end(); ++iter)
355  {
356  assignments += ((*iter).*member_function)();
357  }
358  return assignments;
359  }
360 
373  bool isMapConsistent(Logger::LogStream* stream = nullptr) const;
374 
375 protected:
376 
379 
381  String experiment_type_ = "label-free";
382 
384  std::vector<ProteinIdentification> protein_identifications_;
385 
387  std::vector<PeptideIdentification> unassigned_peptide_identifications_;
388 
390  std::vector<DataProcessing> data_processing_;
391 
392 private:
393 
394  OPENMS_DLLAPI void applyFunctionOnPeptideIDs_(const std::vector<PeptideIdentification>& idvec, std::function<void(const PeptideIdentification&)>& f) const;
395 
396  OPENMS_DLLAPI void applyFunctionOnPeptideHits_(const std::vector<PeptideIdentification>& idvec, std::function<void(const PeptideHit&)>& f) const;
397 
398  OPENMS_DLLAPI void applyFunctionOnPeptideIDs_(std::vector<PeptideIdentification>& idvec, std::function<void(PeptideIdentification&)>& f);
399 
400  OPENMS_DLLAPI void applyFunctionOnPeptideHits_(std::vector<PeptideIdentification>& idvec, std::function<void(PeptideHit&)>& f);
401  };
402 
404  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const ConsensusMap& cons_map);
405 
406 
407 
408 } // namespace OpenMS
409 
OpenMS::ConsensusMap::operator=
ConsensusMap & operator=(const ConsensusMap &source)
Assignment operator.
OpenMS::ConsensusMap::sortByQuality
void sortByQuality(bool reverse=false)
Sorts the peaks according to ascending quality.
UniqueIdInterface.h
OpenMS::ConsensusMap::ColumnHeader
Description of the columns in a consensus map.
Definition: ConsensusMap.h:116
OpenMS::ConsensusMap::applyMemberFunction
Size applyMemberFunction(Size(Type::*member_function)())
Applies a member function of Type to the container itself and all consensus features....
Definition: ConsensusMap.h:337
OpenMS::ConsensusMap::ColumnHeader::filename
String filename
File name of the mzML file.
Definition: ConsensusMap.h:126
OpenMS::ConsensusMap::ColumnHeader::getLabelAsUInt
unsigned getLabelAsUInt(const String &experiment_type) const
Definition: ConsensusMap.h:135
OpenMS::ConsensusMap::protein_identifications_
std::vector< ProteinIdentification > protein_identifications_
protein identifications
Definition: ConsensusMap.h:384
OpenMS::UInt64
OPENMS_UINT64_TYPE UInt64
Unsigned integer type (64bit)
Definition: Types.h:77
OpenMS::ConsensusMap::sortBySize
void sortBySize()
Sorts with respect to the size (number of elements)
OpenMS::ConsensusMap::ColumnHeader::unique_id
UInt64 unique_id
Unique id of the file.
Definition: ConsensusMap.h:133
Types.h
OpenMS::ConsensusMap::sortByPosition
void sortByPosition()
Lexicographically sorts the peaks by their position (First RT then m/z).
OpenMS::ConsensusMap::updateRanges
void updateRanges() override
Updates minimum and maximum position/intensity.
DocumentIdentifier.h
OpenMS::ConsensusMap::applyFunctionOnPeptideIDs
void applyFunctionOnPeptideIDs(std::function< void(PeptideIdentification &)> &f, bool include_unassigned=true)
applies a function on all PeptideIDs or only assigned ones
OpenMS::MetaInfoInterface::getMetaValue
const DataValue & getMetaValue(const String &name, const DataValue &default_value=DataValue::EMPTY) const
Returns the value corresponding to a string, or a default value (default: DataValue::EMPTY) if not fo...
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenMS::UniqueIdInterface
A base class defining a common interface for all classes having a unique id.
Definition: UniqueIdInterface.h:51
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::ConsensusMap::getExperimentType
const String & getExperimentType() const
Non-mutable access to the experiment type.
OpenMS::ConsensusMap::getPrimaryMSRunPath
void getPrimaryMSRunPath(StringList &toFill) const
returns the MS run path (stored in ColumnHeaders)
OpenMS::ConsensusMap::sortByMaps
void sortByMaps()
Sorts with respect to the sets of maps covered by the consensus features (lexicographically).
OPENMS_LOG_WARN
#define OPENMS_LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged.
Definition: LogStream.h:460
OpenMS::ConsensusMap::sortByIntensity
void sortByIntensity(bool reverse=false)
Sorts the peaks according to ascending intensity.
OpenMS::ConsensusMap::applyFunctionOnPeptideHits_
void applyFunctionOnPeptideHits_(const std::vector< PeptideIdentification > &idvec, std::function< void(const PeptideHit &)> &f) const
ConsensusFeature.h
OpenMS::ConsensusMap::sortPeptideIdentificationsByMapIndex
void sortPeptideIdentificationsByMapIndex()
Sorts PeptideIdentifications of consensus features with respect to their map index.
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::RangeManager
Handles the management of a position and intensity range.
Definition: RangeManager.h:47
OpenMS::ConsensusMap::operator!=
bool operator!=(const ConsensusMap &rhs) const
Equality operator.
OpenMS::ConsensusMap::ColumnHeader::size
Size size
Number of elements (features, peaks, ...). This is e.g. used to check for correct element indices whe...
Definition: ConsensusMap.h:131
OpenMS::ConsensusMap::applyMemberFunction
Size applyMemberFunction(Size(Type::*member_function)() const) const
The "const" variant.
Definition: ConsensusMap.h:350
OpenMS::ConsensusMap::appendColumns
ConsensusMap & appendColumns(const ConsensusMap &rhs)
Add consensus map entries as new columns.
OpenMS::ConsensusMap::swap
void swap(ConsensusMap &from)
Swaps the content of this map with the content of from.
OpenMS::ConsensusMap::unassigned_peptide_identifications_
std::vector< PeptideIdentification > unassigned_peptide_identifications_
unassigned peptide identifications (without feature)
Definition: ConsensusMap.h:387
OpenMS::UniqueIdIndexer
A base class for random access containers for classes derived from UniqueIdInterface that adds functi...
Definition: UniqueIdIndexer.h:63
OpenMS::MetaInfoInterface
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:60
OpenMS::DocumentIdentifier
Manage source document information.
Definition: DocumentIdentifier.h:55
OpenMS::ConsensusMap::getProteinIdentifications
const std::vector< ProteinIdentification > & getProteinIdentifications() const
non-mutable access to the protein identifications
OpenMS::ConsensusMap::setColumnHeaders
void setColumnHeaders(const ColumnHeaders &column_description)
Mutable access to the file descriptions.
UniqueIdIndexer.h
OpenMS::ConsensusMap::privvec
std::vector< ConsensusFeature > privvec
Definition: ConsensusMap.h:89
OpenMS::ConsensusMap::ConstIterator
std::vector< ConsensusFeature >::const_iterator ConstIterator
Non-mutable iterator.
Definition: ConsensusMap.h:162
OpenMS::ConsensusMap::appendRows
ConsensusMap & appendRows(const ConsensusMap &rhs)
Add consensus map entries as new rows.
OpenMS::ConsensusMap::getUnassignedPeptideIdentifications
const std::vector< PeptideIdentification > & getUnassignedPeptideIdentifications() const
non-mutable access to the unassigned peptide identifications
OpenMS::ConsensusMap::ColumnHeader::label
String label
Label e.g. 'heavy' and 'light' for ICAT, or 'sample1' and 'sample2' for label-free quantitation.
Definition: ConsensusMap.h:128
OpenMS::ConsensusMap::setProteinIdentifications
void setProteinIdentifications(const std::vector< ProteinIdentification > &protein_identifications)
sets the protein identifications
RangeManager.h
OpenMS::operator<<
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
OpenMS::Logger::LogStream
Log Stream Class.
Definition: LogStream.h:311
OpenMS::ConsensusMap
A container for consensus elements.
Definition: ConsensusMap.h:79
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
OpenMS::ConsensusMap::sortByRT
void sortByRT()
Sorts the peaks to RT position.
OpenMS::ConsensusMap::~ConsensusMap
~ConsensusMap() override
Destructor.
MSExperiment.h
OpenMS::ConsensusMap::getColumnHeaders
const ColumnHeaders & getColumnHeaders() const
Non-mutable access to the file descriptions.
OpenMS::ConsensusMap::ConsensusMap
ConsensusMap()
Default constructor.
OpenMS::PeptideIdentification
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:62
OpenMS::ConsensusMap::getDataProcessing
const std::vector< DataProcessing > & getDataProcessing() const
returns a const reference to the description of the applied data processing
OpenMS::ConsensusMap::clear
void clear(bool clear_meta_data=true)
Clears all data and meta data.
OpenMS::MetaInfoInterface::metaValueExists
bool metaValueExists(const String &name) const
Returns whether an entry with the given name exists.
OpenMS::ConsensusMap::Iterator
std::vector< ConsensusFeature >::iterator Iterator
Mutable iterator.
Definition: ConsensusMap.h:160
OpenMS::ConsensusMap::setDataProcessing
void setDataProcessing(const std::vector< DataProcessing > &processing_method)
sets the description of the applied data processing
MetaInfoInterface.h
OpenMS::ConsensusMap::sortByMZ
void sortByMZ()
Sorts the peaks to m/z position.
String.h
OpenMS::ConsensusMap::ReverseIterator
std::vector< ConsensusFeature >::reverse_iterator ReverseIterator
Mutable reverse iterator.
Definition: ConsensusMap.h:164
OpenMS::ConsensusMap::applyFunctionOnPeptideHits
void applyFunctionOnPeptideHits(std::function< void(PeptideHit &)> &f, bool include_unassigned=true)
applies a function on all PeptideHits or only assigned ones
OpenMS::ConsensusMap::ConstReverseIterator
std::vector< ConsensusFeature >::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition: ConsensusMap.h:166
OpenMS::ConsensusMap::RangeManagerType
RangeManager< 2 > RangeManagerType
Definition: ConsensusMap.h:157
OpenMS::ConsensusMap::experiment_type_
String experiment_type_
type of experiment (label-free, labeled_MS1, labeled_MS2)
Definition: ConsensusMap.h:381
OpenMS::ConsensusMap::Base
std::vector< ConsensusFeature > Base
Definition: ConsensusMap.h:156
OpenMS::ConsensusMap::isMapConsistent
bool isMapConsistent(Logger::LogStream *stream=nullptr) const
checks if the given maps are unique and all FeatureHandles actually refer to a registered map
OpenMS::ConsensusMap::applyFunctionOnPeptideIDs_
void applyFunctionOnPeptideIDs_(const std::vector< PeptideIdentification > &idvec, std::function< void(const PeptideIdentification &)> &f) const
OpenMS::ConsensusMap::operator==
bool operator==(const ConsensusMap &rhs) const
Equality operator.
OpenMS::ConsensusMap::data_processing_
std::vector< DataProcessing > data_processing_
applied data processing
Definition: ConsensusMap.h:390
OpenMS::ConsensusMap::setExperimentType
void setExperimentType(const String &experiment_type)
Mutable access to the experiment type.
OpenMS::ConsensusMap::setPrimaryMSRunPath
void setPrimaryMSRunPath(const StringList &s)
set the file paths to the primary MS run (stored in ColumnHeaders)
OpenMS::ConsensusMap::column_description_
ColumnHeaders column_description_
Map from index to file description.
Definition: ConsensusMap.h:378
OpenMS::ConsensusMap::ColumnHeaders
std::map< UInt64, ColumnHeader > ColumnHeaders
Definition: ConsensusMap.h:158
OpenMS::ConsensusMap::setUnassignedPeptideIdentifications
void setUnassignedPeptideIdentifications(const std::vector< PeptideIdentification > &unassigned_peptide_identifications)
sets the unassigned peptide identifications
OpenMS::PeptideHit
Representation of a peptide hit.
Definition: PeptideHit.h:54