IDFilter#

class pyopenms.IDFilter#

Bases: object

Finds the best-scoring hit in a vector of peptide or protein identifications

This class provides functions for filtering collections of peptide or protein identifications according to various criteria. It also contains helper functions and classes (functors that implement predicates) that are used in this context.

The filter functions modify their inputs, rather than creating filtered copies.

Most filters work on the hit level, i.e. they remove peptide or protein hits from peptide or protein identifications (IDs). A few filters work on the ID level instead, i.e. they remove peptide or protein IDs from vectors thereof. Independent of this, the inputs for all filter functions are vectors of IDs, because the data most often comes in this form. This design also allows many helper objects to be set up only once per vector, rather than once per ID.

The filter functions for vectors of peptide/protein IDs do not include clean-up steps (e.g. removal of IDs without hits, reassignment of hit ranks, …). They only carry out their specific filtering operations. This is so filters can be chained without having to repeat clean-up operations. The group of clean-up functions provides helpers that are useful to ensure data integrity after filters have been applied, but it is up to the individual developer to use them when necessary.

The filter functions for MS/MS experiments do include clean-up steps, because they filter peptide and protein IDs in conjunction and potential contradictions between the two must be eliminated.

__init__() → None#
__init__(arg: pyopenms.IDFilter, /) → None

Methods

__init__()

countHits(ids)

Counts the number of peptide hits in the given identifications

extractPeptideSequences(peptides, ignore_mods)

Extracts all unique peptide sequences from a list of peptide IDs

filterHitsByRank(ids, min_rank, max_rank)

Filters peptide or protein identifications according to the ranking of the hits

filterHitsByScore(annotated_data, ...)

Overloaded function.

filterPeptidesByCharge(peptides, min_charge, ...)

Filters peptide identifications according to charge state

filterPeptidesByLength(peptides, min_length, ...)

Filters peptide identifications according to peptide sequence length

filterPeptidesByMZ(peptides, min_mz, max_mz)

Filters peptide identifications by precursor m/z, keeping only IDs in the given range

filterPeptidesByMZError(peptides, ...)

Filter peptide identifications according to mass deviation

filterPeptidesByRT(peptides, min_rt, max_rt)

Filters peptide identifications by precursor RT, keeping only IDs in the given range

filterPeptidesByRTPredictPValue(peptides, ...)

Filters peptide identifications according to p-values from RTPredict

getBestHit(ids, assume_sorted, best_hit)

Finds the best-scoring hit in a vector of peptide or protein identifications

keepBestPeptideHits(peptides, strict)

Filters peptide identifications keeping only the single best-scoring hit per ID

keepBestPerPeptide(pep_ids, ignore_mods, ...)

Filters PeptideHits from PeptideIdentification by keeping only the best peptide hits for every peptide sequence

keepBestPerPeptidePerRun(prot_ids, pep_ids, ...)

Filters PeptideHits from PeptideIdentification by keeping only the best peptide hits for every peptide sequence on a per run basis

keepHitsMatchingProteins(ids, accessions)

Filters peptide or protein identifications according to the given proteins (positive)

keepNBestHits(pep_ids, n)

Overloaded function.

keepNBestSpectra(peptides, n)

Filter identifications by "N best" PeptideIdentification objects (better PeptideIdentification means better [best] PeptideHit than other)

keepPeptidesWithMatchingModifications(...)

Keeps only peptide hits that have at least one of the given modifications

keepPeptidesWithMatchingSequences(peptides, ...)

Removes all peptide hits with a sequence that does not match one in 'good_peptides'

keepUniquePeptidesPerProtein(peptides)

Removes all peptides that are not annotated as unique for a protein (by PeptideIndexer)

removeDanglingProteinReferences(peptides, ...)

Overloaded function.

removeDecoyHits(ids)

Removes hits annotated as decoys from peptide or protein identifications.

removeDuplicatePeptideHits(peptides[, seq_only])

Removes duplicate peptide hits from each peptide identification, keeping only unique hits (per ID)

removeEmptyIdentifications(ids)

Removes peptide or protein identifications that have no hits in them

removeHitsMatchingProteins(ids, accessions)

Filters peptide or protein identifications according to the given proteins (negative)

removePeptidesWithMatchingModifications(...)

Removes all peptide hits that have at least one of the given modifications

removePeptidesWithMatchingSequences(...)

