OpenMS  2.6.0
DataFilters.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: Timo Sachsenberg $
32 // $Authors: Marc Sturm $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
39 
40 namespace OpenMS
41 {
42  class Feature;
43  class ConsensusFeature;
50  class OPENMS_DLLAPI DataFilters
51  {
52 public:
53  DataFilters();
54 
57  {
61  SIZE,
62  META_DATA
63  };
66  {
70  EXISTS
71  };
72 
74  struct OPENMS_DLLAPI DataFilter
75  {
77  DataFilter();
78 
84  double value;
91 
93  String toString() const;
94 
102  void fromString(const String & filter);
103 
105  bool operator==(const DataFilter & rhs) const;
106 
108  bool operator!=(const DataFilter & rhs) const;
109 
110  };
111 
113  Size size() const;
114 
120  const DataFilter & operator[](Size index) const;
121 
123  void add(const DataFilter & filter);
124 
130  void remove(Size index);
131 
137  void replace(Size index, const DataFilter & filter);
138 
140  void clear();
141 
143  void setActive(bool is_active);
144 
151  inline bool isActive() const
152  {
153  return is_active_;
154  }
155 
157  bool passes(const Feature& feature) const;
158 
160  bool passes(const ConsensusFeature& consensus_feature) const;
161 
163  inline bool passes(const MSSpectrum& spectrum, Size peak_index) const
164  {
165  if (!is_active_) return true;
166 
167  for (Size i = 0; i < filters_.size(); i++)
168  {
169  const DataFilters::DataFilter & filter = filters_[i];
170  if (filter.field == INTENSITY)
171  {
172  switch (filter.op)
173  {
174  case GREATER_EQUAL:
175  if (spectrum[peak_index].getIntensity() < filter.value) return false;
176 
177  break;
178 
179  case EQUAL:
180  if (spectrum[peak_index].getIntensity() != filter.value) return false;
181 
182  break;
183 
184  case LESS_EQUAL:
185  if (spectrum[peak_index].getIntensity() > filter.value) return false;
186 
187  break;
188 
189  default:
190  break;
191  }
192  }
193  else if (filter.field == META_DATA)
194  {
195  const typename MSSpectrum::FloatDataArrays & f_arrays = spectrum.getFloatDataArrays();
196  //find the right meta data array
197  SignedSize f_index = -1;
198  for (Size j = 0; j < f_arrays.size(); ++j)
199  {
200  if (f_arrays[j].getName() == filter.meta_name)
201  {
202  f_index = j;
203  break;
204  }
205  }
206  //if it is present, compare it
207  if (f_index != -1)
208  {
209  if (filter.op == EQUAL && f_arrays[f_index][peak_index] != filter.value) return false;
210  else if (filter.op == LESS_EQUAL && f_arrays[f_index][peak_index] > filter.value) return false;
211  else if (filter.op == GREATER_EQUAL && f_arrays[f_index][peak_index] < filter.value) return false;
212  }
213 
214  //if float array not found, search in integer arrays
215  const typename MSSpectrum::IntegerDataArrays & i_arrays = spectrum.getIntegerDataArrays();
216  //find the right meta data array
217  SignedSize i_index = -1;
218  for (Size j = 0; j < i_arrays.size(); ++j)
219  {
220  if (i_arrays[j].getName() == filter.meta_name)
221  {
222  i_index = j;
223  break;
224  }
225  }
226  //if it is present, compare it
227  if (i_index != -1)
228  {
229  if (filter.op == EQUAL && i_arrays[i_index][peak_index] != filter.value) return false;
230  else if (filter.op == LESS_EQUAL && i_arrays[i_index][peak_index] > filter.value) return false;
231  else if (filter.op == GREATER_EQUAL && i_arrays[i_index][peak_index] < filter.value) return false;
232  }
233 
234  //if it is not present, abort
235  if (f_index == -1 && i_index == -1) return false;
236  }
237  }
238  return true;
239  }
240 
241 protected:
243  std::vector<DataFilter> filters_;
245  std::vector<Size> meta_indices_;
246 
249 
251  bool metaPasses_(const MetaInfoInterface& meta_interface, const DataFilters::DataFilter& filter, Size index) const;
252 
253  };
254 
255 } //namespace
256 
OpenMS::DataFilters::DataFilter::value_is_numerical
bool value_is_numerical
Bool value that indicates if the specified value is numerical.
Definition: DataFilters.h:90
OpenMS::DataFilters::DataFilter::field
FilterType field
Field to filter.
Definition: DataFilters.h:80
OpenMS::DataFilters::DataFilter::value_string
String value_string
String value for comparison (for meta data)
Definition: DataFilters.h:86
OpenMS::String
A more convenient string class.
Definition: String.h:59
OpenMS::DataFilters::DataFilter
Representation of a peak/feature filter combining FilterType, FilterOperation and a value.
Definition: DataFilters.h:74
KDTree::operator!=
bool operator!=(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:824
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::DataFilters::DataFilter::op
FilterOperation op
Filter operation.
Definition: DataFilters.h:82
OpenMS::DataFilters::QUALITY
Filter the overall quality value.
Definition: DataFilters.h:59
OpenMS::DataFilters::DataFilter::value
double value
Value for comparison.
Definition: DataFilters.h:84
OpenMS::DataFilters::is_active_
bool is_active_
Determines if the filters are activated.
Definition: DataFilters.h:248
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::DataFilters::FilterType
FilterType
Information to filter.
Definition: DataFilters.h:56
OpenMS::DataFilters::INTENSITY
Filter the intensity value.
Definition: DataFilters.h:58
OpenMS::DataFilters::FilterOperation
FilterOperation
Filter operation.
Definition: DataFilters.h:65
OpenMS::MetaInfoInterface
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:60
OpenMS::DataFilters::passes
bool passes(const MSSpectrum &spectrum, Size peak_index) const
Returns if the peak fulfills the current filter criteria.
Definition: DataFilters.h:163
OpenMS::ConsensusFeature
A consensus feature spanning multiple LC-MS/MS experiments.
Definition: ConsensusFeature.h:69
OpenMS::MSSpectrum::IntegerDataArrays
std::vector< IntegerDataArray > IntegerDataArrays
Definition: MSSpectrum.h:120
OpenMS::DataFilters::EQUAL
Equal to the value.
Definition: DataFilters.h:68
OpenMS::MSSpectrum::getFloatDataArrays
const FloatDataArrays & getFloatDataArrays() const
Returns a const reference to the float meta data arrays.
OpenMS::MSSpectrum::FloatDataArrays
std::vector< FloatDataArray > FloatDataArrays
Definition: MSSpectrum.h:114
OpenMS::DataFilters::DataFilter::meta_name
String meta_name
Name of the considered meta information.
Definition: DataFilters.h:88
OpenMS::StringConversions::toString
String toString(const T &i)
fallback template for general purpose using Boost::Karma; more specializations below
Definition: StringUtils.h:127
OpenMS::SignedSize
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
OpenMS::DataFilters
DataFilter array providing some convenience functions.
Definition: DataFilters.h:50
OpenMS::Internal::operator==
bool operator==(const IDBoostGraph::ProteinGroup &lhs, const IDBoostGraph::ProteinGroup &rhs)
OpenMS::Feature
An LC-MS feature.
Definition: Feature.h:70
String.h
OpenMS::DataFilters::isActive
bool isActive() const
Returns if the filters are enabled.
Definition: DataFilters.h:151
OpenMS::DataFilters::GREATER_EQUAL
Greater than the value or equal to the value.
Definition: DataFilters.h:67
OpenMS::DataFilters::CHARGE
Filter the charge value.
Definition: DataFilters.h:60
OpenMS::DataFilters::SIZE
Filter the number of subordinates/elements.
Definition: DataFilters.h:61
OpenMS::MSSpectrum::getIntegerDataArrays
const IntegerDataArrays & getIntegerDataArrays() const
Returns a const reference to the integer meta data arrays.
OpenMS::DataFilters::meta_indices_
std::vector< Size > meta_indices_
Vector of meta indices acting as index cache.
Definition: DataFilters.h:245
OpenMS::DataFilters::filters_
std::vector< DataFilter > filters_
Array of DataFilters.
Definition: DataFilters.h:243
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
OpenMS::DataFilters::LESS_EQUAL
Less than the value or equal to the value.
Definition: DataFilters.h:69
MSSpectrum.h