Skip to content

Refactoring FragmentIndex - #7232

Merged
timosachsenberg merged 8 commits into
OpenMS:feature/fi_search_enginefrom
Trapho:feature/local_fi_search_engine
Dec 7, 2023
Merged

timosachsenberg merged 8 commits into
OpenMS:feature/fi_search_enginefrom
Trapho:feature/local_fi_search_engine

Conversation

@Trapho

@Trapho Trapho commented Nov 27, 2023 •

Copy link
Copy Markdown
Contributor

Description

Changed the Format of the struct Peptide (called sPeptide for the beginning, in case something is wrong). During Fragment Creation modification are now recreated. All functions from FragmentIndexScorer are now in FragmentIndex.
The BuildMinHeap function is replaced by Partial-sort.

FragmentIndex3D.h and FragmentIndex3D.cpp is a adapted version of FragmentIndex, which can be used for Top-Down Proteomics. This current version is not finished yet.

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

How can I get additional information on failed tests during CI

Click to expand If your PR is failing you can check out

Advanced commands (admins / reviewer only)

Click to expand
  • /reformat (experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

⚠️ Note: Once you opened a PR try to minimize the number of pushes to it as every push will trigger CI (automated builds and test) and is rather heavy on our infrastructure (e.g., if several pushes per day are performed).

…Scorer are now relocated to FragmentIndex. BuildMinHeap was replaced by std::partial_sort
@timosachsenberg timosachsenberg changed the title Reformating FragmentIndex Object Refactoring FragmentIndex Nov 28, 2023

struct sPeptide
{
UInt32 protein_idx_;

@timosachsenberg timosachsenberg Nov 28, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding doxygen comments like this would be of great help to others because it is such a central data structure.
e.g.

Suggested change
UInt32 protein_idx_;
UInt32 protein_idx_; ///< The index in the protein database

{
UInt32 protein_idx_;
UInt32 modification_idx;
std::pair<Size, Size> sequence;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Size can be rater large.
is this just the index in the protein?
then maybe something like
UInt16, UInt16 could safe some space

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I simply cast pair<size_t, size_t> to pair<UInt16, UInt16> ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not directly, on construction might work or in make_pair(...)

struct SpectrumMatch
{
uint32_t num_matched_{}; ///< Number of peaks-fragment hits
uint32_t precursor_charge_{}; ///< The precursor_charged used for the performed search

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be uint16_t. if it is listed directly before or after with isotope_error we would safe another word (64bit)


SpectrumMatchesTopN() = default;

SpectrumMatchesTopN& operator+=(const SpectrumMatchesTopN& other)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add brief doc as operators are always a bit unpredicatable

* @param peak
* @param peptide_idx_range
* @param peak_charge
* @return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document what is returned



/**
* @brief: queries one complete experimental spectra against the Database. loops over all precursor charges

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document what "loops over all precursor charges" means here.


/**
* @brief queries exactly one peak, with a set range of potential peptides, isotope error and precursor charge Hits are transfered into the a PSM
* @param candidates

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a doxygen keyword to document that this is an "out" parameter

* @param sms
* @param charge
*/
void closedSearch(const MSSpectrum& spectrum, float mz, SpectrumMatchesTopN& sms, uint16_t charge);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function looks a bit redundant to the query peak one? can you clarify a bit in the doc why a separate one is needed? e.g., does the other one call this one?

*/
void openSearch(const MSSpectrum& spectrum, float precursor_mass, SpectrumMatchesTopN& sms, uint16_t charge);

/** @brief 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this does not trim?
is there a reason (e.g., perfomance etc.) why no trimming is performed? if so please document or rename to something with partial sort in its name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does trim, doesn't it? Anyway, I looked again at openSearch and closedSearch and I think it would be best to make one function out of it, instead of two

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was confused because your comment talks about some implementation detail (the partial sort) that suggests that it is indeed not trimmed. If you want to document how this is done I would propose doing it in the cpp file.
A comment that hides this implementation detail could be something like: @brief keeps the top k candidates (according to number of matched fragments)

@@ -150,7 +149,7 @@ namespace OpenMS
/** @brief 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
* Brazenly stolen from sage.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this "stolen" but at the same time more clearly state that the code is inspired and partially directly translated from the rust Sage search engine by Michael R. Lazear.

void updateMembers_() override;

FragmentIndexScorer fragment_index_;
//FragmentIndex fragment_index_;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//FragmentIndex fragment_index_;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: if you want to accept suggestions don't click on "Commit suggestion" but "Add suggestion to batch". Otherwise we will run our CI for every suggested commit.

generate_peptides(fasta_entries);

size_t peptide_idx = 0;
cout << "test2" <<endl;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove test output before we forget ;)

auto debugingStuff = fasta_entries[pep.protein_idx_].sequence;
AASequence unmod_peptide = AASequence::fromString(fasta_entries[pep.protein_idx_].sequence.substr(pep.sequence.first, pep.sequence.second));
vector<AASequence> mod_peptides;
if(!(modifications_fixed_.empty() && modifications_variable_.empty()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!(modifications_fixed_.empty() && modifications_variable_.empty()))
if (!(modifications_fixed_.empty() && modifications_variable_.empty()))

ModifiedPeptideGenerator::applyFixedModifications(fixed_modifications, mod_peptide);
ModifiedPeptideGenerator::applyVariableModifications(variable_modifications, mod_peptide, max_variable_mods_per_peptide_, mod_peptides);
tsg.getSpectrum(b_y_ions, mod_peptides[pep.modification_idx], 1,1);
}else{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}else{
}
else
{


init_hits.hits_.resize(max_processed_hits_);
}
for(auto hit_iter = init_hits.hits_.begin(); hit_iter != init_hits.hits_.end();){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also add space after for and put { into new line. Just some style convention we have ...

{
pair<float, float> precursor_window;
if (open_precursor_window == 0)
precursor_window = make_pair(-precursor_mass * 0.05, precursor_mass * 0.01);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add some documentation


//Search-related params

defaults_.setValue("Min_matched_peaks", 5, "Minimal number of matched ions to report a PSM");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lower case?

defaults_.setValue("min_isotope_error", 0, "Precursor isotope error");
defaults_.setValue("max_isotope_error", 0, "precursor isotope error");
defaults_.setValue("min_precursor_charge", 1, "min precursor charge");
defaults_.setValue("max_precursor_charge", 1, "max precursor charge");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use more common defaults for min / max charge? e.g. see CometAdapter.cpp in OpenMS or defaults of Sage

defaults_.setValue("max_isotope_error", 0, "precursor isotope error");
defaults_.setValue("min_precursor_charge", 1, "min precursor charge");
defaults_.setValue("max_precursor_charge", 1, "max precursor charge");
defaults_.setValue("max_fragment_charge", 1, "max fragment charge");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if max_fragment_charge = 2 does the used charge depend on the actual precursor charge?
I think in general it is not clear if these parameters configure how the fragment index is built, what is related to the query and what is related to the peptide search.

void FragmentIndexScorer::trimHits(OpenMS::FragmentIndexScorer::SpectrumMatchesTopN& init_hits) const
{
buildKMinHeap<SpectrumMatch, uint32_t>(init_hits.hits_, max_processed_hits_, [](SpectrumMatch a) { return a.num_matched_; });
if (max_processed_hits_ < init_hits.hits_.size())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (max_processed_hits_ < init_hits.hits_.size())
if (init_hits.hits_.size() > max_processed_hits_)

for (const sPeptide& pep: fi_peptides_)
{
tsg.getSpectrum(b_y_ions, pep.sequence, 1, 1);
auto debugingStuff = fasta_entries[pep.protein_idx_].sequence;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?

peptide_idx++;
b_y_ions.clear(true);
}
cout << "test3" <<endl;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?

if (max_processed_hits_ < init_hits.hits_.size())
{
std::partial_sort(init_hits.hits_.begin(), init_hits.hits_.begin() + max_processed_hits_, init_hits.hits_.end(), [](SpectrumMatch a, SpectrumMatch b){
return a.num_matched_ > b.num_matched_;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this likely leads to non-deterministic sorting on different platforms in case num_matched peaks are identical.
To make it deterministic one usually includes more fields in the comparison.
e.g., return std::tie(a.num_matched, a.otherfield ..., -1.0 * a.anotherfields ...) > std::tie(b.num_matched, b.otherfield ..., -1.0 * b.anotherfields ...)

for(auto hit_iter = init_hits.hits_.begin(); hit_iter != init_hits.hits_.end();){
if(hit_iter->num_matched_ < min_matched_peaks_)
{
init_hits.hits_.erase(hit_iter);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code can be made much faster!!!

e.g. iterate from rbegin() (note: from the right) until we find the first entry that has hit_iter->num_matched_ >= min_matched_peaks_
and then just do a resize to include this position.
No erasing needed. Every erase needs to relocate all elements after the moved element.

AASequence candidate = fragment_index_.getDB().getPeptides()[sms.peptide_idx_].sequence;

pair<size_t, size_t> candidate_snippet = fragment_index_.getPeptides()[sms.peptide_idx_].sequence;
AASequence candidate = AASequence::fromString(fasta_db[sms.peptide_idx_].sequence.substr(candidate_snippet.first, candidate_snippet.second));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm is this correct if modifications are involved? now this is only the plain peptide right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I´ll fix it.

for (int16_t isotope_error = min_isotope_error_; isotope_error <= max_isotope_error_; isotope_error++)
{
SpectrumMatchesTopN candidates_iso_error;
mz += (float)isotope_error * (float)Constants::NEUTRON_MASS;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks wrong.
You are adding 0, 1, 2 etc to the m/z every time, but m/z is never reset.
Charge is neglected? Or is this uncharged mass? In which case mz is not the best name.
Also NEUTRON_MASS (you meant NEUTRON_MASS_U???) is probably better replaced with C13C12_MASSDIFF_U since isotope m/z's are dominated by carbon.

/**
* @brief: queries one complete experimental spectra against the Database. loops over all precursor charges
* @param spectrum experimental spectrum
* @param sms output

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the Output?

/**
* @brief queries exactly one peak, with a set range of potential peptides, isotope error and precursor charge Hits are transfered into the a PSM
* @param candidates
* @param peak

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Descriptions?

* @brief queries all peaks of a spectrum. loops over all preset isotope errors. The precursor-mass-window is ignored
* @param spectrum experimental query-spectrum
* @param mz
* @param sms

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SMS?

/**@brief queries all peaks of a spectrum. ignores isotope error, applies open window
* @param spectrum
* @param precursor_mass
* @param sms

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SMS?

if(!(modifications_fixed_.empty() && modifications_variable_.empty()))
{
AASequence mod_peptide = AASequence(unmod_peptide); // copy the peptide
ModifiedPeptideGenerator::applyFixedModifications(fixed_modifications, mod_peptide);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: does not support protein terminal mods

tsg_params.setValue("add_z_ions", add_z_ions_);
tsg.setParameters(tsg_params); // TODO: this was missing before!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
auto this_params = getParameters();
tsg_params.setValue("add_a_ions", this_params.getValue("add_a_ions"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be done based on activation method instead.
Note: z-ions are currently wrong

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm good idea but I think one doesn't want to build the fragment index on the a-ions for HCD data. Maybe this part should stay user customizable?

AASequence mod_peptide = AASequence(unmod_peptide); // copy the peptide
ModifiedPeptideGenerator::applyFixedModifications(fixed_modifications, mod_peptide);
ModifiedPeptideGenerator::applyVariableModifications(variable_modifications, mod_peptide, max_variable_mods_per_peptide_, mod_peptides);
tsg.getSpectrum(b_y_ions, mod_peptides[pep.modification_idx], 1,1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: modifications that fragment (e.g. TMT) need to be removed before generating the spectrum!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a fast way to tell if a modification is removed during Fragmentation?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really. I think we could add some special option/extra flag to the search engine to support TMT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this still used?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this datastructure is a bit too specialized to be in the DATASTRUCTURES folder. it is mainly for the 3D FragmentIndex if I understood correctly.
Maybe make it part of the FragmentIndex3D as inner class? I think it has no use outside.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe double check includes. (I did not but maybe it doesn't need #include <OpenMS/DATASTRUCTURES/MultiFragment.h> or QCBase etc.)

digestor.setMissedCleavages(missed_cleavages_);

size_t protein_idx = 0;
// UInt32 protein_idx = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

}
#pragma omp atomic
protein_idx++;
//#pragma omp atomic

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented out code

}
// sort the peptide vector, critical for following steps
sort(fi_peptides_.begin(), fi_peptides_.end(), [](const Peptide& a, const Peptide& b){ return a.precursor_mz < b.precursor_mz; });
sort(fi_peptides_.begin(), fi_peptides_.end(), [](const Peptide& a, const Peptide& b){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sort(fi_peptides_.begin(), fi_peptides_.end(), [](const Peptide& a, const Peptide& b){
sort(fi_peptides_.begin(), fi_peptides_.end(), [](const Peptide& a, const Peptide& b)
{

PeakSpectrum b_y_ions;

/// generate all Peptides
generate_peptides(fasta_entries);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to generatePeptides



/// For each Peptides get all theoretical b and y ions // TODO: include other fragmentation methods
for (const Peptide& pep: fi_peptides_)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can probably also be parallelized using openmp (use SignedSize peptide_index)

{
tsg.getSpectrum(b_y_ions, pep.sequence, 1, 1);
AASequence unmod_peptide = AASequence::fromString(fasta_entries[pep.protein_idx_].sequence.substr(pep.sequence.first, pep.sequence.second));
vector<AASequence> mod_peptides;

@timosachsenberg timosachsenberg Nov 28, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With OpenMP: e.g., declare outside, capture as thread local (private) and only clear(). Prevents frequent reallocations.

{
for (uint16_t fragment_charge = 1; fragment_charge <= max_fragment_charge_; fragment_charge++)
{
for (auto hit : query(peak, candidates_range, fragment_charge))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (init_hits.hits_.size() > max_processed_hits_)
{
std::partial_sort(init_hits.hits_.begin(), init_hits.hits_.begin() + max_processed_hits_, init_hits.hits_.end(), [](const SpectrumMatch& a,const SpectrumMatch& b){
if(a.num_matched_ != b.num_matched_) return a.num_matched_ > b.num_matched_;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(a.num_matched_ != b.num_matched_) return a.num_matched_ > b.num_matched_;
if (a.num_matched_ != b.num_matched_)
{
return a.num_matched_ > b.num_matched_ ;
}

}
for (auto hit_iter = init_hits.hits_.rbegin(); hit_iter != init_hits.hits_.rend(); hit_iter++)
{
if(hit_iter->num_matched_ >= min_matched_peaks_) // search for the first element

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(hit_iter->num_matched_ >= min_matched_peaks_) // search for the first element
if (hit_iter->num_matched_ >= min_matched_peaks_) // search for the first element

int16_t max_isotope_error_applied;
float precursor_window_upper_applied;
float precursor_window_lower_applied;
if(open_search){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(open_search){
if (open_search)
{

for (int16_t isotope_error = min_isotope_error_applied; isotope_error <= max_isotope_error_applied; isotope_error++)
{
SpectrumMatchesTopN candidates_iso_error;
precursor_mass += (float)isotope_error * (float)Constants::C13C12_MASSDIFF_U; // TODO: Potentially still wrong

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
precursor_mass += (float)isotope_error * (float)Constants::C13C12_MASSDIFF_U; // TODO: Potentially still wrong
precursor_mass += (float)isotope_error * (float)Constants::C13C12_MASSDIFF_U; // TODO: Potentially still wrong

fi_peptides_.push_back({modified_peptide, protein_idx, modified_mz});
}
{
fi_peptides_.push_back({static_cast<UInt32>(i),

@jpfeuffer jpfeuffer Nov 29, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would emplace back make sense here for in place construction?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.
@Trapho see
push_back vs. emplace_back
https://quick-bench.com/q/TzNTiv1qc6J8qaAwDdzWnnANl1Q

But this speed advantage only materializes if the most important optimization is done: reserving enough memory such that no reallocations happen .reserve()
https://quick-bench.com/q/Jx19hclilK1VUZz67bX8-eoPg3Q

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool benchmark but I think you just need to increase the number of items a bit to show the benefit with emplace_back (even without reserving).
Instead I would actually propose to benchmark the reserving strategy (if inside a loop) which could be worse than the STLs default ;)

@Trapho Trapho Nov 29, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timosachsenberg For fi_peptides_.reserve() something like the (size of the fasta_enties) * (average number of cleavage sites) ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a sensible choice. Will already prevent many reallocations. Hard to really estimate the exact numbers of unique peptides if also missed cleavages are allowed etc.


#pragma omp critical(FIIndex)
{
fi_peptides_.push_back({static_cast<UInt32>(i), unmodified_mz});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emplace back?
You may need to implement a constructor for this.

@@ -119,68 +116,92 @@ namespace OpenMS
continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check could be done in ModPepGen at some point. Especially if only positive mods are considered you can stop quite early or discard the peptide from the beginning.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if you merge #6859 you will not need to recalculate redundant masses for peptides with the same amount of modifications again.

Mass thresholds could be included in that PR.

       - Replaced all push_back with emplace_back and added reserves
       - build now parallelized; - added tests
precursor_mz_(precursor_mz)
{}

UInt32 protein_idx_; ///< The index in fasta entries vector

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: underscore at the end means: private variable. here it is public

struct SpectrumMatch
{
uint32_t num_matched_{}; ///< Number of peaks-fragment hits
uint32_t num_matched_{}; ///< Number of peaks-fragment hits

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

samre here... no underscore

mod_peptide = mod_peptides[pep.modification_idx_];
tsg.getSpectrum(b_y_ions, mod_peptide, charge, charge);
prec_theo.setMZ(mod_peptide.getMZ(charge));
spec_theo.setMSLevel(2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

precursor charge not set here? not important?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to test the scenario, in which the precursor charge is not known. In this case all different precursor charges are tested during the query (from min_precursor_charge to max_precursor_charge_).

@timosachsenberg
timosachsenberg merged commit e29a8ab into OpenMS:feature/fi_search_engine Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants