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-2015.
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: Stephan Aiche $
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  template <class PeakType>
165  inline bool passes(const MSSpectrum<PeakType> & spectrum, Size peak_index) const
166  {
167  if (!is_active_) return true;
168 
169  for (Size i = 0; i < filters_.size(); i++)
170  {
171  const DataFilters::DataFilter & filter = filters_[i];
172  if (filter.field == INTENSITY)
173  {
174  switch (filter.op)
175  {
176  case GREATER_EQUAL:
177  if (spectrum[peak_index].getIntensity() < filter.value) return false;
178 
179  break;
180 
181  case EQUAL:
182  if (spectrum[peak_index].getIntensity() != filter.value) return false;
183 
184  break;
185 
186  case LESS_EQUAL:
187  if (spectrum[peak_index].getIntensity() > filter.value) return false;
188 
189  break;
190 
191  default:
192  break;
193  }
194  }
195  else if (filter.field == META_DATA)
196  {
197  const typename MSSpectrum<PeakType>::FloatDataArrays & f_arrays = spectrum.getFloatDataArrays();
198  //find the right meta data array
199  SignedSize f_index = -1;
200  for (Size j = 0; j < f_arrays.size(); ++j)
201  {
202  if (f_arrays[j].getName() == filter.meta_name)
203  {
204  f_index = j;
205  break;
206  }
207  }
208  //if it is present, compare it
209  if (f_index != -1)
210  {
211  if (filter.op == EQUAL && f_arrays[f_index][peak_index] != filter.value) return false;
212  else if (filter.op == LESS_EQUAL && f_arrays[f_index][peak_index] > filter.value) return false;
213  else if (filter.op == GREATER_EQUAL && f_arrays[f_index][peak_index] < filter.value) return false;
214  }
215 
216  //if float array not found, search in integer arrays
217  const typename MSSpectrum<PeakType>::IntegerDataArrays & i_arrays = spectrum.getIntegerDataArrays();
218  //find the right meta data array
219  SignedSize i_index = -1;
220  for (Size j = 0; j < i_arrays.size(); ++j)
221  {
222  if (i_arrays[j].getName() == filter.meta_name)
223  {
224  i_index = j;
225  break;
226  }
227  }
228  //if it is present, compare it
229  if (i_index != -1)
230  {
231  if (filter.op == EQUAL && i_arrays[i_index][peak_index] != filter.value) return false;
232  else if (filter.op == LESS_EQUAL && i_arrays[i_index][peak_index] > filter.value) return false;
233  else if (filter.op == GREATER_EQUAL && i_arrays[i_index][peak_index] < filter.value) return false;
234  }
235 
236  //if it is not present, abort
237  if (f_index == -1 && i_index == -1) return false;
238  }
239  }
240  return true;
241  }
242 
243 protected:
245  std::vector<DataFilter> filters_;
247  std::vector<Size> meta_indices_;
248 
251 
253  inline bool metaPasses_(const MetaInfoInterface & meta_interface, const DataFilters::DataFilter & filter, Size index) const
254  {
255  if (!meta_interface.metaValueExists((UInt)index)) return false;
256  else if (filter.op != EXISTS)
257  {
258  const DataValue & data_value = meta_interface.getMetaValue((UInt)index);
259  if (!filter.value_is_numerical)
260  {
261  if (data_value.valueType() != DataValue::STRING_VALUE) return false;
262  else
263  {
264  // for string values, equality is the only valid operation (besides "exists", see above)
265  if (filter.op != EQUAL) return false;
266  else if (filter.value_string != data_value.toString()) return false;
267  }
268  }
269  else // value_is_numerical
270  {
271  if (data_value.valueType() == DataValue::STRING_VALUE || data_value.valueType() == DataValue::EMPTY_VALUE) return false;
272  else
273  {
274  if (filter.op == EQUAL && (double)data_value != filter.value) return false;
275  else if (filter.op == LESS_EQUAL && (double)data_value > filter.value) return false;
276  else if (filter.op == GREATER_EQUAL && (double)data_value < filter.value) return false;
277  }
278  }
279  }
280  return true;
281  }
282 
283  };
284 
285 } //namespace
286 
287 #endif
const DataValue & getMetaValue(const String &name) const
returns the value corresponding to a string
bool passes(const MSSpectrum< PeakType > &spectrum, Size peak_index) const
Returns if the peak fulfills the current filter criteria.
Definition: DataFilters.h:165
Filter the intensity value.
Definition: DataFilters.h:59
A more convenient string class.
Definition: String.h:57
FilterOperation
Filter operation.
Definition: DataFilters.h:66
String toString() const
Conversion to String.
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:128
std::vector< Size > meta_indices_
Vector of meta indices acting as index cache.
Definition: DataFilters.h:247
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
const IntegerDataArrays & getIntegerDataArrays() const
Returns a const reference to the integer meta data arrays.
Definition: MSSpectrum.h:322
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
Representation of a peak/feature filter combining FilterType, FilterOperation and a value...
Definition: DataFilters.h:75
Equal to the value.
Definition: DataFilters.h:69
DataType valueType() const
returns the type of value stored
Definition: DataValue.h:351
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:253
FilterType field
Field to filter.
Definition: DataFilters.h:81
double value
Value for comparison.
Definition: DataFilters.h:85
std::vector< DataFilter > filters_
Array of DataFilters.
Definition: DataFilters.h:245
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
bool isActive() const
Returns if the filters are enabled.
Definition: DataFilters.h:152
String value_string
String value for comparison (for meta data)
Definition: DataFilters.h:87
FilterOperation op
Filter operation.
Definition: DataFilters.h:83
String meta_name
Name of the considered meta information.
Definition: DataFilters.h:89
Filter the overall quality value.
Definition: DataFilters.h:60
DataFilter array providing some convenience functions.
Definition: DataFilters.h:51
const FloatDataArrays & getFloatDataArrays() const
Returns a const reference to the float meta data arrays.
Definition: MSSpectrum.h:298
String toString(T i)
toString functions (single argument)
Definition: StringUtils.h:68
bool metaValueExists(const String &name) const
returns if this MetaInfo is set
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:250
Less than the value or equal to the value.
Definition: DataFilters.h:70
A 2-dimensional consensus feature.
Definition: ConsensusFeature.h:65
empty value
Definition: DataValue.h:74
Filter the number of subordinates/elements.
Definition: DataFilters.h:62

OpenMS / TOPP release 2.0.0 Documentation generated on Wed Mar 30 2016 12:49:22 using doxygen 1.8.11