Go to the documentation of this file.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
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERALGORITHMPICKEDHELPERSTRUCTS_H
00036 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERALGORITHMPICKEDHELPERSTRUCTS_H
00037
00038 #include <OpenMS/CONCEPT/Types.h>
00039 #include <OpenMS/CONCEPT/Exception.h>
00040
00041 #include <OpenMS/DATASTRUCTURES/String.h>
00042 #include <OpenMS/DATASTRUCTURES/StringList.h>
00043 #include <OpenMS/DATASTRUCTURES/ConvexHull2D.h>
00044
00045 #include <vector>
00046
00047 namespace OpenMS
00048 {
00049
00056 struct OPENMS_DLLAPI FeatureFinderAlgorithmPickedHelperStructs
00057 {
00058
00062 struct OPENMS_DLLAPI Seed
00063 {
00065 Size spectrum;
00067 Size peak;
00069 Real intensity;
00070
00072 bool operator<(const Seed & rhs) const
00073 {
00074 return intensity < rhs.intensity;
00075 }
00076
00077 };
00078
00082 template <class PeakType>
00083 struct MassTrace
00084 {
00086 const PeakType * max_peak;
00088 DoubleReal max_rt;
00089
00091 DoubleReal theoretical_int;
00092
00094 std::vector<std::pair<DoubleReal, const PeakType *> > peaks;
00095
00097 ConvexHull2D getConvexhull() const
00098 {
00099 ConvexHull2D::PointArrayType hull_points(peaks.size());
00100 for (Size i = 0; i < peaks.size(); ++i)
00101 {
00102 hull_points[i][0] = peaks[i].first;
00103 hull_points[i][1] = peaks[i].second->getMZ();
00104 }
00105 ConvexHull2D hull;
00106 hull.addPoints(hull_points);
00107 return hull;
00108 }
00109
00111 void updateMaximum()
00112 {
00113 if (peaks.empty()) return;
00114
00115 max_rt = peaks.begin()->first;
00116 max_peak = peaks.begin()->second;
00117
00118 for (Size i = 1; i < peaks.size(); ++i)
00119 {
00120 if (peaks[i].second->getIntensity() > max_peak->getIntensity())
00121 {
00122 max_rt = peaks[i].first;
00123 max_peak = peaks[i].second;
00124 }
00125 }
00126 }
00127
00129 DoubleReal getAvgMZ() const
00130 {
00131 DoubleReal sum = 0.0;
00132 DoubleReal intensities = 0.0;
00133 for (Size i = 0; i < peaks.size(); ++i)
00134 {
00135 sum += peaks[i].second->getMZ() * peaks[i].second->getIntensity();
00136 intensities += peaks[i].second->getIntensity();
00137 }
00138 return sum / intensities;
00139 }
00140
00142 bool isValid() const
00143 {
00144 return peaks.size() >= 3;
00145 }
00146
00147 };
00148
00152 template <class PeakType>
00153 struct MassTraces :
00154 public std::vector<MassTrace<PeakType> >
00155 {
00157 MassTraces() :
00158 max_trace(0)
00159 {
00160 }
00161
00163 Size getPeakCount() const
00164 {
00165 Size sum = 0;
00166 for (Size i = 0; i < this->size(); ++i)
00167 {
00168 sum += this->at(i).peaks.size();
00169 }
00170 return sum;
00171 }
00172
00174 bool isValid(DoubleReal seed_mz, DoubleReal trace_tolerance)
00175 {
00176
00177 if (this->size() < 2) return false;
00178
00179
00180 for (Size j = 0; j < this->size(); ++j)
00181 {
00182 if (std::fabs(seed_mz - this->at(j).getAvgMZ()) <= trace_tolerance)
00183 {
00184 return true;
00185 }
00186 }
00187 return false;
00188 }
00189
00195 Size getTheoreticalmaxPosition() const
00196 {
00197 if (!this->size())
00198 {
00199 throw Exception::Precondition(__FILE__, __LINE__, __PRETTY_FUNCTION__, "There must be at least one trace to determine the theoretical maximum trace!");
00200 }
00201
00202 Size max = 0;
00203 DoubleReal max_int = this->at(0).theoretical_int;
00204 for (Size i = 1; i < this->size(); ++i)
00205 {
00206 if (this->at(i).theoretical_int > max_int)
00207 {
00208 max_int = this->at(i).theoretical_int;
00209 max = i;
00210 }
00211 }
00212 return max;
00213 }
00214
00216 void updateBaseline()
00217 {
00218 if (this->size() == 0)
00219 {
00220 baseline = 0.0;
00221 return;
00222 }
00223 bool first = true;
00224 for (Size i = 0; i < this->size(); ++i)
00225 {
00226 for (Size j = 0; j < this->at(i).peaks.size(); ++j)
00227 {
00228 if (first)
00229 {
00230 baseline = this->at(i).peaks[j].second->getIntensity();
00231 first = false;
00232 }
00233 if (this->at(i).peaks[j].second->getIntensity() < baseline)
00234 {
00235 baseline = this->at(i).peaks[j].second->getIntensity();
00236 }
00237 }
00238 }
00239 }
00240
00246 std::pair<DoubleReal, DoubleReal> getRTBounds() const
00247 {
00248 if (!this->size())
00249 {
00250 throw Exception::Precondition(__FILE__, __LINE__, __PRETTY_FUNCTION__, "There must be at least one trace to determine the RT boundaries!");
00251 }
00252
00253 DoubleReal min = std::numeric_limits<DoubleReal>::max();
00254 DoubleReal max = -std::numeric_limits<DoubleReal>::max();
00255
00256 for (Size i = 0; i < this->size(); ++i)
00257 {
00258 for (Size j = 0; j < this->at(i).peaks.size(); ++j)
00259 {
00260 DoubleReal rt = this->at(i).peaks[j].first;
00261 if (rt > max) max = rt;
00262 if (rt < min) min = rt;
00263 }
00264 }
00265 return std::make_pair(min, max);
00266 }
00267
00269 Size max_trace;
00271 DoubleReal baseline;
00272 };
00273
00277 struct OPENMS_DLLAPI TheoreticalIsotopePattern
00278 {
00280 std::vector<DoubleReal> intensity;
00282 Size optional_begin;
00284 Size optional_end;
00286 DoubleReal max;
00288 Size trimmed_left;
00290 Size size() const
00291 {
00292 return intensity.size();
00293 }
00294
00295 };
00296
00300 struct OPENMS_DLLAPI IsotopePattern
00301 {
00303 std::vector<SignedSize> peak;
00305 std::vector<Size> spectrum;
00307 std::vector<DoubleReal> intensity;
00309 std::vector<DoubleReal> mz_score;
00311 std::vector<DoubleReal> theoretical_mz;
00313 TheoreticalIsotopePattern theoretical_pattern;
00314
00316 IsotopePattern(Size size) :
00317 peak(size, -1),
00318 spectrum(size),
00319 intensity(size),
00320 mz_score(size),
00321 theoretical_mz(size)
00322 {
00323 }
00324
00325 };
00326
00327 };
00328 }
00329
00330 #endif // #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERALGORITHMPICKEDHELPERSTRUCTS_H