OpenMS
Loading...
Searching...
No Matches
MzPAF.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
16#include <OpenMS/OpenMSConfig.h>
17
18#include <iosfwd>
19#include <optional>
20#include <utility>
21#include <vector>
22
23namespace OpenMS
24{
25
26 //--------------------------------------------------------------------------
27 // Data Structures
28 //--------------------------------------------------------------------------
29
37 enum class MzPAFIonSeries
38 {
39 A,
40 B,
41 C,
42 X,
43 Y,
44 Z,
45 PRECURSOR,
46 IMMONIUM,
47 INTERNAL,
48 REPORTER,
49 FORMULA,
50 NAMED,
51 UNKNOWN,
52 D,
53 V,
54 W
55 };
56
62 enum class MzPAFDeltaUnit
63 {
64 DALTON,
65 PPM
66 };
67
75 struct OPENMS_DLLAPI MzPAFNeutralLoss
76 {
78
79 bool operator==(const MzPAFNeutralLoss& other) const;
80 bool operator!=(const MzPAFNeutralLoss& other) const { return !(*this == other); }
81 };
82
91 struct OPENMS_DLLAPI MzPAFMassDelta
92 {
93 double value = 0.0;
94 MzPAFDeltaUnit unit = MzPAFDeltaUnit::DALTON;
95
96 bool operator==(const MzPAFMassDelta& other) const;
97 bool operator!=(const MzPAFMassDelta& other) const { return !(*this == other); }
98 };
99
125 struct OPENMS_DLLAPI MzPAFAnnotation
126 {
127 std::optional<int> analyte_index;
128 MzPAFIonSeries ion_series = MzPAFIonSeries::UNKNOWN;
129 std::optional<int> ordinal;
130 std::optional<char> immonium_residue;
131 std::optional<std::pair<int, int>> internal_range;
132 std::optional<std::string> reporter_name;
133 std::optional<EmpiricalFormula> formula;
134 std::optional<std::string> named_compound;
135 std::vector<MzPAFNeutralLoss> neutral_losses;
136 std::optional<int> isotope_offset;
137 std::optional<EmpiricalFormula> adduct;
138 std::optional<int> charge;
139 std::optional<MzPAFMassDelta> mass_delta;
140 std::optional<double> confidence;
141 std::optional<std::string> embedded_sequence;
142 std::optional<char> satellite_subtype;
143
145 bool isValid() const;
146
148 bool operator==(const MzPAFAnnotation& other) const;
149 bool operator!=(const MzPAFAnnotation& other) const { return !(*this == other); }
150 };
151
153 OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const MzPAFAnnotation& ann);
154
163 struct OPENMS_DLLAPI MzPAFPeakAnnotations
164 {
165 std::vector<MzPAFAnnotation> annotations;
166
168 bool empty() const { return annotations.empty(); }
169
171 size_t size() const { return annotations.size(); }
172
174 bool operator==(const MzPAFPeakAnnotations& other) const;
175 bool operator!=(const MzPAFPeakAnnotations& other) const { return !(*this == other); }
176 };
177
178 //--------------------------------------------------------------------------
179 // Error Handling
180 //--------------------------------------------------------------------------
181
201
208 OPENMS_DLLAPI const char* mzPAFErrorCodeToString(MzPAFErrorCode code);
209
215 class OPENMS_DLLAPI MzPAFParseError : public Exception::ParseError
216 {
217 public:
219 const char* file,
220 int line,
221 const char* function,
222 MzPAFErrorCode error_code,
223 size_t error_position,
224 const std::string& input,
225 const std::string& message
226 ) noexcept;
227
228 MzPAFErrorCode getErrorCode() const noexcept { return code_; }
229 size_t getPosition() const noexcept { return position_; }
230 std::string getFormattedMessage() const;
231
232 private:
234 size_t position_;
235 std::string context_before_;
236 std::string context_after_;
237
238 void extractContext_(const std::string& input, size_t pos);
239 };
240
241 //--------------------------------------------------------------------------
242 // Parser API
243 //--------------------------------------------------------------------------
244
276 class OPENMS_DLLAPI MzPAF
277 {
278 public:
279 //--------------------------------------------------------------------------
280 // Parsing
281 //--------------------------------------------------------------------------
282
293 static MzPAFAnnotation parse(const std::string& input);
294
302 static MzPAFPeakAnnotations parseMultiple(const std::string& input);
303
310 static std::optional<MzPAFAnnotation> tryParse(const std::string& input);
311
318 static std::optional<MzPAFPeakAnnotations> tryParseMultiple(const std::string& input);
319
320 //--------------------------------------------------------------------------
321 // Serialization
322 //--------------------------------------------------------------------------
323
331 static std::string toString(const MzPAFAnnotation& ann);
332
339 static std::string toString(const MzPAFPeakAnnotations& anns);
340
341 //--------------------------------------------------------------------------
342 // PeakAnnotation Integration
343 //--------------------------------------------------------------------------
344
356 const MzPAFAnnotation& mzpaf, double mz, double intensity);
357
367 const PeptideHit::PeakAnnotation& peak_annotation);
368
369 //--------------------------------------------------------------------------
370 // Utilities
371 //--------------------------------------------------------------------------
372
381 static bool isMzPAFFormat(const std::string& annotation);
382
396 static std::optional<double> calculateTheoreticalMZ(
397 const MzPAFAnnotation& ann, const AASequence& sequence);
398
406
414 static char ionSeriesToChar(MzPAFIonSeries series);
415
423 static bool charToIonSeries(char c, MzPAFIonSeries& series);
424
425 private:
426 MzPAF() = delete; // Static class, no instantiation
427 };
428
429} // namespace OpenMS
Representation of a peptide/protein sequence.
Definition AASequence.h:93
Representation of an empirical formula.
Definition EmpiricalFormula.h:62
Parse Error exception.
Definition Exception.h:596
Parse error for mzPAF notation.
Definition MzPAF.h:216
std::string context_before_
Definition MzPAF.h:235
MzPAFErrorCode getErrorCode() const noexcept
Definition MzPAF.h:228
size_t position_
Definition MzPAF.h:234
size_t getPosition() const noexcept
Definition MzPAF.h:229
void extractContext_(const std::string &input, size_t pos)
std::string getFormattedMessage() const
std::string context_after_
Definition MzPAF.h:236
MzPAFErrorCode code_
Definition MzPAF.h:233
MzPAFParseError(const char *file, int line, const char *function, MzPAFErrorCode error_code, size_t error_position, const std::string &input, const std::string &message) noexcept
Parser and writer for mzPAF (Peak Annotation Format) notation.
Definition MzPAF.h:277
static std::optional< MzPAFAnnotation > tryParse(const std::string &input)
Try to parse an mzPAF string (non-throwing)
static std::string toString(const MzPAFPeakAnnotations &anns)
Convert multiple annotations to mzPAF string.
static bool charToIonSeries(char c, MzPAFIonSeries &series)
Parse ion series from character.
static MzPAFAnnotation parse(const std::string &input)
Parse an mzPAF string into a single annotation.
static PeptideHit::PeakAnnotation toPeakAnnotation(const MzPAFAnnotation &mzpaf, double mz, double intensity)
Create a PeptideHit::PeakAnnotation from mzPAF data.
static bool isStandardFragmentIon(MzPAFIonSeries series)
Check if ion series is a peptide fragment ion (a, b, c, d, v, w, x, y, z)
static std::optional< double > calculateTheoreticalMZ(const MzPAFAnnotation &ann, const AASequence &sequence)
Calculate theoretical m/z for an annotation.
static MzPAFPeakAnnotations parseMultiple(const std::string &input)
Parse an mzPAF string with potentially multiple annotations.
static MzPAFPeakAnnotations fromPeakAnnotation(const PeptideHit::PeakAnnotation &peak_annotation)
Parse mzPAF annotations from a PeptideHit::PeakAnnotation.
static std::optional< MzPAFPeakAnnotations > tryParseMultiple(const std::string &input)
Try to parse multiple annotations (non-throwing)
static bool isMzPAFFormat(const std::string &annotation)
Check if a string appears to be in mzPAF format.
MzPAF()=delete
static char ionSeriesToChar(MzPAFIonSeries series)
Get the ion series character for an annotation.
static std::string toString(const MzPAFAnnotation &ann)
Convert an annotation to mzPAF string.
MzPAFIonSeries
Ion series types for mzPAF peak annotations.
Definition MzPAF.h:38
MzPAFErrorCode
Error codes for mzPAF parsing errors.
Definition MzPAF.h:188
MzPAFDeltaUnit
Unit for mass delta values in mzPAF annotations.
Definition MzPAF.h:63
@ X
x-ion (C-terminal)
@ C
c-ion (N-terminal, ETD)
@ INTERNAL
Internal fragment (m)
@ Z
z-ion (C-terminal, ETD)
@ V
v-ion (C-terminal satellite ion, complete side-chain loss)
@ Y
y-ion (C-terminal)
@ W
w-ion (C-terminal satellite ion, partial side-chain loss)
@ UNKNOWN
Unknown or unrecognized ion type.
@ NAMED
Named compound (_)
@ A
a-ion (N-terminal, loses CO)
@ REPORTER
Reporter ion (r)
@ IMMONIUM
Immonium ion (I)
@ B
b-ion (N-terminal)
@ FORMULA
Chemical formula ion (f)
@ PRECURSOR
Precursor ion (p)
@ D
d-ion (N-terminal satellite ion, partial side-chain loss)
@ INVALID_NUMBER
Invalid numeric value.
@ UNEXPECTED_CHARACTER
Unexpected character encountered.
@ EMPTY_INPUT
Empty input string.
@ INVALID_ION_SERIES
Invalid ion series character.
@ INVALID_CONFIDENCE
Invalid confidence score.
@ UNEXPECTED_END_OF_INPUT
Unexpected end of input.
@ INVALID_DELTA
Invalid mass delta specification.
@ UNCLOSED_BRACKET
Opening bracket without matching close.
@ INTERNAL_ERROR
Internal parser error.
@ INVALID_CHARGE
Invalid charge specification.
@ INVALID_FORMULA
Invalid chemical formula.
@ DALTON
Mass delta in Daltons (Da)
@ PPM
Mass delta in parts per million.
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
const char * mzPAFErrorCodeToString(MzPAFErrorCode code)
Convert error code to human-readable string.
A single mzPAF peak annotation.
Definition MzPAF.h:126
std::optional< std::string > named_compound
Name for named compound ions (_[name])
Definition MzPAF.h:134
std::optional< std::string > reporter_name
Name for reporter ions (r[TMT127N])
Definition MzPAF.h:132
std::optional< char > immonium_residue
Residue for immonium ions (Y in IY)
Definition MzPAF.h:130
bool isValid() const
Check if this annotation has minimal valid data.
std::vector< MzPAFNeutralLoss > neutral_losses
Neutral losses (-H2O, -NH3, etc.)
Definition MzPAF.h:135
std::optional< int > charge
Charge state (^2, ^3)
Definition MzPAF.h:138
std::optional< char > satellite_subtype
Optional 'a' or 'b' subtype, valid only for d- and w-ions.
Definition MzPAF.h:142
std::optional< double > confidence
Confidence score (*0.75)
Definition MzPAF.h:140
std::optional< MzPAFMassDelta > mass_delta
Mass delta (/0.001, /-1.4ppm)
Definition MzPAF.h:139
std::optional< int > ordinal
Position/ordinal (4 in y4)
Definition MzPAF.h:129
bool operator!=(const MzPAFAnnotation &other) const
Definition MzPAF.h:149
std::optional< EmpiricalFormula > formula
Chemical formula for formula ions (f{C16H22O})
Definition MzPAF.h:133
std::optional< int > analyte_index
Analyte index (0@, 1@, etc.) for multi-analyte spectra.
Definition MzPAF.h:127
std::optional< EmpiricalFormula > adduct
Adduct ion (+Na, +K, etc.)
Definition MzPAF.h:137
std::optional< std::string > embedded_sequence
Embedded ProForma sequence string ({LC[Carbamidomethyl]})
Definition MzPAF.h:141
std::optional< std::pair< int, int > > internal_range
Range for internal fragments (m3:6 -> {3,6})
Definition MzPAF.h:131
std::optional< int > isotope_offset
Isotope offset (+1i, +2i for M+1, M+2)
Definition MzPAF.h:136
bool operator==(const MzPAFAnnotation &other) const
Equality comparison.
Mass delta in an mzPAF annotation.
Definition MzPAF.h:92
bool operator!=(const MzPAFMassDelta &other) const
Definition MzPAF.h:97
bool operator==(const MzPAFMassDelta &other) const
Neutral loss in an mzPAF annotation.
Definition MzPAF.h:76
bool operator==(const MzPAFNeutralLoss &other) const
bool operator!=(const MzPAFNeutralLoss &other) const
Definition MzPAF.h:80
EmpiricalFormula formula
Parsed chemical formula of the loss.
Definition MzPAF.h:77
Multiple mzPAF annotations for a single peak.
Definition MzPAF.h:164
size_t size() const
Get number of annotations.
Definition MzPAF.h:171
bool empty() const
Check if there are any annotations.
Definition MzPAF.h:168
std::vector< MzPAFAnnotation > annotations
List of alternative annotations.
Definition MzPAF.h:165
bool operator!=(const MzPAFPeakAnnotations &other) const
Definition MzPAF.h:175
bool operator==(const MzPAFPeakAnnotations &other) const
Equality comparison.
Contains annotations of a peak.
Definition PeptideHit.h:87