Removes all peptide hits with a sequence that matches one in 'bad_peptides'

removeUnreferencedProteins(cmap, ...)

Removes protein hits from the protein IDs in a 'cmap' that are not referenced by a peptide in the features or if requested in the unassigned peptide list

updateProteinGroups(groups, hits)

Update protein groups after protein hits were filtered

updateProteinReferences(peptides, proteins)

Deprecated alias of removeDanglingProteinReferences, the pyOpenMS 3.5 name

static countHits(ids: pyopenms.PeptideIdentificationList) → int#

Counts the number of peptide hits in the given identifications

static extractPeptideSequences(peptides: pyopenms.PeptideIdentificationList, ignore_mods: bool) → set[str]#

Extracts all unique peptide sequences from a list of peptide IDs

Parameters:
  • peptides

  • ignore_mods – Boolean operator default to false in case of any modifications in sequences during extraction

Returns:

Sequences

static filterHitsByRank(ids: pyopenms.PeptideIdentificationList, min_rank: int, max_rank: int) → None#

Filters peptide or protein identifications according to the ranking of the hits

The hits between ‘min_rank’ and ‘max_rank’ (both inclusive) in each ID are kept Counting starts at 1, i.e. the best (highest/lowest scoring) hit has rank 1 The ranks are (re-)computed before filtering ‘max_rank’ is ignored if it is smaller than ‘min_rank’

Note: There may be several hits with the same rank in a peptide or protein ID (if the scores are the same). This method is useful if a range of higher hits is needed for decoy fairness analysis

static filterHitsByScore(annotated_data: pyopenms.AnnotatedMSRun, peptide_threshold_score: float, protein_threshold_score: float) → None#
static filterHitsByScore(ids: pyopenms.PeptideIdentificationList, threshold_score: float) → None
static filterHitsByScore(ids: collections.abc.Sequence[pyopenms.ProteinIdentification], threshold_score: float) → list[pyopenms.ProteinIdentification]

Overloaded function.

  1. filterHitsByScore(annotated_data: pyopenms.AnnotatedMSRun, peptide_threshold_score: float, protein_threshold_score: float) -> None

Filters an MS/MS experiment according to score thresholds

  1. filterHitsByScore(ids: pyopenms.PeptideIdentificationList, threshold_score: float) -> None

Filters peptide or protein identifications according to the score of the hits. The score orientation has to be set to higherscorebetter in each PeptideIdentification. Only peptide/protein hits with a score at least as good as ‘threshold_score’ are kept

  1. filterHitsByScore(ids: collections.abc.Sequence[pyopenms.ProteinIdentification], threshold_score: float) -> list[pyopenms.ProteinIdentification]

Filters protein hits by score, keeping hits at least as good as the threshold, and returns the filtered list

In/out compatibility (pyOpenMS 3.5 behaviour): a Python list passed as ids is also updated in place with the returned contents.

static filterPeptidesByCharge(peptides: pyopenms.PeptideIdentificationList, min_charge: int, max_charge: int) → None#

Filters peptide identifications according to charge state

static filterPeptidesByLength(peptides: pyopenms.PeptideIdentificationList, min_length: int, max_length: int) → None#

Filters peptide identifications according to peptide sequence length

static filterPeptidesByMZ(peptides: pyopenms.PeptideIdentificationList, min_mz: float, max_mz: float) → None#

Filters peptide identifications by precursor m/z, keeping only IDs in the given range

static filterPeptidesByMZError(peptides: pyopenms.PeptideIdentificationList, mass_error: float, unit_ppm: bool) → None#

Filter peptide identifications according to mass deviation

static filterPeptidesByRT(peptides: pyopenms.PeptideIdentificationList, min_rt: float, max_rt: float) → None#

Filters peptide identifications by precursor RT, keeping only IDs in the given range

static filterPeptidesByRTPredictPValue(peptides: pyopenms.PeptideIdentificationList, metavalue_key: str, threshold: float) → None#

Filters peptide identifications according to p-values from RTPredict

Filters the peptide hits by the probability (p-value) of a correct peptide identification having a deviation between observed and predicted RT equal to or greater than allowed

Parameters:
  • peptides – Input/output

  • metavalue_key – Name of the meta value that holds the p-value: “predicted_RT_p_value” or “predicted_RT_p_value_first_dim”

  • threshold – P-value threshold

