OpenMS
Loading...
Searching...
No Matches
KDTreeFeatureMaps.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: Johannes Veit $
6// $Authors: Johannes Veit $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <OpenMS/config.h>
18
19namespace OpenMS
20{
21
50class OPENMS_DLLAPI KDTreeFeatureMaps : public DefaultParamHandler
51{
52
53public:
54
57
60 DefaultParamHandler("KDTreeFeatureMaps")
61 {
62 check_defaults_ = false;
63 }
64
74 template <typename MapType>
75 KDTreeFeatureMaps(const std::vector<MapType>& maps, const Param& param) :
76 DefaultParamHandler("KDTreeFeatureMaps")
77 {
78 check_defaults_ = false;
79 setParameters(param);
80 addMaps(maps);
81 }
82
85 {
86 }
87
98 template <typename MapType>
99 void addMaps(const std::vector<MapType>& maps)
100 {
101 num_maps_ = maps.size();
102
103 for (Size i = 0; i < num_maps_; ++i)
104 {
105 const MapType& m = maps[i];
106 for (typename MapType::const_iterator it = m.begin(); it != m.end(); ++it)
107 {
108 addFeature(i, &(*it));
109 }
110 }
111 optimizeTree();
112 }
113
125 void addFeature(Size mt_map_index, const BaseFeature* feature);
126
128 const BaseFeature* feature(Size i) const;
129
131 double rt(Size i) const;
132
134 double mz(Size i) const;
135
137 float intensity(Size i) const;
138
140 Int charge(Size i) const;
141
144
146 Size size() const;
147
149 Size treeSize() const;
150
152 Size numMaps() const;
153
155 void clear();
156
159
179 void getNeighborhood(Size index, std::vector<Size>& result_indices, double rt_tol, double mz_tol, bool mz_ppm, bool include_features_from_same_map = false, double max_pairwise_log_fc = -1.0) const;
180
195 void queryRegion(double rt_low, double rt_high, double mz_low, double mz_high, std::vector<Size>& result_indices, Size ignored_map_index = std::numeric_limits<Size>::max()) const;
196
205 void applyTransformations(const std::vector<TransformationModelLowess*>& trafos);
206
207protected:
208
209 void updateMembers_() override;
210
212 std::vector<const BaseFeature*> features_;
213
215 std::vector<Size> map_index_;
216
218 std::vector<double> rt_;
219
222
225
226};
227}
228
Definition KDTree.h:1054
A basic LC-MS feature.
Definition BaseFeature.h:34
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
Pools features from multiple maps into a single 2D kd-tree on (RT, m/z) for fast range queries.
Definition KDTreeFeatureMaps.h:51
std::vector< double > rt_
(Potentially transformed) retention times, parallel to features_
Definition KDTreeFeatureMaps.h:218
~KDTreeFeatureMaps() override
Destructor (does not delete the wrapped features)
Definition KDTreeFeatureMaps.h:84
KDTreeFeatureMaps(const std::vector< MapType > &maps, const Param &param)
Construct from a list of feature maps and a parameter set.
Definition KDTreeFeatureMaps.h:75
Size numMaps() const
Number of source maps recorded in the most recent addMaps() call.
Size mapIndex(Size i) const
Index of the source map that feature i was added with.
FeatureKDTree kd_tree_
2D kd-tree on features from all input maps (queried in (RT, m/z))
Definition KDTreeFeatureMaps.h:224
std::vector< Size > map_index_
Map of origin for each feature (parallel to features_)
Definition KDTreeFeatureMaps.h:215
std::vector< const BaseFeature * > features_
Feature data (pointers owned by the caller)
Definition KDTreeFeatureMaps.h:212
Int charge(Size i) const
Charge of feature i (read through the wrapped BaseFeature)
KDTreeFeatureMaps()
Default constructor; creates an empty container with no features and zero maps.
Definition KDTreeFeatureMaps.h:59
float intensity(Size i) const
Intensity of feature i (read through the wrapped BaseFeature)
void queryRegion(double rt_low, double rt_high, double mz_low, double mz_high, std::vector< Size > &result_indices, Size ignored_map_index=std::numeric_limits< Size >::max()) const
Range query on the kd-tree: collect indices of features within the given (RT, m/z) rectangle.
void applyTransformations(const std::vector< TransformationModelLowess * > &trafos)
Apply a per-map RT transformation to the cached retention times.
double rt(Size i) const
(Possibly transformed) retention time of feature i
void getNeighborhood(Size index, std::vector< Size > &result_indices, double rt_tol, double mz_tol, bool mz_ppm, bool include_features_from_same_map=false, double max_pairwise_log_fc=-1.0) const
Collect indices of all features compatible with the feature at index.
KDTree::KDTree< 2, KDTreeFeatureNode > FeatureKDTree
2D kd-tree on (RT, m/z) holding KDTreeFeatureNode entries
Definition KDTreeFeatureMaps.h:56
void addFeature(Size mt_map_index, const BaseFeature *feature)
Insert a single feature into the kd-tree.
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
const BaseFeature * feature(Size i) const
Pointer to the feature with global index i.
void clear()
Discard all stored features and clear the kd-tree (does not delete the wrapped features)
Size size() const
Number of features stored (across all maps)
Size num_maps_
Number of source maps (set by addMaps())
Definition KDTreeFeatureMaps.h:221
void addMaps(const std::vector< MapType > &maps)
Insert all features from maps and balance the kd-tree.
Definition KDTreeFeatureMaps.h:99
double mz(Size i) const
m/z of feature i (read through the wrapped BaseFeature)
void optimizeTree()
Re-balance the kd-tree after incremental inserts.
Size treeSize() const
Number of points currently in the kd-tree.
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
Iterator begin() noexcept
Base::const_iterator const_iterator
Definition MSExperiment.h:98
Management and storage of parameters / INI files.
Definition Param.h:46
int Int
Signed integer type.
Definition Types.h:72
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