matchms.similarity.PrecursorMzMatch module
- class matchms.similarity.PrecursorMzMatch.PrecursorMzMatch(tolerance: float = 0.1, tolerance_type: str = 'Dalton')[source]
Bases:
MetadataMatchReturn True if spectra match in precursor m/z, and False otherwise.
The match within tolerance can be calculated based on an absolute m/z difference (
tolerance_type="Dalton") or based on a relative difference in ppm (tolerance_type="ppm").- __init__(tolerance: float = 0.1, tolerance_type: str = 'Dalton')[source]
- Parameters:
tolerance – Specify tolerance below which two precursor m/z values are counted as match.
tolerance_type – Choose between fixed tolerance in Dalton (
"Dalton") or a relative difference in ppm ("ppm").
- keep_score(score) bool
Return whether a score should be retained in sparse outputs.
This defines the default sparse retention behavior. Users can override it per call via
score_filter=....Default behavior: - scalar score: keep if
score != 0- structured score: keep if all fields are non-zero
- matrix(spectra_1: Sequence[Spectrum], spectra_2: Sequence[Spectrum] | None = None, score_fields: Sequence[str] | None = None, progress_bar: bool = True) Scores
Compare metadata entries between all spectra in spectra_1 and spectra_2.
- Parameters:
spectra_1 – First collection of input spectra.
spectra_2 – Second collection of input spectra. If None, compare spectra_1 against itself.
score_fields – Requested score fields. Only
("score",)is supported.progress_bar – Included for API compatibility. Not used here because this optimized implementation does not iterate pairwise in Python.
- pair(spectrum_1: Spectrum, spectrum_2: Spectrum)
Compare metadata entries between two spectra.
- Parameters:
spectrum_1 – First spectrum.
spectrum_2 – Second spectrum.
- sparse_matrix(spectra_1: Sequence[Spectrum], spectra_2: Sequence[Spectrum] | None = None, idx_row=None, idx_col=None, score_fields: Sequence[str] | None = None, score_filter: Callable[[ndarray], bool] | None = None, progress_bar: bool = True) Scores
Compare metadata entries and return sparse scores.
This method uses optimized metadata matching when no explicit indices are provided. If explicit idx_row and idx_col are given, it falls back to the generic sparse implementation from BaseSimilarityWithSparse.