| 168 | } |
| 169 | |
| 170 | void ConsensusFeature::computeConsensus() |
| 171 | { |
| 172 | // for computing average position and intensity |
| 173 | double rt = 0.0; |
| 174 | double mz = 0.0; |
| 175 | double intensity = 0.0; |
| 176 | |
| 177 | // The most frequent charge state wins. Tie breaking prefers smaller charge. |
| 178 | std::map<Int, UInt> charge_occ; |
| 179 | Int charge_most_frequent = 0; |
| 180 | UInt charge_most_frequent_occ = 0; |
| 181 | |
| 182 | for (ConsensusFeature::HandleSetType::const_iterator it = handles_.begin(); it != handles_.end(); ++it) |
| 183 | { |
| 184 | rt += it->getRT(); |
| 185 | mz += it->getMZ(); |
| 186 | intensity += it->getIntensity(); |
| 187 | const Int it_charge = it->getCharge(); |
| 188 | const UInt it_charge_occ = ++charge_occ[it_charge]; |
| 189 | if (it_charge_occ > charge_most_frequent_occ) |
| 190 | { |
| 191 | charge_most_frequent_occ = it_charge_occ; |
| 192 | charge_most_frequent = it_charge; |
| 193 | } |
| 194 | else |
| 195 | { |
| 196 | if (it_charge_occ >= charge_most_frequent_occ && abs(it_charge) < abs(charge_most_frequent)) |
| 197 | { |
| 198 | charge_most_frequent = it_charge; |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | // compute the average position and intensity |
| 204 | setRT(rt / size()); |
| 205 | setMZ(mz / size()); |
| 206 | setIntensity(intensity / size()); |
| 207 | setCharge(charge_most_frequent); |
| 208 | return; |
| 209 | } |
| 210 | |
| 211 | void ConsensusFeature::computeMonoisotopicConsensus() |
| 212 | { |