matchms.similarity.spectrum_similarity_functions module¶
- matchms.similarity.spectrum_similarity_functions.collect_peak_pairs(spec1: ndarray, spec2: ndarray, tolerance: float, shift: float = 0, mz_power: float = 0.0, intensity_power: float = 1.0)[source]¶
Find matching pairs between two spectra.
- Parameters:
spec1 – Spectrum peaks and intensities as numpy array.
spec2 – Spectrum peaks and intensities as numpy array.
tolerance – Peaks will be considered a match when <= tolerance appart.
shift – Shift spectra peaks by shift. The default is 0.
mz_power – The power to raise mz to in the cosine function. The default is 0, in which case the peak intensity products will not depend on the m/z ratios.
intensity_power – The power to raise intensity to in the cosine function. The default is 1.
- Returns:
matching_pairs – Array of found matching peaks.
- Return type:
numpy array
- matchms.similarity.spectrum_similarity_functions.find_matches(spec1_mz: ndarray, spec2_mz: ndarray, tolerance: float, shift: float = 0) List[Tuple[int, int]] [source]¶
Faster search for matching peaks. Makes use of the fact that spec1 and spec2 contain ordered peak m/z (from low to high m/z).
- Parameters:
spec1_mz – Spectrum peak m/z values as numpy array. Peak mz values must be ordered.
spec2_mz – Spectrum peak m/z values as numpy array. Peak mz values must be ordered.
tolerance – Peaks will be considered a match when <= tolerance appart.
shift – Shift peaks of second spectra by shift. The default is 0.
- Returns:
List containing entries of type (idx1, idx2).
- Return type:
matches
- matchms.similarity.spectrum_similarity_functions.number_matching(numbers_1, numbers_2, tolerance)[source]¶
Find all pairs between numbers_1 and numbers_2 which are within tolerance.
- matchms.similarity.spectrum_similarity_functions.number_matching_ppm(numbers_1, numbers_2, tolerance_ppm)[source]¶
Find all pairs between numbers_1 and numbers_2 which are within tolerance.
- matchms.similarity.spectrum_similarity_functions.number_matching_symmetric(numbers_1, tolerance)[source]¶
Find all pairs between numbers_1 and numbers_1 which are within tolerance.
- matchms.similarity.spectrum_similarity_functions.number_matching_symmetric_ppm(numbers_1, tolerance_ppm)[source]¶
Find all pairs between numbers_1 and numbers_1 which are within tolerance.
- matchms.similarity.spectrum_similarity_functions.score_best_matches(matching_pairs: ndarray, spec1: ndarray, spec2: ndarray, mz_power: float = 0.0, intensity_power: float = 1.0) Tuple[float, int] [source]¶
Calculate cosine-like score by multiplying matches. Does require a sorted list of matching peaks (sorted by intensity product).