merge proteins across fractions and replicates
| 284 | |
| 285 | //merge proteins across fractions and replicates |
| 286 | void ConsensusMapMergerAlgorithm::mergeAllIDRuns(ConsensusMap& cmap) const |
| 287 | { |
| 288 | if (cmap.getProteinIdentifications().size() == 1) |
| 289 | return; |
| 290 | |
| 291 | // Everything needs to agree |
| 292 | checkOldRunConsistency_(cmap.getProteinIdentifications(), cmap.getExperimentType()); |
| 293 | |
| 294 | ProteinIdentification new_prot_id_run; |
| 295 | //TODO create better ID |
| 296 | new_prot_id_run.setIdentifier("merged"); |
| 297 | //TODO merge SearchParams e.g. in case of SILAC |
| 298 | new_prot_id_run.setSearchEngine(cmap.getProteinIdentifications()[0].getSearchEngine()); |
| 299 | new_prot_id_run.setSearchEngineVersion(cmap.getProteinIdentifications()[0].getSearchEngineVersion()); |
| 300 | new_prot_id_run.setSearchParameters(cmap.getProteinIdentifications()[0].getSearchParameters()); |
| 301 | String old_inference_engine = cmap.getProteinIdentifications()[0].getInferenceEngine(); |
| 302 | if (!old_inference_engine.empty()) |
| 303 | { |
| 304 | OPENMS_LOG_WARN << "Inference was already performed on the runs in this ConsensusXML." |
| 305 | " Merging their proteins, will invalidate correctness of the inference." |
| 306 | " You should redo it.\n"; |
| 307 | // deliberately do not take over old inference settings. |
| 308 | } |
| 309 | |
| 310 | //we do it based on the IDRuns since ID Runs maybe different from quantification in e.g. TMT |
| 311 | vector<String> merged_origin_files{}; |
| 312 | map<String,pair<Size,bool>> oldrunid2offset_multi_pair; |
| 313 | for (const auto& pid : cmap.getProteinIdentifications()) |
| 314 | { |
| 315 | vector<String> out; |
| 316 | pid.getPrimaryMSRunPath(out); |
| 317 | Size offset = merged_origin_files.size(); |
| 318 | merged_origin_files.insert(merged_origin_files.end(), out.begin(), out.end()); |
| 319 | oldrunid2offset_multi_pair.emplace(std::piecewise_construct, |
| 320 | std::forward_as_tuple(pid.getIdentifier()), |
| 321 | std::forward_as_tuple(offset, out.size() > 1)); |
| 322 | } |
| 323 | new_prot_id_run.setPrimaryMSRunPath(merged_origin_files); |
| 324 | |
| 325 | unordered_set<ProteinHit,hash_type,equal_type> proteins_collected_hits(0, accessionHash_, accessionEqual_); |
| 326 | |
| 327 | std::vector<ProteinIdentification>& old_prot_runs = cmap.getProteinIdentifications(); |
| 328 | typedef std::vector<ProteinHit>::iterator iter_t; |
| 329 | for (auto& prot_run : old_prot_runs) |
| 330 | { |
| 331 | auto& hits = prot_run.getHits(); |
| 332 | proteins_collected_hits.insert( |
| 333 | std::move_iterator<iter_t>(hits.begin()), |
| 334 | std::move_iterator<iter_t>(hits.end()) |
| 335 | ); |
| 336 | hits.clear(); |
| 337 | } |
| 338 | |
| 339 | std::map<String, Size> run_id_to_run_idx; |
| 340 | for (Size old_prot_run_idx = 0; old_prot_run_idx < old_prot_runs.size(); ++old_prot_run_idx) |
| 341 | { |
| 342 | ProteinIdentification& protIDRun = old_prot_runs[old_prot_run_idx]; |
| 343 | run_id_to_run_idx[protIDRun.getIdentifier()] = old_prot_run_idx; |