| 253 | } |
| 254 | |
| 255 | void ConsensusFeature::computeDechargeConsensus(const FeatureMap& fm, bool intensity_weighted_averaging) |
| 256 | { |
| 257 | // for computing average position and intensity |
| 258 | double rt = 0.0; |
| 259 | double m = 0.0; |
| 260 | double intensity = 0.0; |
| 261 | |
| 262 | double proton_mass = Constants::PROTON_MASS_U; |
| 263 | |
| 264 | // intensity sum (for weighting) |
| 265 | for (ConsensusFeature::HandleSetType::const_iterator it = handles_.begin(); it != handles_.end(); ++it) |
| 266 | { |
| 267 | intensity += it->getIntensity(); |
| 268 | } |
| 269 | |
| 270 | // unweighted averaging by default |
| 271 | // TODO: add outlier removal |
| 272 | // TODO: split cluster for each channel (in FD.C) |
| 273 | double weighting_factor = 1.0 / size(); |
| 274 | |
| 275 | // RT and Mass |
| 276 | for (ConsensusFeature::HandleSetType::const_iterator it = handles_.begin(); it != handles_.end(); ++it) |
| 277 | { |
| 278 | Int q = it->getCharge(); |
| 279 | if (q == 0) |
| 280 | { |
| 281 | OPENMS_LOG_WARN << "ConsensusFeature::computeDechargeConsensus() WARNING: Feature's charge is 0! This will lead to M=0!\n"; |
| 282 | } |
| 283 | double adduct_mass; |
| 284 | Size index = fm.uniqueIdToIndex(it->getUniqueId()); |
| 285 | if (index > fm.size()) |
| 286 | { |
| 287 | throw Exception::IndexOverflow(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, index, fm.size()); |
| 288 | } |
| 289 | if (fm[index].metaValueExists("dc_charge_adduct_mass")) |
| 290 | { |
| 291 | adduct_mass = (double) fm[index].getMetaValue("dc_charge_adduct_mass"); |
| 292 | } |
| 293 | else |
| 294 | { |
| 295 | adduct_mass = q * proton_mass; |
| 296 | } |
| 297 | |
| 298 | if (intensity_weighted_averaging) |
| 299 | { |
| 300 | weighting_factor = it->getIntensity() / intensity; |
| 301 | } |
| 302 | rt += it->getRT() * weighting_factor; |
| 303 | m += (it->getMZ() * abs(q) - adduct_mass) * weighting_factor; |
| 304 | } |
| 305 | |
| 306 | // compute the average position and intensity |
| 307 | setRT(rt); |
| 308 | setMZ(m); |
| 309 | setIntensity(intensity); |
| 310 | setCharge(0); |
| 311 | return; |
| 312 | } |
no test coverage detected