OpenMS
Loading...
Searching...
No Matches
PeptDeepUtils.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Satyam Yadav $
7// --------------------------------------------------------------------------
8#pragma once
9
12#include <string>
13#include <vector>
14
15namespace OpenMS {
16 namespace ML {
17
18 // --- Shared PeptDeep Architecture Constants ---
19 constexpr int64_t PEPTDEEP_MOD_ELEMENTS = 109;
20 const std::string PEPTDEEP_VALID_AAS = "ACDEFGHIKLMNPQRSTVWY";
21
32 inline OpenMS::Int64 getAAIndex(char aa) {
33 if (aa >= 'A' && aa <= 'Z') return aa - 'A' + 1;
34 if (aa >= 'a' && aa <= 'z') return aa - 'a' + 1;
35 return 0; // 0 serves as the padding and unknown token
36 }
37
43 inline void validatePeptide(const std::string& peptide) {
44 if (peptide.empty()) {
45 throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Peptide sequence cannot be empty.");
46 }
47 if (peptide.find_first_of("[]()") != std::string::npos) {
48 throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Modified peptides are not currently supported in this engine.");
49 }
50 if (peptide.find_first_not_of(PEPTDEEP_VALID_AAS) != std::string::npos) {
51 throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Unsupported residue encountered.", peptide);
52 }
53 }
54
59 inline std::vector<float> generateUnmodifiedModXTensor(size_t batch_size, size_t sequence_length) {
60 return std::vector<float>(batch_size * sequence_length * PEPTDEEP_MOD_ELEMENTS, 0.0f);
61 }
62
63 }
64}
A method or algorithm argument contains illegal values.
Definition Exception.h:633
Invalid value exception.
Definition Exception.h:306
int64_t Int64
Signed integer type (64bit)
Definition Types.h:40
OpenMS::Int64 getAAIndex(char aa)
Maps amino acid characters to 1-based token indices for PeptDeep models.
Definition PeptDeepUtils.h:32
constexpr int64_t PEPTDEEP_MOD_ELEMENTS
Definition PeptDeepUtils.h:19
const std::string PEPTDEEP_VALID_AAS
Definition PeptDeepUtils.h:20
std::vector< float > generateUnmodifiedModXTensor(size_t batch_size, size_t sequence_length)
Generates an empty mod_x tensor for unmodified peptides. Resolves to a flat vector of zeros of size (...
Definition PeptDeepUtils.h:59
void validatePeptide(const std::string &peptide)
Validates a peptide sequence for PeptDeep inference. Throws explicit OpenMS exceptions if the sequenc...
Definition PeptDeepUtils.h:43
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19