OpenMS
Loading...
Searching...
No Matches
TransitionExperiment.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: Hannes Roest $
6// $Authors: Hannes Roest $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <string>
12#include <vector>
13#include <map>
14#include <cstdint>
15#include <functional>
16
17#include <OpenMS/OPENSWATHALGO/OpenSwathAlgoConfig.h>
18
19namespace OpenSwath
20{
21
24 enum class FragmentIonType : uint8_t
25 {
26 Unknown = 0,
27 AIon,
28 BIon,
29 CIon,
30 XIon,
31 YIon,
32 ZIon,
33 ZPrimeIon,
34 ZDotIon,
35 Precursor,
36 BMinusH2O,
37 YMinusH2O,
38 BMinusNH3,
39 YMinusNH3,
40 Empty = 255
41 };
42
46 inline FragmentIonType stringToFragmentIonType(const std::string& s)
47 {
48 if (s.empty()) return FragmentIonType::Empty;
49 if (s == "a") return FragmentIonType::AIon;
50 if (s == "b") return FragmentIonType::BIon;
51 if (s == "c") return FragmentIonType::CIon;
52 if (s == "x") return FragmentIonType::XIon;
53 if (s == "y") return FragmentIonType::YIon;
54 if (s == "z") return FragmentIonType::ZIon;
55 if (s == "z'") return FragmentIonType::ZPrimeIon;
56 if (s == "z.") return FragmentIonType::ZDotIon;
57 if (s == "prec" || s == "precursor") return FragmentIonType::Precursor;
58 if (s == "b-H2O" || s == "b-H20") return FragmentIonType::BMinusH2O;
59 if (s == "y-H2O" || s == "y-H20") return FragmentIonType::YMinusH2O;
60 if (s == "b-NH3") return FragmentIonType::BMinusNH3;
61 if (s == "y-NH3") return FragmentIonType::YMinusNH3;
63 }
64
69 {
70 switch (t)
71 {
72 case FragmentIonType::Empty: return "";
73 case FragmentIonType::AIon: return "a";
74 case FragmentIonType::BIon: return "b";
75 case FragmentIonType::CIon: return "c";
76 case FragmentIonType::XIon: return "x";
77 case FragmentIonType::YIon: return "y";
78 case FragmentIonType::ZIon: return "z";
79 case FragmentIonType::ZPrimeIon: return "z'";
80 case FragmentIonType::ZDotIon: return "z.";
81 case FragmentIonType::Precursor: return "prec";
82 case FragmentIonType::BMinusH2O: return "b-H2O";
83 case FragmentIonType::YMinusH2O: return "y-H2O";
84 case FragmentIonType::BMinusNH3: return "b-NH3";
85 case FragmentIonType::YMinusNH3: return "y-NH3";
87 default: return "unknown";
88 }
89 }
90
94 {
95 uint8_t decoy : 1;
96 uint8_t detecting : 1;
97 uint8_t quantifying : 1;
98 uint8_t identifying : 1;
99 uint8_t reserved : 4;
100
102 };
103
105 {
106 std::string transition_name;
107 std::string peptide_ref;
109 double product_mz{};
110 double precursor_mz{};
111 double precursor_im{-1};
114
115 // Additional fields for roundtrip TSV/PQP I/O
116 int16_t fragment_nr{-1};
118 std::vector<std::string> peptidoforms;
119
120 // Legacy bool accessors for API compatibility
121 bool getDecoy() const { return flags.decoy; }
122 void setDecoy(bool d) { flags.decoy = d; }
123
124 // Fragment type string accessors for backward compatibility
126 void setFragmentType(const std::string& s) { fragment_type = stringToFragmentIonType(s); }
127
130 std::string getAnnotation() const
131 {
133 {
134 return "";
135 }
137 {
138 return "prec";
139 }
140 std::string result = fragmentIonTypeToString(fragment_type);
141 if (fragment_nr >= 0)
142 {
143 result += std::to_string(fragment_nr);
144 }
145 if (fragment_charge > 0)
146 {
147 result += "^" + std::to_string(static_cast<int>(fragment_charge));
148 }
149 return result;
150 }
151
153 {
154 return fragment_charge;
155 }
156
158 {
159 return !(fragment_charge == 0);
160 }
161
162 bool isPrecursorImSet() const
163 {
164 return !(precursor_im == -1);
165 }
166
167 std::string getNativeID() const
168 {
169 return transition_name;
170 }
171
172 std::string getPeptideRef() const
173 {
174 return peptide_ref;
175 }
176
177 std::string getCompoundRef() const
178 {
179 return peptide_ref;
180 }
181
182 double getLibraryIntensity() const
183 {
184 return library_intensity;
185 }
186
187 void setLibraryIntensity(double l)
188 {
190 }
191
192 double getProductMZ() const
193 {
194 return product_mz;
195 }
196
197 double getPrecursorMZ() const
198 {
199 return precursor_mz;
200 }
201
202 double getPrecursorIM() const
203 {
204 return precursor_im;
205 }
206
208 {
209 flags.detecting = d;
210 }
211
213 {
214 return flags.detecting;
215 }
216
218 {
219 flags.quantifying = q;
220 }
221
223 {
224 return flags.quantifying;
225 }
226
228 {
229 flags.identifying = i;
230 }
231
233 {
234 return flags.identifying;
235 }
236
238 bool operator==(const LightTransition& rhs) const
239 {
240 return transition_name == rhs.transition_name;
241 }
242
243 bool operator!=(const LightTransition& rhs) const
244 {
245 return !(*this == rhs);
246 }
247 };
248
250 {
253
255 bool operator==(const LightModification& rhs) const
256 {
257 return location == rhs.location && unimod_id == rhs.unimod_id;
258 }
259
260 bool operator!=(const LightModification& rhs) const
261 {
262 return !(*this == rhs);
263 }
264 };
265
266 // A compound is either a peptide or a metabolite
268 {
269
271 drift_time(-1),
272 charge(0)
273 {
274 }
275
277 double rt;
279 std::string sequence;
280 std::vector<std::string> protein_refs;
281 // Peptide group label (corresponds to MS:1000893, all peptides that are isotopic forms of the same peptide should be assigned the same peptide group label)
283 std::string gene_name;
284 std::string id;
285
286 // for metabolites
287 std::string sum_formula;
288 std::string compound_name;
289
290 // Additional fields for roundtrip TSV/PQP I/O
291 std::string label_type;
292 std::string smiles;
293 std::string adducts;
294
295 // By convention, if there is no (metabolic) compound name, it is a peptide
296 bool isPeptide() const
297 {
298 return compound_name.empty();
299 }
300
301 void setChargeState(int ch)
302 {
303 charge = ch;
304 }
305
306 int getChargeState() const
307 {
308 return charge;
309 }
310
311 void setDriftTime(double d)
312 {
313 drift_time = d;
314 }
315
316 double getDriftTime() const
317 {
318 return drift_time;
319 }
320
321 std::vector<LightModification> modifications;
322
324 bool operator==(const LightCompound& rhs) const
325 {
326 return id == rhs.id;
327 }
328
329 bool operator!=(const LightCompound& rhs) const
330 {
331 return !(*this == rhs);
332 }
333 };
334
336 {
337 std::string id;
338 std::string sequence;
339
340 // Additional fields for roundtrip TSV/PQP I/O
341 std::string uniprot_id;
342
344 bool operator==(const LightProtein& rhs) const
345 {
346 return id == rhs.id;
347 }
348
349 bool operator!=(const LightProtein& rhs) const
350 {
351 return !(*this == rhs);
352 }
353 };
354
356 {
358
363
364 std::vector<LightTransition> transitions;
365 std::vector<LightCompound> compounds;
366 std::vector<LightProtein> proteins;
367 std::vector<LightTransition> & getTransitions()
368 {
369 return transitions;
370 }
371
372 const std::vector<LightTransition> & getTransitions() const
373 {
374 return transitions;
375 }
376
377 std::vector<LightCompound> & getCompounds()
378 {
379 return compounds;
380 }
381
382 const std::vector<LightCompound> & getCompounds() const
383 {
384 return compounds;
385 }
386
387 std::vector<LightProtein> & getProteins()
388 {
389 return proteins;
390 }
391
392 const std::vector<LightProtein> & getProteins() const
393 {
394 return proteins;
395 }
396
397 // legacy
398 const LightCompound& getPeptideByRef(const std::string& ref)
399 {
400 return getCompoundByRef(ref);
401 }
402
403 const LightCompound& getCompoundByRef(const std::string& ref)
404 {
406 {
408 }
409 return *(compound_reference_map_[ref]);
410 }
411
412 private:
413
415 {
416 for (size_t i = 0; i < getCompounds().size(); i++)
417 {
419 }
421 }
422
423 // Map of compounds (peptides or metabolites)
425 std::map<std::string, LightCompound*> compound_reference_map_;
426
427 };
428
429} //end Namespace OpenSwath
430
431// Hash function specializations for OpenSwath types
432namespace std
433{
440 template<>
441 struct hash<OpenSwath::LightTransition>
442 {
443 std::size_t operator()(const OpenSwath::LightTransition& t) const noexcept
444 {
445 return std::hash<std::string>{}(t.transition_name);
446 }
447 };
448
455 template<>
456 struct hash<OpenSwath::LightCompound>
457 {
458 std::size_t operator()(const OpenSwath::LightCompound& c) const noexcept
459 {
460 return std::hash<std::string>{}(c.id);
461 }
462 };
463
470 template<>
471 struct hash<OpenSwath::LightProtein>
472 {
473 std::size_t operator()(const OpenSwath::LightProtein& p) const noexcept
474 {
475 return std::hash<std::string>{}(p.id);
476 }
477 };
478
486 template<>
487 struct hash<OpenSwath::LightModification>
488 {
489 std::size_t operator()(const OpenSwath::LightModification& m) const noexcept
490 {
491 std::size_t seed = std::hash<int>{}(m.location);
492 // Use standard hash combine formula (from boost) for better distribution
493 seed ^= std::hash<int>{}(m.unimod_id) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
494 return seed;
495 }
496 };
497} // namespace std
498
Definition Scoring.h:18
FragmentIonType
Compact enum for fragment ion types (replaces string storage) Reduces memory from ~32 bytes (std::str...
Definition TransitionExperiment.h:25
@ BMinusNH3
b-ion with ammonia loss
@ ZPrimeIon
z'-ion (z prime)
@ YMinusH2O
y-ion with water loss
@ BMinusH2O
b-ion with water loss
@ YMinusNH3
y-ion with ammonia loss
@ Precursor
Precursor ion.
@ Empty
No fragment type set.
std::string fragmentIonTypeToString(FragmentIonType t)
Convert fragment ion type enum to string.
Definition TransitionExperiment.h:68
FragmentIonType stringToFragmentIonType(const std::string &s)
Convert fragment ion type string to enum.
Definition TransitionExperiment.h:46
STL namespace.
Definition TransitionExperiment.h:268
bool operator!=(const LightCompound &rhs) const
Definition TransitionExperiment.h:329
std::vector< std::string > protein_refs
Definition TransitionExperiment.h:280
std::string sum_formula
Definition TransitionExperiment.h:287
void setDriftTime(double d)
Definition TransitionExperiment.h:311
std::string gene_name
Definition TransitionExperiment.h:283
bool isPeptide() const
Definition TransitionExperiment.h:296
int getChargeState() const
Definition TransitionExperiment.h:306
std::string peptide_group_label
Definition TransitionExperiment.h:282
std::vector< LightModification > modifications
Definition TransitionExperiment.h:321
std::string adducts
Adducts (metabolomics)
Definition TransitionExperiment.h:293
double drift_time
Definition TransitionExperiment.h:276
std::string sequence
Definition TransitionExperiment.h:279
void setChargeState(int ch)
Definition TransitionExperiment.h:301
LightCompound()
Definition TransitionExperiment.h:270
bool operator==(const LightCompound &rhs) const
Equality operator - compares id (consistent with hash)
Definition TransitionExperiment.h:324
std::string compound_name
Definition TransitionExperiment.h:288
std::string label_type
Label type (e.g. "heavy" or "light")
Definition TransitionExperiment.h:291
double getDriftTime() const
Definition TransitionExperiment.h:316
double rt
Definition TransitionExperiment.h:277
int charge
Definition TransitionExperiment.h:278
std::string smiles
SMILES representation (metabolomics)
Definition TransitionExperiment.h:292
std::string id
Definition TransitionExperiment.h:284
Definition TransitionExperiment.h:250
int unimod_id
Definition TransitionExperiment.h:252
bool operator!=(const LightModification &rhs) const
Definition TransitionExperiment.h:260
int location
Definition TransitionExperiment.h:251
bool operator==(const LightModification &rhs) const
Equality operator - compares location and unimod_id (consistent with hash)
Definition TransitionExperiment.h:255
Definition TransitionExperiment.h:336
std::string uniprot_id
UniProt identifier.
Definition TransitionExperiment.h:341
std::string sequence
Definition TransitionExperiment.h:338
bool operator==(const LightProtein &rhs) const
Equality operator - compares id (consistent with hash)
Definition TransitionExperiment.h:344
std::string id
Definition TransitionExperiment.h:337
bool operator!=(const LightProtein &rhs) const
Definition TransitionExperiment.h:349
Definition TransitionExperiment.h:356
const std::vector< LightCompound > & getCompounds() const
Definition TransitionExperiment.h:382
std::vector< LightTransition > transitions
Definition TransitionExperiment.h:364
std::vector< LightProtein > proteins
Definition TransitionExperiment.h:366
std::vector< LightTransition > & getTransitions()
Definition TransitionExperiment.h:367
bool compound_reference_map_dirty_
Definition TransitionExperiment.h:424
std::vector< LightProtein > & getProteins()
Definition TransitionExperiment.h:387
void createPeptideReferenceMap_()
Definition TransitionExperiment.h:414
const std::vector< LightTransition > & getTransitions() const
Definition TransitionExperiment.h:372
std::map< std::string, LightCompound * > compound_reference_map_
Definition TransitionExperiment.h:425
LightProtein Protein
Definition TransitionExperiment.h:362
LightCompound Compound
Definition TransitionExperiment.h:361
LightTransition Transition
Definition TransitionExperiment.h:359
const LightCompound & getCompoundByRef(const std::string &ref)
Definition TransitionExperiment.h:403
const std::vector< LightProtein > & getProteins() const
Definition TransitionExperiment.h:392
const LightCompound & getPeptideByRef(const std::string &ref)
Definition TransitionExperiment.h:398
LightTargetedExperiment()
Definition TransitionExperiment.h:357
LightCompound Peptide
Definition TransitionExperiment.h:360
std::vector< LightCompound > compounds
Definition TransitionExperiment.h:365
std::vector< LightCompound > & getCompounds()
Definition TransitionExperiment.h:377
Definition TransitionExperiment.h:105
void setFragmentType(const std::string &s)
Definition TransitionExperiment.h:126
void setLibraryIntensity(double l)
Definition TransitionExperiment.h:187
std::string transition_name
Definition TransitionExperiment.h:106
void setIdentifyingTransition(bool i)
Definition TransitionExperiment.h:227
std::string getPeptideRef() const
Definition TransitionExperiment.h:172
double getPrecursorMZ() const
Definition TransitionExperiment.h:197
bool getDecoy() const
Definition TransitionExperiment.h:121
std::string getAnnotation() const
Definition TransitionExperiment.h:130
double getProductMZ() const
Definition TransitionExperiment.h:192
std::string peptide_ref
Definition TransitionExperiment.h:107
bool operator!=(const LightTransition &rhs) const
Definition TransitionExperiment.h:243
void setQuantifyingTransition(bool q)
Definition TransitionExperiment.h:217
bool isProductChargeStateSet() const
Definition TransitionExperiment.h:157
bool operator==(const LightTransition &rhs) const
Equality operator - compares transition_name (consistent with hash)
Definition TransitionExperiment.h:238
double product_mz
Definition TransitionExperiment.h:109
bool isIdentifyingTransition() const
Definition TransitionExperiment.h:232
std::vector< std::string > peptidoforms
Peptidoforms for IPF.
Definition TransitionExperiment.h:118
std::string getFragmentType() const
Definition TransitionExperiment.h:125
double getLibraryIntensity() const
Definition TransitionExperiment.h:182
void setDecoy(bool d)
Definition TransitionExperiment.h:122
bool isQuantifyingTransition() const
Definition TransitionExperiment.h:222
std::string getNativeID() const
Definition TransitionExperiment.h:167
bool isDetectingTransition() const
Definition TransitionExperiment.h:212
void setDetectingTransition(bool d)
Definition TransitionExperiment.h:207
double getPrecursorIM() const
Definition TransitionExperiment.h:202
int16_t fragment_nr
Fragment ion ordinal (e.g. 7 for y7)
Definition TransitionExperiment.h:116
FragmentIonType fragment_type
Fragment ion type enum.
Definition TransitionExperiment.h:117
bool isPrecursorImSet() const
Definition TransitionExperiment.h:162
std::string getCompoundRef() const
Definition TransitionExperiment.h:177
int8_t fragment_charge
Fragment charge (compact: range typically 1-8)
Definition TransitionExperiment.h:112
double library_intensity
Definition TransitionExperiment.h:108
double precursor_mz
Definition TransitionExperiment.h:110
int getProductChargeState() const
Definition TransitionExperiment.h:152
TransitionFlags flags
Packed boolean flags.
Definition TransitionExperiment.h:113
double precursor_im
Definition TransitionExperiment.h:111
Packed boolean flags for transitions Reduces memory from 4 bytes (4 separate bools) to 1 byte.
Definition TransitionExperiment.h:94
uint8_t identifying
Definition TransitionExperiment.h:98
uint8_t decoy
Definition TransitionExperiment.h:95
uint8_t reserved
Definition TransitionExperiment.h:99
uint8_t quantifying
Definition TransitionExperiment.h:97
uint8_t detecting
Definition TransitionExperiment.h:96
TransitionFlags()
Definition TransitionExperiment.h:101
std::size_t operator()(const OpenSwath::LightCompound &c) const noexcept
Definition TransitionExperiment.h:458
std::size_t operator()(const OpenSwath::LightModification &m) const noexcept
Definition TransitionExperiment.h:489
std::size_t operator()(const OpenSwath::LightProtein &p) const noexcept
Definition TransitionExperiment.h:473
std::size_t operator()(const OpenSwath::LightTransition &t) const noexcept
Definition TransitionExperiment.h:443