| 209 | } |
| 210 | |
| 211 | void ConsensusFeature::computeMonoisotopicConsensus() |
| 212 | { |
| 213 | // for computing average rt position, minimal m/z position and intensity |
| 214 | double rt = 0.0; |
| 215 | double mz = std::numeric_limits<double>::max(); |
| 216 | double intensity = 0.0; |
| 217 | |
| 218 | // The most frequent charge state wins. Tie breaking prefers smaller charge. |
| 219 | std::map<Int, UInt> charge_occ; |
| 220 | Int charge_most_frequent = 0; |
| 221 | UInt charge_most_frequent_occ = 0; |
| 222 | |
| 223 | for (ConsensusFeature::HandleSetType::const_iterator it = handles_.begin(); it != handles_.end(); ++it) |
| 224 | { |
| 225 | rt += it->getRT(); |
| 226 | if (it->getMZ() < mz) |
| 227 | { |
| 228 | mz = it->getMZ(); |
| 229 | } |
| 230 | intensity += it->getIntensity(); |
| 231 | const Int it_charge = it->getCharge(); |
| 232 | const UInt it_charge_occ = ++charge_occ[it_charge]; |
| 233 | if (it_charge_occ > charge_most_frequent_occ) |
| 234 | { |
| 235 | charge_most_frequent_occ = it_charge_occ; |
| 236 | charge_most_frequent = it_charge; |
| 237 | } |
| 238 | else |
| 239 | { |
| 240 | if (it_charge_occ >= charge_most_frequent_occ && abs(it_charge) < abs(charge_most_frequent)) |
| 241 | { |
| 242 | charge_most_frequent = it_charge; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | // compute the position and intensity |
| 248 | setRT(rt / size()); |
| 249 | setMZ(mz); |
| 250 | setIntensity(intensity / size()); |
| 251 | setCharge(charge_most_frequent); |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | void ConsensusFeature::computeDechargeConsensus(const FeatureMap& fm, bool intensity_weighted_averaging) |
| 256 | { |