OpenMS
FeatureGroupingAlgorithm.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: Marc Sturm, Clemens Groepl, Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
14 
15 namespace OpenMS
16 {
17 
23  class OPENMS_DLLAPI FeatureGroupingAlgorithm :
24  public DefaultParamHandler
25  {
26 public:
29 
32 
34  virtual void group(const std::vector<FeatureMap > & maps, ConsensusMap & out) = 0;
35 
39  virtual void group(const std::vector<ConsensusMap> & maps, ConsensusMap & out);
40 
42  void transferSubelements(const std::vector<ConsensusMap> & maps, ConsensusMap & out) const;
43 
45  static void registerChildren();
46 
47 protected:
48 
51  template<class MapType>
52  void postprocess_(const std::vector<MapType>& maps, ConsensusMap& out)
53  {
54  // add protein IDs and unassigned peptide IDs to the result map here,
55  // to keep the same order as the input maps (useful for output later):
56  auto& newIDs = out.getUnassignedPeptideIdentifications();
57  Size map_idx = 0;
58 
59  for (typename std::vector<MapType>::const_iterator map_it = maps.begin();
60  map_it != maps.end(); ++map_it)
61  {
62  // add protein identifications to result map:
63  out.getProteinIdentifications().insert(
64  out.getProteinIdentifications().end(),
65  map_it->getProteinIdentifications().begin(),
66  map_it->getProteinIdentifications().end());
67 
68  // assign the map_index to unassigned PepIDs as well.
69  // for the assigned ones, this has to be done in the subclass.
70  for (const PeptideIdentification& pepID : map_it->getUnassignedPeptideIdentifications())
71  {
72  auto newPepID = pepID;
73  // Note: during linking of _consensus_Maps we have the problem that old identifications
74  // should already have a map_index associated. Since we group the consensusFeatures only anyway
75  // (without keeping the subfeatures) the method for now is to "re"-index based on the input file/map index.
76  // Subfeatures have to be transferred in postprocessing if required
77  // (see FeatureGroupingAlgorithm::transferSubelements as used in the TOPP tools, i.e. FeatureLinkerBase),
78  // which also takes care of a re-re-indexing if the old map_index of the IDs was saved.
79  newPepID.setMetaValue("map_index", map_idx);
80  newIDs.push_back(newPepID);
81  }
82  map_idx++;
83  }
84 
85  // canonical ordering for checking the results:
86  out.sortByQuality();
87  out.sortByMaps();
88  out.sortBySize();
89  }
90 private:
95 
96 
97 
98  };
99 
100 } // namespace OpenMS
101 
A container for consensus elements.
Definition: ConsensusMap.h:66
void sortByMaps()
Sorts with respect to the sets of maps covered by the consensus features (lexicographically).
void sortBySize()
Sorts with respect to the size (number of elements)
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 sortByQuality(bool reverse=false)
Sorts the peaks according to ascending quality.
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
Base class for all feature grouping algorithms.
Definition: FeatureGroupingAlgorithm.h:25
void transferSubelements(const std::vector< ConsensusMap > &maps, ConsensusMap &out) const
Transfers subelements (grouped features) from input consensus maps to the result consensus map.
FeatureGroupingAlgorithm()
Default constructor.
static void registerChildren()
Register all derived classes in this method.
virtual void group(const std::vector< ConsensusMap > &maps, ConsensusMap &out)
FeatureGroupingAlgorithm & operator=(const FeatureGroupingAlgorithm &)
Assignment operator is not implemented -> private.
~FeatureGroupingAlgorithm() override
Destructor.
void postprocess_(const std::vector< MapType > &maps, ConsensusMap &out)
Definition: FeatureGroupingAlgorithm.h:52
virtual void group(const std::vector< FeatureMap > &maps, ConsensusMap &out)=0
Applies the algorithm. The features in the input maps are grouped and the output is written to the co...
FeatureGroupingAlgorithm(const FeatureGroupingAlgorithm &)
Copy constructor is not implemented -> private.
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:39
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22