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

Generates from a set of Fasta files a 2D-datastructure which stores all theoretical masses of all b and y ions from all peptides generated from the Fasta file. The datastructure is build such that on one axis the fragments are sorted by their own mass and the axis by the mass of their precursor/protein. The FI has two options: Bottom-up and Top Down. In later digestion is skiped and the fragments have a direct reference to the mass of the proteins instead of digested peptides. More...

#include <OpenMS/ANALYSIS/ID/FragmentIndex.h>

Inheritance diagram for FragmentIndex:
DefaultParamHandler

Classes

struct  CandidateBlock_
 One (precursor charge, isotope error) block of a queryPeaks() call. More...
 
struct  Fragment
 One entry in the fragment index. More...
 
struct  Hit
 
struct  IonOffsets
 Precomputed ion-type mass offsets (from Residue::getInternalTo*Ion formulas) More...
 
struct  ModShift_
 
struct  ModSlot
 A candidate modification slot for a specific peptide. More...
 
struct  Peptide
 Compact descriptor of a peptide instance held by the FragmentIndex. More...
 
struct  PeptidoformRendering_
 Rendering classes of the configured modifications, for samePeptidoform_() (peptide:deduplicate) More...
 
struct  RemovedOccurrence
 A protein occurrence of an indexed peptidoform that peptide:deduplicate removed from the index. More...
 
struct  SpectrumMatch
 Match between a query peak and an entry in the DB. More...
 
struct  SpectrumMatchesTopN
 container for SpectrumMatch. Also keeps count of total number of candidates and total number of matches. More...
 
struct  VarModEntry
 Entry in the per-AA variable modification lookup table. More...
 

Public Member Functions

 FragmentIndex ()
 Default constructor.
 
 ~FragmentIndex () override=default
 Default destructor.
 
 FragmentIndex (const FragmentIndex &)=default
 Copy and move operations.
 
FragmentIndex & operator= (const FragmentIndex &)=default
 
 FragmentIndex (FragmentIndex &&)=default
 
FragmentIndex & operator= (FragmentIndex &&)=default
 
bool isBuild () const
 Indicates whether the fragment index has been built.
 
const std::vector< Peptide > & getPeptides () const
 Returns a reference to the internal peptide container.
 
const std::vector< RemovedOccurrence > & getRemovedOccurrences () const noexcept
 The protein occurrences that peptide:deduplicate removed, ordered by RemovedOccurrence::peptide_idx and, for one kept entry, in the order of the entries before deduplication (sortPeptides_() order).
 
bool hasProteinOccurrences (const std::vector< FASTAFile::FASTAEntry > &fasta_entries) const
 Whether getProteinOccurrences() lists every span of the digest that has the residues of an index peptide.
 
void getProteinOccurrences (Size peptide_idx, const std::vector< FASTAFile::FASTAEntry > &fasta_entries, std::vector< std::pair< UInt32, UInt32 > > &occurrences) const
 Appends the protein occurrences {protein index, start} of the residues of getPeptides()[peptide_idx].
 
Size getNumFragments () const noexcept
 
void build (const std::vector< FASTAFile::FASTAEntry > &fasta_entries)
 Given a set of Fasta files, builds the Fragment Index datastructure (FID). First all fragments are sorted by their own mass. Next they are placed in buckets. The min-fragment mass is stored for each bucket, whereupon the fragments are sorted within the buckets by their originating precursor mass. Replaces any previously built index; a failed build leaves isBuild() false.
 
void build (const std::vector< FASTAFile::FASTAEntry > &fasta_entries, const std::function< const MSExperiment *(Size)> &searched_spectra)
 Builds the index like build(fasta_entries), but only with the peptides that the spectra to be searched can reach.
 
void clear ()
 Delete fragment index. Sets is_build=false.
 
std::pair< size_t, size_t > getPeptidesInMassWindow (float precursor_mass, const std::pair< float, float > &window) const
 
- Public Member Functions inherited from DefaultParamHandler
 DefaultParamHandler (const std::string &name)
 Constructor with name that is displayed in error messages.
 
 DefaultParamHandler (const DefaultParamHandler &rhs)
 Copy constructor.
 
virtual ~DefaultParamHandler ()
 Destructor.
 
DefaultParamHandler & operator= (const DefaultParamHandler &rhs)
 Assignment operator.
 
virtual bool operator== (const DefaultParamHandler &rhs) const
 Equality operator.
 
void setParameters (const Param &param)
 Sets the parameters.
 
const Param & getParameters () const
 Non-mutable access to the parameters.
 
const Param & getDefaults () const
 Non-mutable access to the default parameters.
 
const std::string & getName () const
 Non-mutable access to the name.
 
void setName (const std::string &name)
 Mutable access to the name.
 
const std::vector< std::string > & getSubsections () const
 Non-mutable access to the registered subsections.
 

Static Public Member Functions

static bool isOpenSearchMode (double lower_magnitude, double upper_magnitude, bool unit_ppm) noexcept
 
static void checkFixedModifications (const StringList &fixed_modifications)
 Rejects fixed terminal modifications that the index cannot restrict to the peptides they apply to.
 
static StringList shadowedVariableTerminalModifications (const StringList &fixed_modifications, const StringList &variable_modifications)
 Variable terminal modifications that a fixed terminal modification excludes.
 
static StringList shadowedVariableResidueModifications (const StringList &fixed_modifications, const StringList &variable_modifications)
 Variable residue modifications that a fixed modification of the same residue excludes.
 
- Static Public Member Functions inherited from DefaultParamHandler
static void writeParametersToMetaValues (const Param &write_this, MetaInfoInterface &write_here, const std::string &key_prefix="")
 Writes all parameters to meta values.
 

Peptide-mass mode (low_memory)

When the index is built in peptide-mass mode (isPeptideMassMode), a Peptide entry represents a mother peptide: the longest peptide (at most peptide:max_size residues) that starts at a position of a protein. Every sub-peptide of the non-specific digest is a prefix of the mother at its start, so the mothers hold the digest in one entry per protein position instead of one per (start, length, variable modifications) as the fragment index. mod_bitmask_ of a mother is 0, precursor_mz_ its own (M+H)+.

The index holds no fragments of the mothers. Instead, its entries are the (M+H)+ of every unmodified prefix of a mother with a length in [peptide:min_size, peptide:max_size], sorted by mass. A query looks up the prefixes whose mass, shifted by any sum of variable modification deltas, lies in a precursor window, generates the fragments of each such peptidoform as the fragment index would (same ion series, fragment:min_ion_index and m/z range) and counts the peaks they match. The candidates and their numbers of matched fragments are therefore those of the fragment index, which needs far more memory for a non-specific digest. Only which of equally ranked candidates of one protein survive the cut to scoring:max_candidates_per_spectrum can differ (see querySpectrumPeptideMasses_()).

bool is_build_ {false}
 true, if the database has been populated with fragments
 
std::array< double, 128 > fixed_mod_deltas_ {}
 Per-AA fixed modification delta mass (0.0 if no fixed mod applies)
 
std::array< const ResidueModification *, 128 > fixed_mod_ptrs_ {}
 Per-AA fixed modification pointer (nullptr if none)
 
double fixed_nterm_delta_ {0.0}
 Fixed N-terminal mod delta (0 if none)
 
double fixed_cterm_delta_ {0.0}
 Fixed C-terminal mod delta (0 if none)
 
const ResidueModification * fixed_nterm_mod_ptr_ {nullptr}
 
const ResidueModification * fixed_cterm_mod_ptr_ {nullptr}
 
std::array< std::vector< VarModEntry >, 128 > variable_mod_table_ {}
 Per-AA variable modification table: for each ASCII char, list of possible variable mods.
 
std::vector< VarModEntry > variable_nterm_mods_
 Pure N-terminal variable mods (not residue-specific)
 
std::vector< VarModEntry > variable_cterm_mods_
 Pure C-terminal variable mods (not residue-specific)
 
bool mod_tables_initialized_ {false}
 
std::array< double, 128 > fixed_residue_masses_ {}
 
bool is_peptide_mass_mode_ {false}
 
std::vector< double > sigma_delta_set_
 
std::vector< double > sigma_delta_set_with_prot_nterm_
 Peptide-mass mode: as sigma_delta_set_, with the PROTEIN_N_TERM variable modifications.
 
std::vector< double > sigma_delta_set_with_prot_cterm_
 Peptide-mass mode: as sigma_delta_set_, with the PROTEIN_C_TERM variable modifications.
 
