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