OpenMS
KDTreeFeatureMaps.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- 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>
13 #include <OpenMS/KERNEL/Feature.h>
18 
19 namespace OpenMS
20 {
21 
23 class OPENMS_DLLAPI KDTreeFeatureMaps : public DefaultParamHandler
24 {
25 
26 public:
27 
30 
33  DefaultParamHandler("KDTreeFeatureMaps")
34  {
35  check_defaults_ = false;
36  }
37 
39  template <typename MapType>
40  KDTreeFeatureMaps(const std::vector<MapType>& maps, const Param& param) :
41  DefaultParamHandler("KDTreeFeatureMaps")
42  {
43  check_defaults_ = false;
44  setParameters(param);
45  addMaps(maps);
46  }
47 
49  ~KDTreeFeatureMaps() override
50  {
51  }
52 
54  template <typename MapType>
55  void addMaps(const std::vector<MapType>& maps)
56  {
57  num_maps_ = maps.size();
58 
59  for (Size i = 0; i < num_maps_; ++i)
60  {
61  const MapType& m = maps[i];
62  for (typename MapType::const_iterator it = m.begin(); it != m.end(); ++it)
63  {
64  addFeature(i, &(*it));
65  }
66  }
67  optimizeTree();
68  }
69 
71  void addFeature(Size mt_map_index, const BaseFeature* feature);
72 
74  const BaseFeature* feature(Size i) const;
75 
77  double rt(Size i) const;
78 
80  double mz(Size i) const;
81 
83  float intensity(Size i) const;
84 
86  Int charge(Size i) const;
87 
89  Size mapIndex(Size i) const;
90 
92  Size size() const;
93 
95  Size treeSize() const;
96 
98  Size numMaps() const;
99 
101  void clear();
102 
104  void optimizeTree();
105 
107  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;
108 
110  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;
111 
113  void applyTransformations(const std::vector<TransformationModelLowess*>& trafos);
114 
115 protected:
116 
117  void updateMembers_() override;
118 
120  std::vector<const BaseFeature*> features_;
121 
123  std::vector<Size> map_index_;
124 
126  std::vector<double> rt_;
127 
130 
133 
134 };
135 }
136 
A basic LC-MS feature.
Definition: BaseFeature.h:33
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
Stores a set of features, together with a 2D tree for fast search.
Definition: KDTreeFeatureMaps.h:24
std::vector< double > rt_
(Potentially transformed) retention times
Definition: KDTreeFeatureMaps.h:126
~KDTreeFeatureMaps() override
Destructor.
Definition: KDTreeFeatureMaps.h:49
KDTreeFeatureMaps(const std::vector< MapType > &maps, const Param &param)
Constructor.
Definition: KDTreeFeatureMaps.h:40
Size numMaps() const
Number of maps.
Size mapIndex(Size i) const
Map index.
FeatureKDTree kd_tree_
2D tree on features from all input maps.
Definition: KDTreeFeatureMaps.h:132
std::vector< Size > map_index_
Map indices.
Definition: KDTreeFeatureMaps.h:123
std::vector< const BaseFeature * > features_
Feature data.
Definition: KDTreeFeatureMaps.h:120
Int charge(Size i) const
Charge.
KDTreeFeatureMaps()
Default constructor.
Definition: KDTreeFeatureMaps.h:32
float intensity(Size i) const
Intensity.
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
Fill result with indices of all features within the specified boundaries.
void applyTransformations(const std::vector< TransformationModelLowess * > &trafos)
Apply RT transformations.
double rt(Size i) const
RT.
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
Fill result with indices of all features compatible (wrt. RT, m/z, map index) to the feature with ind...
KDTree::KDTree< 2, KDTreeFeatureNode > FeatureKDTree
2D tree on features
Definition: KDTreeFeatureMaps.h:29
void addFeature(Size mt_map_index, const BaseFeature *feature)
Add feature.
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
void clear()
Clear all data.
Size size() const
Number of features stored.
Size num_maps_
Number of maps.
Definition: KDTreeFeatureMaps.h:129
void addMaps(const std::vector< MapType > &maps)
Add maps and balance kd-tree.
Definition: KDTreeFeatureMaps.h:55
double mz(Size i) const
m/z
void optimizeTree()
Optimize the kD tree.
Size treeSize() const
Number of points in the tree.
const BaseFeature * feature(Size i) const
Return pointer to feature i.
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:45
Iterator begin() noexcept
Definition: MSExperiment.h:155
Iterator end()
Definition: MSExperiment.h:170
Base::const_iterator const_iterator
Definition: MSExperiment.h:90
Management and storage of parameters / INI files.
Definition: Param.h:44
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