bool zero_sigma_subsets_ {false}
 
std::vector< ModShift_ > mod_shifts_
 
double min_mod_shift_ {0.0}
 Peptide-mass mode: smallest and largest shift (0 if no variable modification is configured)
 
double max_mod_shift_ {0.0}
 
bool entry_sites_ {false}
 whether the entries carry the bound
 
std::vector< Peptide > fi_peptides_
 vector of all (digested) peptides
 
std::vector< RemovedOccurrence > removed_occurrences_
 occurrences removed by peptide:deduplicate (getRemovedOccurrences())
 
std::vector< Fragment > fi_fragments_
 
std::vector< Fragment > electron_fragments_
 
std::vector< float > electron_bucket_min_mz_
 smallest fragment m/z of each bucket of electron_fragments_
 
std::vector< uint32_t > protein_lengths_
 Protein lengths indexed by protein_idx, populated at build() time.
 
float fragment_min_mz_
 smallest fragment mz
 
float fragment_max_mz_
 largest fragment mz
 
size_t min_ion_index_ {0}
 skip ions below this index (0=all, 2=skip b1/b2/y1/y2)
 
size_t bucketsize_
 number of fragments per outer node
 
std::vector< float > bucket_min_mz_
 vector of the smalles fragment mz of each bucket
 
double precursor_mass_tolerance_lower_ {20.0}
 positive magnitude, effective lower bound is -lower
 
double precursor_mass_tolerance_upper_ {20.0}
 positive magnitude, effective upper bound is +upper
 
bool precursor_mass_tolerance_unit_ppm_ {true}
 
float fragment_mz_tolerance_
 
bool fragment_mz_tolerance_unit_ppm_ {true}
 
static constexpr size_t MAX_MOD_SLOTS = 32
 max variable mod slots per peptide (uint32_t bitmask)
 
static constexpr uint32_t ENTRY_SITES_SHIFT_ = 28
 
static constexpr uint32_t ENTRY_MOTHER_MASK_ = (1u << ENTRY_SITES_SHIFT_) - 1
 
static constexpr uint32_t ENTRY_MAX_SITES_ = (1u << (32 - ENTRY_SITES_SHIFT_)) - 1
 
static std::array< double, 128 > residue_mass_table_
 
static std::once_flag mass_table_once_flag_
 
static IonOffsets ion_offsets_
 
static constexpr size_t SKIP_STRIDE_ = 64
 
size_t skip_per_bucket_ {0}
 
std::vector< UInt32 > bucket_skip_
 
std::vector< UInt32 > electron_bucket_skip_
 
bool add_b_ions_
 
bool add_y_ions_
 
bool add_a_ions_
 
bool add_c_ions_
 
bool add_x_ions_
 
bool add_z_ions_
 
bool add_zp1_ions_
 
bool electron_ions_ {false}
 ions:electron_ions: also index c and z+1 ions, in electron_fragments_
 
std::string digestion_enzyme_
 
EnzymaticDigestion::Specificity enzyme_specificity_ {EnzymaticDigestion::SPEC_FULL}
 'full' (default), 'semi' (semi-tryptic), or 'none' (e.g. immunopeptidomics)
 
bool clip_nterm_methionine_ {false}
 Include initial Met loss (enabled by ProSE).
 
size_t missed_cleavages_
 number of missed cleavages
 
float peptide_min_mass_
 
float peptide_max_mass_
 
size_t peptide_min_length_
 
size_t peptide_max_length_
 
StringList modifications_fixed_
 Modification that are one all peptides.
 
StringList modifications_variable_
 Variable Modification -> all possible comibnations are created.
 
size_t max_variable_mods_per_peptide_
 
uint16_t min_matched_peaks_
 PSM with less hits are discarded.
 
int16_t min_isotope_error_
 Minimal possible isotope error.
 
int16_t max_isotope_error_
 Maximal possible isotope error (both only used for closed search)
 
uint16_t min_precursor_charge_
 minimal possible precursor charge (usually always 1)
 
uint16_t max_precursor_charge_
 maximal possible precursor charge
 
uint16_t max_fragment_charge_
 The maximal possible charge of the fragments.
 
uint32_t max_processed_hits_
 The amount of PSM that will be used. the rest is filtered out.
 
bool deduplicate_ {false}
 peptide:deduplicate
 
bool isPeptideMassMode () const noexcept
 
std::vector< Hit > query (const Peak1D &peak, const std::pair< size_t, size_t > &peptide_idx_range, uint16_t peak_charge)
 Queries one peak (against the ion series of the ions:add_*_ions parameters, not the c and z+1 ions of ions:electron_ions)
 
void querySpectrum (const MSSpectrum &spectrum, SpectrumMatchesTopN &sms)
 : queries one complete experimental spectra against the Database. Loops over all precursor charges Starts at min_precursor_charge and iteratively goes to max_precursor_charge. We query all peaks multiple times with all the different precursor charges and corresponding precursor masses. Returns no matches in peptide-mass mode, which needs the FASTA entries (see the overload that takes them).
 
void querySpectrum (const MSSpectrum &spectrum, const std::vector< FASTAFile::FASTAEntry > &fasta_entries, SpectrumMatchesTopN &sms)
 Query a spectrum against the fragment index with FASTA context.
 
void querySpectrum (const MSSpectrum &spectrum, const std::vector< FASTAFile::FASTAEntry > &fasta_entries, SpectrumMatchesTopN &sms, bool with_electron_ions)
 Query a spectrum, optionally also against the c and z+1 ions of ions:electron_ions.
 
AASequence reconstructModifiedSequence (const Peptide &peptide, const std::vector< FASTAFile::FASTAEntry > &fasta_entries) const
 Reconstruct a fully modified AASequence from a Peptide's bitmask.
 
int realizePrefixLength (const Peptide &mother, const std::vector< FASTAFile::FASTAEntry > &fasta_entries, double target_mh_plus, double tolerance_lower_magnitude, double tolerance_upper_magnitude, bool tolerance_ppm) const
 Find the realized sub-peptide length of a mother that best matches the observed precursor mass.
 
AASequence reconstructRealizedSubSequence (const Peptide &mother, const std::vector< FASTAFile::FASTAEntry > &fasta_entries, size_t realized_length, uint32_t subset_bitmask=0) const
 
void updateMembers_ () override
 This method is used to update extra member variables at the end of the setParameters() method.
 
void generatePeptides (const std::vector< FASTAFile::FASTAEntry > &fasta_entries)
 Generates all peptides from given fasta entries. If Bottom-up is set to false skips digestion. If set to true the Digestion enzyme can be set in the parameters. Additionally introduces fixed and variable modifications for restrictive PSM search.
 
void generateMothers_ (const std::vector< FASTAFile::FASTAEntry > &fasta_entries)
 Peptide-mass mode peptide enumeration: emit the mother peptides.
 
PeptidoformRendering_ peptidoformRendering_ () const
 Rendering classes of the configured modifications. Requires the modification tables (generatePeptides()).
 
void renderPeptidoform_ (const Peptide &peptide, const std::vector< FASTAFile::FASTAEntry > &fasta_entries, const PeptidoformRendering_ &rendering, std::vector< uint32_t > &tokens) const
 
bool samePeptidoform_ (const Peptide &a, const Peptide &b, const std::vector< FASTAFile::FASTAEntry > &fasta_entries, const PeptidoformRendering_ &rendering, std::vector< uint32_t > &tokens_a, std::vector< uint32_t > &tokens_b) const
 Whether reconstructModifiedSequence() renders a and b to the same AASequence::toString().
 
Size deduplicateByString_ (const std::vector< FASTAFile::FASTAEntry > &fasta_entries)
 Keeps the first entry of fi_peptides_ of every reconstructModifiedSequence(...).toString(), in order.
 
void initModificationTables_ ()
 
size_t buildModSlots_ (const char *sequence, size_t seq_len, ModSlot *out_slots, bool is_protein_nterm=false, bool is_protein_cterm=false) const
 
std::vector< double > computeSigmaDeltaSet_ (bool include_prot_nterm_mods, bool include_prot_cterm_mods) const
 
std::vector< std::vector< double > > modShiftLevels_ (bool include_prot_nterm_mods, bool include_prot_cterm_mods) const
 
bool nonemptyZeroSigmaSubsetExists_ () const
 Whether a nonempty subset of at most max_variable_mods_per_peptide_ variable modifications has Σ = 0 (zero_sigma_subsets_)
 
