OpenMS  2.6.0
KDTreeFeatureMaps.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-2020.
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: Johannes Veit $
32 // $Authors: Johannes Veit $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/config.h>
39 #include <OpenMS/KERNEL/Feature.h>
44 
45 namespace OpenMS
46 {
47 
49 class OPENMS_DLLAPI KDTreeFeatureMaps : public DefaultParamHandler
50 {
51 
52 public:
53 
56 
59  DefaultParamHandler("KDTreeFeatureMaps")
60  {
61  check_defaults_ = false;
62  }
63 
65  template <typename MapType>
66  KDTreeFeatureMaps(const std::vector<MapType>& maps, const Param& param) :
67  DefaultParamHandler("KDTreeFeatureMaps")
68  {
69  check_defaults_ = false;
70  setParameters(param);
71  addMaps(maps);
72  }
73 
75  ~KDTreeFeatureMaps() override
76  {
77  }
78 
80  template <typename MapType>
81  void addMaps(const std::vector<MapType>& maps)
82  {
83  num_maps_ = maps.size();
84 
85  for (Size i = 0; i < num_maps_; ++i)
86  {
87  const MapType& m = maps[i];
88  for (typename MapType::const_iterator it = m.begin(); it != m.end(); ++it)
89  {
90  addFeature(i, &(*it));
91  }
92  }
93  optimizeTree();
94  }
95 
97  void addFeature(Size mt_map_index, const BaseFeature* feature);
98 
100  const BaseFeature* feature(Size i) const;
101 
103  double rt(Size i) const;
104 
106  double mz(Size i) const;
107 
109  float intensity(Size i) const;
110 
112  Int charge(Size i) const;
113 
115  Size mapIndex(Size i) const;
116 
118  Size size() const;
119 
121  Size treeSize() const;
122 
124  Size numMaps() const;
125 
127  void clear();
128 
130  void optimizeTree();
131 
133  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;
134 
136  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;
137 
139  void applyTransformations(const std::vector<TransformationModelLowess*>& trafos);
140 
141 protected:
142 
143  void updateMembers_() override;
144 
146  std::vector<const BaseFeature*> features_;
147 
149  std::vector<Size> map_index_;
150 
152  std::vector<double> rt_;
153 
156 
159 
160 };
161 }
162 
DefaultParamHandler.h
KDTree::KDTree< 2, KDTreeFeatureNode >
KDTree.h
OpenMS::MSExperiment::begin
Iterator begin()
Definition: MSExperiment.h:157
OpenMS::BaseFeature
A basic LC-MS feature.
Definition: BaseFeature.h:56
Feature.h
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
TransformationModelLowess.h
OpenMS::MSExperiment::const_iterator
Base::const_iterator const_iterator
Definition: MSExperiment.h:125
OpenMS::KDTreeFeatureMaps::KDTreeFeatureMaps
KDTreeFeatureMaps(const std::vector< MapType > &maps, const Param &param)
Constructor.
Definition: KDTreeFeatureMaps.h:66
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::KDTreeFeatureMaps::rt_
std::vector< double > rt_
(Potentially transformed) retention times
Definition: KDTreeFeatureMaps.h:152
OpenMS::KDTreeFeatureMaps::addMaps
void addMaps(const std::vector< MapType > &maps)
Add maps and balance kd-tree.
Definition: KDTreeFeatureMaps.h:81
int
OpenMS::KDTreeFeatureMaps::map_index_
std::vector< Size > map_index_
Map indices.
Definition: KDTreeFeatureMaps.h:149
KDTreeFeatureNode.h
OpenMS::KDTreeFeatureMaps::features_
std::vector< const BaseFeature * > features_
Feature data.
Definition: KDTreeFeatureMaps.h:146
OpenMS::KDTreeFeatureMaps::kd_tree_
FeatureKDTree kd_tree_
2D tree on features from all input maps.
Definition: KDTreeFeatureMaps.h:158
OpenMS::MSExperiment::end
Iterator end()
Definition: MSExperiment.h:167
OpenMS::KDTreeFeatureMaps::FeatureKDTree
KDTree::KDTree< 2, KDTreeFeatureNode > FeatureKDTree
2D tree on features
Definition: KDTreeFeatureMaps.h:55
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:73
OpenMS::KDTreeFeatureMaps::num_maps_
Size num_maps_
Number of maps.
Definition: KDTreeFeatureMaps.h:155
OpenMS::KDTreeFeatureMaps::~KDTreeFeatureMaps
~KDTreeFeatureMaps() override
Destructor.
Definition: KDTreeFeatureMaps.h:75
OpenMS::KDTreeFeatureMaps::KDTreeFeatureMaps
KDTreeFeatureMaps()
Default constructor.
Definition: KDTreeFeatureMaps.h:58
StandardTypes.h
OpenMS::KDTreeFeatureMaps
Stores a set of features, together with a 2D tree for fast search.
Definition: KDTreeFeatureMaps.h:49