Skip to content

Commit

Permalink
add option to filter spectra by peptide (OpenMS#7021)
Browse files Browse the repository at this point in the history
* add option to filter spectra by peptide

* Update src/topp/IDFilter.cpp
  • Loading branch information
timosachsenberg authored Aug 18, 2023
1 parent 6e2ab75 commit 2ac52ad
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/topp/IDFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ class TOPPIDFilter :
setMinInt_("best:n_spectra", 0);
registerIntOption_("best:n_peptide_hits", "<integer>", 0, "Keep only the 'n' highest scoring peptide hits per spectrum (for n > 0).", false);
setMinInt_("best:n_peptide_hits", 0);
registerStringOption_("best:spectrum_per_peptide", "<String>", "false", "Keep one spectrum per peptide. Value determines if same sequence but different charges or modifications are treated as separate peptides or the same peptide. (default: false = filter disabled).", false);
setValidStrings_("best:spectrum_per_peptide", {"false", "sequence", "sequence+charge", "sequence+modification", "sequence+charge+modification"});
registerIntOption_("best:n_protein_hits", "<integer>", 0, "Keep only the 'n' highest scoring protein hits (for n > 0).", false);
setMinInt_("best:n_protein_hits", 0);
registerFlag_("best:strict", "Keep only the highest scoring peptide hit.\n"
Expand Down Expand Up @@ -607,6 +609,25 @@ class TOPPIDFilter :
IDFilter::keepNBestHits(peptides, best_n_pep);
}

String spectrum_per_peptide = getStringOption_("best:spectrum_per_peptide");
if (spectrum_per_peptide != "false")
{
OPENMS_LOG_INFO << "Keeping best spectrum per " << spectrum_per_peptide << endl;
if (spectrum_per_peptide == "sequence") // group by sequence and return best spectrum (->smallest number of spectra)
{
IDFilter::keepBestPerPeptide(peptides, true, true, 1);
} else if (spectrum_per_peptide == "sequence+modification")
{
IDFilter::keepBestPerPeptide(peptides, false, true, 1);
} else if (spectrum_per_peptide == "sequence+charge")
{
IDFilter::keepBestPerPeptide(peptides, true, false, 1);
} else if (spectrum_per_peptide == "sequence+charge+modification") // group by sequence, modificationm, charge combination and return best spectrum (->largest number of spectra)
{
IDFilter::keepBestPerPeptide(peptides, false, false, 1);
}
}

Int min_rank = 0, max_rank = 0;
if (parseRange_(getStringOption_("best:n_to_m_peptide_hits"), min_rank,
max_rank))
Expand Down

0 comments on commit 2ac52ad

Please sign in to comment.