template<typename FragmentSink >
void generatePeptidoformFragments_ (FragmentSink &fragments, FragmentSink &electron_fragments, const char *sequence, size_t seq_len, UInt32 peptide_idx, uint32_t slot_bits, const ModSlot *slots, size_t n_slots, std::vector< double > &mod_masses) const
 Generates the fragments of a peptidoform, as the index holds them.
 
template<typename F >
void forEachPrefixMass_ (const char *sequence, size_t len, F &&f) const
 
template<typename FragmentSink >
void generateFragmentsLightweight_ (FragmentSink &fragments, FragmentSink &electron_fragments, const char *sequence, size_t seq_len, UInt32 peptide_idx, double n_term_mod_mass, double c_term_mod_mass, const double *residue_masses, const double *residue_mod_masses) const
 
template<typename FragmentSink >
void generateFragmentsForSeries_ (FragmentSink &fragments, const char *sequence, size_t seq_len, UInt32 peptide_idx, double n_term_mod_mass, double c_term_mod_mass, const double *residue_masses, const double *residue_mod_masses, bool add_b, bool add_a, bool add_c, bool add_y, bool add_x, bool add_z, bool add_zp1) const
 
static void sortPeptides_ (std::vector< Peptide > &peptides, size_t min_task_size=8192)
 Sorts peptides by (precursor_mz_, protein_idx), exactly as std::sort does with that comparator.
 
static void initResidueMassTable_ ()
 
void querySpectrumPeptideMasses_ (const MSSpectrum &spectrum, const std::vector< FASTAFile::FASTAEntry > &fasta_entries, SpectrumMatchesTopN &sms, bool with_electron_ions)
 Peptide-mass mode spectrum query: the candidates and matched-fragment counts of the fragment index.
 
void queryPeaks (SpectrumMatchesTopN &candidates, const MSSpectrum &spectrum, const std::vector< CandidateBlock_ > &blocks, const uint16_t precursor_charge, const bool with_electron_ions)
 Counts fragment matches for the (isotope error) blocks of ONE precursor charge and appends the surviving candidates to candidates.
 
void buildSkipTables_ ()
 Fills the skip tables; called by build() once the buckets are sorted.
 
void searchDifferentPrecursorRanges (const MSSpectrum &spectrum, float precursor_mass, SpectrumMatchesTopN &sms, uint16_t charge, bool with_electron_ions)
 If closed search collects the candidate ranges of all isotope errors and loops over all peaks once for them with queryPeaks.
 
void sortAndBucketFragments_ (std::vector< Fragment > &fragments, std::vector< float > &bucket_min_mz, int num_threads)
 
void trimHits (SpectrumMatchesTopN &init_hits) const
 places the k-largest elements in the front of the input array. Inside of the k-largest elements and outside the elements are not sorted
 
bool isProteinNTerminal_ (const std::string &protein, Size start) const
 Whether a position is the original or, with Met clipping enabled, mature protein N-terminus.
 
bool isOpenSearchMode_ () const noexcept
 Instance delegate — same rule, reads the member bounds.
 
std::pair< float, float > computeMassWindow_ (float precursor_mass) const
 
void keepPeptidesInPrecursorWindows_ (const MSExperiment &spectra)
 

Additional Inherited Members

- Protected Member Functions inherited from DefaultParamHandler
void defaultsToParam_ ()
 Updates the parameters after the defaults have been set in the constructor.
 
- Protected Attributes inherited from DefaultParamHandler
Param param_
 Container for current parameters.
 
Param defaults_
 Container for default parameters. This member should be filled in the constructor of derived classes!
 
std::vector< std::string > subsections_
 Container for registered subsections. This member should be filled in the constructor of derived classes!
 
std::string error_name_
 Name that is displayed in error messages during the parameter checking.
 
bool check_defaults_
 If this member is set to false no checking if parameters in done;.
 
bool warn_empty_defaults_
 If this member is set to false no warning is emitted when defaults are empty;.
 

Detailed Description

Generates from a set of Fasta files a 2D-datastructure which stores all theoretical masses of all b and y ions from all peptides generated from the Fasta file. The datastructure is build such that on one axis the fragments are sorted by their own mass and the axis by the mass of their precursor/protein. The FI has two options: Bottom-up and Top Down. In later digestion is skiped and the fragments have a direct reference to the mass of the proteins instead of digested peptides.


Class Documentation

◆ OpenMS::FragmentIndex::CandidateBlock_

struct OpenMS::FragmentIndex::CandidateBlock_

One (precursor charge, isotope error) block of a queryPeaks() call.

Class Members
size_t cell_offset sum of the range sizes of the preceding blocks of the call
size_t first half-open range [first, second) of peptides the precursor could belong to
int16_t isotope_error the applied isotope error
size_t second

◆ OpenMS::FragmentIndex::IonOffsets

struct OpenMS::FragmentIndex::IonOffsets

Precomputed ion-type mass offsets (from Residue::getInternalTo*Ion formulas)

Class Members
double a_offset {0.0}
double b_offset {0.0}
double c_offset {0.0}
double x_offset {0.0}
double y_offset {0.0}
double z_offset {0.0}
double zp1_offset {0.0} z+1 (z-dot) ions, the main C-terminal fragments of ETD-type spectra

◆ OpenMS::FragmentIndex::ModShift_

struct OpenMS::FragmentIndex::ModShift_

Peptide-mass mode: a shift Σ at which querySpectrumPeptideMasses_() looks up prefixes. A peptidoform belongs to the shift closest to the sum of its modification deltas.

Class Members
size_t min_mods the fewest variable modifications that sum to it (within the matching tolerance)
bool protein_terminal only reached with a protein-terminal modification: the prefix must start or end a protein
double sigma the shift

◆ OpenMS::FragmentIndex::RemovedOccurrence

struct OpenMS::FragmentIndex::RemovedOccurrence

A protein occurrence of an indexed peptidoform that peptide:deduplicate removed from the index.

The removed entry had the same peptidoform (reconstructModifiedSequence(...).toString()) as the kept entry getPeptides()[peptide_idx], hence the same length; it started at start in protein protein_idx.

Class Members
UInt32 peptide_idx index into getPeptides() of the kept entry of the same peptidoform
UInt32 protein_idx protein of the removed entry (index into the FASTA entries passed to build())
uint16_t start 0-based start of the removed entry in that protein

◆ OpenMS::FragmentIndex::SpectrumMatch

struct OpenMS::FragmentIndex::SpectrumMatch

Match between a query peak and an entry in the DB.

Class Members
int16_t isotope_error_ {} The isotope_error used for the performed search.
uint32_t num_matched_ {} Number of peaks-fragment hits.
size_t peptide_idx_ {} The idx this struct belongs to.
uint16_t precursor_charge_ {} The precursor_charge used for the performed search.
uint16_t realized_length_ {} Peptide-mass mode: length of the realized sub-peptide, a prefix of the mother peptide_idx_. 0 without low_memory.
float sigma_delta_ {} Peptide-mass mode: Σ of the variable-mod deltas of subset_bitmask_. 0 without low_memory or unmodified.
uint32_t subset_bitmask_ {} Peptide-mass mode: active slots in the slot list returned by buildModSlots_ for the realized sub-peptide. 0 = unmodified. Ignored without low_memory.

◆ OpenMS::FragmentIndex::VarModEntry

struct OpenMS::FragmentIndex::VarModEntry

Entry in the per-AA variable modification lookup table.

Class Members
double delta_mass mass delta from this modification
const ResidueModification * mod_ptr pointer to the modification (for AASequence reconstruction)
TermSpecificity term_spec where this mod can be applied

Constructor & Destructor Documentation

◆ FragmentIndex() [1/3]

Default constructor.

Initializes an empty FragmentIndex. Call build() before using any query functions. After clear(), the index returns to this unbuilt state.

Thread-safety: constructing the object is thread-safe as long as the instance is not shared across threads before initialization completes.

◆ ~FragmentIndex()

~FragmentIndex ( )
overridedefault

Default destructor.

Releases owned memory. If the index was built, all internal buffers and fragment buckets are freed. No exceptions are thrown.

◆ FragmentIndex() [2/3]

FragmentIndex ( const FragmentIndex &  )
default

Copy and move operations.

Declared explicitly because the user-declared destructor above suppresses the implicit move operations: without them, every move of a FragmentIndex (and of a ProSEAlgorithm::SearchContext that holds one) copies the whole index.

◆ FragmentIndex() [3/3]

FragmentIndex ( FragmentIndex &&  )
default

Member Function Documentation

◆ build() [1/2]