static getBestHit(ids: pyopenms.PeptideIdentificationList, assume_sorted: bool, best_hit: pyopenms.PeptideHit) → bool#

Finds the best-scoring hit in a vector of peptide or protein identifications

If there are several hits with the best score, the first one is taken

Parameters:
  • ids – Vector of peptide or protein IDs, each containing one or more (peptide/protein) hits

  • assume_sorted – Are hits sorted by score (best score first) already? This allows for faster query, since only the first hit needs to be looked at

  • best_hit – Contains the best hit if successful in a vector of peptide identifications

Returns:

true if a hit was present, false otherwise

static keepBestPeptideHits(peptides: pyopenms.PeptideIdentificationList, strict: bool) → None#

Filters peptide identifications keeping only the single best-scoring hit per ID

Parameters:
  • peptides – Input/output

  • strict – If set, keep the best hit only if its score is unique - i.e. ties are not allowed. (Otherwise all hits with the best score is kept.)

static keepBestPerPeptide(pep_ids: pyopenms.PeptideIdentificationList, ignore_mods: bool, ignore_charges: bool, nr_best_spectrum: int) → None#

Filters PeptideHits from PeptideIdentification by keeping only the best peptide hits for every peptide sequence

static keepBestPerPeptidePerRun(prot_ids: collections.abc.Sequence[pyopenms.ProteinIdentification], pep_ids: pyopenms.PeptideIdentificationList, ignore_mods: bool, ignore_charges: bool, nr_best_spectrum: int) → list[pyopenms.ProteinIdentification]#

Filters PeptideHits from PeptideIdentification by keeping only the best peptide hits for every peptide sequence on a per run basis

static keepHitsMatchingProteins(ids: pyopenms.PeptideIdentificationList, accessions: set[str]) → None#

Filters peptide or protein identifications according to the given proteins (positive)

static keepNBestHits(pep_ids: pyopenms.PeptideIdentificationList, n: int) → None#
static keepNBestHits(annotated_data: pyopenms.AnnotatedMSRun, n: int) → None

Overloaded function.

  1. keepNBestHits(pep_ids: pyopenms.PeptideIdentificationList, n: int) -> None

  2. keepNBestHits(annotated_data: pyopenms.AnnotatedMSRun, n: int) -> None

Filters an MS/MS experiment by keeping the N best peptide hits for every spectrum

static keepNBestSpectra(peptides: pyopenms.PeptideIdentificationList, n: int) → None#

Filter identifications by “N best” PeptideIdentification objects (better PeptideIdentification means better [best] PeptideHit than other)

static keepPeptidesWithMatchingModifications(peptides: pyopenms.PeptideIdentificationList, modifications: set[str]) → None#

Keeps only peptide hits that have at least one of the given modifications

static keepPeptidesWithMatchingSequences(peptides: pyopenms.PeptideIdentificationList, good_peptides: pyopenms.PeptideIdentificationList, ignore_mods: bool) → None#

Removes all peptide hits with a sequence that does not match one in ‘good_peptides’

static keepUniquePeptidesPerProtein(peptides: pyopenms.PeptideIdentificationList) → None#

Removes all peptides that are not annotated as unique for a protein (by PeptideIndexer)

static removeDanglingProteinReferences(peptides: pyopenms.PeptideIdentificationList, proteins: collections.abc.Sequence[pyopenms.ProteinIdentification], remove_peptides_without_reference: bool) → None#
static removeDanglingProteinReferences(cmap: pyopenms.ConsensusMap, remove_peptides_without_reference: bool) → None
static removeDanglingProteinReferences(cmap: pyopenms.ConsensusMap, ref_run: pyopenms.ProteinIdentification, remove_peptides_without_reference: bool) → None

Overloaded function.

  1. removeDanglingProteinReferences(peptides: pyopenms.PeptideIdentificationList, proteins: collections.abc.Sequence[pyopenms.ProteinIdentification], remove_peptides_without_reference: bool) -> None

Removes dangling protein references from peptide hits

Cleans up PeptideEvidence entries by removing references to proteins that no longer exist in the provided protein identifications. This is typically called after filtering protein hits to maintain consistency between peptide-to-protein mappings.

