OpenMS
Loading...
Searching...
No Matches
CometNativeIDRemapper.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Timo Sachsenberg $
7// --------------------------------------------------------------------------
8
9#pragma once
10
15#include <string>
16#include <unordered_map>
17
18namespace OpenMS
19{
36namespace CometNativeIDRemapper
37{
39 inline const std::string ORIGINAL_NATIVE_ID = "original_native_id";
40
51 {
52 Size idx = 0;
53 for (auto& spec : exp.getSpectra())
54 {
55 spec.setMetaValue(ORIGINAL_NATIVE_ID, spec.getNativeID());
56 spec.setNativeID("index=" + StringUtils::toStr(idx++));
57 }
58 return idx;
59 }
60
73 {
74 if (exp.empty()) { return; }
75
76 // Build rewritten-id -> original-id map once (O(N) vs O(N*M) linear scan).
77 std::unordered_map<std::string, std::string> id_map;
78 id_map.reserve(exp.size());
79 for (const auto& spec : exp.getSpectra())
80 {
81 if (spec.metaValueExists(ORIGINAL_NATIVE_ID)) { id_map.emplace(spec.getNativeID(), spec.getMetaValue(ORIGINAL_NATIVE_ID).toString()); }
82 }
83 if (id_map.empty()) { return; }
84
85 for (auto& pid : pids)
86 {
87 auto it = id_map.find(pid.getSpectrumReference());
88 if (it != id_map.end()) { pid.setSpectrumReference(it->second); }
89 }
90 }
91} // namespace CometNativeIDRemapper
92} // namespace OpenMS
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
bool empty() const noexcept
Are there any spectra (does not consider chromatograms)
Size size() const noexcept
The number of spectra.
const std::vector< MSSpectrum > & getSpectra() const
returns the spectrum list
Container for peptide identifications from multiple spectra.
Definition PeptideIdentificationList.h:66
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
Size rewriteToIndex(MSExperiment &exp)
Rewrite every spectrum's native ID to "index=N" (monotonic, 0-based).
Definition CometNativeIDRemapper.h:50
void translateReferencesBack(const MSExperiment &exp, PeptideIdentificationList &pids)
Translate PSM spectrum references from the rewritten "index=N" form back to the original IDs.
Definition CometNativeIDRemapper.h:72
const std::string ORIGINAL_NATIVE_ID
MetaValue key under which the original native ID is stashed by rewriteToIndex().
Definition CometNativeIDRemapper.h:39
std::string toStr(int i)
Definition StringUtils.h:257
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19