void build ( const std::vector< FASTAFile::FASTAEntry > &  fasta_entries)

Given a set of Fasta files, builds the Fragment Index datastructure (FID). First all fragments are sorted by their own mass. Next they are placed in buckets. The min-fragment mass is stored for each bucket, whereupon the fragments are sorted within the buckets by their originating precursor mass. Replaces any previously built index; a failed build leaves isBuild() false.

Parameters
[in]fasta_entriesThe FASTA entries used to build the index.

◆ build() [2/2]

void build ( const std::vector< FASTAFile::FASTAEntry > &  fasta_entries,
const std::function< const MSExperiment *(Size)> &  searched_spectra 
)

Builds the index like build(fasta_entries), but only with the peptides that the spectra to be searched can reach.

Once the peptides are generated and sorted, searched_spectra is called with their number (to judge whether waiting for spectra that are still being read pays off); it may block. If it returns spectra, every peptide whose precursor mass lies in none of their precursor windows (each charge and isotope error querySpectrum() tries, widened by a margin) is removed before the fragments are generated (after peptide:deduplicate has chosen the kept entry of every peptidoform among all of its entries). The others keep their order, so querySpectrum() returns the same candidates for these spectra as with the full index, from an index that is built faster and takes less memory. Search the index only with these spectra and the current parameters. The full index is built if searched_spectra is empty or returns nullptr, and in peptide-mass and open search mode.

Parameters
[in]fasta_entriesThe FASTA entries used to build the index.
[in]searched_spectraCalled with the number of peptides; returns the spectra the index will be searched with, or nullptr.

◆ buildModSlots_()

size_t buildModSlots_ ( const char *  sequence,
size_t  seq_len,
ModSlot *  out_slots,
bool  is_protein_nterm = false,
bool  is_protein_cterm = false 
) const
protected

Scan a peptide sequence to find all variable modification slots. Returns the number of slots written to out_slots (at most MAX_MOD_SLOTS). Deterministic ordering: N-term pure-terminal mods, then left-to-right residue mods (ANYWHERE as residue slots; residue-specific terminal ones, e.g. Gln->pyro-Glu (N-term Q), as NTERM_SLOT/CTERM_SLOT, which AASequence holds as terminal modifications), then C-term pure-terminal mods. As in ModifiedPeptideGenerator, residues with a fixed modification get no variable residue slot (a residue-specific terminal modification still gets its terminal slot), and a terminus with a fixed terminal modification no terminal one.

Parameters
sequenceraw amino acid character array
seq_lenlength of the sequence
out_slotsoutput array for modification slots (must have space for MAX_MOD_SLOTS entries)
is_protein_ntermtrue if this peptide starts at protein position 0
is_protein_ctermtrue if this peptide ends at the last protein residue

◆ buildSkipTables_()

void buildSkipTables_ ( )
private

Fills the skip tables; called by build() once the buckets are sorted.

◆ checkFixedModifications()

static void checkFixedModifications ( const StringList &  fixed_modifications)
static

Rejects fixed terminal modifications that the index cannot restrict to the peptides they apply to.

A fixed terminal modification adds one N- or C-terminal mass to every peptide of the index. A protein-terminal fixed modification (e.g. 'Acetyl (Protein N-term)') or a residue-specific terminal one (e.g. 'Gln->pyro-Glu (N-term Q)') applies to some peptides only, and a terminus carries one modification. As variable modifications (modifications:variable) they are applied to the eligible peptides only.

Parameters
[in]fixed_modificationsNames of the fixed modifications (as in modifications:fixed)
Exceptions
Exception::InvalidParameterfor a protein-terminal or residue-specific terminal fixed modification, or for a second fixed modification on the same terminus

◆ clear()

void clear ( )

Delete fragment index. Sets is_build=false.

◆ computeMassWindow_()

std::pair< float, float > computeMassWindow_ ( float  precursor_mass) const
private

Compute the signed mass window {lo, hi} around a precursor_mass, converting ppm → Da if the unit is ppm. lo is negative (or zero), hi is positive (or zero). This is the only place where positive member magnitudes become signed offsets.

◆ computeSigmaDeltaSet_()

std::vector< double > computeSigmaDeltaSet_ ( bool  include_prot_nterm_mods,
bool  include_prot_cterm_mods 
) const
protected

Enumerate distinct Σ values achievable by any subset of configured variable mods with popcount ≤ max_variable_mods_per_peptide_. Configuration-global; does not consider per-peptide residue inventory. Per-peptide applicability is enforced at query-time subset enumeration.

Parameters
include_prot_nterm_modsinclude mods with PROTEIN_N_TERM specificity
include_prot_cterm_modsinclude mods with PROTEIN_C_TERM specificity
Returns
sorted ascending distinct Σ values; always includes 0.0

◆ deduplicateByString_()

Size deduplicateByString_ ( const std::vector< FASTAFile::FASTAEntry > &  fasta_entries)
protected

Keeps the first entry of fi_peptides_ of every reconstructModifiedSequence(...).toString(), in order.

peptide:deduplicate for configurations in which equal peptidoforms need not lie in one run of equal precursor_mz_ (see PeptidoformRendering_::runs_hold_peptidoforms); build() handles the others while it generates the fragments. Records the removed entries in removed_occurrences_.

Returns
Number of entries removed

◆ forEachPrefixMass_()

template<typename F >
void forEachPrefixMass_ ( const char *  sequence,
size_t  len,
F &&  f 
) const
protected

Calls f(k, mass) for k = 1 .. len with the (M+H)+ of the first k residues of sequence, with fixed modifications, computed as generatePeptides() computes that of a peptide (so that their float roundings agree). Stops early once f returns false.

◆ generateFragmentsForSeries_()

template<typename FragmentSink >
void generateFragmentsForSeries_ ( FragmentSink &  fragments,
const char *  sequence,
size_t  seq_len,
UInt32  peptide_idx,
double  n_term_mod_mass,
double  c_term_mod_mass,
const double *  residue_masses,
const double *  residue_mod_masses,
bool  add_b,
bool  add_a,
bool  add_c,
bool  add_y,
bool  add_x,
bool  add_z,
bool  add_zp1 
) const
protected

Fragment generation with explicit per-call ion-series selection.

generateFragmentsLightweight_ forwards to this function after packing the class flags; both share a single implementation.

Parameters
[out]fragmentsReceives the fragments through emplace_back(peptide_idx, mz)
[in]sequenceRaw amino acid string (no modifications)
[in]seq_lenLength of sequence
[in]peptide_idxIndex of this peptide in fi_peptides_
[in]n_term_mod_massMass delta from N-terminal modification (0 if none)
[in]c_term_mod_massMass delta from C-terminal modification (0 if none)
[in]residue_massesMass of a residue by its character (128 doubles)
[in]residue_mod_massesPer-residue modification mass deltas (nullptr if none; array of seq_len doubles)
[in]add_bEmit b-ions (prefix).
[in]add_aEmit a-ions (prefix).
[in]add_cEmit c-ions (prefix).
[in]add_yEmit y-ions (suffix).
[in]add_xEmit x-ions (suffix).
[in]add_zEmit z-ions (suffix).
[in]add_zp1Emit z+1 ions (z-dot, suffix).

◆ generateFragmentsLightweight_()

template<typename FragmentSink >
void generateFragmentsLightweight_ ( FragmentSink &  fragments,
FragmentSink &  electron_fragments,
const char *  sequence,
size_t  seq_len,
UInt32  peptide_idx,
double  n_term_mod_mass,
double  c_term_mod_mass,
const double *  residue_masses,
const double *  residue_mod_masses 
) const
protected

Lightweight fragment generation: compute b/y ion m/z directly from amino acid chars. Bypasses AASequence::fromString and TheoreticalSpectrumGenerator. Uses the class-level add_b_ions_ / add_y_ions_ / ... flags for the ion series selection. See generateFragmentsForSeries_ for the explicit-flag variant.

Parameters
[out]fragmentsReceives the fragments through emplace_back(peptide_idx, mz): a vector of Fragment, or one of the counting / placing sinks of build()
[out]electron_fragmentsThe same for the c and z+1 ions of ions:electron_ions that the series above lack (untouched if ions:electron_ions is off)
[in]sequenceRaw amino acid string (no modifications)
[in]seq_lenLength of sequence
[in]peptide_idxIndex of this peptide in fi_peptides_
[in]n_term_mod_massMass delta from N-terminal modification (0 if none)
[in]c_term_mod_massMass delta from C-terminal modification (0 if none)
[in]residue_massesMass of a residue by its character (128 doubles): residue_mass_table_, or that with the deltas of the fixed modifications added
[in]residue_mod_massesPer-residue modification mass deltas (nullptr if none; array of seq_len doubles)

