OpenMS
Loading...
Searching...
No Matches
FeatureGroupingAlgorithm.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- 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#include <algorithm>
16
17namespace OpenMS
18{
19
25 class OPENMS_DLLAPI FeatureGroupingAlgorithm :
27 {
28public:
31
34
36 virtual void group(const std::vector<FeatureMap > & maps, ConsensusMap & out) = 0;
37
41 virtual void group(const std::vector<ConsensusMap> & maps, ConsensusMap & out);
42
44 void transferSubelements(const std::vector<ConsensusMap> & maps, ConsensusMap & out) const;
45
46
47protected:
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 // Position first, so the order is independent of the features' (random) unique ids;
86 // size/maps/quality only break exact-position ties.
87 std::stable_sort(out.begin(), out.end(),
88 [](const ConsensusFeature& a, const ConsensusFeature& b)
89 {
90 if (ConsensusFeature::PositionLess()(a, b)) { return true; } // asc
91 if (ConsensusFeature::PositionLess()(b, a)) { return false; }
92 if (ConsensusFeature::SizeLess()(b, a)) { return true; } // desc
93 if (ConsensusFeature::SizeLess()(a, b)) { return false; }
94 if (ConsensusFeature::MapsLess()(a, b)) { return true; } // asc
95 if (ConsensusFeature::MapsLess()(b, a)) { return false; }
96 if (ConsensusFeature::QualityLess()(a, b)) { return true; } // asc
97 if (ConsensusFeature::QualityLess()(b, a)) { return false; }
98 return false;
99 });
100 }
101private:
106
107
108
109 };
110
111} // namespace OpenMS
112
A consensus feature spanning multiple LC-MS/MS experiments.
Definition ConsensusFeature.h:45
A container for consensus elements.
Definition ConsensusMap.h:67
const PeptideIdentificationList & getUnassignedPeptideIdentifications() const
non-mutable access to the unassigned peptide identifications
const std::vector< ProteinIdentification > & getProteinIdentifications() const
non-mutable access to the protein identifications
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
iterator begin() noexcept
Definition ExposedVector.h:104
iterator end() noexcept
Definition ExposedVector.h:108
Base class for all feature grouping algorithms.
Definition FeatureGroupingAlgorithm.h:27
void transferSubelements(const std::vector< ConsensusMap > &maps, ConsensusMap &out) const
Transfers subelements (grouped features) from input consensus maps to the result consensus map.
FeatureGroupingAlgorithm & operator=(const FeatureGroupingAlgorithm &)
Assignment operator is not implemented -> private.
FeatureGroupingAlgorithm()
Default constructor.
virtual void group(const std::vector< ConsensusMap > &maps, ConsensusMap &out)
~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 set of candidates (SpectrumMatches) identified for a single precursor spectrum.
Definition PeptideIdentification.h:66
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Compare by quality.
Definition BaseFeature.h:106
Compare by the sets of consensus elements (lexicographically)
Definition ConsensusFeature.h:83
Compare by size(), the number of consensus elements.
Definition ConsensusFeature.h:58
Comparator by position. Lexicographical comparison (first RT then m/z) is done.
Definition Peak2D.h:290