| 330 | } |
| 331 | |
| 332 | void mergeIds_(StringList file_names, |
| 333 | bool annotate_file_origin, |
| 334 | const String& add_to, |
| 335 | vector<ProteinIdentification>& proteins, |
| 336 | vector<PeptideIdentification>& peptides) |
| 337 | { |
| 338 | map<String, ProteinIdentification> proteins_by_id; |
| 339 | vector<vector<PeptideIdentification> > peptides_by_file; |
| 340 | StringList add_to_ids; // IDs from the "add_to" file (if any) |
| 341 | |
| 342 | if (!add_to.empty()) |
| 343 | { // make 'add_to' filename the first in the list |
| 344 | file_names.erase(remove(file_names.begin(), file_names.end(), add_to), file_names.end()); |
| 345 | file_names.insert(file_names.begin(), add_to); |
| 346 | } |
| 347 | |
| 348 | peptides_by_file.resize(file_names.size()); |
| 349 | for (Size i = 0; i < file_names.size(); ++i) |
| 350 | { |
| 351 | const String& file_name = file_names[i]; |
| 352 | vector<ProteinIdentification> additional_proteins; |
| 353 | IdXMLFile().load(file_name, additional_proteins, peptides_by_file[i]); |
| 354 | |
| 355 | if (annotate_file_origin) // set MetaValue "file_origin" if flag is set |
| 356 | { |
| 357 | annotateFileOrigin_(additional_proteins, peptides_by_file[i], |
| 358 | file_name); |
| 359 | } |
| 360 | |
| 361 | for (const ProteinIdentification& prot : additional_proteins) |
| 362 | { |
| 363 | const String& id = prot.getIdentifier(); |
| 364 | proteins_by_id[id] = prot; |
| 365 | if (i == 0) { add_to_ids.push_back(id); } |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | if (add_to.empty()) // copy proteins from map into vector for writing |
| 370 | { |
| 371 | // append peptides in same vector |
| 372 | for (vector<PeptideIdentification> & peps : peptides_by_file) |
| 373 | { |
| 374 | peptides.insert(peptides.end(), peps.begin(), peps.end()); |
| 375 | } |
| 376 | // only append the runs (no merging of proteins) |
| 377 | for (auto map_it = proteins_by_id.begin(); map_it != proteins_by_id.end(); ++map_it) |
| 378 | { |
| 379 | proteins.push_back(map_it->second); |
| 380 | } |
| 381 | } |
| 382 | else // add only new IDs to an existing file |
| 383 | { |
| 384 | // copy over data from reference file ("add_to"): |
| 385 | map<String, ProteinIdentification> selected_proteins; |
| 386 | for (auto ids_it = add_to_ids.begin(); |
| 387 | ids_it != add_to_ids.end(); ++ids_it) |
| 388 | { |
| 389 | selected_proteins[*ids_it] = proteins_by_id[*ids_it]; |
nothing calls this directly
no test coverage detected