◆ generateMothers_()

void generateMothers_ ( const std::vector< FASTAFile::FASTAEntry > &  fasta_entries)
protected

Peptide-mass mode peptide enumeration: emit the mother peptides.

Called instead of the usual enzymatic-digestion path when is_peptide_mass_mode_ is true. For each span of indexable residues [s, e) of a protein (split at X/B/Z, stop codons and other symbols), emits one mother at every position i in [s, e - min_length], spanning residues [i, i + min(max_length, e - i)). Every sub-peptide of the span with a length of at least min_length is a prefix of one of them. Mothers too light to reach peptide:min_mass with any variable modifications are skipped. The mothers are sorted by mass.

Parameters
[in]fasta_entriesProtein database (same semantics as generatePeptides).

◆ generatePeptides()

void generatePeptides ( const std::vector< FASTAFile::FASTAEntry > &  fasta_entries)
protected

Generates all peptides from given fasta entries. If Bottom-up is set to false skips digestion. If set to true the Digestion enzyme can be set in the parameters. Additionally introduces fixed and variable modifications for restrictive PSM search.

Parameters
[in]fasta_entries

◆ generatePeptidoformFragments_()

template<typename FragmentSink >
void generatePeptidoformFragments_ ( FragmentSink &  fragments,
FragmentSink &  electron_fragments,
const char *  sequence,
size_t  seq_len,
UInt32  peptide_idx,
uint32_t  slot_bits,
const ModSlot *  slots,
size_t  n_slots,
std::vector< double > &  mod_masses 
) const
protected

Generates the fragments of a peptidoform, as the index holds them.

The one implementation of the fragments of an index entry: build() uses it for the fragment-index entries, the peptide-mass query for the peptidoforms it realizes, so that both count the same fragments.

Parameters
[out]fragmentsReceives the fragments of the ion series of ions:add_*_ions (see generateFragmentsLightweight_)
[out]electron_fragmentsReceives the c and z+1 ions of ions:electron_ions that these lack
[in]sequenceResidues of the peptide
[in]seq_lenNumber of residues
[in]peptide_idxPassed on to the sinks
[in]slot_bitsActive variable modification slots (0: unmodified)
[in]slotsThe slots of the peptide (buildModSlots_()); only read if slot_bits is not 0
[in]n_slotsNumber of slots
mod_massesScratch buffer

◆ getNumFragments()

Size getNumFragments ( ) const
inlinenoexcept

Number of theoretical fragments stored in the index (0 before build()), including the c and z+1 ions of ions:electron_ions. In peptide-mass mode: the number of prefix masses (one per unmodified sub-peptide).

◆ getPeptides()

const std::vector< Peptide > & getPeptides ( ) const

Returns a reference to the internal peptide container.

Provides read-only access to all peptides currently held by the index, typically populated during build(). With peptide:deduplicate=true, fragment-index entries retain one representative protein coordinate per exact peptidoform, not every protein occurrence (getProteinOccurrences() lists them all).

Returns
const reference to the internal std::vector of Peptide.

Preconditions: The vector may be empty if build() has not been called yet. Thread-safety: read-only view; safe to access concurrently as long as no thread mutates the index (e.g., build()/clear()).

◆ getPeptidesInMassWindow()

std::pair< size_t, size_t > getPeptidesInMassWindow ( float  precursor_mass,
const std::pair< float, float > &  window 
) const

Return the [begin_idx, end_idx) peptide index range such that fi_peptides_[i].precursor_mz_ ∈ [precursor_mass + window.first, precursor_mass + window.second] for all i in the returned range.

Parameters
[in]precursor_massThe mono-charged precursor mass (M+H).
[in]windowSigned absolute offsets around the precursor mass. By convention window.first is <= 0 and window.second is >= 0 (produced by computeMassWindow_). A reversed window trivially returns an empty range; no diagnostic is emitted. No hidden tolerance is added.
Returns
[begin_idx, end_idx) half-open index range into fi_peptides_.

◆ getProteinOccurrences()

void getProteinOccurrences ( Size  peptide_idx,
const std::vector< FASTAFile::FASTAEntry > &  fasta_entries,
std::vector< std::pair< UInt32, UInt32 > > &  occurrences 
) const

Appends the protein occurrences {protein index, start} of the residues of getPeptides()[peptide_idx].

These are the spans of the digest of build() with the same residues, including those of the entries that peptide:deduplicate removed from getPeptides() (getRemovedOccurrences()); each span once, in no particular order. They are complete only if hasProteinOccurrences(). Spans the digest did not produce (with ambiguous residues, outside of enzymatic cleavage sites, ...) are not listed.

Parameters
[in]peptide_idxIndex into getPeptides()
[in]fasta_entriesThe FASTA entries the index was built from
[out]occurrencesReceives the occurrences (appended)

Thread-safety: read-only; may be called concurrently.

◆ getRemovedOccurrences()

const std::vector< RemovedOccurrence > & getRemovedOccurrences ( ) const
inlinenoexcept

The protein occurrences that peptide:deduplicate removed, ordered by RemovedOccurrence::peptide_idx and, for one kept entry, in the order of the entries before deduplication (sortPeptides_() order).

A kept entry's protein occurrences are its own coordinate plus its removed occurrences, so a caller can map the indexed peptides to proteins without searching the database again. Empty without deduplication (and for peptide-mass indices, which are not deduplicated); released by clear(). In chunked searches every chunk has its own index, and a peptidoform that occurs in several chunks is listed in each of them.

◆ hasProteinOccurrences()

bool hasProteinOccurrences ( const std::vector< FASTAFile::FASTAEntry > &  fasta_entries) const

Whether getProteinOccurrences() lists every span of the digest that has the residues of an index peptide.

build() gives every span of its digest one entry per combination of variable modification slots (mod_bitmask_). If the slots and masses of a span depend on its residues only, every span with the residues of an entry holds an entry with the same mod_bitmask_ and the same precursor_mz_ (the masses are added in the same order), i.e. one in the same run of equal precursor_mz_. That holds unless the index is in peptide-mass mode (its entries are mother peptides) or a protein-terminal modification is configured (its sites depend on where a span lies in its protein).

Parameters
[in]fasta_entriesThe FASTA entries the index was built from (checked: their number and lengths).
Returns
false before build(), after clear(), in the cases above and for other FASTA entries.

◆ initModificationTables_()

void initModificationTables_ ( )
protected

Build per-AA modification lookup tables from modifications_fixed_ and modifications_variable_. Called once at the start of generatePeptides().

◆ initResidueMassTable_()

static void initResidueMassTable_ ( )
staticprotected

◆ isBuild()

bool isBuild ( ) const

Indicates whether the fragment index has been built.

Returns
true if build() has completed successfully and the index is ready for queries; false otherwise (e.g., after construction or after clear()).

Thread-safety: read-only and can be called concurrently with other read-only methods. Must not race with build()/clear() on the same instance.

◆ isOpenSearchMode()

static bool isOpenSearchMode ( double  lower_magnitude,
double  upper_magnitude,
bool  unit_ppm 
)
inlinestaticnoexcept

Shared auto-detection: open-search iff max(lower, upper) > threshold (1000 ppm or 1 Da). Strict >: exactly 1000 ppm stays closed. This is the single source of truth for the open-search auto-detection rule and is reused by ProSEAlgorithm and the TOPP tool.

◆ isOpenSearchMode_()

bool isOpenSearchMode_ ( ) const
inlineprivatenoexcept

Instance delegate — same rule, reads the member bounds.

◆ isPeptideMassMode()

bool isPeptideMassMode ( ) const
inlinenoexcept
Returns
true if the index was built in peptide-mass mode, i.e. with low_memory and peptide:enzyme_specificity none (low_memory is ignored for specific and semi-specific searches).

◆ isProteinNTerminal_()

bool isProteinNTerminal_ ( const std::string &  protein,
Size  start 
) const
private

Whether a position is the original or, with Met clipping enabled, mature protein N-terminus.

◆ keepPeptidesInPrecursorWindows_()

void keepPeptidesInPrecursorWindows_ ( const MSExperiment &  spectra)
private

Removes the peptides (sorted by precursor_mz_) whose precursor mass lies in no precursor window of the MS2 spectra of spectra, keeping the order of the others (see build(fasta_entries, searched_spectra)). Removed occurrences recorded before (removed_occurrences_) follow their kept entries to their new indices or are dropped with them.

