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 };
53
59 enum class MzPAFDeltaUnit
60 {
61 DALTON,
62 PPM
63 };
64
72 struct OPENMS_DLLAPI MzPAFNeutralLoss
73 {
75
76 bool operator==(const MzPAFNeutralLoss& other) const;
77 bool operator!=(const MzPAFNeutralLoss& other) const { return !(*this == other); }
78 };
79
88 struct OPENMS_DLLAPI MzPAFMassDelta
89 {
90 double value = 0.0;
91 MzPAFDeltaUnit unit = MzPAFDeltaUnit::DALTON;
92
93 bool operator==(const MzPAFMassDelta& other) const;
94 bool operator!=(const MzPAFMassDelta& other) const { return !(*this == other); }
95 };
96
120 struct OPENMS_DLLAPI MzPAFAnnotation
121 {
122 std::optional<int> analyte_index;
123 MzPAFIonSeries ion_series = MzPAFIonSeries::UNKNOWN;
124 std::optional<int> ordinal;
125 std::optional<char> immonium_residue;
126 std::optional<std::pair<int, int>> internal_range;
127 std::optional<String> reporter_name;
128 std::optional<EmpiricalFormula> formula;
129 std::optional<String> named_compound;
130 std::vector<MzPAFNeutralLoss> neutral_losses;
131 std::optional<int> isotope_offset;
132 std::optional<EmpiricalFormula> adduct;
133 std::optional<int> charge;
134 std::optional<MzPAFMassDelta> mass_delta;
135 std::optional<double> confidence;
136 std::optional<String> embedded_sequence;
137
139 bool isValid() const;
140
142 bool operator==(const MzPAFAnnotation& other) const;
143 bool operator!=(const MzPAFAnnotation& other) const { return !(*this == other); }
144 };
145
147 OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const MzPAFAnnotation& ann);
148
157 struct OPENMS_DLLAPI MzPAFPeakAnnotations
158 {
159 std::vector<MzPAFAnnotation> annotations;
160
162 bool empty() const { return annotations.empty(); }
163
165 size_t size() const { return annotations.size(); }
166
168 bool operator==(const MzPAFPeakAnnotations& other) const;
169 bool operator!=(const MzPAFPeakAnnotations& other) const { return !(*this == other); }
170 };
171
172 //--------------------------------------------------------------------------
173 // Error Handling
174 //--------------------------------------------------------------------------
175
195
202 OPENMS_DLLAPI const char* mzPAFErrorCodeToString(MzPAFErrorCode code);
203
209 class OPENMS_DLLAPI MzPAFParseError : public Exception::ParseError
210 {
211 public:
213 const char* file,
214 int line,
215 const char* function,
216 MzPAFErrorCode error_code,
217 size_t error_position,
218 const String& input,
219 const String& message
220 ) noexcept;
221
222 MzPAFErrorCode getErrorCode() const noexcept { return code_; }
223 size_t getPosition() const noexcept { return position_; }
225
226 private:
228 size_t position_;
231
232 void extractContext_(const String& input, size_t pos);
233 };
234
235 //--------------------------------------------------------------------------
236 // Parser API
237 //--------------------------------------------------------------------------
238
270 class OPENMS_DLLAPI MzPAF
271 {
272 public:
273 //--------------------------------------------------------------------------
274 // Parsing
275 //--------------------------------------------------------------------------
276
287 static MzPAFAnnotation parse(const String& input);
288
297
304 static std::optional<MzPAFAnnotation> tryParse(const String& input);
305
312 static std::optional<MzPAFPeakAnnotations> tryParseMultiple(const String& input);
313
314 //--------------------------------------------------------------------------
315 // Serialization
316 //--------------------------------------------------------------------------
317
324 static String toString(const MzPAFAnnotation& ann);
325
333
334 //--------------------------------------------------------------------------
335 // PeakAnnotation Integration
336 //--------------------------------------------------------------------------
337
349 const MzPAFAnnotation& mzpaf, double mz, double intensity);
350
360 const PeptideHit::PeakAnnotation& peak_annotation);
361
362 //--------------------------------------------------------------------------
363 // Utilities
364 //--------------------------------------------------------------------------
365
374 static bool isMzPAFFormat(const String& annotation);
375
385 static std::optional<double> calculateTheoreticalMZ(
386 const MzPAFAnnotation& ann, const AASequence& sequence);
387
395
402 static char ionSeriesToChar(MzPAFIonSeries series);
403
411 static bool charToIonSeries(char c, MzPAFIonSeries& series);
412
413 private:
414 MzPAF() = delete; // Static class, no instantiation
415 };
416
417} // namespace OpenMS
subpage TOPP_TargetedFileConverter Converts targeted feature or consensus feature files subpage TOPP_FileInfo Shows basic information about the file
Definition TOPP.doxygen:44
Representation of a peptide/protein sequence.
Definition AASequence.h:88
Representation of an empirical formula.
Definition EmpiricalFormula.h:63
Parse Error exception.
Definition Exception.h:593
Parse error for mzPAF notation.
Definition MzPAF.h:210
MzPAFErrorCode getErrorCode() const noexcept
Definition MzPAF.h:222
size_t position_
Definition MzPAF.h:228
void extractContext_(const String &input, size_t pos)
MzPAFParseError(const char *file, int line, const char *function, MzPAFErrorCode error_code, size_t error_position, const String &input, const String &message) noexcept
size_t getPosition() const noexcept
Definition MzPAF.h:223
String context_before_
Definition MzPAF.h:229
MzPAFErrorCode code_
Definition MzPAF.h:227
String context_after_
Definition MzPAF.h:230
String getFormattedMessage() const
Parser and writer for mzPAF (Peak Annotation Format) notation.
Definition MzPAF.h:271
static String toString(const MzPAFPeakAnnotations &anns)
Convert multiple annotations to mzPAF string.
static MzPAFPeakAnnotations parseMultiple(const String &input)
Parse an mzPAF string with potentially multiple annotations.
static MzPAFAnnotation parse(const String &input)
Parse an mzPAF string into a single annotation.
static bool charToIonSeries(char c, MzPAFIonSeries &series)
Parse ion series from character.
static std::optional< MzPAFAnnotation > tryParse(const String &input)
Try to parse an mzPAF string (non-throwing)
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 standard fragment ion (a, b, c, x, y, z)
static std::optional< MzPAFPeakAnnotations > tryParseMultiple(const String &input)
Try to parse multiple annotations (non-throwing)
static std::optional< double > calculateTheoreticalMZ(const MzPAFAnnotation &ann, const AASequence &sequence)
Calculate theoretical m/z for an annotation.
static bool isMzPAFFormat(const String &annotation)
Check if a string appears to be in mzPAF format.
static MzPAFPeakAnnotations fromPeakAnnotation(const PeptideHit::PeakAnnotation &peak_annotation)
Parse mzPAF annotations from a PeptideHit::PeakAnnotation.
static String toString(const MzPAFAnnotation &ann)
Convert an annotation to mzPAF string.
MzPAF()=delete
static char ionSeriesToChar(MzPAFIonSeries series)
Get the ion series character for an annotation.
A more convenient string class.
Definition String.h:34
MzPAFIonSeries
Ion series types for mzPAF peak annotations.
Definition MzPAF.h:38
MzPAFErrorCode
Error codes for mzPAF parsing errors.
Definition MzPAF.h:182
MzPAFDeltaUnit
Unit for mass delta values in mzPAF annotations.
Definition MzPAF.h:60
@ X
x-ion (C-terminal)
@ C
c-ion (N-terminal, ETD)
@ INTERNAL
Internal fragment (m)
@ Z
z-ion (C-terminal, ETD)
@ Y
y-ion (C-terminal)
@ 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)
@ 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:121
std::optional< String > named_compound
Name for named compound ions (_[name])
Definition MzPAF.h:129
std::optional< char > immonium_residue
Residue for immonium ions (Y in IY)
Definition MzPAF.h:125
bool isValid() const
Check if this annotation has minimal valid data.
std::vector< MzPAFNeutralLoss > neutral_losses
Neutral losses (-H2O, -NH3, etc.)
Definition MzPAF.h:130
std::optional< String > embedded_sequence
Embedded ProForma sequence string ({LC[Carbamidomethyl]})
Definition MzPAF.h:136
std::optional< int > charge
Charge state (^2, ^3)
Definition MzPAF.h:133
std::optional< double > confidence
Confidence score (*0.75)
Definition MzPAF.h:135
std::optional< String > reporter_name
Name for reporter ions (r[TMT127N])
Definition MzPAF.h:127
std::optional< MzPAFMassDelta > mass_delta
Mass delta (/0.001, /-1.4ppm)
Definition MzPAF.h:134
std::optional< int > ordinal
Position/ordinal (4 in y4)
Definition MzPAF.h:124
bool operator!=(const MzPAFAnnotation &other) const
Definition MzPAF.h:143
std::optional< EmpiricalFormula > formula
Chemical formula for formula ions (f{C16H22O})
Definition MzPAF.h:128
std::optional< int > analyte_index
Analyte index (0@, 1@, etc.) for multi-analyte spectra.
Definition MzPAF.h:122
std::optional< EmpiricalFormula > adduct
Adduct ion (+Na, +K, etc.)
Definition MzPAF.h:132
std::optional< std::pair< int, int > > internal_range
Range for internal fragments (m3:6 -> {3,6})
Definition MzPAF.h:126
std::optional< int > isotope_offset
Isotope offset (+1i, +2i for M+1, M+2)
Definition MzPAF.h:131
bool operator==(const MzPAFAnnotation &other) const
Equality comparison.
Mass delta in an mzPAF annotation.
Definition MzPAF.h:89
bool operator!=(const MzPAFMassDelta &other) const
Definition MzPAF.h:94
bool operator==(const MzPAFMassDelta &other) const
Neutral loss in an mzPAF annotation.
Definition MzPAF.h:73
bool operator==(const MzPAFNeutralLoss &other) const
bool operator!=(const MzPAFNeutralLoss &other) const
Definition MzPAF.h:77
EmpiricalFormula formula
Parsed chemical formula of the loss.
Definition MzPAF.h:74
Multiple mzPAF annotations for a single peak.
Definition MzPAF.h:158
size_t size() const
Get number of annotations.
Definition MzPAF.h:165
bool empty() const
Check if there are any annotations.
Definition MzPAF.h:162
std::vector< MzPAFAnnotation > annotations
List of alternative annotations.
Definition MzPAF.h:159
bool operator!=(const MzPAFPeakAnnotations &other) const
Definition MzPAF.h:169
bool operator==(const MzPAFPeakAnnotations &other) const
Equality comparison.
Contains annotations of a peak.
Definition PeptideHit.h:87