00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef OPENMS_FILTERING_DATAREDUCTION_DATAFILTERS_H
00028 #define OPENMS_FILTERING_DATAREDUCTION_DATAFILTERS_H
00029
00030 #include <OpenMS/DATASTRUCTURES/String.h>
00031 #include <OpenMS/METADATA/MetaInfoInterface.h>
00032
00033 #include <vector>
00034
00035 #include <iostream>
00036
00037 namespace OpenMS
00038 {
00039 class Feature;
00040
00046 class DataFilters
00047 {
00048 public:
00050 enum FilterType
00051 {
00052 INTENSITY,
00053 QUALITY,
00054 CHARGE,
00055 META_DATA
00056 };
00058 enum FilterOperation
00059 {
00060 GREATER_EQUAL,
00061 EQUAL,
00062 LESS_EQUAL,
00063 EXISTS
00064 };
00065
00067 struct DataFilter
00068 {
00070 DataFilter()
00071 : field(DataFilters::INTENSITY),
00072 op(DataFilters::GREATER_EQUAL),
00073 value(0.0),
00074 value_string(),
00075 meta_name(),
00076 value_is_numerical(false)
00077 {
00078 }
00080 FilterType field;
00082 FilterOperation op;
00084 DoubleReal value;
00086 String value_string;
00088 String meta_name;
00090 bool value_is_numerical;
00091
00093 String toString() const;
00094
00100 void fromString(const String& filter) throw (Exception::InvalidValue);
00101
00103 bool operator==(const DataFilter& rhs) const
00104 {
00105 return field==rhs.field && op==rhs.op && value==rhs.value;
00106 }
00108 bool operator!=(const DataFilter& rhs) const
00109 {
00110 return !operator==(rhs);
00111 }
00112
00113 };
00114
00116 UInt size() const;
00117
00119 const DataFilter& operator[](UInt index) const throw (Exception::IndexOverflow);
00120
00122 void add(const DataFilter& filter);
00123
00125 void remove(UInt index) throw (Exception::IndexOverflow);
00126
00128 void replace(UInt index, const DataFilter& filter) throw (Exception::IndexOverflow);
00129
00131 void clear();
00132
00134 template<class PeakType>
00135 bool passes(const PeakType& peak) const
00136 {
00137 DataFilters::DataFilter filter;
00138 for (UInt i = 0; i < filters_.size(); i++)
00139 {
00140 filter = filters_[i];
00141 if (filter.field==INTENSITY)
00142 {
00143 if (filter.op==GREATER_EQUAL && peak.getIntensity()<filter.value) return false;
00144 else if (filter.op==LESS_EQUAL && peak.getIntensity()>filter.value) return false;
00145 else if (filter.op==EQUAL && peak.getIntensity()!=filter.value) return false;
00146 }
00147 else if (filter.field==META_DATA)
00148 {
00149 const MetaInfoInterface& mii = static_cast<MetaInfoInterface>(peak);
00150 if(!metaPasses_(mii,filter,meta_indices_[i])) return false;
00151 }
00152 }
00153 return true;
00154 }
00155
00157 bool passes(const Feature& feature) const;
00158
00159 protected:
00161 std::vector<DataFilter> filters_;
00163 std::vector<UInt> meta_indices_;
00164
00166 inline bool metaPasses_(const MetaInfoInterface& meta_interface, const DataFilters::DataFilter& filter, UInt index) const
00167 {
00168 if (!meta_interface.metaValueExists(index)) return false;
00169 else if (filter.op!=EXISTS)
00170 {
00171 DataValue data_value = meta_interface.getMetaValue(index);
00172 if(!filter.value_is_numerical)
00173 {
00174 if(data_value.valueType() != DataValue::STRING_VALUE) return false;
00175 else
00176 {
00177
00178 if(filter.op != EQUAL) return false;
00179 else if(filter.value_string != data_value.toString()) return false;
00180 }
00181 }
00182 else
00183 {
00184 if (data_value.valueType() == DataValue::STRING_VALUE || data_value.valueType() == DataValue::EMPTY_VALUE) return false;
00185 else
00186 {
00187 if(filter.op == EQUAL && (double)data_value != filter.value) return false;
00188 else if(filter.op == LESS_EQUAL && (double)data_value > filter.value) return false;
00189 else if(filter.op == GREATER_EQUAL && (double)data_value < filter.value) return false;
00190 }
00191 }
00192 }
00193 return true;
00194 }
00195 };
00196
00197 }
00198
00199 #endif