◆ modShiftLevels_()

std::vector< std::vector< double > > modShiftLevels_ ( bool  include_prot_nterm_mods,
bool  include_prot_cterm_mods 
) const
protected

The sums of exactly m deltas of the configured variable mods (with repetition), distinct within 1e-6 Da, for m = 0..max_variable_mods_per_peptide_ (level 0: {0}; only level 0 without variable mods). Flags as in computeSigmaDeltaSet_().

◆ nonemptyZeroSigmaSubsetExists_()

bool nonemptyZeroSigmaSubsetExists_ ( ) const
protected

Whether a nonempty subset of at most max_variable_mods_per_peptide_ variable modifications has Σ = 0 (zero_sigma_subsets_)

◆ operator=() [1/2]

FragmentIndex & operator= ( const FragmentIndex &  )
default

◆ operator=() [2/2]

FragmentIndex & operator= ( FragmentIndex &&  )
default

◆ peptidoformRendering_()

PeptidoformRendering_ peptidoformRendering_ ( ) const
protected

Rendering classes of the configured modifications. Requires the modification tables (generatePeptides()).

◆ query()

std::vector< Hit > query ( const Peak1D &  peak,
const std::pair< size_t, size_t > &  peptide_idx_range,
uint16_t  peak_charge 
)

Queries one peak (against the ion series of the ions:add_*_ions parameters, not the c and z+1 ions of ions:electron_ions)

Parameters
[in]peakThe queried peak
[in]peptide_idx_rangeThe range of precursors/peptides the peptide could potentially belongs to
[in]peak_chargeThe charge of the peak. Is used to calculate the mass from the mz
Returns
a vector of Hits(matching peptide_idx_range and matching fragment_mz_) containing the idx of the hitted peptide and the mass of the hit

◆ queryPeaks()

void queryPeaks ( SpectrumMatchesTopN &  candidates,
const MSSpectrum &  spectrum,
const std::vector< CandidateBlock_ > &  blocks,
const uint16_t  precursor_charge,
const bool  with_electron_ions 
)
private

Counts fragment matches for the (isotope error) blocks of ONE precursor charge and appends the surviving candidates to candidates.

Every peak of spectrum is walked against the fragment buckets at fragment charges 1..min(precursor_charge, fragment:max_charge) — once for all blocks — and the hits are counted per block and peptide of its range. Only candidates reaching fragment:min_matched_ions — clamped to at least one matched peak, so a candidate that matched nothing is never a candidate — are emitted, block after block and in ascending peptide index within a block. Candidates that could not survive trimHits are therefore never materialized.

Parameters
[in,out]candidatesAccumulator the blocks' matches are APPENDED to. Must NOT be pre-sized — entries are appended, never indexed into. Pre-existing entries are preserved, so one container can accumulate several calls.
[in]spectrumThe queried experimental spectrum
[in]blocksThe candidate ranges and their isotope errors; non-empty ranges, disjoint and ascending (first of a block >= second of its predecessor)
[in]precursor_chargeThe applied precursor charge
[in]with_electron_ionsAlso count matches to the c and z+1 ions of ions:electron_ions

◆ querySpectrum() [1/3]

void querySpectrum ( const MSSpectrum &  spectrum,
const std::vector< FASTAFile::FASTAEntry > &  fasta_entries,
SpectrumMatchesTopN &  sms 
)

Query a spectrum against the fragment index with FASTA context.

Required in peptide-mass mode: the FASTA is needed to realize the sub-peptides of the mothers. The caller must pass the entries passed to build(), in the same order: the index holds only prefix masses and reads the residues, termini and modification sites of the candidates from fasta_entries. Only a different number of entries is detected (no matches are returned then); different entries of the same number give candidates that do not belong to the index. The fragment-index path ignores the fasta_entries argument.

Parameters
[in]spectrumExperimental spectrum with a single precursor.
[in]fasta_entriesThe FASTA entries passed to build(), in the same order.
[out]smsAccumulated candidate matches.

◆ querySpectrum() [2/3]

void querySpectrum ( const MSSpectrum &  spectrum,
const std::vector< FASTAFile::FASTAEntry > &  fasta_entries,
SpectrumMatchesTopN &  sms,
bool  with_electron_ions 
)

Query a spectrum, optionally also against the c and z+1 ions of ions:electron_ions.

As querySpectrum(spectrum, fasta_entries, sms). Candidates are ranked by their number of matched fragments before scoring:max_candidates_per_spectrum cuts them. With with_electron_ions, matches to the c and z+1 ions indexed by ions:electron_ions count as well, as if the ion series above held them; without, the candidates are those of an index without these ions. Use it for electron-activated spectra, so that the c and z+1 ions do not change the candidates of other spectra.

Parameters
[in]spectrumExperimental spectrum with a single precursor.
[in]fasta_entriesThe FASTA database passed to build().
[out]smsAccumulated candidate matches.
[in]with_electron_ionsAlso match the c and z+1 ions of ions:electron_ions.

◆ querySpectrum() [3/3]

void querySpectrum ( const MSSpectrum &  spectrum,
SpectrumMatchesTopN &  sms 
)

: queries one complete experimental spectra against the Database. Loops over all precursor charges Starts at min_precursor_charge and iteratively goes to max_precursor_charge. We query all peaks multiple times with all the different precursor charges and corresponding precursor masses. Returns no matches in peptide-mass mode, which needs the FASTA entries (see the overload that takes them).

Parameters
[in]spectrumexperimental spectrum
[out]smsThe n best Spectrum matches

◆ querySpectrumPeptideMasses_()

void querySpectrumPeptideMasses_ ( const MSSpectrum &  spectrum,
const std::vector< FASTAFile::FASTAEntry > &  fasta_entries,
SpectrumMatchesTopN &  sms,
bool  with_electron_ions 
)
private

Peptide-mass mode spectrum query: the candidates and matched-fragment counts of the fragment index.

For each precursor charge and isotope error, and each shift Σ of mod_shifts_, the index entries (unmodified prefixes of the mothers, sorted by (M+H)+) whose mass plus Σ can lie in the precursor window are looked up and realized: their peptidoforms that belong to Σ (the unmodified one at Σ = 0, combinations of at most variable_max_per_peptide variable modifications) and whose (M+H)+ lies in the precursor window and in [peptide:min_mass, peptide:max_mass] are the candidates, exactly those that the fragment index holds in the window. The fragments of each candidate are generated as the fragment index generates them and matched against the peaks with the windows of queryPeaks(); candidates with at least fragment:min_matched_ions matches are kept (with peptide:deduplicate, one per peptidoform) and cut to scoring:max_candidates_per_spectrum in the order of trimHits(). Ties are broken by (precursor m/z, protein, start, length, modification subset). The fragment index orders its peptides by precursor m/z and protein only and leaves the order within a protein to the sort algorithm, so a cut through equally ranked candidates of one protein can keep other candidates than the fragment index.

Only called when isPeptideMassMode is true.

Parameters
[in]spectrumExperimental spectrum with a single precursor.
[in]fasta_entriesSource database passed to build().
[out]smsAccumulated candidate matches; SpectrumMatch::realized_length_ and subset_bitmask_ name the realized peptidoform.
[in]with_electron_ionsAlso count matches to the c and z+1 ions of ions:electron_ions

◆ realizePrefixLength()

int realizePrefixLength ( const Peptide &  mother,
const std::vector< FASTAFile::FASTAEntry > &  fasta_entries,
double  target_mh_plus,
double  tolerance_lower_magnitude,
double  tolerance_upper_magnitude,
bool  tolerance_ppm 
) const

Find the realized sub-peptide length of a mother that best matches the observed precursor mass.

Scans realizable lengths k in [peptide_min_length_, mother.sequence_.second] from the start of the mother, computing the cumulative residue mass plus fixed modifications. Returns the length whose realized (M+H)+ mass is closest to target_mh_plus within the given tolerance, or -1 if no length satisfies the tolerance.

Must only be called in peptide-mass mode; returns -1 immediately otherwise.

Parameters
[in]motherA mother peptide.
[in]fasta_entriesSource database (same one passed to build()).
[in]target_mh_plusObserved (M+H)+ mass after isotope-error correction.
[in]tolerance_lower_magnitudePositive tolerance magnitude on the low side (realized_mass - target >= -tolerance_lower_magnitude).
[in]tolerance_upper_magnitudePositive tolerance magnitude on the high side (realized_mass - target <= +tolerance_upper_magnitude).
[in]tolerance_ppmTrue if the magnitudes are in ppm.
Returns
Realized length, or -1 on failure.