Parameters:
  • peptides – The peptide identifications to process (in/out)

  • proteins – The protein identifications containing valid protein hits (in)

  • remove_peptides_without_reference – If true, peptide hits that have no remaining protein references after cleanup are also removed (default: false) (in)

  1. removeDanglingProteinReferences(cmap: pyopenms.ConsensusMap, remove_peptides_without_reference: bool) -> None

Removes dangling protein references from peptide hits in a ConsensusMap

Cleans up PeptideEvidence entries by removing references to proteins that no longer exist in the ConsensusMap’s protein identifications. This is typically called after filtering protein hits to maintain consistency between peptide-to-protein mappings.

Parameters:
  • cmap – The ConsensusMap containing peptide and protein identifications (modified in place)

  • remove_peptides_without_reference – If true, peptide hits that have no remaining protein references after cleanup are also removed

  1. removeDanglingProteinReferences(cmap: pyopenms.ConsensusMap, ref_run: pyopenms.ProteinIdentification, remove_peptides_without_reference: bool) -> None

Removes dangling protein references from peptide hits using a reference protein run

Cleans up PeptideEvidence entries by removing references to proteins that do not exist in the specified reference protein run.

Parameters:
  • cmap – The ConsensusMap containing peptide identifications to process (modified in place)

  • ref_run – The reference ProteinIdentification containing valid protein hits

  • remove_peptides_without_reference – If true, peptide hits that have no remaining protein references after cleanup are also removed

static removeDecoyHits(ids: pyopenms.PeptideIdentificationList) → None#

Removes hits annotated as decoys from peptide or protein identifications. Checks for meta values named “target_decoy” and “isDecoy”, and removes protein/peptide hits if the values are “decoy” and “true”, respectively

static removeDuplicatePeptideHits(peptides: pyopenms.PeptideIdentificationList, seq_only: bool = False) → None#

Removes duplicate peptide hits from each peptide identification, keeping only unique hits (per ID)

static removeEmptyIdentifications(ids: pyopenms.PeptideIdentificationList) → None#

Removes peptide or protein identifications that have no hits in them

static removeHitsMatchingProteins(ids: pyopenms.PeptideIdentificationList, accessions: set[str]) → None#

Filters peptide or protein identifications according to the given proteins (negative)

static removePeptidesWithMatchingModifications(peptides: pyopenms.PeptideIdentificationList, modifications: set[str]) → None#

Removes all peptide hits that have at least one of the given modifications

static removePeptidesWithMatchingSequences(peptides: pyopenms.PeptideIdentificationList, bad_peptides: pyopenms.PeptideIdentificationList, ignore_mods: bool) → None#

Removes all peptide hits with a sequence that matches one in ‘bad_peptides’

static removeUnreferencedProteins(cmap: pyopenms.ConsensusMap, include_unassigned: bool) → None#
static removeUnreferencedProteins(proteins: collections.abc.Sequence[pyopenms.ProteinIdentification], peptides: pyopenms.PeptideIdentificationList) → list[pyopenms.ProteinIdentification]
static removeUnreferencedProteins(proteins: pyopenms.ProteinIdentification, peptides: pyopenms.PeptideIdentificationList) → None
static removeUnreferencedProteins(proteins: collections.abc.Sequence[pyopenms.ProteinIdentification], ids: pyopenms.PeptideIdentificationList) → list[pyopenms.ProteinIdentification]

Removes protein hits from the protein IDs in a ‘cmap’ that are not referenced by a peptide in the features or if requested in the unassigned peptide list

In/out compatibility (pyOpenMS 3.5 behaviour): a Python list passed as proteins is also updated in place with the returned contents.

static updateProteinGroups(groups: collections.abc.Sequence[pyopenms.ProteinGroup], hits: collections.abc.Sequence[pyopenms.ProteinHit]) → tuple#

Update protein groups after protein hits were filtered

Parameters:
  • groups – Input/output protein groups

  • hits – Available protein hits (all others are removed from the groups)

Returns:

Returns whether the groups are still valid (which is the case if only whole groups, if any, were removed)

In/out compatibility (pyOpenMS 3.5 behaviour): a Python list passed as groups is also updated in place with the returned contents.

static updateProteinReferences(peptides: pyopenms.PeptideIdentificationList, proteins: collections.abc.Sequence[pyopenms.ProteinIdentification], remove_peptides_without_reference: bool = False) → None#

Deprecated alias of removeDanglingProteinReferences, the pyOpenMS 3.5 name