OpenMS
Loading...
Searching...
No Matches
FragmentIndex.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: $
6// $Authors: $
7// --------------------------------------------------------------------------
8
9#pragma once
10
19
20
21#include <array>
22#include <mutex>
23#include <vector>
24#include <functional>
25#include <algorithm> // std::max (used by inline static isOpenSearchMode)
26
27namespace OpenMS
28{
35 class OPENMS_DLLAPI FragmentIndex : public DefaultParamHandler
36 {
37 public:
38
39
53 struct Peptide {
54
57 // We need a constructor in order to emplace back
58 Peptide(UInt32 protein_idx, uint32_t mod_bitmask, std::pair<uint16_t , uint16_t> sequence, float precursor_mz):
59 protein_idx(protein_idx),
60 mod_bitmask_(mod_bitmask),
61 sequence_(sequence),
62 precursor_mz_(precursor_mz)
63 {}
64
68 struct Span
69 {
70 Span() = default;
71 Span(std::pair<uint16_t, uint16_t> span) : first(span.first), second(span.second) {}
72 operator std::pair<uint16_t, uint16_t>() const { return {first, second}; }
73 bool operator==(const Span&) const = default;
74 uint16_t first;
75 uint16_t second;
76 };
77
79 uint32_t mod_bitmask_;
82 };
83
88 {
89 uint32_t num_matched_{};
90 uint32_t subset_bitmask_{};
91 float sigma_delta_{};
92 uint16_t precursor_charge_{};
93 int16_t isotope_error_{};
94 uint16_t realized_length_{};
95 size_t peptide_idx_{};
96 };
97
98
103 {
104 std::vector<SpectrumMatch> hits_;
105
107
114 {
115 this->hits_.insert(this->hits_.end(), other.hits_.begin(), other.hits_.end());
116 return *this;
117 }
118
119 void clear()
120 {
121 hits_.clear();
122 }
123 };
134
141 ~FragmentIndex() override = default;
142
150 FragmentIndex(const FragmentIndex&) = default;
154
164 bool isBuild() const;
165
181 const std::vector<Peptide>& getPeptides() const;
182
195
205 const std::vector<RemovedOccurrence>& getRemovedOccurrences() const noexcept { return removed_occurrences_; }
206
220 bool hasProteinOccurrences(const std::vector<FASTAFile::FASTAEntry>& fasta_entries) const;
221
232 bool isBuiltFrom(const std::vector<FASTAFile::FASTAEntry>& fasta_entries) const;
233
248 void getProteinOccurrences(Size peptide_idx, const std::vector<FASTAFile::FASTAEntry>& fasta_entries,
249 std::vector<std::pair<UInt32, UInt32>>& occurrences) const;
250
254 Size getNumFragments() const noexcept { return fi_fragments_.size() + electron_fragments_.size() + entry_words_.size(); }
255
256#ifdef DEBUG_FRAGMENT_INDEX
280 void addSpecialPeptide(AASequence& peptide, Size source_idx);
281#endif
282
290 void build(const std::vector<FASTAFile::FASTAEntry> & fasta_entries);
291
309 void build(const std::vector<FASTAFile::FASTAEntry>& fasta_entries,
310 const std::function<const MSExperiment*(Size)>& searched_spectra);
311
313 void clear();
314
315
327 std::pair<size_t, size_t> getPeptidesInMassWindow(float precursor_mass,
328 const std::pair<float, float>& window) const;
329
334 static bool isOpenSearchMode(double lower_magnitude,
335 double upper_magnitude,
336 bool unit_ppm) noexcept
337 {
338 const double threshold = unit_ppm ? 1000.0 : 1.0;
339 return std::max(lower_magnitude, upper_magnitude) > threshold;
340 }
341
354 static void restrictSearchParameters(Param& param);
355
371 static void checkSearchParameters(const Param& param, const std::string& name_prefix = "");
372
387 static void precursorCharges(const Precursor& precursor, int min_charge, int max_charge, std::vector<uint16_t>& charges,
388 bool search_outside_range = false);
389
403 static void checkFixedModifications(const StringList& fixed_modifications, const std::string& name_prefix = "");
404
418 const StringList& variable_modifications);
419
433 const StringList& variable_modifications);
434
453
456 bool isPeptideMassMode() const noexcept { return is_peptide_mass_mode_; }
457
458
462 struct Hit
463 {
464 Hit(UInt32 peptide_idx, float fragment_mz) :
465 peptide_idx(peptide_idx),
466 fragment_mz(fragment_mz)
467 {}
468 UInt32 peptide_idx; // index in database
470 };
471
479 std::vector<Hit> query(const Peak1D& peak,
480 const std::pair<size_t,size_t>& peptide_idx_range,
481 uint16_t peak_charge);
482
491 void querySpectrum(const MSSpectrum& spectrum,
493
507 void querySpectrum(const MSSpectrum& spectrum,
508 const std::vector<FASTAFile::FASTAEntry>& fasta_entries,
510
526 void querySpectrum(const MSSpectrum& spectrum,
527 const std::vector<FASTAFile::FASTAEntry>& fasta_entries,
529 bool with_electron_ions);
530
542 const std::vector<FASTAFile::FASTAEntry>& fasta_entries) const;
543
564 int realizePrefixLength(const Peptide& mother,
565 const std::vector<FASTAFile::FASTAEntry>& fasta_entries,
566 double target_mh_plus,
567 double tolerance_lower_magnitude,
568 double tolerance_upper_magnitude,
569 bool tolerance_ppm) const;
570
579 const std::vector<FASTAFile::FASTAEntry>& fasta_entries,
580 size_t realized_length,
581 uint32_t subset_bitmask = 0) const;
582
583protected:
584
585
588 struct Fragment
589 {
593 Fragment(UInt32 peptide_idx, float fragment_mz):
594 peptide_idx_(peptide_idx),
595 fragment_mz_(fragment_mz)
596 {}
597 UInt32 peptide_idx_; // 32 bit in sage
599 };
600
606 {
609 };
611 {
613 uint8_t length_;
614 };
615
616 bool is_build_{false};
617
618 void updateMembers_() override;
619
626 void generatePeptides(const std::vector<FASTAFile::FASTAEntry>& fasta_entries);
627
639 void generateMothers_(const std::vector<FASTAFile::FASTAEntry>& fasta_entries);
640
652 static void sortPeptides_(std::vector<Peptide>& peptides, size_t min_task_size = 8192,
653 size_t min_parallel_partition = size_t(1) << 18);
654
657 {
659 std::vector<std::pair<const ResidueModification*, uint32_t>> mod_class;
663 bool runs_hold_peptidoforms{true};
665 bool unique_variable_renderings{true};
667 bool slots_depend_on_context{false};
668
670 uint32_t classOf(const ResidueModification* mod) const
671 {
672 for (const auto& [ptr, cls] : mod_class)
673 {
674 if (ptr == mod) return cls;
675 }
676 return 0;
677 }
678 };
679
682
685 void renderPeptidoform_(const Peptide& peptide, const std::vector<FASTAFile::FASTAEntry>& fasta_entries,
686 const PeptidoformRendering_& rendering, std::vector<uint32_t>& tokens) const;
687
693 bool samePeptidoform_(const Peptide& a, const Peptide& b, const std::vector<FASTAFile::FASTAEntry>& fasta_entries,
694 const PeptidoformRendering_& rendering, std::vector<uint32_t>& tokens_a,
695 std::vector<uint32_t>& tokens_b) const;
696
704 Size deduplicateByString_(const std::vector<FASTAFile::FASTAEntry>& fasta_entries);
705
714
720 struct ModSlot
721 {
722 uint16_t position;
723 double delta_mass;
725 const Residue* residue{nullptr};
726
727 static constexpr uint16_t NTERM_SLOT = UINT16_MAX - 1;
728 static constexpr uint16_t CTERM_SLOT = UINT16_MAX;
729 };
730
731 static constexpr size_t MAX_MOD_SLOTS = 32;
732
736
750 size_t buildModSlots_(const char* sequence, size_t seq_len, ModSlot* out_slots,
751 bool is_protein_nterm = false, bool is_protein_cterm = false) const;
752
761 std::vector<double> computeSigmaDeltaSet_(bool include_prot_nterm_mods,
762 bool include_prot_cterm_mods) const;
763
767 std::vector<std::vector<double>> modShiftLevels_(bool include_prot_nterm_mods,
768 bool include_prot_cterm_mods) const;
769
772
788 template <typename FragmentSink>
789 void generatePeptidoformFragments_(FragmentSink& fragments, FragmentSink& electron_fragments, const char* sequence,
790 size_t seq_len, UInt32 peptide_idx, uint32_t slot_bits, const ModSlot* slots,
791 size_t n_slots, std::vector<double>& mod_masses) const;
792
796 template <typename F>
797 void forEachPrefixMass_(const char* sequence, size_t len, F&& f) const;
798
800 std::array<double, 128> fixed_mod_deltas_{};
802 std::array<const ResidueModification*, 128> fixed_mod_ptrs_{};
805 std::array<const Residue*, 128> fixed_mod_residues_{};
806 double fixed_nterm_delta_{0.0};
807 double fixed_cterm_delta_{0.0};
808 const ResidueModification* fixed_nterm_mod_ptr_{nullptr};
809 const ResidueModification* fixed_cterm_mod_ptr_{nullptr};
810
812 std::array<std::vector<VarModEntry>, 128> variable_mod_table_{};
814 std::vector<VarModEntry> variable_nterm_mods_;
816 std::vector<VarModEntry> variable_cterm_mods_;
817
818 bool mod_tables_initialized_{false};
819
822 std::array<double, 128> fixed_residue_masses_{};
823
828 bool is_peptide_mass_mode_{false};
829
833 std::vector<double> sigma_delta_set_;
840 bool zero_sigma_subsets_{false};
841
845 {
846 double sigma;
848 size_t min_mods;
849 };
852 std::vector<ModShift_> mod_shifts_;
854 double min_mod_shift_{0.0};
855 double max_mod_shift_{0.0};
856
859 static constexpr uint32_t ENTRY_SITES_SHIFT_ = 28;
860 static constexpr uint32_t ENTRY_MOTHER_MASK_ = (1u << ENTRY_SITES_SHIFT_) - 1;
861 static constexpr uint32_t ENTRY_MAX_SITES_ = (1u << (32 - ENTRY_SITES_SHIFT_)) - 1;
862 bool entry_sites_{false};
863
866 static std::array<double, 128> residue_mass_table_;
867 static std::once_flag mass_table_once_flag_;
869
872 {
873 double b_offset{0.0};
874 double y_offset{0.0};
875 double a_offset{0.0};
876 double c_offset{0.0};
877 double x_offset{0.0};
878 double z_offset{0.0};
879 double zp1_offset{0.0};
880 };
882
900 template <typename FragmentSink>
902 FragmentSink& fragments,
903 FragmentSink& electron_fragments,
904 const char* sequence,
905 size_t seq_len,
906 UInt32 peptide_idx,
907 double n_term_mod_mass,
908 double c_term_mod_mass,
909 const double* residue_masses,
910 const double* residue_mod_masses) const;
911
932 template <typename FragmentSink>
934 FragmentSink& fragments,
935 const char* sequence,
936 size_t seq_len,
937 UInt32 peptide_idx,
938 double n_term_mod_mass,
939 double c_term_mod_mass,
940 const double* residue_masses,
941 const double* residue_mod_masses,
942 bool add_b,
943 bool add_a,
944 bool add_c,
945 bool add_y,
946 bool add_x,
947 bool add_z,
948 bool add_zp1) const;
949
950 std::vector<Peptide> fi_peptides_;
951 std::vector<RemovedOccurrence> removed_occurrences_;
952 std::vector<Fragment> fi_fragments_;
984 std::vector<EntryWord> entry_words_;
985 std::vector<EntryLength> entry_lengths_;
986 bool packed_entries_{false};
989 std::vector<Fragment> electron_fragments_;
990 std::vector<float> electron_bucket_min_mz_;
991
993 std::vector<uint32_t> protein_lengths_;
994
997 size_t min_ion_index_{0};
998 size_t bucketsize_;
999 std::vector<float> bucket_min_mz_;
1000 double precursor_mass_tolerance_lower_{20.0};
1001 double precursor_mass_tolerance_upper_{20.0};
1002 bool precursor_mass_tolerance_unit_ppm_{true};
1004 bool fragment_mz_tolerance_unit_ppm_{true};
1005private:
1006
1007
1033 const std::vector<FASTAFile::FASTAEntry>& fasta_entries,
1035 bool with_electron_ions);
1036
1039 double prefixMass_(const char* sequence, size_t length) const;
1040
1043 float packedEntryMz_(size_t e, const std::vector<FASTAFile::FASTAEntry>& fasta_entries) const;
1044
1050 void sortPackedEntries_(const std::vector<FASTAFile::FASTAEntry>& fasta_entries, const std::vector<size_t>& bin_start,
1051 uint32_t first_bin);
1052
1055 {
1056 size_t first;
1057 size_t second;
1060 };
1061
1084 const MSSpectrum& spectrum,
1085 const std::vector<CandidateBlock_>& blocks,
1086 const uint16_t precursor_charge,
1087 const bool with_electron_ions);
1088
1091 static constexpr size_t SKIP_STRIDE_ = 64;
1092 size_t skip_per_bucket_{0};
1093 std::vector<UInt32> bucket_skip_;
1094 std::vector<UInt32> electron_bucket_skip_;
1097
1108 float precursor_mass,
1110 uint16_t charge,
1111 bool with_electron_ions);
1112
1115 void sortAndBucketFragments_(std::vector<Fragment>& fragments,
1116 std::vector<float>& bucket_min_mz,
1117 int num_threads);
1118
1122 void trimHits(SpectrumMatchesTopN& init_hits) const;
1123
1124 //since we work with TheoreticalSpectrumGenerator, we must transfer some of those member variables
1132 bool electron_ions_{false};
1133
1134 // SpectrumGenerator independend member variables
1136 EnzymaticDigestion::Specificity enzyme_specificity_{EnzymaticDigestion::SPEC_FULL};
1137
1139 bool isProteinNTerminal_(const std::string& protein, Size start) const;
1140
1141 bool clip_nterm_methionine_ {false};
1147
1151
1152 // Search Related member variables
1153
1159 bool search_outside_charges_ = false;
1162 bool deduplicate_{false};
1164
1166 bool matchesMotif_(const char* sequence, size_t length) const;
1167
1169 bool isOpenSearchMode_() const noexcept
1170 {
1171 return isOpenSearchMode(precursor_mass_tolerance_lower_,
1172 precursor_mass_tolerance_upper_,
1173 precursor_mass_tolerance_unit_ppm_);
1174 }
1175
1180 std::pair<float, float> computeMassWindow_(float precursor_mass) const;
1181
1188 bool precursorWindows_(const MSExperiment& spectra, bool with_margin, std::vector<std::pair<float, float>>& windows) const;
1189
1194
1195 };
1196
1197}
Definition AASequence.h:96
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
Specificity
when querying for valid digestion products, this determines if the specificity of the two peptide end...
Definition EnzymaticDigestion.h:43
Generates from a set of Fasta files a 2D-datastructure which stores all theoretical masses of all b a...
Definition FragmentIndex.h:36
size_t bucketsize_
number of fragments per outer node
Definition FragmentIndex.h:998
uint16_t min_matched_peaks_
PSM with less hits are discarded.
Definition FragmentIndex.h:1154
UInt32 peptide_idx
index into getPeptides() of the kept entry of the same peptidoform
Definition FragmentIndex.h:191
bool add_x_ions_
Definition FragmentIndex.h:1129
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
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 matchesMotif_(const char *sequence, size_t length) const
Whether the unmodified peptide sequence of length residues passes peptide:motif.
double prefixMass_(const char *sequence, size_t length) const
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 fo...
Size deduplicateByString_(const std::vector< FASTAFile::FASTAEntry > &fasta_entries)
Keeps the first entry of fi_peptides_ of every reconstructModifiedSequence(...).toString(),...
std::vector< EntryLength > entry_lengths_
packed_entries_: the prefix lengths, parallel to entry_words_
Definition FragmentIndex.h:985
static void precursorCharges(const Precursor &precursor, int min_charge, int max_charge, std::vector< uint16_t > &charges, bool search_outside_range=false)
The precursor charges a spectrum is searched with.
FragmentIndex & operator=(const FragmentIndex &)=default
AASequence reconstructRealizedSubSequence(const Peptide &mother, const std::vector< FASTAFile::FASTAEntry > &fasta_entries, size_t realized_length, uint32_t subset_bitmask=0) const
uint16_t start
0-based start of the removed entry in that protein
Definition FragmentIndex.h:193
std::vector< double > sigma_delta_set_
Definition FragmentIndex.h:833
std::vector< double > computeSigmaDeltaSet_(bool include_prot_nterm_mods, bool include_prot_cterm_mods) const
std::vector< UInt32 > electron_bucket_skip_
Definition FragmentIndex.h:1094
std::vector< RemovedOccurrence > removed_occurrences_
occurrences removed by peptide:deduplicate (getRemovedOccurrences())
Definition FragmentIndex.h:951
const ResidueModification * mod_ptr
pointer to the modification (for AASequence reconstruction)
Definition FragmentIndex.h:710
static StringList shadowedVariableResidueModifications(const StringList &fixed_modifications, const StringList &variable_modifications)
Variable residue modifications that a fixed modification of the same residue excludes.
bool add_a_ions_
Definition FragmentIndex.h:1127
bool precursorWindows_(const MSExperiment &spectra, bool with_margin, std::vector< std::pair< float, float > > &windows) const
void querySpectrum(const MSSpectrum &spectrum, SpectrumMatchesTopN &sms)
: queries one complete experimental spectra against the Database. Loops over all precursor charges St...
std::vector< float > electron_bucket_min_mz_
smallest fragment m/z of each bucket of electron_fragments_
Definition FragmentIndex.h:990
bool add_b_ions_
Definition FragmentIndex.h:1125
std::vector< ModShift_ > mod_shifts_
Definition FragmentIndex.h:852
std::vector< std::vector< double > > modShiftLevels_(bool include_prot_nterm_mods, bool include_prot_cterm_mods) const
static bool isOpenSearchMode(double lower_magnitude, double upper_magnitude, bool unit_ppm) noexcept
Definition FragmentIndex.h:334
static IonOffsets ion_offsets_
Definition FragmentIndex.h:881
size_t buildModSlots_(const char *sequence, size_t seq_len, ModSlot *out_slots, bool is_protein_nterm=false, bool is_protein_cterm=false) const
ResidueModification::TermSpecificity term_spec
where this mod can be applied
Definition FragmentIndex.h:711
void renderPeptidoform_(const Peptide &peptide, const std::vector< FASTAFile::FASTAEntry > &fasta_entries, const PeptidoformRendering_ &rendering, std::vector< uint32_t > &tokens) const
FragmentIndex(const FragmentIndex &)=default
Copy and move operations.
static std::once_flag mass_table_once_flag_
Definition FragmentIndex.h:867
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].
void sortAndBucketFragments_(std::vector< Fragment > &fragments, std::vector< float > &bucket_min_mz, int num_threads)
std::pair< float, float > computeMassWindow_(float precursor_mass) const
StringList modifications_fixed_
Modification that are one all peptides.
Definition FragmentIndex.h:1148
float fragment_mz_tolerance_
Definition FragmentIndex.h:1003
bool add_y_ions_
Definition FragmentIndex.h:1126
static void restrictSearchParameters(Param &param)
Sets the restrictions of the search parameters that FragmentIndex and ProSEAlgorithm share,...
std::vector< Peptide > fi_peptides_
vector of all (digested) peptides
Definition FragmentIndex.h:950
std::vector< VarModEntry > variable_cterm_mods_
Pure C-terminal variable mods (not residue-specific)
Definition FragmentIndex.h:816
double sigma
the shift
Definition FragmentIndex.h:846
size_t missed_cleavages_
number of missed cleavages
Definition FragmentIndex.h:1142
static void sortPeptides_(std::vector< Peptide > &peptides, size_t min_task_size=8192, size_t min_parallel_partition=size_t(1)<< 18)
Sorts peptides by (precursor_mz_, protein_idx), exactly as std::sort does with that comparator.
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.
void forEachPrefixMass_(const char *sequence, size_t len, F &&f) const
static void checkFixedModifications(const StringList &fixed_modifications, const std::string &name_prefix="")
Rejects fixed terminal modifications that the index cannot restrict to the peptides they apply to.
std::vector< double > sigma_delta_set_with_prot_nterm_
Peptide-mass mode: as sigma_delta_set_, with the PROTEIN_N_TERM variable modifications.
Definition FragmentIndex.h:835
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.
float fragment_min_mz_
smallest fragment mz
Definition FragmentIndex.h:995
std::vector< EntryWord > entry_words_
packed_entries_: the 32-bit words of the prefix entries, sorted by (recomputed) mass
Definition FragmentIndex.h:984
uint16_t min_precursor_charge_
minimal possible precursor charge (usually always 1)
Definition FragmentIndex.h:1157
uint32_t max_processed_hits_
The amount of PSM that will be used. the rest is filtered out.
Definition FragmentIndex.h:1161
void sortPackedEntries_(const std::vector< FASTAFile::FASTAEntry > &fasta_entries, const std::vector< size_t > &bin_start, uint32_t first_bin)
float peptide_max_mass_
Definition FragmentIndex.h:1144
bool add_zp1_ions_
Definition FragmentIndex.h:1131
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 surviv...
std::vector< Fragment > electron_fragments_
Definition FragmentIndex.h:989
uint16_t max_fragment_charge_
The maximal possible charge of the fragments.
Definition FragmentIndex.h:1160
std::pair< size_t, size_t > getPeptidesInMassWindow(float precursor_mass, const std::pair< float, float > &window) const
int16_t isotope_error
the applied isotope error
Definition FragmentIndex.h:1059
void generateMothers_(const std::vector< FASTAFile::FASTAEntry > &fasta_entries)
Peptide-mass mode peptide enumeration: emit the mother peptides.
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...
void keepPeptidesInPrecursorWindows_(const MSExperiment &spectra)
bool isOpenSearchMode_() const noexcept
Instance delegate — same rule, reads the member bounds.
Definition FragmentIndex.h:1169
FragmentIndex & operator=(FragmentIndex &&)=default
std::vector< Fragment > fi_fragments_
vector of all theoretical fragments (b- and y- ions); in peptide-mass mode the prefix entries,...
Definition FragmentIndex.h:952
void querySpectrum(const MSSpectrum &spectrum, const std::vector< FASTAFile::FASTAEntry > &fasta_entries, SpectrumMatchesTopN &sms)
Query a spectrum against the fragment index with FASTA context.
int16_t max_isotope_error_
Maximal possible isotope error (both only used for closed search)
Definition FragmentIndex.h:1156
std::vector< double > sigma_delta_set_with_prot_cterm_
Peptide-mass mode: as sigma_delta_set_, with the PROTEIN_C_TERM variable modifications.
Definition FragmentIndex.h:837
float fragment_max_mz_
largest fragment mz
Definition FragmentIndex.h:996
std::string digestion_enzyme_
Definition FragmentIndex.h:1135
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 searche...
bool isPeptideMassMode() const noexcept
Definition FragmentIndex.h:456
void buildSkipTables_()
Fills the skip tables; called by build() once the buckets are sorted.
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().
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
RegularExpression peptide_motif_
peptide:motif (empty(): none, every peptide is searched)
Definition FragmentIndex.h:1163
bool protein_terminal
only reached with a protein-terminal modification: the prefix must start or end a protein
Definition FragmentIndex.h:847
bool isBuild() const
Indicates whether the fragment index has been built.
static StringList shadowedVariableTerminalModifications(const StringList &fixed_modifications, const StringList &variable_modifications)
Variable terminal modifications that a fixed terminal modification excludes.
bool isBuiltFrom(const std::vector< FASTAFile::FASTAEntry > &fasta_entries) const
Whether the index was built from fasta_entries in peptide mode: every entry of getPeptides() is a spa...
size_t peptide_max_length_
Definition FragmentIndex.h:1146
~FragmentIndex() override=default
Default destructor.
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 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.
UInt32 protein_idx
protein of the removed entry (index into the FASTA entries passed to build())
Definition FragmentIndex.h:192
PeptidoformRendering_ peptidoformRendering_() const
Rendering classes of the configured modifications. Requires the modification tables (generatePeptides...
bool nonemptyZeroSigmaSubsetExists_() const
Whether a nonempty subset of at most max_variable_mods_per_peptide_ variable modifications has Σ = 0 ...
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 pept...
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....
std::vector< float > bucket_min_mz_
vector of the smalles fragment mz of each bucket
Definition FragmentIndex.h:999
double delta_mass
mass delta from this modification
Definition FragmentIndex.h:709
float peptide_min_mass_
Definition FragmentIndex.h:1143
int16_t min_isotope_error_
Minimal possible isotope error.
Definition FragmentIndex.h:1155
uint16_t max_precursor_charge_
maximal possible precursor charge
Definition FragmentIndex.h:1158
std::vector< UInt32 > bucket_skip_
Definition FragmentIndex.h:1093
std::vector< uint32_t > protein_lengths_
Protein lengths indexed by protein_idx, populated at build() time.
Definition FragmentIndex.h:993
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
FragmentIndex(FragmentIndex &&)=default
void clear()
Delete fragment index. Sets is_build=false.
StringList modifications_variable_
Variable Modification -> all possible comibnations are created.
Definition FragmentIndex.h:1149
size_t max_variable_mods_per_peptide_
Definition FragmentIndex.h:1150
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 so...
const std::vector< RemovedOccurrence > & getRemovedOccurrences() const noexcept
The protein occurrences that peptide:deduplicate removed, ordered by RemovedOccurrence::peptide_idx a...
Definition FragmentIndex.h:205
float packedEntryMz_(size_t e, const std::vector< FASTAFile::FASTAEntry > &fasta_entries) const
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 o...
Size getNumFragments() const noexcept
Definition FragmentIndex.h:254
const std::vector< Peptide > & getPeptides() const
Returns a reference to the internal peptide container.
AASequence reconstructModifiedSequence(const Peptide &peptide, const std::vector< FASTAFile::FASTAEntry > &fasta_entries) const
Reconstruct a fully modified AASequence from a Peptide's bitmask.
std::vector< VarModEntry > variable_nterm_mods_
Pure N-terminal variable mods (not residue-specific)
Definition FragmentIndex.h:814
size_t peptide_min_length_
Definition FragmentIndex.h:1145
size_t cell_offset
sum of the range sizes of the preceding blocks of the call
Definition FragmentIndex.h:1058
static void initResidueMassTable_()
size_t first
half-open range [first, second) of peptides the precursor could belong to
Definition FragmentIndex.h:1056
bool add_c_ions_
Definition FragmentIndex.h:1128
FragmentIndex()
Default constructor.
static void checkSearchParameters(const Param &param, const std::string &name_prefix="")
Rejects search parameters whose combination searches nothing or cannot be searched.
size_t min_mods
the fewest variable modifications that sum to it (within the matching tolerance)
Definition FragmentIndex.h:848
bool add_z_ions_
Definition FragmentIndex.h:1130
static std::array< double, 128 > residue_mass_table_
Definition FragmentIndex.h:866
size_t second
Definition FragmentIndex.h:1057
One (precursor charge, isotope error) block of a queryPeaks() call.
Definition FragmentIndex.h:1055
Precomputed ion-type mass offsets (from Residue::getInternalTo*Ion formulas)
Definition FragmentIndex.h:872
Definition FragmentIndex.h:845
A protein occurrence of an indexed peptidoform that peptide:deduplicate removed from the index.
Definition FragmentIndex.h:190
Match between a query peak and an entry in the DB.
Definition FragmentIndex.h:88
Entry in the per-AA variable modification lookup table.
Definition FragmentIndex.h:708
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
The representation of a 1D spectrum.
Definition MSSpectrum.h:44
Management and storage of parameters / INI files.
Definition Param.h:46
A 1-dimensional raw data point or peak.
Definition Peak1D.h:30
Precursor meta information.
Definition Precursor.h:37
Compiled Perl-compatible regular expression, including named capture groups.
Definition RegularExpression.h:30
Representation of a modification on an amino acid residue.
Definition ResidueModification.h:55
TermSpecificity
Position where the modification is allowed to occur.
Definition ResidueModification.h:74
Representation of an amino acid residue.
Definition Residue.h:41
OpenMS looks in the< code > OPENMS_THERMO_MANAGED_DIR</code > environment variable first
Definition common-cmake-parameters.doxygen:191
uint32_t UInt32
Unsigned integer type (32bit)
Definition Types.h:33
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
std::vector< std::string > StringList
Vector of String.
Definition TypeAliases.h:39
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Definition FragmentIndex.h:611
EntryLength()
Definition FragmentIndex.h:612
uint8_t length_
the prefix length in residues (1..255); the entry's mass is that of the mother's first length_ residu...
Definition FragmentIndex.h:613
Peptide-mass mode: the two halves of a packed prefix entry, held in the parallel arrays entry_words_ ...
Definition FragmentIndex.h:606
EntryWord()
Definition FragmentIndex.h:607
UInt32 word_
bit for bit the peptide_idx_ of the Fragment the entry replaces: mother index, and the site bound abo...
Definition FragmentIndex.h:608
One entry in the fragment index.
Definition FragmentIndex.h:589
Fragment(UInt32 peptide_idx, float fragment_mz)
Definition FragmentIndex.h:593
Fragment()
Definition FragmentIndex.h:592
UInt32 peptide_idx_
Definition FragmentIndex.h:597
float fragment_mz_
Definition FragmentIndex.h:598
Definition FragmentIndex.h:463
UInt32 peptide_idx
Definition FragmentIndex.h:468
Hit(UInt32 peptide_idx, float fragment_mz)
Definition FragmentIndex.h:464
float fragment_mz
Definition FragmentIndex.h:469
A candidate modification slot for a specific peptide.
Definition FragmentIndex.h:721
const ResidueModification * mod_ptr
for AASequence reconstruction
Definition FragmentIndex.h:724
uint16_t position
residue index, or NTERM_SLOT/CTERM_SLOT
Definition FragmentIndex.h:722
double delta_mass
mass delta
Definition FragmentIndex.h:723
Definition FragmentIndex.h:69
bool operator==(const Span &) const =default
uint16_t second
Definition FragmentIndex.h:75
Span(std::pair< uint16_t, uint16_t > span)
Definition FragmentIndex.h:71
uint16_t first
Definition FragmentIndex.h:74
Compact descriptor of a peptide instance held by the FragmentIndex.
Definition FragmentIndex.h:53
Peptide()
Leaves the members uninitialised: resizing a vector of peptides then writes nothing (see generatePept...
Definition FragmentIndex.h:56
Span sequence_
{start, length} within the source protein sequence (start is 0-based; length in residues)
Definition FragmentIndex.h:80
uint32_t mod_bitmask_
Bitmask of active variable mod slots (0 = unmodified/fixed-only; up to 32 slots)
Definition FragmentIndex.h:79
UInt32 protein_idx
0-based index into FASTA entries provided to build(); identifies the source protein
Definition FragmentIndex.h:78
float precursor_mz_
Mono-isotopic m/z at charge 1 (M+H)+ of this peptide; used for sorting/filtering.
Definition FragmentIndex.h:81
Peptide(UInt32 protein_idx, uint32_t mod_bitmask, std::pair< uint16_t, uint16_t > sequence, float precursor_mz)
Definition FragmentIndex.h:58
Rendering classes of the configured modifications, for samePeptidoform_() (peptide:deduplicate)
Definition FragmentIndex.h:657
std::vector< std::pair< const ResidueModification *, uint32_t > > mod_class
Modification -> class of its toString(); classes start at 256, above the residue bytes.
Definition FragmentIndex.h:659
uint32_t classOf(const ResidueModification *mod) const
Class of mod (0 for nullptr or a modification not configured)
Definition FragmentIndex.h:670
container for SpectrumMatch. Also keeps count of total number of candidates and total number of match...
Definition FragmentIndex.h:103
SpectrumMatchesTopN & operator+=(const SpectrumMatchesTopN &other)
Appends a SpectrumMatchesTopN to another one.
Definition FragmentIndex.h:113
void clear()
Definition FragmentIndex.h:119
std::vector< SpectrumMatch > hits_
The preliminary candidates.
Definition FragmentIndex.h:104