OpenMS
Loading...
Searching...
No Matches
OpenMS::ML Namespace Reference

Classes

struct  PeptDeepInputBatch
 Flat tensor buffers and dimensions for a PeptDeep ONNX batch. More...
 
class  PeptDeepInputBuilder
 Shared featurization for PeptDeep RT, CCS, and MS2 ONNX predictors. More...
 
struct  PeptDeepInputConfig
 Sequence-padding policy for PeptDeep ONNX inputs. More...
 

Functions

int64_t instrumentIndex (std::string_view name)
 Instrument index for name, mirroring peptdeep's parse_instrument_indices().
 
void validateInstrumentIndices (const std::vector< int64_t > &instrument_indices)
 Validates instrument indices for PeptDeep MS2 inference.
 
OpenMS::Int64 getAAIndex (char aa)
 Maps amino acid characters to 1-based token indices for PeptDeep models.
 
void validatePeptide (const std::string &peptide)
 Validates a peptide sequence for PeptDeep inference. Complex character validation and modification parsing is handled downstream by AASequence.
 

Variables

constexpr int64_t PEPTDEEP_MOD_ELEMENTS = 109
 
constexpr std::array< std::string_view, 109 > ALPHAPEPTDEEP_MOD_ELEMENTS
 AlphaPeptDeep's exact 109-element array for modification tensor mapping. Elements missing from this list are binned into the final "Other" channel ("?"). Heavy isotopes (2H, 13C, 15N, 18O) map strictly to their dedicated channels.
 
constexpr int64_t PEPTDEEP_MAX_INSTRUMENT_NUM = 8
 Width of the instrument one-hot in AlphaPeptDeep's MS2 model.
 
constexpr int64_t PEPTDEEP_UNKNOWN_INSTRUMENT_INDEX = PEPTDEEP_MAX_INSTRUMENT_NUM - 1
 Index peptdeep gives an instrument it does not recognise (featurize.py: max_instrument_num - 1).
 
constexpr std::array< std::string_view, 5 > ALPHAPEPTDEEP_INSTRUMENTS
 AlphaPeptDeep's instrument names, in the order that is their encoding.
 

Class Documentation

◆ OpenMS::ML::PeptDeepInputBatch

struct OpenMS::ML::PeptDeepInputBatch

Flat tensor buffers and dimensions for a PeptDeep ONNX batch.

Class Members
vector< int64_t > aa_indices
size_t batch_size = 0
vector< float > charges
vector< int64_t > instrument_indices
vector< float > mod_x
vector< float > nces
size_t sequence_length = 0

◆ OpenMS::ML::PeptDeepInputConfig

struct OpenMS::ML::PeptDeepInputConfig

Sequence-padding policy for PeptDeep ONNX inputs.

Class Members
bool add_terminal_tokens = true Add PeptDeep terminal padding tokens around each peptide.
size_t fixed_sequence_length = 0

If non-zero, pad every batch to this fixed sequence length. If zero, pad only to the longest encoded peptide in the batch.

Function Documentation

◆ getAAIndex()

OpenMS::Int64 getAAIndex ( char  aa)
inline

Maps amino acid characters to 1-based token indices for PeptDeep models.

Converts uppercase and lowercase letters A-Z to indices 1-26 using canonical ord-offset encoding. Non-alphabetic characters map to 0, which serves as the padding and unknown token in PeptDeep ONNX input tensors.

Parameters
aaAmino acid character (case-insensitive)
Returns
Token index: 1-26 for A-Z/a-z, 0 for padding/unknown

◆ instrumentIndex()

int64_t instrumentIndex ( std::string_view  name)
inline

Instrument index for name, mirroring peptdeep's parse_instrument_indices().

Case-insensitive, as peptdeep's own lookup is, and a name that is not in ALPHAPEPTDEEP_INSTRUMENTS lands on the catch-all slot rather than on a neighbouring instrument. Prefer this over writing index literals: the order is peptdeep's, not ours.

Parameters
nameInstrument name, e.g. "QE" or "timsTOF".
Returns
Index in [0, PEPTDEEP_MAX_INSTRUMENT_NUM).

References ALPHAPEPTDEEP_INSTRUMENTS, and PEPTDEEP_UNKNOWN_INSTRUMENT_INDEX.

◆ validateInstrumentIndices()

