OpenMS  2.6.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>
49 #include <OpenMS/OpenMSConfig.h>
50 
51 #include <map>
52 #include <vector>
53 
54 namespace OpenMS
55 {
56  class PeptideIdentification;
57  class PeptideHit;
58  class ProteinIdentification;
59  class DataProcessing;
60  namespace Logger
61  {
62  class LogStream;
63  }
64 
80  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
81  private std::vector<ConsensusFeature>,
82  public MetaInfoInterface,
83  public RangeManager<2>,
84  public DocumentIdentifier,
85  public UniqueIdInterface,
86  public UniqueIdIndexer<ConsensusMap>,
87  public MapUtilities<ConsensusMap>
88  {
89 
90 public:
91  typedef std::vector<ConsensusFeature> privvec;
92 
93  // types
94  using privvec::value_type;
95  using privvec::iterator;
96  using privvec::const_iterator;
97  using privvec::size_type;
98  using privvec::pointer; // ConstRefVector
99  using privvec::reference; // ConstRefVector
100  using privvec::const_reference; // ConstRefVector
101  using privvec::difference_type; // ConstRefVector
102 
103  // functions
104  using privvec::begin;
105  using privvec::end;
106 
107  using privvec::size;
108  using privvec::resize;
109  using privvec::empty;
110  using privvec::reserve;
111  using privvec::operator[];
112  using privvec::at;
113  using privvec::back;
114  using privvec::push_back;
115  using privvec::emplace_back;
116  using privvec::erase;
117 
118  enum class SplitMeta
119  {
120  DISCARD,
121  COPY_ALL,
122  COPY_FIRST
123  };
124 
126  struct OPENMS_DLLAPI ColumnHeader :
127  public MetaInfoInterface
128  {
130  ColumnHeader();
131 
133  ColumnHeader(const ColumnHeader&);
134 
144 
145  unsigned getLabelAsUInt(const String& experiment_type) const
146  {
147  if (metaValueExists("channel_id"))
148  {
149  return static_cast<unsigned int>(getMetaValue("channel_id")) + 1;
150  }
151  else
152  {
153  if (experiment_type != "label-free")
154  {
155  // TODO There seem to be files in our test data from the Multiplex toolset that do not annotate
156  // a channel id but only add the "label" attribute with the SILAC modification. Add a fall-back here?
157  OPENMS_LOG_WARN << "No channel id annotated in labelled consensusXML. Assuming only a single channel was used." << std::endl;
158  }
159  return 1;
160  }
161  }
162  };
163 
165 
166  typedef std::vector<ConsensusFeature> Base;
168  typedef std::map<UInt64, ColumnHeader> ColumnHeaders;
170  typedef std::vector<ConsensusFeature>::iterator Iterator;
172  typedef std::vector<ConsensusFeature>::const_iterator ConstIterator;
174  typedef std::vector<ConsensusFeature>::reverse_iterator ReverseIterator;
176  typedef std::vector<ConsensusFeature>::const_reverse_iterator ConstReverseIterator;
178 
180  OPENMS_DLLAPI ConsensusMap();
181 
183  OPENMS_DLLAPI ConsensusMap(const ConsensusMap& source);
184 
186  OPENMS_DLLAPI ~ConsensusMap() override;
187 
189  OPENMS_DLLAPI explicit ConsensusMap(Base::size_type n);
190 
192  OPENMS_DLLAPI ConsensusMap& operator=(const ConsensusMap& source);
193 
203  OPENMS_DLLAPI ConsensusMap& appendRows(const ConsensusMap& rhs);
204 
212  OPENMS_DLLAPI ConsensusMap& appendColumns(const ConsensusMap& rhs);
213 
214 
220  OPENMS_DLLAPI void clear(bool clear_meta_data = true);
221 
223  OPENMS_DLLAPI const ColumnHeaders& getColumnHeaders() const;
224 
226  OPENMS_DLLAPI ColumnHeaders& getColumnHeaders();
227 
229  OPENMS_DLLAPI void setColumnHeaders(const ColumnHeaders& column_description);
230 
232  OPENMS_DLLAPI const String& getExperimentType() const;
233 
235  OPENMS_DLLAPI void setExperimentType(const String& experiment_type);
236 
244  OPENMS_DLLAPI void sortByIntensity(bool reverse = false);
246 
248  OPENMS_DLLAPI void sortByRT();
249 
251  OPENMS_DLLAPI void sortByMZ();
252 
254  OPENMS_DLLAPI void sortByPosition();
255 
257  OPENMS_DLLAPI void sortByQuality(bool reverse = false);
258 
260  OPENMS_DLLAPI void sortBySize();
261 
263  OPENMS_DLLAPI void sortByMaps();
264 
266  OPENMS_DLLAPI void sortPeptideIdentificationsByMapIndex();
268 
269  // Docu in base class
270  OPENMS_DLLAPI void updateRanges() override;
271 
273  OPENMS_DLLAPI void swap(ConsensusMap& from);
274 
276  OPENMS_DLLAPI const std::vector<ProteinIdentification>& getProteinIdentifications() const;
277 
279  OPENMS_DLLAPI std::vector<ProteinIdentification>& getProteinIdentifications();
280 
282  OPENMS_DLLAPI void setProteinIdentifications(const std::vector<ProteinIdentification>& protein_identifications);
283 
285  OPENMS_DLLAPI void setProteinIdentifications(std::vector<ProteinIdentification>&& protein_identifications);
286 
288  OPENMS_DLLAPI const std::vector<PeptideIdentification>& getUnassignedPeptideIdentifications() const;
289 
291  OPENMS_DLLAPI std::vector<PeptideIdentification>& getUnassignedPeptideIdentifications();
292 
294  OPENMS_DLLAPI void setUnassignedPeptideIdentifications(const std::vector<PeptideIdentification>& unassigned_peptide_identifications);
295 
297  OPENMS_DLLAPI const std::vector<DataProcessing>& getDataProcessing() const;
298 
300  OPENMS_DLLAPI std::vector<DataProcessing>& getDataProcessing();
301 
303  OPENMS_DLLAPI void setDataProcessing(const std::vector<DataProcessing>& processing_method);
304 
306  OPENMS_DLLAPI void setPrimaryMSRunPath(const StringList& s);
307 
310  OPENMS_DLLAPI void setPrimaryMSRunPath(const StringList& s, MSExperiment & e);
311 
313  OPENMS_DLLAPI void getPrimaryMSRunPath(StringList& toFill) const;
314 
316  OPENMS_DLLAPI bool operator==(const ConsensusMap& rhs) const;
317 
319  OPENMS_DLLAPI bool operator!=(const ConsensusMap& rhs) const;
320 
334  template <typename Type>
335  Size applyMemberFunction(Size (Type::* member_function)())
336  {
337  Size assignments = 0;
338  assignments += ((*this).*member_function)();
339  for (Iterator iter = this->begin(); iter != this->end(); ++iter)
340  {
341  assignments += ((*iter).*member_function)();
342  }
343  return assignments;
344  }
345 
347  template <typename Type>
348  Size applyMemberFunction(Size (Type::* member_function)() const) const
349  {
350  Size assignments = 0;
351  assignments += ((*this).*member_function)();
352  for (ConstIterator iter = this->begin(); iter != this->end(); ++iter)
353  {
354  assignments += ((*iter).*member_function)();
355  }
356  return assignments;
357  }
358 
371  OPENMS_DLLAPI bool isMapConsistent(Logger::LogStream* stream = nullptr) const;
372 
386  OPENMS_DLLAPI std::vector<FeatureMap> split(SplitMeta mode = SplitMeta::DISCARD) const;
387 
388 protected:
389 
392 
394  String experiment_type_ = "label-free";
395 
397  std::vector<ProteinIdentification> protein_identifications_;
398 
400  std::vector<PeptideIdentification> unassigned_peptide_identifications_;
401 
403  std::vector<DataProcessing> data_processing_;
404 
405  };
406 
408  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const ConsensusMap& cons_map);
409 
410 
411 
412 } // namespace OpenMS
413 
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:126
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:335
OpenMS::ConsensusMap::ColumnHeader::filename
String filename
File name of the mzML file.
Definition: ConsensusMap.h:136
OpenMS::ConsensusMap::ColumnHeader::getLabelAsUInt
unsigned getLabelAsUInt(const String &experiment_type) const
Definition: ConsensusMap.h:145
OpenMS::ConsensusMap::protein_identifications_
std::vector< ProteinIdentification > protein_identifications_
protein identifications
Definition: ConsensusMap.h:397
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:143
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::SplitMeta
SplitMeta
Definition: ConsensusMap.h:118
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::ConsensusMap::split
std::vector< FeatureMap > split(SplitMeta mode=SplitMeta::DISCARD) const
splits ConsensusMap into its original FeatureMaps
OpenMS::String
A more convenient string class.
Definition: String.h:59
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
MapUtilities.h
OpenMS::ConsensusMap::sortByIntensity
void sortByIntensity(bool reverse=false)
Sorts the peaks according to ascending intensity.
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:141
OpenMS::ConsensusMap::applyMemberFunction
Size applyMemberFunction(Size(Type::*member_function)() const) const
The "const" variant.
Definition: ConsensusMap.h:348
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:400
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:91
OpenMS::ConsensusMap::ConstIterator
std::vector< ConsensusFeature >::const_iterator ConstIterator
Non-mutable iterator.
Definition: ConsensusMap.h:172
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:138
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:80
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
OpenMS::ConsensusMap::SplitMeta::COPY_ALL
copy all meta values to all feature maps
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::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:170
OpenMS::ConsensusMap::setDataProcessing
void setDataProcessing(const std::vector< DataProcessing > &processing_method)
sets the description of the applied data processing
MetaInfoInterface.h
OpenMS::ConsensusMap::SplitMeta::COPY_FIRST
copy all meta values to first feature map
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:174
OpenMS::ConsensusMap::ConstReverseIterator
std::vector< ConsensusFeature >::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition: ConsensusMap.h:176
OpenMS::MapUtilities
Utilities for Feature and ConsensusMap.
Definition: MapUtilities.h:49
OpenMS::ConsensusMap::SplitMeta::DISCARD
do not copy any meta values
OpenMS::ConsensusMap::RangeManagerType
RangeManager< 2 > RangeManagerType
Definition: ConsensusMap.h:167
OpenMS::ConsensusMap::experiment_type_
String experiment_type_
type of experiment (label-free, labeled_MS1, labeled_MS2)
Definition: ConsensusMap.h:394
OpenMS::ConsensusMap::Base
std::vector< ConsensusFeature > Base
Definition: ConsensusMap.h:166
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::operator==
bool operator==(const ConsensusMap &rhs) const
Equality operator.
OpenMS::ConsensusMap::data_processing_
std::vector< DataProcessing > data_processing_
applied data processing
Definition: ConsensusMap.h:403
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:391
OpenMS::ConsensusMap::ColumnHeaders
std::map< UInt64, ColumnHeader > ColumnHeaders
Definition: ConsensusMap.h:168
OpenMS::ConsensusMap::setUnassignedPeptideIdentifications
void setUnassignedPeptideIdentifications(const std::vector< PeptideIdentification > &unassigned_peptide_identifications)
sets the unassigned peptide identifications