OpenMS
Loading...
Searching...
No Matches
MzPAF Class Reference

Parser and writer for mzPAF (Peak Annotation Format) notation. More...

#include <OpenMS/CHEMISTRY/MzPAF.h>

Static Public Member Functions

static MzPAFAnnotation parse (const std::string &input)
 Parse an mzPAF string into a single annotation.
 
static MzPAFPeakAnnotations parseMultiple (const std::string &input)
 Parse an mzPAF string with potentially multiple annotations.
 
static std::optional< MzPAFAnnotation > tryParse (const std::string &input)
 Try to parse an mzPAF string (non-throwing)
 
static std::optional< MzPAFPeakAnnotations > tryParseMultiple (const std::string &input)
 Try to parse multiple annotations (non-throwing)
 
static std::string toString (const MzPAFAnnotation &ann)
 Convert an annotation to mzPAF string.
 
static std::string toString (const MzPAFPeakAnnotations &anns)
 Convert multiple annotations to mzPAF string.
 
static PeptideHit::PeakAnnotation toPeakAnnotation (const MzPAFAnnotation &mzpaf, double mz, double intensity)
 Create a PeptideHit::PeakAnnotation from mzPAF data.
 
static MzPAFPeakAnnotations fromPeakAnnotation (const PeptideHit::PeakAnnotation &peak_annotation)
 Parse mzPAF annotations from a PeptideHit::PeakAnnotation.
 
static bool isMzPAFFormat (const std::string &annotation)
 Check if a string appears to be in mzPAF format.
 
static std::optional< double > calculateTheoreticalMZ (const MzPAFAnnotation &ann, const AASequence &sequence)
 Calculate theoretical m/z for an annotation.
 
static bool isPeptideFragmentIon (MzPAFIonSeries series)
 Check if ion series is a peptide fragment ion (a, b, c, d, v, w, x, y, z)
 
static char ionSeriesToChar (MzPAFIonSeries series)
 Get the ion series character for an annotation.
 
static bool charToIonSeries (char c, MzPAFIonSeries &series)
 Parse ion series from character.
 

Private Member Functions

 MzPAF ()=delete
 

Detailed Description

Parser and writer for mzPAF (Peak Annotation Format) notation.

mzPAF is the HUPO-PSI standard string notation for fragment ion peak annotations, used in mzSpecLib and other spectral library formats.

This class provides static methods for:

Usage example:

// Parse a single annotation
MzPAFAnnotation ann = MzPAF::parse("y4^2-H2O/0.001*0.75");
// Parse multiple annotations (comma-separated)
// Convert back to string
std::string s = MzPAF::toString(ann);
// Check if a string is mzPAF format
if (MzPAF::isMzPAFFormat("y4^2")) { ... }
static MzPAFAnnotation parse(const std::string &input)
Parse an mzPAF string into a single annotation.
static MzPAFPeakAnnotations parseMultiple(const std::string &input)
Parse an mzPAF string with potentially multiple annotations.
static bool isMzPAFFormat(const std::string &annotation)
Check if a string appears to be in mzPAF format.
static std::string toString(const MzPAFAnnotation &ann)
Convert an annotation to mzPAF string.
A single mzPAF peak annotation.
Definition MzPAF.h:129
Multiple mzPAF annotations for a single peak.
Definition MzPAF.h:167
See also
MzPAFAnnotation, MzPAFPeakAnnotations

Constructor & Destructor Documentation

◆ MzPAF()

MzPAF ( )
privatedelete

Member Function Documentation

◆ calculateTheoreticalMZ()

static std::optional< double > calculateTheoreticalMZ ( const MzPAFAnnotation &  ann,
const AASequence &  sequence 
)
static

Calculate theoretical m/z for an annotation.

Calculates the theoretical m/z value for the annotated ion based on the sequence.

Note
Satellite ions (d, v, w, including their subtypes) are parsed and serialized, but their residue-dependent side-chain losses are not yet supported here; these ions return std::nullopt.
Parameters
[in]annThe annotation
[in]sequenceThe peptide sequence
Returns
Theoretical m/z, or std::nullopt if calculation not possible

◆ charToIonSeries()

static bool charToIonSeries ( char  c,
MzPAFIonSeries &  series 
)
static

Parse ion series from character.

Parameters
[in]cThe character to parse
[out]seriesOutput ion series if successful
Returns
True if parsing successful

