@Note sip peptides get reordered in same order as clusters
| 319 | |
| 320 | //@Note sip peptides get reordered in same order as clusters |
| 321 | static vector<vector<SIPPeptide> > clusterSIPPeptides(const vector<double>& centers, vector<SIPPeptide>& sip_peptides) |
| 322 | { |
| 323 | // one cluster for each cluster center |
| 324 | vector<vector<SIPPeptide> > clusters(centers.size(), vector<SIPPeptide>()); |
| 325 | |
| 326 | // assign sip peptide to cluster center with largest RIA |
| 327 | for (vector<SIPPeptide>::const_iterator sit = sip_peptides.begin(); sit != sip_peptides.end(); ++sit) |
| 328 | { |
| 329 | const vector<SIPIncorporation>& incs = sit->incorporations; |
| 330 | if (!incs.empty()) |
| 331 | { |
| 332 | double largest_ria = incs[incs.size() - 1].rate; |
| 333 | Size closest_cluster_idx = 0; |
| 334 | double closest_cluster_dist = std::numeric_limits<double>::max(); |
| 335 | for (Size i = 0; i != centers.size(); ++i) |
| 336 | { |
| 337 | double dist = std::fabs(centers[i] - largest_ria); |
| 338 | if (dist < closest_cluster_dist) |
| 339 | { |
| 340 | closest_cluster_dist = dist; |
| 341 | closest_cluster_idx = i; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | // add SIP peptide to closest cluster |
| 346 | clusters[closest_cluster_idx].push_back(*sit); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | // rearrange SIP peptides to reflect new order |
| 351 | sip_peptides.clear(); |
| 352 | for (vector<vector<SIPPeptide> >::const_iterator sit = clusters.begin(); sit != clusters.end(); ++sit) |
| 353 | { |
| 354 | sip_peptides.insert(sip_peptides.end(), sit->begin(), sit->end()); |
| 355 | } |
| 356 | |
| 357 | return clusters; |
| 358 | } |
| 359 | |
| 360 | }; |
| 361 |