void validateInstrumentIndices ( const std::vector< int64_t > &  instrument_indices)
inline

Validates instrument indices for PeptDeep MS2 inference.

Parameters
instrument_indicesOne index per peptide.
Exceptions
Exception::IllegalArgumentif an index is outside the one-hot the model encodes.

References PEPTDEEP_MAX_INSTRUMENT_NUM.

◆ validatePeptide()

void validatePeptide ( const std::string &  peptide)
inline

Validates a peptide sequence for PeptDeep inference. Complex character validation and modification parsing is handled downstream by AASequence.

Parameters
peptideThe raw peptide string to validate.

Variable Documentation

◆ ALPHAPEPTDEEP_INSTRUMENTS

constexpr std::array<std::string_view, 5> ALPHAPEPTDEEP_INSTRUMENTS
inlineconstexpr
Initial value:
= {
"QE", "Lumos", "timsTOF", "SciexTOF", "ThermoTOF"
}

AlphaPeptDeep's instrument names, in the order that is their encoding.

From model_const.yaml, whose own comment reads "We MUST keep the order of these instruments for models": position is the index the models were trained against, so entries may only be appended, never reordered or removed. The slots between the last name and PEPTDEEP_UNKNOWN_INSTRUMENT_INDEX are the room peptdeep has left for new instruments.

Referenced by instrumentIndex().

◆ ALPHAPEPTDEEP_MOD_ELEMENTS

constexpr std::array<std::string_view, 109> ALPHAPEPTDEEP_MOD_ELEMENTS
inlineconstexpr
Initial value:
= {
"C", "H", "N", "O", "P", "S", "B", "F", "I", "K", "U", "V", "W", "X", "Y",
"Ac", "Ag", "Al", "Am", "Ar", "As", "At", "Au", "Ba", "Be", "Bi", "Bk",
"Br", "Ca", "Cd", "Ce", "Cf", "Cl", "Cm", "Co", "Cr", "Cs", "Cu", "Dy",
"Er", "Es", "Eu", "Fe", "Fm", "Fr", "Ga", "Gd", "Ge", "He", "Hf", "Hg",
"Ho", "In", "Ir", "Kr", "La", "Li", "Lr", "Lu", "Md", "Mg", "Mn", "Mo",
"Na", "Nb", "Nd", "Ne", "Ni", "No", "Np", "Os", "Pa", "Pb", "Pd", "Pm",
"Po", "Pr", "Pt", "Pu", "Ra", "Rb", "Re", "Rh", "Rn", "Ru", "Sb", "Sc",
"Se", "Si", "Sm", "Sn", "Sr", "Ta", "Tb", "Tc", "Te", "Th", "Ti", "Tl",
"Tm", "Xe", "Yb", "Zn", "Zr", "2H", "13C", "15N", "18O", "?"
}

AlphaPeptDeep's exact 109-element array for modification tensor mapping. Elements missing from this list are binned into the final "Other" channel ("?"). Heavy isotopes (2H, 13C, 15N, 18O) map strictly to their dedicated channels.

◆ PEPTDEEP_MAX_INSTRUMENT_NUM

constexpr int64_t PEPTDEEP_MAX_INSTRUMENT_NUM = 8
constexpr

Width of the instrument one-hot in AlphaPeptDeep's MS2 model.

Mirrors max_instrument_num in peptdeep's model_const.yaml. Valid instrument indices are [0, PEPTDEEP_MAX_INSTRUMENT_NUM): the MS2 graph feeds the index through a OneHot of this width, so the bound is a property of the trained weights rather than a choice. Out of range is not an error to ONNX – its OneHot answers with an all-off row, which silently drops the instrument from the prediction – so it has to be rejected here instead. tools/scripts/export_peptdeep_models_to_onnx.py checks an exported graph against this.

Referenced by validateInstrumentIndices().

◆ PEPTDEEP_MOD_ELEMENTS

constexpr int64_t PEPTDEEP_MOD_ELEMENTS = 109
constexpr

◆ PEPTDEEP_UNKNOWN_INSTRUMENT_INDEX

constexpr int64_t PEPTDEEP_UNKNOWN_INSTRUMENT_INDEX = PEPTDEEP_MAX_INSTRUMENT_NUM - 1
constexpr

Index peptdeep gives an instrument it does not recognise (featurize.py: max_instrument_num - 1).

Referenced by instrumentIndex().