◆ fromPeakAnnotation()

static MzPAFPeakAnnotations fromPeakAnnotation ( const PeptideHit::PeakAnnotation &  peak_annotation)
static

Parse mzPAF annotations from a PeptideHit::PeakAnnotation.

Attempts to parse the annotation string from a PeakAnnotation as mzPAF.

Parameters
[in]peak_annotationThe PeakAnnotation to parse
Returns
Parsed mzPAF annotations, or empty if not valid mzPAF

◆ ionSeriesToChar()

static char ionSeriesToChar ( MzPAFIonSeries  series)
static

Get the ion series character for an annotation.

Parameters
[in]seriesThe ion series enum
Returns
The character representation (a, b, c, d, v, w, x, y, z, p, I, m, r, f, _)
Note
The satellite subtype is stored separately in MzPAFAnnotation::satellite_subtype.

◆ isMzPAFFormat()

static bool isMzPAFFormat ( const std::string &  annotation)
static

Check if a string appears to be in mzPAF format.

Performs a quick heuristic check to determine if a string looks like mzPAF notation.

Parameters
[in]annotationThe string to check
Returns
True if the string appears to be mzPAF format

◆ isPeptideFragmentIon()

static bool isPeptideFragmentIon ( MzPAFIonSeries  series)
static

Check if ion series is a peptide fragment ion (a, b, c, d, v, w, x, y, z)

These are exactly the series that mzPAF requires to carry an ordinal.

Parameters
[in]seriesThe ion series to check
Returns
True if it's a peptide fragment ion type
Note
True here does not imply a computable mass. calculateTheoreticalMZ() returns std::nullopt for the satellite series d/v/w, so if (isPeptideFragmentIon(s)) mz = *calculateTheoreticalMZ(...) would dereference an empty optional.

◆ parse()

static MzPAFAnnotation parse ( const std::string &  input)
static

Parse an mzPAF string into a single annotation.

Parameters
[in]inputThe mzPAF string to parse
Returns
The parsed annotation
Exceptions
MzPAFParseErrorif parsing fails
Note
If the input contains multiple comma-separated annotations, only the first is returned. Use parseMultiple() for multi-annotation strings.

◆ parseMultiple()

static MzPAFPeakAnnotations parseMultiple ( const std::string &  input)
static

Parse an mzPAF string with potentially multiple annotations.

Parameters
[in]inputThe mzPAF string to parse (may contain comma-separated annotations)
Returns
All parsed annotations
Exceptions
MzPAFParseErrorif parsing fails

◆ toPeakAnnotation()

static PeptideHit::PeakAnnotation toPeakAnnotation ( const MzPAFAnnotation &  mzpaf,
double  mz,
double  intensity 
)
static

Create a PeptideHit::PeakAnnotation from mzPAF data.

Converts an MzPAFAnnotation to the OpenMS PeakAnnotation format used in PeptideHit.

Parameters
[in]mzpafThe mzPAF annotation
[in]mzThe observed m/z value
[in]intensityThe peak intensity
Returns
A PeptideHit::PeakAnnotation

◆ toString() [1/2]

static std::string toString ( const MzPAFAnnotation &  ann)
static

Convert an annotation to mzPAF string.

Parameters
[in]annThe annotation to convert
Returns
The mzPAF string representation
Note
This function is total and never throws. An annotation carrying a satellite subtype that mzPAF does not allow – anything other than 'a'/'b', or a subtype on a series other than d/w – is written without it, mirroring how an UNKNOWN series is written as '?'. Use isValid() to reject such an annotation.

◆ toString() [2/2]

static std::string toString ( const MzPAFPeakAnnotations &  anns)
static

Convert multiple annotations to mzPAF string.

Parameters
[in]annsThe annotations to convert
Returns
The mzPAF string representation (comma-separated)

◆ tryParse()

static std::optional< MzPAFAnnotation > tryParse ( const std::string &  input)
static

Try to parse an mzPAF string (non-throwing)

Parameters
[in]inputThe mzPAF string to parse
Returns
The parsed annotation, or std::nullopt on failure

◆ tryParseMultiple()

static std::optional< MzPAFPeakAnnotations > tryParseMultiple ( const std::string &  input)
static

Try to parse multiple annotations (non-throwing)

Parameters
[in]inputThe mzPAF string to parse
Returns
The parsed annotations, or empty on failure