Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
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-2017.
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 #ifndef OPENMS_FILTERING_DATAREDUCTION_DATAFILTERS_H
36 #define OPENMS_FILTERING_DATAREDUCTION_DATAFILTERS_H
37 
40 
41 namespace OpenMS
42 {
43  class Feature;
44  class ConsensusFeature;
51  class OPENMS_DLLAPI DataFilters
52  {
53 public:
54  DataFilters();
55 
58  {
62  SIZE,
63  META_DATA
64  };
67  {
71  EXISTS
72  };
73 
75  struct OPENMS_DLLAPI DataFilter
76  {
78  DataFilter();
79 
85  double value;
92 
94  String toString() const;
95 
103  void fromString(const String & filter);
104 
106  bool operator==(const DataFilter & rhs) const;
107 
109  bool operator!=(const DataFilter & rhs) const;
110 
111  };
112 
114  Size size() const;
115 
121  const DataFilter & operator[](Size index) const;
122 
124  void add(const DataFilter & filter);
125 
131  void remove(Size index);
132 
138  void replace(Size index, const DataFilter & filter);
139 
141  void clear();
142 
144  void setActive(bool is_active);
145 
152  inline bool isActive() const
153  {
154  return is_active_;
155  }
156 
158  bool passes(const Feature & feature) const;
159 
161  bool passes(const ConsensusFeature & consensus_feature) const;
162 
164  inline bool passes(const MSSpectrum & spectrum, Size peak_index) const
165  {
166  if (!is_active_) return true;
167 
168  for (Size i = 0; i < filters_.size(); i++)
169  {
170  const DataFilters::DataFilter & filter = filters_[i];
171  if (filter.field == INTENSITY)
172  {
173  switch (filter.op)
174  {
175  case GREATER_EQUAL:
176  if (spectrum[peak_index].getIntensity() < filter.value) return false;
177 
178  break;
179 
180  case EQUAL:
181  if (spectrum[peak_index].getIntensity() != filter.value) return false;
182 
183  break;
184 
185  case LESS_EQUAL:
186  if (spectrum[peak_index].getIntensity() > filter.value) return false;
187 
188  break;
189 
190  default:
191  break;
192  }
193  }
194  else if (filter.field == META_DATA)
195  {
196  const typename MSSpectrum::FloatDataArrays & f_arrays = spectrum.getFloatDataArrays();
197  //find the right meta data array
198  SignedSize f_index = -1;
199  for (Size j = 0; j < f_arrays.size(); ++j)
200  {
201  if (f_arrays[j].getName() == filter.meta_name)
202  {
203  f_index = j;
204  break;
205  }
206  }
207  //if it is present, compare it
208  if (f_index != -1)
209  {
210  if (filter.op == EQUAL && f_arrays[f_index][peak_index] != filter.value) return false;
211  else if (filter.op == LESS_EQUAL && f_arrays[f_index][peak_index] > filter.value) return false;
212  else if (filter.op == GREATER_EQUAL && f_arrays[f_index][peak_index] < filter.value) return false;
213  }
214 
215  //if float array not found, search in integer arrays
216  const typename MSSpectrum::IntegerDataArrays & i_arrays = spectrum.getIntegerDataArrays();
217  //find the right meta data array
218  SignedSize i_index = -1;
219  for (Size j = 0; j < i_arrays.size(); ++j)
220  {
221  if (i_arrays[j].getName() == filter.meta_name)
222  {
223  i_index = j;
224  break;
225  }
226  }
227  //if it is present, compare it
228  if (i_index != -1)
229  {
230  if (filter.op == EQUAL && i_arrays[i_index][peak_index] != filter.value) return false;
231  else if (filter.op == LESS_EQUAL && i_arrays[i_index][peak_index] > filter.value) return false;
232  else if (filter.op == GREATER_EQUAL && i_arrays[i_index][peak_index] < filter.value) return false;
233  }
234 
235  //if it is not present, abort
236  if (f_index == -1 && i_index == -1) return false;
237  }
238  }
239  return true;
240  }
241 
242 protected:
244  std::vector<DataFilter> filters_;
246  std::vector<Size> meta_indices_;
247 
250 
252  inline bool metaPasses_(const MetaInfoInterface & meta_interface, const DataFilters::DataFilter & filter, Size index) const
253  {
254  if (!meta_interface.metaValueExists((UInt)index)) return false;
255  else if (filter.op != EXISTS)
256  {
257  const DataValue & data_value = meta_interface.getMetaValue((UInt)index);
258  if (!filter.value_is_numerical)
259  {
260  if (data_value.valueType() != DataValue::STRING_VALUE) return false;
261  else
262  {
263  // for string values, equality is the only valid operation (besides "exists", see above)
264  if (filter.op != EQUAL) return false;
265  else if (filter.value_string != data_value.toString()) return false;
266  }
267  }
268  else // value_is_numerical
269  {
270  if (data_value.valueType() == DataValue::STRING_VALUE || data_value.valueType() == DataValue::EMPTY_VALUE) return false;
271  else
272  {
273  if (filter.op == EQUAL && (double)data_value != filter.value) return false;
274  else if (filter.op == LESS_EQUAL && (double)data_value > filter.value) return false;
275  else if (filter.op == GREATER_EQUAL && (double)data_value < filter.value) return false;
276  }
277  }
278  }
279  return true;
280  }
281 
282  };
283 
284 } //namespace
285 
286 #endif
Filter the intensity value.
Definition: DataFilters.h:59
bool isActive() const
Returns if the filters are enabled.
Definition: DataFilters.h:152
A more convenient string class.
Definition: String.h:57
FilterOperation
Filter operation.
Definition: DataFilters.h:66
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:135
DataType valueType() const
returns the type of value stored
Definition: DataValue.h:351
std::vector< Size > meta_indices_
Vector of meta indices acting as index cache.
Definition: DataFilters.h:246
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
const FloatDataArrays & getFloatDataArrays() const
Returns a const reference to the float meta data arrays.
const DataValue & getMetaValue(const String &name) const
Returns the value corresponding to a string (or DataValue::EMPTY if not found)
String toString() const
Conversion to String.
std::vector< FloatDataArray > FloatDataArrays
Definition: MSSpectrum.h:90
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:57
FilterType
Information to filter.
Definition: DataFilters.h:57
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
Representation of a peak/feature filter combining FilterType, FilterOperation and a value...
Definition: DataFilters.h:75
Equal to the value.
Definition: DataFilters.h:69
FilterType field
Field to filter.
Definition: DataFilters.h:81
bool metaValueExists(const String &name) const
Returns whether an entry with the given name exists.
bool passes(const MSSpectrum &spectrum, Size peak_index) const
Returns if the peak fulfills the current filter criteria.
Definition: DataFilters.h:164
double value
Value for comparison.
Definition: DataFilters.h:85
std::vector< DataFilter > filters_
Array of DataFilters.
Definition: DataFilters.h:244
string value
Definition: DataValue.h:68
An LC-MS feature.
Definition: Feature.h:70
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:56
Filter the charge value.
Definition: DataFilters.h:61
std::vector< IntegerDataArray > IntegerDataArrays
Definition: MSSpectrum.h:96
String value_string
String value for comparison (for meta data)
Definition: DataFilters.h:87
FilterOperation op
Filter operation.
Definition: DataFilters.h:83
bool metaPasses_(const MetaInfoInterface &meta_interface, const DataFilters::DataFilter &filter, Size index) const
Returns if the meta value at index of meta_interface (a peak or feature) passes the filter...
Definition: DataFilters.h:252
String meta_name
Name of the considered meta information.
Definition: DataFilters.h:89
bool operator!=(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:824
Filter the overall quality value.
Definition: DataFilters.h:60
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
DataFilter array providing some convenience functions.
Definition: DataFilters.h:51
String toString(T i)
toString functions (single argument)
Definition: StringUtils.h:69
Greater than the value or equal to the value.
Definition: DataFilters.h:68
bool value_is_numerical
Bool value that indicates if the specified value is numerical.
Definition: DataFilters.h:91
bool is_active_
Determines if the filters are activated.
Definition: DataFilters.h:249
Less than the value or equal to the value.
Definition: DataFilters.h:70
A 2-dimensional consensus feature.
Definition: ConsensusFeature.h:65
const IntegerDataArrays & getIntegerDataArrays() const
Returns a const reference to the integer meta data arrays.
empty value
Definition: DataValue.h:74
Filter the number of subordinates/elements.
Definition: DataFilters.h:62

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:21:59 using doxygen 1.8.13