MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / filter

Method filter

src/openms/source/FILTERING/DATAREDUCTION/FeatureOverlapFilter.cpp:121–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119 }
120
121 void FeatureOverlapFilter::filter(FeatureMap& fmap,
122 std::function<bool(const Feature&, const Feature&)> FeatureComparator,
123 std::function<bool(Feature&, Feature&)> FeatureOverlapCallback,
124 bool check_overlap_at_trace_level)
125 {
126 fmap.updateRanges();
127 // Sort all features according to the comparator. After the sort, the "smallest" == best feature will be the first entry we will start processing with...
128 std::stable_sort(fmap.begin(), fmap.end(), FeatureComparator);
129
130 const auto getBox = [](const Feature* f)
131 {
132 const auto& bb = f->getConvexHull().getBoundingBox();
133 return quadtree::Box<float>(bb.minY(), bb.minX(), bb.maxY()-bb.minY(), bb.maxX()-bb.minX());
134 };
135
136 float minMZ = fmap.getMinMZ();
137 float maxMZ = fmap.getMaxMZ();
138 float minRT = fmap.getMinRT();
139 float maxRT = fmap.getMaxRT();
140
141 // build quadtree with all features
142 quadtree::Box<float> fullExp(minMZ-1, minRT-1, maxMZ-minMZ+2, maxRT-minRT+2);
143 auto quadtree = quadtree::Quadtree<Feature*, decltype(getBox)>(fullExp, getBox);
144 for (auto& f : fmap)
145 {
146 quadtree.add(&f);
147 }
148
149 // if we check for overlapping traces we need a faster lookup structure
150 FeatureBoundsMap fbm;
151 if (check_overlap_at_trace_level)
152 {
153 fbm = getFeatureBounds(fmap);
154 }
155
156 std::unordered_set<Size> removed_uids;
157 for (auto& f : fmap)
158 {
159 if (removed_uids.count(f.getUniqueId()) == 0)
160 {
161 for (auto& overlap : quadtree.query(getBox(&f)))
162 {
163 if ((overlap != &f))
164 {
165 // Because feature boundaries might be large and lead to many overlapps, we (optionally) also can check if the boundaries of traces overlap
166 bool is_true_overlap = true;
167 if (check_overlap_at_trace_level)
168 {
169 is_true_overlap = tracesOverlap(f, *overlap, fbm);
170 }
171
172 if (is_true_overlap)
173 {
174 // callback allows to e.g., transfer information from the to-be-removed feature to the representative feature
175 // if the callback returns false, overlap will not be removed (at least not because of an overlap with f)
176 if (FeatureOverlapCallback(f, *overlap))
177 {
178 removed_uids.insert(overlap->getUniqueId());

Callers 1

smoothDataMethod · 0.45

Calls 15

getFeatureBoundsFunction · 0.85
tracesOverlapFunction · 0.85
getBoundingBoxMethod · 0.80
minYMethod · 0.80
minXMethod · 0.80
maxYMethod · 0.80
maxXMethod · 0.80
getMinMZMethod · 0.80
getMaxMZMethod · 0.80
getMinRTMethod · 0.80
getMaxRTMethod · 0.80
countMethod · 0.80

Tested by

no test coverage detected