Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
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-2013.
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: Erhan Kenar $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_KERNEL_CONSENSUSMAP_H
36 #define OPENMS_KERNEL_CONSENSUSMAP_H
37 
46 
47 namespace OpenMS
48 {
60  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
61  private std::vector<ConsensusFeature>,
62  public MetaInfoInterface,
63  public RangeManager<2>,
64  public DocumentIdentifier,
65  public UniqueIdInterface,
66  public UniqueIdIndexer<ConsensusMap>
67  {
68 
69 public:
70  typedef std::vector<ConsensusFeature> privvec;
71 
72  // types
73  using privvec::value_type;
74  using privvec::iterator;
75  using privvec::const_iterator;
76  using privvec::size_type;
77  using privvec::pointer; // ConstRefVector
78  using privvec::reference; // ConstRefVector
79  using privvec::const_reference; // ConstRefVector
80  using privvec::difference_type; // ConstRefVector
81 
82  // functions
83  using privvec::begin;
84  using privvec::end;
85 
86  using privvec::size;
87  using privvec::resize;
88  using privvec::empty;
89  using privvec::reserve;
90  using privvec::operator[];
91  using privvec::at; // UniqueIdIndexer
92  using privvec::back; // source/ANALYSIS/DECHARGING/FeatureDeconvolution.C:977:
93 
94  using privvec::push_back;
95 
97  struct OPENMS_DLLAPI FileDescription :
98  public MetaInfoInterface
99  {
101  FileDescription();
102 
104  FileDescription(const FileDescription &);
105 
115  };
116 
118 
119  typedef std::vector<ConsensusFeature> Base;
123  typedef std::vector<ConsensusFeature>::iterator Iterator;
125  typedef std::vector<ConsensusFeature>::const_iterator ConstIterator;
127  typedef std::vector<ConsensusFeature>::reverse_iterator ReverseIterator;
129  typedef std::vector<ConsensusFeature>::const_reverse_iterator ConstReverseIterator;
131 
133  OPENMS_DLLAPI ConsensusMap();
134 
136  OPENMS_DLLAPI ConsensusMap(const ConsensusMap & source);
137 
139  OPENMS_DLLAPI ~ConsensusMap();
140 
142  OPENMS_DLLAPI explicit ConsensusMap(Base::size_type n);
143 
145  OPENMS_DLLAPI ConsensusMap & operator=(const ConsensusMap & source);
146 
156  OPENMS_DLLAPI ConsensusMap & operator+=(const ConsensusMap & rhs);
157 
163  OPENMS_DLLAPI void clear(bool clear_meta_data = true);
164 
166  OPENMS_DLLAPI const FileDescriptions & getFileDescriptions() const;
167 
169  OPENMS_DLLAPI FileDescriptions & getFileDescriptions();
170 
172  OPENMS_DLLAPI void setFileDescriptions(const FileDescriptions & file_description);
173 
175  OPENMS_DLLAPI const String & getExperimentType() const;
176 
178  OPENMS_DLLAPI void setExperimentType(const String & experiment_type);
179 
187  OPENMS_DLLAPI void sortByIntensity(bool reverse = false);
189 
191  OPENMS_DLLAPI void sortByRT();
192 
194  OPENMS_DLLAPI void sortByMZ();
195 
197  OPENMS_DLLAPI void sortByPosition();
198 
200  OPENMS_DLLAPI void sortByQuality(bool reverse = false);
201 
203  OPENMS_DLLAPI void sortBySize();
204 
206  OPENMS_DLLAPI void sortByMaps();
207 
209 
229  template <typename FeatureT>
230  static void convert(UInt64 const input_map_index,
231  FeatureMap<FeatureT> const & input_map,
232  ConsensusMap & output_map,
233  Size n = -1)
234  {
235  if (n > input_map.size())
236  {
237  n = input_map.size();
238  }
239 
240  output_map.clear(true);
241  output_map.reserve(n);
242 
243  // An arguable design decision, see above.
244  output_map.setUniqueId(input_map.getUniqueId());
245 
246  for (UInt64 element_index = 0; element_index < n; ++element_index)
247  {
248  output_map.push_back(ConsensusFeature(input_map_index, input_map[element_index]));
249  }
250  output_map.getFileDescriptions()[input_map_index].size = (Size) input_map.size();
253  output_map.updateRanges();
254  }
255 
269  OPENMS_DLLAPI static void convert(UInt64 const input_map_index,
270  MSExperiment<> & input_map,
271  ConsensusMap & output_map,
272  Size n = -1)
273  {
274  output_map.clear(true);
275 
276  // see @todo above
277  output_map.setUniqueId();
278 
279  input_map.updateRanges(1);
280  if (n > input_map.getSize())
281  {
282  n = input_map.getSize();
283  }
284  output_map.reserve(n);
285  std::vector<Peak2D> tmp;
286  tmp.reserve(input_map.getSize());
287 
288  // TODO Avoid tripling the memory consumption by this call
289  input_map.get2DData(tmp);
290 
291  std::partial_sort(tmp.begin(),
292  tmp.begin() + n,
293  tmp.end(),
295 
296  for (Size element_index = 0; element_index < n; ++element_index)
297  {
298  output_map.push_back(ConsensusFeature(input_map_index,
299  tmp[element_index],
300  element_index));
301  }
302 
303  output_map.getFileDescriptions()[input_map_index].size = n;
304  output_map.updateRanges();
305  }
306 
319  OPENMS_DLLAPI static void convert(UInt64 const input_map_index,
320  std::vector<Peak2D> & input_map,
321  ConsensusMap & output_map,
322  Size n = -1)
323  {
324  // Clear the map and assign new ID.
325  output_map.setUniqueId();
326  output_map.clear(true);
327 
328  // Determine the maximum size of the map and resize the output map accordingly.
329  if (n > input_map.size())
330  {
331  n = input_map.size();
332  }
333  output_map.reserve(n);
334 
335  std::partial_sort(input_map.begin(),
336  input_map.begin() + n,
337  input_map.end(),
339 
340  for (Size element_index = 0; element_index < n; ++element_index)
341  {
342  output_map.push_back(ConsensusFeature(input_map_index, input_map[element_index], element_index));
343  }
344 
345  output_map.getFileDescriptions()[input_map_index].size = n;
346  output_map.updateRanges();
347  }
348 
359  template <typename FeatureT>
360  static void convert(ConsensusMap const & input_map,
361  const bool keep_uids,
362  FeatureMap<FeatureT> & output_map)
363  {
364  output_map.clear(true);
365  output_map.resize(input_map.size());
366  output_map.DocumentIdentifier::operator=(input_map);
367 
368  if (keep_uids) output_map.UniqueIdInterface::operator=(input_map);
369  else output_map.setUniqueId();
370 
373 
374  for (Size i = 0; i < input_map.size(); ++i)
375  {
376  Feature & f = output_map[i];
377  const ConsensusFeature & c = input_map[i];
378  f.BaseFeature::operator=(c);
379  if (!keep_uids) f.setUniqueId();
380  }
381 
382  output_map.updateRanges();
383  }
384 
385  // Docu in base class
386  OPENMS_DLLAPI void updateRanges();
387 
389  OPENMS_DLLAPI void swap(ConsensusMap & from);
390 
392  OPENMS_DLLAPI const std::vector<ProteinIdentification> & getProteinIdentifications() const;
393 
395  OPENMS_DLLAPI std::vector<ProteinIdentification> & getProteinIdentifications();
396 
398  OPENMS_DLLAPI void setProteinIdentifications(const std::vector<ProteinIdentification> & protein_identifications);
399 
401  OPENMS_DLLAPI const std::vector<PeptideIdentification> & getUnassignedPeptideIdentifications() const;
402 
404  OPENMS_DLLAPI std::vector<PeptideIdentification> & getUnassignedPeptideIdentifications();
405 
407  OPENMS_DLLAPI void setUnassignedPeptideIdentifications(const std::vector<PeptideIdentification> & unassigned_peptide_identifications);
408 
410  OPENMS_DLLAPI const std::vector<DataProcessing> & getDataProcessing() const;
411 
413  OPENMS_DLLAPI std::vector<DataProcessing> & getDataProcessing();
414 
416  OPENMS_DLLAPI void setDataProcessing(const std::vector<DataProcessing> & processing_method);
417 
419  OPENMS_DLLAPI bool operator==(const ConsensusMap & rhs) const;
420 
422  OPENMS_DLLAPI bool operator!=(const ConsensusMap & rhs) const;
423 
437  template <typename Type>
438  Size applyMemberFunction(Size (Type::* member_function)())
439  {
440  Size assignments = 0;
441  assignments += ((*this).*member_function)();
442  for (Iterator iter = this->begin(); iter != this->end(); ++iter)
443  {
444  assignments += ((*iter).*member_function)();
445  }
446  return assignments;
447  }
448 
450  template <typename Type>
451  Size applyMemberFunction(Size (Type::* member_function)() const) const
452  {
453  Size assignments = 0;
454  assignments += ((*this).*member_function)();
455  for (ConstIterator iter = this->begin(); iter != this->end(); ++iter)
456  {
457  assignments += ((*iter).*member_function)();
458  }
459  return assignments;
460  }
461 
474  bool isMapConsistent(Logger::LogStream* stream = 0) const;
475 
476 protected:
477 
480 
483 
485  std::vector<ProteinIdentification> protein_identifications_;
486 
488  std::vector<PeptideIdentification> unassigned_peptide_identifications_;
489 
491  std::vector<DataProcessing> data_processing_;
492  };
493 
495  OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const ConsensusMap & cons_map);
496 
497 } // namespace OpenMS
498 
499 #endif // OPENMS_KERNEL_CONSENSUSMAP_H
void setDataProcessing(const std::vector< DataProcessing > &processing_method)
sets the description of the applied data processing
std::vector< ConsensusFeature >::iterator Iterator
Mutable iterator.
Definition: ConsensusMap.h:123
void sortByMZ()
Sorts the peaks to m/z position.
const std::vector< ProteinIdentification > & getProteinIdentifications() const
non-mutable access to the protein identifications
void get2DData(Container &cont) const
Reads out a 2D Spectrum.
Definition: MSExperiment.h:248
A more convenient string class.
Definition: String.h:56
void clear(bool clear_meta_data=true)
Clears all data and meta data.
String label
Label e.g. &#39;heavy&#39; and &#39;light&#39; for ICAT, or &#39;sample1&#39; and &#39;sample2&#39; for label-free quantitation...
Definition: ConsensusMap.h:109
const std::vector< ProteinIdentification > & getProteinIdentifications() const
non-mutable access to the protein identifications
Definition: FeatureMap.h:410
std::vector< ConsensusFeature >::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition: ConsensusMap.h:129
Source file description for input files.
Definition: ConsensusMap.h:97
const std::vector< PeptideIdentification > & getUnassignedPeptideIdentifications() const
non-mutable access to the unassigned peptide identifications
static void convert(ConsensusMap const &input_map, const bool keep_uids, FeatureMap< FeatureT > &output_map)
Convert a ConsensusMap to a FeatureMap (of any feature type).
Definition: ConsensusMap.h:360
A container for features.
Definition: FeatureMap.h:111
std::vector< PeptideIdentification > unassigned_peptide_identifications_
protein identifications
Definition: ConsensusMap.h:488
const FileDescriptions & getFileDescriptions() const
Non-mutable access to the file descriptions.
const std::vector< PeptideIdentification > & getUnassignedPeptideIdentifications() const
non-mutable access to the unassigned peptide identifications
Definition: FeatureMap.h:428
UInt64 unique_id
Unique id of the file.
Definition: ConsensusMap.h:114
std::ostream & operator<<(std::ostream &os, const ItraqQuantifier::ItraqQuantifierStats &stats)
Size setUniqueId()
Assigns a new, valid unique id. Always returns 1.
Definition: UniqueIdInterface.h:150
ReverseComparator< Cmp > reverseComparator(Cmp const &cmp)
Make-function to create a ReverseComparator from another comparator without the need to specify the t...
Definition: ComparatorUtils.h:261
A container for consensus elements.
Definition: ConsensusMap.h:60
void sortByQuality(bool reverse=false)
Sorts the peaks according to ascending quality.
Size applyMemberFunction(Size(Type::*member_function)())
Applies a member function of Type to the container itself and all consensus features. The returned values are accumulated.
Definition: ConsensusMap.h:438
Definition: Peak2D.h:246
const double c
std::vector< DataProcessing > data_processing_
applied data processing
Definition: ConsensusMap.h:491
void setExperimentType(const String &experiment_type)
Mutable access to the experiment type.
ConsensusMap()
Default constructor.
Log Stream Class.
Definition: LogStream.h:303
~ConsensusMap()
Destructor.
const String & getExperimentType() const
Non-mutable access to the experiment type.
static void convert(UInt64 const input_map_index, std::vector< Peak2D > &input_map, ConsensusMap &output_map, Size n=-1)
Convert a vector of 2D Peaks (Peak2D) into a ConsensusMap.
Definition: ConsensusMap.h:319
FileDescriptions file_description_
Map from index to file description.
Definition: ConsensusMap.h:479
std::vector< ConsensusFeature >::reverse_iterator ReverseIterator
Mutable reverse iterator.
Definition: ConsensusMap.h:127
void setProteinIdentifications(const std::vector< ProteinIdentification > &protein_identifications)
sets the protein identifications
Definition: FeatureMap.h:422
String experiment_type_
type of experiment (label-free, itraq, ...); see xsd schema
Definition: ConsensusMap.h:482
std::vector< ConsensusFeature > Base
Definition: ConsensusMap.h:119
void sortByMaps()
Sorts with respect to the sets of maps covered by the consensus features (lexicographically).
A base class for random access containers for classes derived from UniqueIdInterface that adds functi...
Definition: UniqueIdIndexer.h:63
void setFileDescriptions(const FileDescriptions &file_description)
Mutable access to the file descriptions.
RangeManager< 2 > RangeManagerType
Definition: ConsensusMap.h:120
An LC-MS feature.
Definition: Feature.h:66
void setUnassignedPeptideIdentifications(const std::vector< PeptideIdentification > &unassigned_peptide_identifications)
sets the unassigned peptide identifications
OPENMS_UINT64_TYPE UInt64
Unsigned integer type (64bit)
Definition: Types.h:75
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:61
A base class defining a common interface for all classes having a unique id.
Definition: UniqueIdInterface.h:51
const std::vector< DataProcessing > & getDataProcessing() const
returns a const reference to the description of the applied data processing
Representation of a mass spectrometry experiment.
Definition: MSExperiment.h:68
std::vector< ProteinIdentification > protein_identifications_
protein identifications
Definition: ConsensusMap.h:485
Map< UInt64, FileDescription > FileDescriptions
Definition: ConsensusMap.h:121
ConsensusMap & operator=(const ConsensusMap &source)
Assignment operator.
static void convert(UInt64 const input_map_index, MSExperiment<> &input_map, ConsensusMap &output_map, Size n=-1)
Similar to convert for FeatureMaps.
Definition: ConsensusMap.h:269
UInt64 getSize() const
returns the total number of peaks
Definition: MSExperiment.h:555
void sortBySize()
Sorts with respect to the size (number of elements)
void updateRanges()
Updates minimum and maximum position/intensity.
Definition: FeatureMap.h:343
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
std::vector< ConsensusFeature > privvec
Definition: ConsensusMap.h:70
void swap(ConsensusMap &from)
Swaps the content of this map with the content of from.
static void convert(UInt64 const input_map_index, FeatureMap< FeatureT > const &input_map, ConsensusMap &output_map, Size n=-1)
Convert a FeatureMap (of any feature type) to a ConsensusMap.
Definition: ConsensusMap.h:230
bool isMapConsistent(Logger::LogStream *stream=0) const
checks if the given maps are unique and all FeatureHandles actually refer to a registered map ...
bool operator==(const ConsensusMap &rhs) const
Equality operator.
bool operator!=(const ConsensusMap &rhs) const
Equality operator.
void sortByPosition()
Lexicographically sorts the peaks by their position (First RT then m/z).
Handles the managment of a position and intensity range.
Definition: RangeManager.h:48
void updateRanges()
Updates minimum and maximum position/intensity.
virtual void updateRanges()
Updates minimum and maximum position/intensity.
Definition: MSExperiment.h:403
std::vector< ConsensusFeature >::const_iterator ConstIterator
Non-mutable iterator.
Definition: ConsensusMap.h:125
String filename
File name of the file.
Definition: ConsensusMap.h:107
Size size
Number of elements (features, peaks, ...). This is e.g. used to check for correct element indices whe...
Definition: ConsensusMap.h:112
void setProteinIdentifications(const std::vector< ProteinIdentification > &protein_identifications)
sets the protein identifications
void sortByRT()
Sorts the peaks to RT position.
ConsensusMap & operator+=(const ConsensusMap &rhs)
Add one consensus map to another.
UInt64 getUniqueId() const
Non-mutable access to unique id - returns the unique id.
Definition: UniqueIdInterface.h:109
void clear(bool clear_meta_data=true)
Clears all data and meta data.
Definition: FeatureMap.h:468
Manage source document information.
Definition: DocumentIdentifier.h:56
A 2-dimensional consensus feature.
Definition: ConsensusFeature.h:59
void sortByIntensity(bool reverse=false)
Sorts the peaks according to ascending intensity.
void setUnassignedPeptideIdentifications(const std::vector< PeptideIdentification > &unassigned_peptide_identifications)
sets the unassigned peptide identifications
Definition: FeatureMap.h:440
Size applyMemberFunction(Size(Type::*member_function)() const) const
The &quot;const&quot; variant.
Definition: ConsensusMap.h:451

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:12 using doxygen 1.8.5