◆ reconstructModifiedSequence()

AASequence reconstructModifiedSequence ( const Peptide &  peptide,
const std::vector< FASTAFile::FASTAEntry > &  fasta_entries 
) const

Reconstruct a fully modified AASequence from a Peptide's bitmask.

Used for result output - only called for final hits (not in the build hot path). Applies fixed modifications, then uses the bitmask to determine which variable modifications are active at which positions.

Parameters
[in]peptideThe Peptide descriptor with mod_bitmask_
[in]fasta_entriesThe FASTA database used during build()
Returns
The fully modified AASequence

◆ reconstructRealizedSubSequence()

AASequence reconstructRealizedSubSequence ( const Peptide &  mother,
const std::vector< FASTAFile::FASTAEntry > &  fasta_entries,
size_t  realized_length,
uint32_t  subset_bitmask = 0 
) const

Reconstruct a realized sub-peptide (the first realized_length residues of the mother) as an AASequence.

Parameters
motherthe mother Peptide entry
fasta_entriesthe FASTA entries used to build the index
realized_lengththe length of the realized sub-peptide (SpectrumMatch::realized_length_)
subset_bitmaskactive slots from buildModSlots_(seq_ptr, realized_length, ...) to apply as variable modifications (SpectrumMatch::subset_bitmask_). 0 = unmodified.
Returns
AASequence representing the realized sub-peptide with any variable mods from subset_bitmask applied

◆ renderPeptidoform_()

void renderPeptidoform_ ( const Peptide &  peptide,
const std::vector< FASTAFile::FASTAEntry > &  fasta_entries,
const PeptidoformRendering_ &  rendering,
std::vector< uint32_t > &  tokens 
) const
protected

Token sequence of reconstructModifiedSequence(peptide).toString(): [N-term, residue 0, ..., residue len-1, C-term]; a residue byte or modification class each, 0 for no terminal modification.

◆ samePeptidoform_()

bool samePeptidoform_ ( const Peptide &  a,
const Peptide &  b,
const std::vector< FASTAFile::FASTAEntry > &  fasta_entries,
const PeptidoformRendering_ &  rendering,
std::vector< uint32_t > &  tokens_a,
std::vector< uint32_t > &  tokens_b 
) const
protected

Whether reconstructModifiedSequence() renders a and b to the same AASequence::toString().

Compares residues and the rendering of the modification at each position instead of building the strings. Requires rendering.runs_hold_peptidoforms. tokens_a and tokens_b are scratch buffers.

◆ searchDifferentPrecursorRanges()

void searchDifferentPrecursorRanges ( const MSSpectrum &  spectrum,
float  precursor_mass,
SpectrumMatchesTopN &  sms,
uint16_t  charge,
bool  with_electron_ions 
)
private

If closed search collects the candidate ranges of all isotope errors and loops over all peaks once for them with queryPeaks.

If open search applies a precursor-mass window

Parameters
[in]spectrumexperimental query-spectrum
[in]precursor_massThe mass of the precursor (mz * charge)
[out]smsThe Top m SpectrumMatches
[in]chargeApplied charge
[in]with_electron_ionsAlso count matches to the c and z+1 ions of ions:electron_ions

◆ shadowedVariableResidueModifications()

static StringList shadowedVariableResidueModifications ( const StringList &  fixed_modifications,
const StringList &  variable_modifications 
)
static

Variable residue modifications that a fixed modification of the same residue excludes.

A residue carries one modification. A variable modification of a residue anywhere in the peptide (e.g. 'Glutathione (C)', or 'Carbamidomethyl (C)' configured as fixed and variable) is therefore not searched where a fixed one (e.g. 'Carbamidomethyl (C)') sits, as in ModifiedPeptideGenerator. Terminal modifications with a residue preference (e.g. 'Ammonia-loss (N-term C)') sit on the terminus and are searched next to it.

Parameters
[in]fixed_modificationsNames of the fixed modifications (as in modifications:fixed)
[in]variable_modificationsNames of the variable modifications (as in modifications:variable)
Returns
Full ids of the variable residue modifications that the index does not apply, in the given order

◆ shadowedVariableTerminalModifications()

static StringList shadowedVariableTerminalModifications ( const StringList &  fixed_modifications,
const StringList &  variable_modifications 
)
static

Variable terminal modifications that a fixed terminal modification excludes.

A terminus carries one modification. A variable peptide- or protein-terminal modification (e.g. 'Acetyl (Protein N-term)') is therefore not searched where a fixed one (e.g. 'TMT6plex (N-term)') sits on that terminus. This also applies to terminal modifications with a residue preference (e.g. 'Gln->pyro-Glu (N-term Q)'), which AASequence stores on the terminus as well.

Parameters
[in]fixed_modificationsNames of the fixed modifications (as in modifications:fixed)
[in]variable_modificationsNames of the variable modifications (as in modifications:variable)
Returns
Full ids of the variable terminal modifications that the index does not apply, in the given order

◆ sortAndBucketFragments_()

void sortAndBucketFragments_ ( std::vector< Fragment > &  fragments,
std::vector< float > &  bucket_min_mz,
int  num_threads 
)
private

Sorts fragments by m/z, cuts them into buckets of bucketsize_ and sorts each bucket by peptide index; bucket_min_mz receives the smallest m/z of each bucket.

◆ sortPeptides_()

static void sortPeptides_ ( std::vector< Peptide > &  peptides,
size_t  min_task_size = 8192 
)
staticprotected

Sorts peptides by (precursor_mz_, protein_idx), exactly as std::sort does with that comparator.

"Exactly" includes the order of peptides with equal keys: the comparator covers neither mod_bitmask_ nor sequence_, std::sort is not stable, and the resulting order defines the peptide indices and thereby the search results. With libstdc++ and OpenMP, inputs of more than min_task_size peptides are sorted by a multi-threaded reproduction of libstdc++'s std::sort; everything else calls std::sort.

Parameters
[in,out]peptidesPeptides to sort
[in]min_task_sizeParts of at most this many peptides are sorted by the thread that created them

◆ trimHits()

void trimHits ( SpectrumMatchesTopN &  init_hits) const
private

places the k-largest elements in the front of the input array. Inside of the k-largest elements and outside the elements are not sorted

◆ updateMembers_()

void updateMembers_ ( )
overrideprotectedvirtual

This method is used to update extra member variables at the end of the setParameters() method.

Also call it at the end of the derived classes' copy constructor and assignment operator.

The default implementation is empty.

Reimplemented from DefaultParamHandler.

Member Data Documentation

◆ add_a_ions_

bool add_a_ions_
private

◆ add_b_ions_

bool add_b_ions_
private

◆ add_c_ions_

bool add_c_ions_
private

◆ add_x_ions_

bool add_x_ions_
private

◆ add_y_ions_

bool add_y_ions_
private

◆ add_z_ions_

bool add_z_ions_
private

◆ add_zp1_ions_

bool add_zp1_ions_
private

◆ bucket_min_mz_

std::vector<float> bucket_min_mz_
protected

vector of the smalles fragment mz of each bucket

◆ bucket_skip_

std::vector<UInt32> bucket_skip_
private

◆ bucketsize_

size_t bucketsize_
protected

number of fragments per outer node

◆ clip_nterm_methionine_

bool clip_nterm_methionine_ {false}
private

Include initial Met loss (enabled by ProSE).

◆ deduplicate_

bool deduplicate_ {false}
private

peptide:deduplicate

◆ digestion_enzyme_

std::string digestion_enzyme_
private

◆ electron_bucket_min_mz_

std::vector<float> electron_bucket_min_mz_
protected

smallest fragment m/z of each bucket of electron_fragments_

◆ electron_bucket_skip_

std::vector<UInt32> electron_bucket_skip_
private

◆ electron_fragments_

std::vector<Fragment> electron_fragments_
protected

The c and z+1 ions of ions:electron_ions that fi_fragments_ lacks. They are bucketed on their own (electron_bucket_min_mz_) and matched only when a query asks for them.

◆ electron_ions_

bool electron_ions_ {false}
private

ions:electron_ions: also index c and z+1 ions, in electron_fragments_

◆ ENTRY_MAX_SITES_

constexpr uint32_t ENTRY_MAX_SITES_ = (1u << (32 - ENTRY_SITES_SHIFT_)) - 1
staticconstexprprotected

