Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
FeatureMap.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: Chris Bielow $
32 // $Authors: Marc Sturm, Chris Bielow, Clemens Groepl $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_KERNEL_FEATUREMAP_H
36 #define OPENMS_KERNEL_FEATUREMAP_H
37 
38 #include <OpenMS/KERNEL/Feature.h>
45 
46 #include <algorithm>
47 #include <vector>
48 #include <exception>
49 
50 namespace OpenMS
51 {
52 
53 
54 
58  {
59  std::vector<Size> states; //< count each state, indexing by BaseFeature::AnnotationState
60 
62  : states(BaseFeature::SIZE_OF_ANNOTATIONSTATE, 0) // initialize all with 0
63  {
64  }
65 
67  : states(rhs.states)
68  {
69  }
70 
72  {
73  if (this == &rhs) return *this;
74 
75  states = rhs.states;
76  return *this;
77  }
78 
79  bool operator==(const AnnotationStatistics& rhs) const
80  {
81  return states == rhs.states;
82  }
83 
85  {
86  ++states[(Size)state];
87  return *this;
88  }
89 
90  };
91 
92 
94  OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const AnnotationStatistics& ann);
95 
110  template <typename FeatureT = Feature>
111  class FeatureMap :
112  private std::vector<FeatureT>,
113  public RangeManager<2>,
114  public DocumentIdentifier,
115  public UniqueIdInterface,
116  public UniqueIdIndexer<FeatureMap<FeatureT> >
117  {
118 public:
122  typedef std::vector<FeatureT> privvec;
123 
124  // types
125  using typename privvec::value_type;
126  using typename privvec::iterator;
127  using typename privvec::const_iterator;
128  using typename privvec::size_type;
129  using typename privvec::pointer; // ConstRefVector
130  using typename privvec::reference; // ConstRefVector
131  using typename privvec::const_reference; // ConstRefVector
132  using typename privvec::difference_type; // ConstRefVector
133 
134  // functions
135  using privvec::begin;
136  using privvec::end;
137 
138  using privvec::size;
139  using privvec::resize; // ConsensusMap, FeatureXMLFile
140  using privvec::empty;
141  using privvec::reserve;
142  using privvec::operator[];
143  using privvec::at; // UniqueIdIndexer
144  using privvec::back; // FeatureXMLFile
145 
146  using privvec::push_back;
147  using privvec::pop_back; // FeatureXMLFile
148  using privvec::erase; // source/VISUAL/Spectrum2DCanvas.C 2871, FeatureMap_test 599
149 
153  typedef std::vector<FeatureType> Base;
154  typedef typename Base::iterator Iterator;
155  typedef typename Base::const_iterator ConstIterator;
156  typedef typename Base::reverse_iterator ReverseIterator;
157  typedef typename Base::const_reverse_iterator ConstReverseIterator;
159  typedef const FeatureType & ConstReference;
161 
166 
169  Base(),
177  {}
178 
180  FeatureMap(const FeatureMap & source) :
181  Base(source),
182  RangeManagerType(source),
183  DocumentIdentifier(source),
184  UniqueIdInterface(source),
189  {}
190 
192  virtual ~FeatureMap()
193  {}
195 
198  {
199  if (&rhs == this) return *this;
200 
201  Base::operator=(rhs);
208 
209  return *this;
210  }
211 
213  bool operator==(const FeatureMap & rhs) const
214  {
215  return std::operator==(*this, rhs) &&
222  }
223 
225  bool operator!=(const FeatureMap & rhs) const
226  {
227  return !(operator==(rhs));
228  }
229 
235  FeatureMap operator+(const FeatureMap & rhs) const
236  {
237  FeatureMap tmp(*this);
238  tmp += rhs;
239  return tmp;
240  }
241 
255  {
256  FeatureMap empty_map;
257  // reset these:
258  RangeManagerType::operator=(empty_map);
259 
260  if (!this->getIdentifier().empty() || !rhs.getIdentifier().empty()) LOG_INFO << "DocumentIdentifiers are lost during merge of FeatureMaps\n";
262 
263  UniqueIdInterface::operator=(empty_map);
264 
265  // merge these:
268  data_processing_.insert(data_processing_.end(), rhs.data_processing_.begin(), rhs.data_processing_.end());
269 
270  // append features:
271  this->insert(this->end(), rhs.begin(), rhs.end());
272 
273  // todo: check for double entries
274  // features, unassignedpeptides, proteins...
275 
276  // consistency
277  try
278  {
280  }
281  catch (Exception::Postcondition /*&e*/) // assign new UID's for conflicting entries
282  {
284  LOG_INFO << "Replaced " << replaced_uids << " invalid uniqueID's\n";
285  }
286 
287  return *this;
288  }
289 
296  void sortByIntensity(bool reverse = false)
298  {
299  if (reverse)
300  {
301  std::sort(this->begin(), this->end(), reverseComparator(typename FeatureType::IntensityLess()));
302  }
303  else
304  {
305  std::sort(this->begin(), this->end(), typename FeatureType::IntensityLess());
306  }
307  }
308 
311  {
312  std::sort(this->begin(), this->end(), typename FeatureType::PositionLess());
313  }
314 
316  void sortByRT()
317  {
318  std::sort(this->begin(), this->end(), typename FeatureType::RTLess());
319  }
320 
322  void sortByMZ()
323  {
324  std::sort(this->begin(), this->end(), typename FeatureType::MZLess());
325  }
326 
328  void sortByOverallQuality(bool reverse = false)
329  {
330  if (reverse)
331  {
332  std::sort(this->begin(), this->end(), reverseComparator(typename FeatureType::OverallQualityLess()));
333  }
334  else
335  {
336  std::sort(this->begin(), this->end(), typename FeatureType::OverallQualityLess());
337  }
338  }
339 
341 
342  // Docu in base class
344  {
345  this->clearRanges();
346  updateRanges_(this->begin(), this->end());
347 
348  //enlarge the range by the convex hull points
349  for (Size i = 0; i < this->size(); ++i)
350  {
351  DBoundingBox<2> box = this->operator[](i).getConvexHull().getBoundingBox();
352  if (!box.isEmpty())
353  {
354  //update RT
355  if (box.minPosition()[Peak2D::RT] < this->pos_range_.minPosition()[Peak2D::RT])
356  {
357  this->pos_range_.setMinX(box.minPosition()[Peak2D::RT]);
358  }
359  if (box.maxPosition()[Peak2D::RT] > this->pos_range_.maxPosition()[Peak2D::RT])
360  {
361  this->pos_range_.setMaxX(box.maxPosition()[Peak2D::RT]);
362  }
363  //update m/z
364  if (box.minPosition()[Peak2D::MZ] < this->pos_range_.minPosition()[Peak2D::MZ])
365  {
366  this->pos_range_.setMinY(box.minPosition()[Peak2D::MZ]);
367  }
368  if (box.maxPosition()[Peak2D::MZ] > this->pos_range_.maxPosition()[Peak2D::MZ])
369  {
370  this->pos_range_.setMaxY(box.maxPosition()[Peak2D::MZ]);
371  }
372  }
373  }
374  }
375 
378  {
379  // TODO used by FeatureFinderAlgorithmPicked -- could it also use regular swap?
380  Base::swap(from);
381 
382  // swap range information (otherwise its false in both maps)
383  FeatureMap tmp;
384  tmp.RangeManagerType::operator=(* this);
385  this->RangeManagerType::operator=(from);
386  from.RangeManagerType::operator=(tmp);
387  }
388 
389  void swap(FeatureMap& from)
390  {
391  // swap features and ranges
392  swapFeaturesOnly(from);
393 
394  // swap DocumentIdentifier
396 
397  // swap unique id
399 
400  // swap unique id index
402 
403  // swap the remaining members
407  }
408 
410  const std::vector<ProteinIdentification> & getProteinIdentifications() const
411  {
413  }
414 
416  std::vector<ProteinIdentification> & getProteinIdentifications()
417  {
419  }
420 
422  void setProteinIdentifications(const std::vector<ProteinIdentification> & protein_identifications)
423  {
424  protein_identifications_ = protein_identifications;
425  }
426 
428  const std::vector<PeptideIdentification> & getUnassignedPeptideIdentifications() const
429  {
431  }
432 
434  std::vector<PeptideIdentification> & getUnassignedPeptideIdentifications()
435  {
437  }
438 
440  void setUnassignedPeptideIdentifications(const std::vector<PeptideIdentification> & unassigned_peptide_identifications)
441  {
442  unassigned_peptide_identifications_ = unassigned_peptide_identifications;
443  }
444 
446  const std::vector<DataProcessing> & getDataProcessing() const
447  {
448  return data_processing_;
449  }
450 
452  std::vector<DataProcessing> & getDataProcessing()
453  {
454  return data_processing_;
455  }
456 
458  void setDataProcessing(const std::vector<DataProcessing> & processing_method)
459  {
460  data_processing_ = processing_method;
461  }
462 
468  void clear(bool clear_meta_data = true)
469  {
470  Base::clear();
471 
472  if (clear_meta_data)
473  {
474  clearRanges();
475  this->DocumentIdentifier::operator=(DocumentIdentifier()); // no "clear" method
476  clearUniqueId();
477  protein_identifications_.clear();
479  data_processing_.clear();
480  }
481  }
482 
495  template <typename Type>
496  Size applyMemberFunction(Size (Type::* member_function)())
497  {
498  Size assignments = 0;
499  assignments += ((*this).*member_function)();
500  for (Iterator iter = this->begin(); iter != this->end(); ++iter)
501  {
502  assignments += iter->applyMemberFunction(member_function);
503  }
504  return assignments;
505  }
506 
508  template <typename Type>
509  Size applyMemberFunction(Size (Type::* member_function)() const) const
510  {
511  Size assignments = 0;
512  assignments += ((*this).*member_function)();
513  for (ConstIterator iter = this->begin(); iter != this->end(); ++iter)
514  {
515  assignments += iter->applyMemberFunction(member_function);
516  }
517  return assignments;
518  }
519 
521  {
522  AnnotationStatistics result;
523  for (ConstIterator iter = this->begin(); iter != this->end(); ++iter)
524  {
525  result += iter->getAnnotationState();
526  }
527  return result;
528  }
529 
530 protected:
531 
533  std::vector<ProteinIdentification> protein_identifications_;
534 
536  std::vector<PeptideIdentification> unassigned_peptide_identifications_;
537 
539  std::vector<DataProcessing> data_processing_;
540  };
541 
543  template <typename FeatureType>
544  std::ostream & operator<<(std::ostream & os, const FeatureMap<FeatureType> & map)
545  {
546  os << "# -- DFEATUREMAP BEGIN --" << "\n";
547  os << "# POS \tINTENS\tOVALLQ\tCHARGE\tUniqueID" << "\n";
548  for (typename FeatureMap<FeatureType>::const_iterator iter = map.begin(); iter != map.end(); ++iter)
549  {
550  os << iter->getPosition() << '\t'
551  << iter->getIntensity() << '\t'
552  << iter->getOverallQuality() << '\t'
553  << iter->getCharge() << '\t'
554  << iter->getUniqueId() << "\n";
555  }
556  os << "# -- DFEATUREMAP END --" << std::endl;
557  return os;
558  }
559 
560 
561 } // namespace OpenMS
562 
563 #endif // OPENMS_KERNEL_DFEATUREMAP_H
Base::const_iterator ConstIterator
Definition: FeatureMap.h:155
void sortByMZ()
Sort features by m/z position.
Definition: FeatureMap.h:322
void sortByRT()
Sort features by RT position.
Definition: FeatureMap.h:316
std::vector< Size > states
Definition: FeatureMap.h:59
FeatureMap()
Default constructor.
Definition: FeatureMap.h:168
std::vector< ProteinIdentification > & getProteinIdentifications()
mutable access to the protein identifications
Definition: FeatureMap.h:416
PositionRangeType pos_range_
Position range (D-dimensional)
Definition: RangeManager.h:151
const std::vector< ProteinIdentification > & getProteinIdentifications() const
non-mutable access to the protein identifications
Definition: FeatureMap.h:410
#define LOG_INFO
Macro if a information, e.g. a status should be reported.
Definition: LogStream.h:455
AnnotationStatistics getAnnotationStatistics() const
Definition: FeatureMap.h:520
FeatureMap & operator+=(const FeatureMap &rhs)
Add one feature map to another.
Definition: FeatureMap.h:254
Compare by quality.
Definition: BaseFeature.h:108
std::vector< PeptideIdentification > & getUnassignedPeptideIdentifications()
mutable access to the unassigned peptide identifications
Definition: FeatureMap.h:434
Retention time dimension id (0 if used as a const int)
Definition: Peak2D.h:76
void swap(FeatureMap &from)
Definition: FeatureMap.h:389
A container for features.
Definition: FeatureMap.h:111
const std::vector< PeptideIdentification > & getUnassignedPeptideIdentifications() const
non-mutable access to the unassigned peptide identifications
Definition: FeatureMap.h:428
AnnotationStatistics(const AnnotationStatistics &rhs)
Definition: FeatureMap.h:66
Base::reverse_iterator ReverseIterator
Definition: FeatureMap.h:156
bool operator==(const FeatureMap &rhs) const
Equality operator.
Definition: FeatureMap.h:213
std::ostream & operator<<(std::ostream &os, const ItraqQuantifier::ItraqQuantifierStats &stats)
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
Mass-to-charge dimension id (1 if used as a const int)
Definition: Peak2D.h:77
FeatureType & Reference
Definition: FeatureMap.h:158
AnnotationStatistics & operator+=(BaseFeature::AnnotationState state)
Definition: FeatureMap.h:84
Size applyMemberFunction(Size(Type::*member_function)())
Applies a member function of Type to the container itself and all features (including subordinates)...
Definition: FeatureMap.h:496
std::vector< DataProcessing > & getDataProcessing()
returns a mutable reference to the description of the applied data processing
Definition: FeatureMap.h:452
bool operator==(const RangeManager &rhs) const
Equality operator.
Definition: RangeManager.h:88
Size clearUniqueId()
Clear the unique id. The new unique id will be invalid. Returns 1 if the unique id was changed...
Definition: UniqueIdInterface.h:116
Base::const_reverse_iterator ConstReverseIterator
Definition: FeatureMap.h:157
A basic LC-MS feature.
Definition: BaseFeature.h:55
void setDataProcessing(const std::vector< DataProcessing > &processing_method)
sets the description of the applied data processing
Definition: FeatureMap.h:458
Comparator by position. Lexicographical comparison (first RT then m/z) is done.
Definition: Peak2D.h:324
const std::vector< DataProcessing > & getDataProcessing() const
returns a const reference to the description of the applied data processing
Definition: FeatureMap.h:446
const FeatureType & ConstReference
Definition: FeatureMap.h:159
RangeManager< 2 > RangeManagerType
Definition: FeatureMap.h:152
void setProteinIdentifications(const std::vector< ProteinIdentification > &protein_identifications)
sets the protein identifications
Definition: FeatureMap.h:422
bool operator==(const DocumentIdentifier &rhs) const
Equality operator.
FeatureMap & operator=(const FeatureMap &rhs)
Assignment operator.
Definition: FeatureMap.h:197
RangeManager & operator=(const RangeManager &rhs)
Assignment operator.
Definition: RangeManager.h:77
bool operator!=(const FeatureMap &rhs) const
Equality operator.
Definition: FeatureMap.h:225
FeatureMap operator+(const FeatureMap &rhs) const
Joins two feature maps.
Definition: FeatureMap.h:235
Size resolveUniqueIdConflicts()
Assign new UID&#39;s to doubly occurring UID&#39;s.
Definition: UniqueIdIndexer.h:167
std::vector< ProteinIdentification > protein_identifications_
protein identifications
Definition: FeatureMap.h:533
void clearRanges()
Resets the ranges.
Definition: RangeManager.h:140
void sortByPosition()
Sort features by position. Lexicographical comparison (first RT then m/z) is done.
Definition: FeatureMap.h:310
void updateUniqueIdToIndex() const
Updates the hash map from unique id to index.
Definition: UniqueIdIndexer.h:116
A base class for random access containers for classes derived from UniqueIdInterface that adds functi...
Definition: UniqueIdIndexer.h:63
Base::iterator Iterator
Definition: FeatureMap.h:154
FeatureMap(const FeatureMap &source)
Copy constructor.
Definition: FeatureMap.h:180
An LC-MS feature.
Definition: Feature.h:66
bool operator==(const AnnotationStatistics &rhs) const
Definition: FeatureMap.h:79
std::vector< PeptideIdentification > unassigned_peptide_identifications_
peptide identifications not matched to a specific feature
Definition: FeatureMap.h:536
A base class defining a common interface for all classes having a unique id.
Definition: UniqueIdInterface.h:51
Comparator by RT position.
Definition: Peak2D.h:272
std::vector< FeatureType > Base
Definition: FeatureMap.h:153
void swapFeaturesOnly(FeatureMap &from)
Swaps the feature content (plus its range information) of this map with the content of from...
Definition: FeatureMap.h:377
std::vector< DataProcessing > data_processing_
applied data processing
Definition: FeatureMap.h:539
PositionType const & minPosition() const
Accessor to minimum position.
Definition: DIntervalBase.h:121
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
AnnotationState
state of identification, use getIDState() to query it
Definition: BaseFeature.h:69
void swap(DocumentIdentifier &from)
exchange content with from
virtual ~FeatureMap()
Destructor.
Definition: FeatureMap.h:192
DocumentIdentifier()
default constructor
void swap(UniqueIdInterface &from)
Definition: UniqueIdInterface.h:128
void sortByOverallQuality(bool reverse=false)
Sort features by ascending overall quality.
Definition: FeatureMap.h:328
UniqueIdInterface & operator=(UniqueIdInterface const &rhs)
Assignment operator - copies the unique id.
Definition: UniqueIdInterface.h:89
const String & getIdentifier() const
retrieve document identifier (e.g. an LSID)
PositionType const & maxPosition() const
Accessor to maximum position.
Definition: DIntervalBase.h:127
bool operator==(UniqueIdInterface const &rhs) const
Equality comparison operator - the unique ids must be equal (!)
Definition: UniqueIdInterface.h:102
Postcondition failed exception.
Definition: Exception.h:181
Definition: FeatureMap.h:57
A D-dimensional bounding box.
Definition: DBoundingBox.h:51
Size applyMemberFunction(Size(Type::*member_function)() const) const
The &quot;const&quot; variant.
Definition: FeatureMap.h:509
void updateRanges_(const PeakIteratorType &begin, const PeakIteratorType &end)
Updates the range using data points in the iterator range.
Definition: RangeManager.h:155
Handles the managment of a position and intensity range.
Definition: RangeManager.h:48
AnnotationStatistics & operator=(const AnnotationStatistics &rhs)
Definition: FeatureMap.h:71
bool isEmpty() const
Test if bounding box is empty.
Definition: DBoundingBox.h:192
DocumentIdentifier & operator=(const DocumentIdentifier &source)
Assignment operator.
void sortByIntensity(bool reverse=false)
Sorts the peaks according to ascending intensity.
Definition: FeatureMap.h:297
Comparator by m/z position.
Definition: Peak2D.h:298
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
std::vector< FeatureT > privvec
Definition: FeatureMap.h:122
void setUnassignedPeptideIdentifications(const std::vector< PeptideIdentification > &unassigned_peptide_identifications)
sets the unassigned peptide identifications
Definition: FeatureMap.h:440
FeatureT FeatureType
Definition: FeatureMap.h:151
AnnotationStatistics()
Definition: FeatureMap.h:61

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