◆ ENTRY_MOTHER_MASK_

constexpr uint32_t ENTRY_MOTHER_MASK_ = (1u << ENTRY_SITES_SHIFT_) - 1
staticconstexprprotected

◆ entry_sites_

bool entry_sites_ {false}
protected

whether the entries carry the bound

◆ ENTRY_SITES_SHIFT_

constexpr uint32_t ENTRY_SITES_SHIFT_ = 28
staticconstexprprotected

Peptide-mass mode: the index entries carry an upper bound of the variable modification sites of their prefix in the bits above ENTRY_SITES_SHIFT_ of Fragment::peptide_idx_ (if the mothers leave them free, see build())

◆ enzyme_specificity_

'full' (default), 'semi' (semi-tryptic), or 'none' (e.g. immunopeptidomics)

◆ fi_fragments_

std::vector<Fragment> fi_fragments_
protected

vector of all theoretical fragments (b- and y- ions)

◆ fi_peptides_

std::vector<Peptide> fi_peptides_
protected

vector of all (digested) peptides

◆ fixed_cterm_delta_

double fixed_cterm_delta_ {0.0}
protected

Fixed C-terminal mod delta (0 if none)

◆ fixed_cterm_mod_ptr_

const ResidueModification* fixed_cterm_mod_ptr_ {nullptr}
protected

◆ fixed_mod_deltas_

std::array<double, 128> fixed_mod_deltas_ {}
protected

Per-AA fixed modification delta mass (0.0 if no fixed mod applies)

◆ fixed_mod_ptrs_

std::array<const ResidueModification*, 128> fixed_mod_ptrs_ {}
protected

Per-AA fixed modification pointer (nullptr if none)

◆ fixed_nterm_delta_

double fixed_nterm_delta_ {0.0}
protected

Fixed N-terminal mod delta (0 if none)

◆ fixed_nterm_mod_ptr_

const ResidueModification* fixed_nterm_mod_ptr_ {nullptr}
protected

◆ fixed_residue_masses_

std::array<double, 128> fixed_residue_masses_ {}
protected

Residue masses with the deltas of the fixed residue modifications added (set by build()). The fragments of an entry without variable modifications are computed from them.

◆ fragment_max_mz_

float fragment_max_mz_
protected

largest fragment mz

◆ fragment_min_mz_

float fragment_min_mz_
protected

smallest fragment mz

◆ fragment_mz_tolerance_

float fragment_mz_tolerance_
protected

◆ fragment_mz_tolerance_unit_ppm_

bool fragment_mz_tolerance_unit_ppm_ {true}
protected

◆ ion_offsets_

IonOffsets ion_offsets_
staticprotected

◆ is_build_

bool is_build_ {false}
protected

true, if the database has been populated with fragments

◆ is_peptide_mass_mode_

bool is_peptide_mass_mode_ {false}
protected

Peptide-mass mode state. Set in updateMembers_ from low_memory and peptide:enzyme_specificity. When true, generatePeptides dispatches to generateMothers_, build() indexes the prefix masses of the mothers and querySpectrum() runs querySpectrumPeptideMasses_(). When false, no peptide-mass code path is active.

◆ mass_table_once_flag_

std::once_flag mass_table_once_flag_
staticprotected

◆ max_fragment_charge_

uint16_t max_fragment_charge_
private

The maximal possible charge of the fragments.

◆ max_isotope_error_

int16_t max_isotope_error_
private

Maximal possible isotope error (both only used for closed search)

◆ max_mod_shift_

double max_mod_shift_ {0.0}
protected

◆ MAX_MOD_SLOTS

constexpr size_t MAX_MOD_SLOTS = 32
staticconstexprprotected

max variable mod slots per peptide (uint32_t bitmask)

◆ max_precursor_charge_

uint16_t max_precursor_charge_
private

maximal possible precursor charge

◆ max_processed_hits_

uint32_t max_processed_hits_
private

The amount of PSM that will be used. the rest is filtered out.

◆ max_variable_mods_per_peptide_

size_t max_variable_mods_per_peptide_
private

◆ min_ion_index_

size_t min_ion_index_ {0}
protected

skip ions below this index (0=all, 2=skip b1/b2/y1/y2)

◆ min_isotope_error_

int16_t min_isotope_error_
private

Minimal possible isotope error.

◆ min_matched_peaks_

uint16_t min_matched_peaks_
private

PSM with less hits are discarded.

◆ min_mod_shift_

double min_mod_shift_ {0.0}
protected

Peptide-mass mode: smallest and largest shift (0 if no variable modification is configured)

◆ min_precursor_charge_

uint16_t min_precursor_charge_
private

minimal possible precursor charge (usually always 1)

◆ missed_cleavages_

size_t missed_cleavages_
private

number of missed cleavages

◆ mod_shifts_

std::vector<ModShift_> mod_shifts_
protected

Peptide-mass mode: the sums of at most variable_max_per_peptide variable modification deltas (with protein-terminal ones), ascending, with 0 (set by updateMembers_())

◆ mod_tables_initialized_

bool mod_tables_initialized_ {false}
protected

◆ modifications_fixed_

StringList modifications_fixed_
private

Modification that are one all peptides.

◆ modifications_variable_

StringList modifications_variable_
private

Variable Modification -> all possible comibnations are created.

◆ peptide_max_length_

size_t peptide_max_length_
private

◆ peptide_max_mass_

float peptide_max_mass_
private

◆ peptide_min_length_

size_t peptide_min_length_
private

◆ peptide_min_mass_

float peptide_min_mass_
private

◆ precursor_mass_tolerance_lower_

double precursor_mass_tolerance_lower_ {20.0}
protected

positive magnitude, effective lower bound is -lower

◆ precursor_mass_tolerance_unit_ppm_

bool precursor_mass_tolerance_unit_ppm_ {true}
protected

◆ precursor_mass_tolerance_upper_

double precursor_mass_tolerance_upper_ {20.0}
protected

positive magnitude, effective upper bound is +upper

◆ protein_lengths_

std::vector<uint32_t> protein_lengths_
protected

Protein lengths indexed by protein_idx, populated at build() time.

◆ removed_occurrences_

std::vector<RemovedOccurrence> removed_occurrences_
protected

occurrences removed by peptide:deduplicate (getRemovedOccurrences())

◆ residue_mass_table_

std::array<double, 128> residue_mass_table_
staticprotected

Precomputed residue mass lookup table: ASCII char -> internal monoisotopic mass (Da). Indexed by single-letter amino acid code (e.g., 'A'=65). Entries for non-AA chars are 0.

◆ sigma_delta_set_

std::vector<double> sigma_delta_set_
protected

Peptide-mass mode: distinct sums Σ of the deltas of at most variable_max_per_peptide variable modifications, i.e. the shifts between the mass of a peptidoform and that of its unmodified peptide; always includes 0. Excludes protein-terminal variable modifications.

◆ sigma_delta_set_with_prot_cterm_

std::vector<double> sigma_delta_set_with_prot_cterm_
protected

Peptide-mass mode: as sigma_delta_set_, with the PROTEIN_C_TERM variable modifications.

◆ sigma_delta_set_with_prot_nterm_

std::vector<double> sigma_delta_set_with_prot_nterm_
protected

Peptide-mass mode: as sigma_delta_set_, with the PROTEIN_N_TERM variable modifications.

◆ skip_per_bucket_

size_t skip_per_bucket_ {0}
private

◆ SKIP_STRIDE_

constexpr size_t SKIP_STRIDE_ = 64
staticconstexprprivate

Skip tables of fi_fragments_ and electron_fragments_ for queryPeaks(): the peptide_idx_ of every SKIP_STRIDE_-th fragment of each bucket, skip_per_bucket_ entries per bucket.

◆ variable_cterm_mods_

std::vector<VarModEntry> variable_cterm_mods_
protected

Pure C-terminal variable mods (not residue-specific)

◆ variable_mod_table_

std::array<std::vector<VarModEntry>, 128> variable_mod_table_ {}
protected

Per-AA variable modification table: for each ASCII char, list of possible variable mods.

◆ variable_nterm_mods_

std::vector<VarModEntry> variable_nterm_mods_
protected

Pure N-terminal variable mods (not residue-specific)

◆ zero_sigma_subsets_

bool zero_sigma_subsets_ {false}
protected

A nonempty subset of at most max_variable_mods_per_peptide_ variable modifications sums to Σ = 0 (within the Σ tolerance of the subset enumeration), so the prefixes found at Σ = 0 are expanded into subsets too